LCOV - code coverage report
Current view: top level - oksconflibs/src - OksConfigObject.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 20.8 % 515 107
Test Date: 2025-12-21 13:07:08 Functions: 21.3 % 122 26

            Line data    Source code
       1              : #include "ers/ers.hpp"
       2              : 
       3              : #include "oks/file.hpp"
       4              : #include "oks/relationship.hpp"
       5              : 
       6              : #include "conffwk/ConfigObject.hpp"
       7              : 
       8              : #include "oksconflibs/OksConfigObject.hpp"
       9              : #include "oksconflibs/OksConfiguration.hpp"
      10              : 
      11              : #include "logging/Logging.hpp"
      12              : 
      13              : using namespace dunedaq;
      14              : using namespace dunedaq::oks;
      15              : using namespace dunedaq::oksconflibs;
      16              : 
      17              : static std::string
      18            0 : mk_error_text(const char *op, const char * what, const std::string& name, const OksObject * o, const char * error)
      19              : {
      20            0 :   std::ostringstream text;
      21            0 :   text << "failed to " << op << ' ' << what << " \"" << name << "\" of object " << o;
      22            0 :   if (error)
      23            0 :     text << ": " << error;
      24            0 :   return text.str();
      25            0 : }
      26              : 
      27              : static std::string
      28            0 : mk_get_error_text(const char * what, const std::string& name, const OksObject * o, const char * error = nullptr)
      29              : {
      30            0 :   return mk_error_text("read", what, name, o, error);
      31              : }
      32              : 
      33              : static std::string
      34            0 : mk_set_error_text(const char * what, const std::string& name, const OksObject * o, const char * error = nullptr)
      35              : {
      36            0 :   return mk_error_text("set value", what, name, o, error);
      37              : }
      38              : 
      39              : 
      40              : OksData::Type
      41            0 : OksConfigObject::get_type(const std::string& name) const
      42              : {
      43            0 :   try
      44              :     {
      45            0 :       return m_obj->GetAttributeValue(name)->type;
      46              :     }
      47            0 :   catch (oks::exception& ex)
      48              :     {
      49            0 :       throw dunedaq::conffwk::Generic(ERS_HERE, mk_get_error_text("attribute", name, m_obj).c_str(), ex);
      50            0 :     }
      51              : }
      52              : 
      53              : // helper function to extract value out of OKS database
      54              : template<class T>
      55              :   void
      56         1387 :   OksConfigObject::get_value(const std::string& name, T& value)
      57              :   {
      58         1387 :     std::lock_guard<std::mutex> scoped_lock(m_mutex);
      59              : 
      60              :     try
      61              :       {
      62         1387 :         throw_if_deleted();
      63         1387 :         OksData * data(m_obj->GetAttributeValue(name));
      64         1387 :         value = *reinterpret_cast<T*>(&data->data); // really ugly stuff here, but should come out right
      65              :       }
      66            0 :     catch (oks::exception& ex)
      67              :       {
      68            0 :         throw dunedaq::conffwk::Generic(ERS_HERE, mk_get_error_text("attribute", name, m_obj).c_str(), ex);
      69              :       }
      70         1387 :   }
      71              : 
      72              : 
      73              : // helper function to extract vector of values out of OKS database
      74              : template<class T>
      75              :   void
      76            0 :   OksConfigObject::get_vector(const std::string& name, std::vector<T>& value)
      77              :   {
      78            0 :     OksData * data = 0;
      79              : 
      80            0 :     std::lock_guard<std::mutex> scoped_lock(m_mutex);
      81              : 
      82              :     try
      83              :       {
      84            0 :         throw_if_deleted();
      85            0 :         data = m_obj->GetAttributeValue(name);
      86              :       }
      87            0 :     catch (oks::exception& ex)
      88              :       {
      89            0 :         throw dunedaq::conffwk::Generic( ERS_HERE, mk_get_error_text("attribute", name, m_obj).c_str(), ex);
      90              :       }
      91              : 
      92            0 :     if (data->type != OksData::list_type)
      93              :       {
      94            0 :         std::ostringstream text;
      95            0 :         text << "attribute \"" << name << "\" of object " << m_obj << " is not of a multi-value";
      96            0 :         throw dunedaq::conffwk::Generic( ERS_HERE, text.str().c_str() );
      97            0 :       }
      98              : 
      99            0 :     value.clear();
     100            0 :     for (const auto& it : *data->data.LIST)
     101              :       {
     102            0 :         value.push_back(*reinterpret_cast<T*>(&it->data));
     103              :       }
     104            0 :   }
     105              : 
     106              : 
     107         1145 : OksConfigObject::OksConfigObject(OksObject *obj, dunedaq::conffwk::ConfigurationImpl * impl) noexcept :
     108              :   ConfigObjectImpl (impl, obj->GetId()),
     109         1145 :   m_obj            (obj)
     110              : {
     111         1145 : }
     112              : 
     113         2290 : OksConfigObject::~OksConfigObject() noexcept
     114              : {
     115         2290 : }
     116              : 
     117              : const std::string
     118            0 : OksConfigObject::contained_in() const
     119              : {
     120            0 :   std::lock_guard<std::mutex> scoped_lock(m_mutex);
     121            0 :   throw_if_deleted();
     122            0 :   return m_obj->get_file()->get_full_file_name();
     123            0 : }
     124              : 
     125              : void
     126           70 : OksConfigObject::get(const std::string& name, bool& value)
     127              : {
     128           70 :   get_value(name, value);
     129           70 : }
     130              : 
     131              : void
     132            5 : OksConfigObject::get(const std::string& name, uint8_t& value)
     133              : {
     134            5 :   get_value(name, value);
     135            5 : }
     136              : 
     137              : void
     138            0 : OksConfigObject::get(const std::string& name, int8_t& value)
     139              : {
     140            0 :   get_value(name, value);
     141            0 : }
     142              : 
     143              : void
     144           37 : OksConfigObject::get(const std::string& name, uint16_t& value)
     145              : {
     146           37 :   get_value(name, value);
     147           37 : }
     148              : 
     149              : void
     150            0 : OksConfigObject::get(const std::string& name, int16_t& value)
     151              : {
     152            0 :   get_value(name, value);
     153            0 : }
     154              : 
     155              : void
     156         1206 : OksConfigObject::get(const std::string& name, uint32_t& value)
     157              : {
     158         1206 :   get_value(name, value);
     159         1206 : }
     160              : 
     161              : void
     162           64 : OksConfigObject::get(const std::string& name, int32_t& value)
     163              : {
     164           64 :   get_value(name, value);
     165           64 : }
     166              : 
     167              : void
     168            5 : OksConfigObject::get(const std::string& name, uint64_t& value)
     169              : {
     170            5 :   get_value(name, value);
     171            5 : }
     172              : 
     173              : void
     174            0 : OksConfigObject::get(const std::string& name, int64_t& value)
     175              : {
     176            0 :   get_value(name, value);
     177            0 : }
     178              : 
     179              : void
     180            0 : OksConfigObject::get(const std::string& name, float& value)
     181              : {
     182            0 :   get_value(name, value);
     183            0 : }
     184              : 
     185              : void
     186            0 : OksConfigObject::get(const std::string& name, double& value)
     187              : {
     188            0 :   get_value(name, value);
     189            0 : }
     190              : 
     191              : void
     192         1041 : OksConfigObject::get(const std::string& name, std::string& value)
     193              : {
     194         1041 :   OksData * data = 0;
     195              : 
     196         1041 :   std::lock_guard<std::mutex> scoped_lock(m_mutex);
     197              : 
     198         1041 :   try
     199              :     {
     200         1041 :       throw_if_deleted();
     201         1041 :       data = m_obj->GetAttributeValue(name);
     202              :     }
     203            0 :   catch (oks::exception& ex)
     204              :     {
     205            0 :       throw dunedaq::conffwk::Generic( ERS_HERE, mk_get_error_text("attribute", name, m_obj).c_str(), ex);
     206            0 :     }
     207              : 
     208         1041 :   if ((data->type == OksData::string_type) || (data->type == OksData::enum_type))
     209              :     {
     210         1041 :       value = *data->data.STRING;
     211              :       return;
     212              :     }
     213            0 :   else if (data->type == OksData::date_type || data->type == OksData::time_type)
     214              :     {
     215            0 :       value = data->str();
     216            0 :       return;
     217              :     }
     218            0 :   else if (data->type == OksData::class_type)
     219              :     {
     220            0 :       value = data->data.CLASS->get_name();
     221              :       return;
     222              :     }
     223              :   else
     224              :     {
     225            0 :       std::ostringstream text;
     226            0 :       text << "read wrong attribute type instead of expected \'string\' for attribute \"" << name << "\" of object " << m_obj;
     227            0 :       throw dunedaq::conffwk::Generic( ERS_HERE, text.str().c_str() );
     228            0 :     }
     229         1041 : }
     230              : 
     231              : void
     232          629 : OksConfigObject::get(const std::string& name, dunedaq::conffwk::ConfigObject& value)
     233              : {
     234          629 :   OksData * data = 0;
     235              : 
     236          629 :   std::lock_guard<std::mutex> scoped_lock(m_mutex);
     237              : 
     238          629 :   try
     239              :     {
     240          629 :       throw_if_deleted();
     241          629 :       data = m_obj->GetRelationshipValue(name);
     242              :     }
     243            0 :   catch (oks::exception& ex)
     244              :     {
     245            0 :       throw dunedaq::conffwk::Generic(ERS_HERE, mk_get_error_text("relationship", name, m_obj).c_str(), ex);
     246            0 :     }
     247              : 
     248          629 :   if (data->type != OksData::object_type)
     249              :     {
     250            0 :       if (data->type == OksData::uid_type || data->type == OksData::uid2_type)
     251              :         {
     252            0 :           std::ostringstream text;
     253            0 :           text << "referenced object " << *data << " is not loaded";
     254            0 :           throw dunedaq::conffwk::Generic(ERS_HERE, mk_get_error_text("relationship", name, m_obj, text.str().c_str()).c_str());
     255            0 :         }
     256              : 
     257            0 :       std::ostringstream text;
     258            0 :       text << "bad value of relationship \"" << name << "\" of object " << m_obj << ": ";
     259              : 
     260            0 :       if(data->type == OksData::list_type)
     261              :         {
     262            0 :           text << "the relationship is multi-value";
     263              :         }
     264              :       else
     265              :         {
     266            0 :           text << "non-object type was read";
     267              :         }
     268            0 :       throw dunedaq::conffwk::Generic(ERS_HERE, text.str().c_str());
     269            0 :     }
     270              : 
     271          629 :   if (data->data.OBJECT != nullptr)
     272              :     {
     273          524 :       value = static_cast<OksConfiguration *>(m_impl)->new_object(data->data.OBJECT);
     274              :     }
     275              :   else
     276              :     {
     277          105 :       value = nullptr;
     278              :     }
     279          629 : }
     280              : 
     281              : void
     282            0 : OksConfigObject::get(const std::string& name, std::vector<bool>& value)
     283              : {
     284            0 :   get_vector(name, value);
     285            0 : }
     286              : 
     287              : void
     288            0 : OksConfigObject::get(const std::string& name, std::vector<uint8_t>& value)
     289              : {
     290            0 :   get_vector(name, value);
     291            0 : }
     292              : 
     293              : void
     294            0 : OksConfigObject::get(const std::string& name, std::vector<int8_t>& value)
     295              : {
     296            0 :   get_vector(name, value);
     297            0 : }
     298              : 
     299              : void
     300            0 : OksConfigObject::get(const std::string& name, std::vector<uint16_t>& value)
     301              : {
     302            0 :   get_vector(name, value);
     303            0 : }
     304              : 
     305              : void
     306            0 : OksConfigObject::get(const std::string& name, std::vector<int16_t>& value)
     307              : {
     308            0 :   get_vector(name, value);
     309            0 : }
     310              : 
     311              : void
     312            0 : OksConfigObject::get(const std::string& name, std::vector<uint32_t>& value)
     313              : {
     314            0 :   get_vector(name, value);
     315            0 : }
     316              : 
     317              : void
     318            0 : OksConfigObject::get(const std::string& name, std::vector<int32_t>& value)
     319              : {
     320            0 :   get_vector(name, value);
     321            0 : }
     322              : 
     323              : void
     324            0 : OksConfigObject::get(const std::string& name, std::vector<uint64_t>& value)
     325              : {
     326            0 :   get_vector(name, value);
     327            0 : }
     328              : 
     329              : void
     330            0 : OksConfigObject::get(const std::string& name, std::vector<int64_t>& value)
     331              : {
     332            0 :   get_vector(name, value);
     333            0 : }
     334              : 
     335              : void
     336            0 : OksConfigObject::get(const std::string& name, std::vector<float>& value)
     337              : {
     338            0 :   get_vector(name, value);
     339            0 : }
     340              : 
     341              : void
     342            0 : OksConfigObject::get(const std::string& name, std::vector<double>& value)
     343              : {
     344            0 :   get_vector(name, value);
     345            0 : }
     346              : 
     347              : void
     348           60 : OksConfigObject::get(const std::string& name, std::vector<std::string>& value)
     349              : {
     350           60 :   OksData * data = 0;
     351              : 
     352           60 :   std::lock_guard<std::mutex> scoped_lock(m_mutex);
     353              : 
     354           60 :   try
     355              :     {
     356           60 :       throw_if_deleted();
     357           60 :       data = m_obj->GetAttributeValue(name);
     358              :     }
     359            0 :   catch (oks::exception& ex)
     360              :     {
     361            0 :       throw dunedaq::conffwk::Generic(ERS_HERE, mk_get_error_text("attribute", name, m_obj).c_str(), ex);
     362            0 :     }
     363              : 
     364           60 :   if (data->type != OksData::list_type)
     365              :     {
     366            0 :       std::ostringstream text;
     367            0 :       text << "attribute \"" << name << "\" of object " << m_obj << " is not of a multi-value";
     368            0 :       throw dunedaq::conffwk::Generic( ERS_HERE, text.str().c_str());
     369            0 :     }
     370              : 
     371           60 :   value.clear();
     372              : 
     373           75 :   for (const auto & it : *data->data.LIST)
     374              :     {
     375           15 :       if ((it->type == OksData::string_type) || (it->type == OksData::enum_type))
     376              :         {
     377            0 :           value.emplace_back(*it->data.STRING);
     378              :         }
     379           15 :       else if (it->type == OksData::class_type)
     380              :         {
     381           15 :           value.emplace_back(it->data.CLASS->get_name());
     382              :         }
     383            0 :       else if (it->type == OksData::date_type || it->type == OksData::time_type)
     384              :         {
     385            0 :           value.emplace_back(it->str());
     386              :         }
     387              :       else
     388              :         {
     389            0 :           std::ostringstream text;
     390            0 :           text << "wrong type of attribute \"" << name << "\" of object " << m_obj << " (instead of expected string)";
     391            0 :           throw dunedaq::conffwk::Generic( ERS_HERE, text.str().c_str() );
     392            0 :         }
     393              :     }
     394           60 : }
     395              : 
     396              : 
     397              : void
     398          625 : OksConfigObject::get(const std::string& name, std::vector<dunedaq::conffwk::ConfigObject>& value)
     399              : {
     400          625 :   OksData * data = 0;
     401              : 
     402          625 :   std::lock_guard<std::mutex> scoped_lock(m_mutex);
     403              : 
     404          625 :   try
     405              :     {
     406          625 :       throw_if_deleted();
     407          625 :       data = m_obj->GetRelationshipValue(name);
     408              :     }
     409            0 :   catch (oks::exception& ex)
     410              :     {
     411            0 :       throw dunedaq::conffwk::Generic(ERS_HERE, mk_get_error_text("relationship", name, m_obj).c_str(), ex);
     412            0 :     }
     413              : 
     414          625 :   if (data->type != OksData::list_type)
     415              :     {
     416            0 :       std::ostringstream text;
     417            0 :       text << "the value of relationship \"" << name << "\" of object " << m_obj << " is not multi-value";
     418            0 :       throw dunedaq::conffwk::Generic( ERS_HERE, text.str().c_str());
     419            0 :     }
     420              : 
     421          625 :   value.clear();
     422              : 
     423         1084 :   for (const auto& it : *data->data.LIST)
     424              :     {
     425          459 :       if (it->type != OksData::object_type)
     426              :         {
     427            0 :           TLOG_DEBUG(1) <<  "object " << *it << " is not loaded (relationship \'" << name << "\' of object " << m_obj << ')' ;
     428              :         }
     429          459 :       else if (!it->data.OBJECT)
     430              :         {
     431            0 :           TLOG_DEBUG(1) <<  "skip (null) object in relationship \'" << name << "\' of object " << m_obj ;
     432              :         }
     433              :       else
     434              :         {
     435          459 :           value.push_back(conffwk::ConfigObject(static_cast<OksConfiguration *>(m_impl)->new_object(it->data.OBJECT)));
     436              :         }
     437              :     }
     438          625 : }
     439              : 
     440              : bool
     441            0 : OksConfigObject::rel(const std::string& name, std::vector<conffwk::ConfigObject>& value)
     442              : {
     443            0 :   std::lock_guard<std::mutex> scoped_lock(m_mutex);
     444              : 
     445            0 :   try
     446              :     {
     447            0 :       throw_if_deleted();
     448              : 
     449            0 :       if (OksDataInfo * di = m_obj->GetClass()->get_data_info(name))
     450              :         {
     451            0 :           if (di->relationship)
     452              :             {
     453            0 :               OksData * data = m_obj->GetRelationshipValue(di);
     454              : 
     455            0 :               if (data->type == OksData::object_type)
     456              :                 {
     457            0 :                   if (data->data.OBJECT != nullptr)
     458              :                     {
     459            0 :                       value.push_back(conffwk::ConfigObject(static_cast<OksConfiguration *>(m_impl)->new_object(data->data.OBJECT)));
     460              :                     }
     461              :                 }
     462            0 :               else if (data->type == OksData::list_type)
     463              :                 {
     464            0 :                   for (const auto& it : *data->data.LIST)
     465              :                     {
     466            0 :                       if (it->type == OksData::object_type)
     467              :                         {
     468            0 :                           value.push_back(conffwk::ConfigObject(static_cast<OksConfiguration *>(m_impl)->new_object(it->data.OBJECT)));
     469              :                         }
     470              :                     }
     471              :                 }
     472              : 
     473            0 :               return true;
     474              :             }
     475              :         }
     476              : 
     477              :       return false;
     478              :     }
     479            0 :   catch (oks::exception& ex)
     480              :     {
     481            0 :       throw dunedaq::conffwk::Generic(ERS_HERE, mk_get_error_text("relationship", name, m_obj).c_str(), ex);
     482            0 :     }
     483            0 : }
     484              : 
     485              : void
     486            0 : OksConfigObject::referenced_by(std::vector<conffwk::ConfigObject>& value, const std::string& rname, bool check_composite_only, unsigned long /* rlevel */, const std::vector<std::string> * /* rclasses */) const
     487              : {
     488            0 :   value.clear();
     489              : 
     490            0 :   std::lock_guard<std::mutex> scoped_lock(m_mutex);
     491            0 :   throw_if_deleted();
     492              : 
     493            0 :   if (check_composite_only)
     494              :     {
     495            0 :       bool any_name = (rname == "*");
     496              : 
     497            0 :       if (const std::list<OksRCR *> * rcr = m_obj->reverse_composite_rels())
     498              :         {
     499            0 :           for (const auto& i : *rcr)
     500              :             {
     501            0 :               if (any_name || rname == i->relationship->get_name())
     502              :                 {
     503            0 :                   value.push_back(conffwk::ConfigObject(static_cast<OksConfiguration *>(m_impl)->new_object(i->obj)));
     504              :                 }
     505              :             }
     506              :         }
     507              :     }
     508              :   else
     509              :     {
     510            0 :       if (OksObject::FList * objs = m_obj->get_all_rels(rname))
     511              :         {
     512            0 :           for (const auto& i : *objs)
     513              :             {
     514            0 :               value.push_back(conffwk::ConfigObject(static_cast<OksConfiguration *>(m_impl)->new_object(i)));
     515              :             }
     516              : 
     517            0 :           delete objs;
     518              :         }
     519              :     }
     520            0 : }
     521              : 
     522              :    /////////////////////////////////////////////////////////////////////////////
     523              :    //
     524              :    //  set functions
     525              :    //
     526              :    /////////////////////////////////////////////////////////////////////////////
     527              : 
     528              : void
     529            8 : OksConfigObject::set_attr_value(const std::string& name, OksData & data)
     530              : {
     531            8 :   std::lock_guard<std::mutex> scoped_lock(m_mutex);
     532              : 
     533            8 :   try
     534              :     {
     535            8 :       throw_if_deleted();
     536              :       //test_checkout_needs();
     537            8 :       m_obj->SetAttributeValue(name, &data);
     538              :     }
     539            0 :   catch (dunedaq::conffwk::Generic& ex)
     540              :     {
     541            0 :       throw dunedaq::conffwk::Generic( ERS_HERE, mk_set_error_text("attribute", name, m_obj).c_str(), ex);
     542            0 :     }
     543            0 :   catch(oks::exception& ex)
     544              :     {
     545            0 :       throw dunedaq::conffwk::Generic( ERS_HERE, mk_set_error_text("attribute", name, m_obj).c_str(), ex);
     546            0 :     }
     547            8 : }
     548              : 
     549              : void
     550            9 : OksConfigObject::set_rel_value(const std::string& name, OksData & data, bool skip_non_null_check)
     551              : {
     552            9 :   std::lock_guard<std::mutex> scoped_lock(m_mutex);
     553              : 
     554            9 :   try
     555              :     {
     556            9 :       throw_if_deleted();
     557              :       //test_checkout_needs();
     558            9 :       m_obj->SetRelationshipValue(name, &data, skip_non_null_check);
     559              :     }
     560            0 :   catch (dunedaq::conffwk::Generic& ex)
     561              :     {
     562            0 :       throw dunedaq::conffwk::Generic(ERS_HERE, mk_set_error_text("relationship", name, m_obj).c_str(), ex );
     563            0 :     }
     564            0 :   catch(oks::exception& ex)
     565              :     {
     566            0 :       throw dunedaq::conffwk::Generic(ERS_HERE, mk_set_error_text("relationship", name, m_obj).c_str(), ex);
     567            0 :     }
     568            9 : }
     569              : 
     570              : 
     571              : template<class T>
     572              :   void
     573            8 :   OksConfigObject::set_value(const std::string& name, const T& value)
     574              :   {
     575            8 :     OksData d(value);
     576            8 :     set_attr_value(name, d);
     577            8 :   }
     578              : 
     579              : template<class T>
     580              :   void
     581            0 :   OksConfigObject::set_vector(const std::string& name, const std::vector<T>& value)
     582              :   {
     583            0 :     OksData d(new OksData::List());
     584              : 
     585            0 :     for (const auto& i : value)
     586              :       {
     587            0 :         d.data.LIST->push_back(new OksData(i));
     588              :       }
     589              : 
     590            0 :     set_attr_value(name, d);
     591            0 :   }
     592              : 
     593              : 
     594            0 : void OksConfigObject::set(const std::string& name, bool value)
     595              : {
     596            0 :   set_value(name, value);
     597            0 : }
     598              : 
     599            0 : void OksConfigObject::set(const std::string& name, uint8_t value)
     600              : {
     601            0 :   set_value(name, value);
     602            0 : }
     603              : 
     604            0 : void OksConfigObject::set(const std::string& name, int8_t value)
     605              : {
     606            0 :   set_value(name, value);
     607            0 : }
     608              : 
     609            0 : void OksConfigObject::set(const std::string& name, uint16_t value)
     610              : {
     611            0 :   set_value(name, value);
     612            0 : }
     613              : 
     614            0 : void OksConfigObject::set(const std::string& name, int16_t value)
     615              : {
     616            0 :   set_value(name, value);
     617            0 : }
     618              : 
     619            0 : void OksConfigObject::set(const std::string& name, uint32_t value)
     620              : {
     621            0 :   set_value(name, value);
     622            0 : }
     623              : 
     624            2 : void OksConfigObject::set(const std::string& name, int32_t value)
     625              : {
     626            2 :   set_value(name, value);
     627            2 : }
     628              : 
     629            0 : void OksConfigObject::set(const std::string& name, uint64_t value)
     630              : {
     631            0 :   set_value(name, value);
     632            0 : }
     633              : 
     634            0 : void OksConfigObject::set(const std::string& name, int64_t value)
     635              : {
     636            0 :   set_value(name, value);
     637            0 : }
     638              : 
     639            0 : void OksConfigObject::set(const std::string& name, float value)
     640              : {
     641            0 :   set_value(name, value);
     642            0 : }
     643              : 
     644            0 : void OksConfigObject::set(const std::string& name, double value)
     645              : {
     646            0 :   set_value(name, value);
     647            0 : }
     648              : 
     649            6 : void OksConfigObject::set(const std::string& name, const std::string& value)
     650              : {
     651            6 :   set_value(name, value);
     652            6 : }
     653              : 
     654              : void
     655            0 : OksConfigObject::set_enum(const std::string& name, const std::string& value)
     656              : {
     657            0 :   OksData d;
     658              : 
     659            0 :     {
     660            0 :       std::lock_guard<std::mutex> scoped_lock(m_mutex);
     661            0 :       throw_if_deleted();
     662              : 
     663            0 :       if (OksAttribute * a = m_obj->GetClass()->find_attribute(name))
     664              :         {
     665            0 :           try
     666              :             {
     667            0 :               d.data.ENUMERATION = a->get_enum_value(value);
     668            0 :               d.type = OksData::enum_type;
     669              :             }
     670            0 :           catch (std::exception& ex)
     671              :             {
     672            0 :               throw(dunedaq::conffwk::Generic( ERS_HERE, mk_set_error_text("attribute", name, m_obj, ex.what()).c_str()) );
     673            0 :             }
     674              :         }
     675              :       else
     676              :         {
     677            0 :           throw ( dunedaq::conffwk::Generic( ERS_HERE, mk_set_error_text("attribute", name, m_obj, "no such attribute").c_str()) );
     678              :         }
     679            0 :     }
     680              : 
     681            0 :   set_attr_value(name, d);
     682            0 : }
     683              : 
     684            0 : void OksConfigObject::set_class(const std::string& name, const std::string& value)
     685              : {
     686            0 :   OksData d;
     687              : 
     688            0 :   d.data.CLASS = nullptr;
     689            0 :   d.type = OksData::class_type;
     690              : 
     691              :     // try to find any attribute in this class; throw exception "no such attribute", if the class has no attributes at all
     692            0 :     {
     693            0 :       std::lock_guard<std::mutex> scoped_lock(m_mutex);
     694            0 :       throw_if_deleted();
     695              : 
     696            0 :       const std::list<OksAttribute *> * attrs = m_obj->GetClass()->all_attributes();
     697              : 
     698            0 :       if (!attrs || attrs->empty())
     699              :         {
     700            0 :           throw dunedaq::conffwk::Generic(ERS_HERE, mk_set_error_text("attribute", name, m_obj, "no such attribute").c_str());
     701              :         }
     702              : 
     703            0 :       try
     704              :         {
     705            0 :           d.SetValue(value.c_str(), attrs->front());
     706              :         }
     707            0 :       catch (oks::exception & ex)
     708              :         {
     709            0 :           throw dunedaq::conffwk::Generic(ERS_HERE, mk_set_error_text("attribute", name, m_obj).c_str(), ex);
     710            0 :         }
     711            0 :     }
     712              : 
     713            0 :   set_attr_value(name, d);
     714            0 : }
     715              : 
     716              : void
     717            0 : OksConfigObject::set_date(const std::string& name, const std::string& value)
     718              : {
     719            0 :   OksData d;
     720            0 :   d.type = OksData::date_type;
     721              : 
     722            0 :   try
     723              :     {
     724            0 :       d.SetValue(value.c_str(), nullptr);
     725              :     }
     726            0 :   catch (oks::exception& ex)
     727              :     {
     728            0 :       throw dunedaq::conffwk::Generic(ERS_HERE, mk_set_error_text("attribute", name, m_obj).c_str(), ex);
     729            0 :     }
     730              : 
     731            0 :   set_attr_value(name, d);
     732            0 : }
     733              : 
     734              : void
     735            0 : OksConfigObject::set_time(const std::string& name, const std::string& value)
     736              : {
     737            0 :   OksData d;
     738            0 :   d.type = OksData::time_type;
     739              : 
     740            0 :   try
     741              :     {
     742            0 :       d.SetValue(value.c_str(), nullptr);
     743              :     }
     744            0 :   catch (oks::exception& ex)
     745              :     {
     746            0 :       throw dunedaq::conffwk::Generic( ERS_HERE, mk_set_error_text("attribute", name, m_obj).c_str(), ex);
     747            0 :     }
     748              : 
     749            0 :   set_attr_value(name, d);
     750            0 : }
     751              : 
     752              : 
     753              : void
     754            0 : OksConfigObject::set(const std::string& name, const std::vector<bool>& value)
     755              : {
     756            0 :   set_vector(name, value);
     757            0 : }
     758              : 
     759              : void
     760            0 : OksConfigObject::set(const std::string& name, const std::vector<uint8_t>& value)
     761              : {
     762            0 :   set_vector(name, value);
     763            0 : }
     764              : 
     765              : void
     766            0 : OksConfigObject::set(const std::string& name, const std::vector<int8_t>& value)
     767              : {
     768            0 :   set_vector(name, value);
     769            0 : }
     770              : 
     771              : void
     772            0 : OksConfigObject::set(const std::string& name, const std::vector<uint16_t>& value)
     773              : {
     774            0 :   set_vector(name, value);
     775            0 : }
     776              : 
     777              : void
     778            0 : OksConfigObject::set(const std::string& name, const std::vector<int16_t>& value)
     779              : {
     780            0 :   set_vector(name, value);
     781            0 : }
     782              : 
     783              : void
     784            0 : OksConfigObject::set(const std::string& name, const std::vector<uint32_t>& value)
     785              : {
     786            0 :   set_vector(name, value);
     787            0 : }
     788              : 
     789              : void
     790            0 : OksConfigObject::set(const std::string& name, const std::vector<int32_t>& value)
     791              : {
     792            0 :   set_vector(name, value);
     793            0 : }
     794              : 
     795              : void
     796            0 : OksConfigObject::set(const std::string& name, const std::vector<uint64_t>& value)
     797              : {
     798            0 :   set_vector(name, value);
     799            0 : }
     800              : 
     801              : void
     802            0 : OksConfigObject::set(const std::string& name, const std::vector<int64_t>& value)
     803              : {
     804            0 :   set_vector(name, value);
     805            0 : }
     806              : 
     807              : void
     808            0 : OksConfigObject::set(const std::string& name, const std::vector<float>& value)
     809              : {
     810            0 :   set_vector(name, value);
     811            0 : }
     812              : 
     813              : void
     814            0 : OksConfigObject::set(const std::string& name, const std::vector<double>& value)
     815              : {
     816            0 :   set_vector(name, value);
     817            0 : }
     818              : 
     819              : void
     820            0 : OksConfigObject::set(const std::string& name, const std::vector<std::string>& value)
     821              : {
     822            0 :   set_vector(name, value);
     823            0 : }
     824              : 
     825              : void
     826            0 : OksConfigObject::set_enum(const std::string& name, const std::vector<std::string>& value)
     827              : {
     828            0 :   OksData d(new OksData::List());
     829              : 
     830            0 :     {
     831            0 :       std::lock_guard<std::mutex> scoped_lock(m_mutex);
     832            0 :       throw_if_deleted();
     833              : 
     834            0 :       if (OksAttribute * a = m_obj->GetClass()->find_attribute(name))
     835              :         {
     836            0 :           for (const auto& i : value)
     837              :             {
     838            0 :               OksData * d2 = new OksData();
     839            0 :               try
     840              :                 {
     841            0 :                   d2->data.ENUMERATION = a->get_enum_value(i); // new OksString(i);
     842            0 :                   d2->type = OksData::enum_type;
     843            0 :                   d.data.LIST->push_back(d2);
     844              :                 }
     845            0 :               catch (std::exception& ex)
     846              :                 {
     847            0 :                   throw dunedaq::conffwk::Generic( ERS_HERE, mk_set_error_text("attribute", name, m_obj).c_str(), ex);
     848            0 :                 }
     849              : 
     850              :             }
     851              :         }
     852              :       else
     853              :         {
     854            0 :           throw dunedaq::conffwk::Generic( ERS_HERE, mk_set_error_text("attribute", name, m_obj, "no such attribute").c_str());
     855              :         }
     856            0 :     }
     857              : 
     858            0 :   set_attr_value(name, d);
     859            0 : }
     860              : 
     861              : void
     862            0 : OksConfigObject::set_class(const std::string& name, const std::vector<std::string>& value)
     863              : {
     864            0 :   OksData d(new OksData::List());
     865              : 
     866              :   // try to find any attribute in this class; throw exception "no such attribute", if the class has no attributes at all
     867              : 
     868            0 :     {
     869            0 :       std::lock_guard<std::mutex> scoped_lock(m_mutex);
     870            0 :       throw_if_deleted();
     871              : 
     872            0 :       const std::list<OksAttribute *> * attrs = m_obj->GetClass()->all_attributes();
     873              : 
     874            0 :       if (!attrs || attrs->empty())
     875              :         {
     876            0 :           throw dunedaq::conffwk::Generic( ERS_HERE, mk_set_error_text("attribute", name, m_obj, "no such attribute").c_str());
     877              :         }
     878              : 
     879            0 :       for (const auto& i : value)
     880              :         {
     881            0 :           OksData * d2 = new OksData();
     882            0 :           d2->data.CLASS = 0;
     883            0 :           d2->type = OksData::class_type;
     884              : 
     885            0 :           try
     886              :             {
     887            0 :               d2->SetValue(i.c_str(), attrs->front());
     888              :             }
     889            0 :           catch (oks::exception & ex)
     890              :             {
     891            0 :               throw dunedaq::conffwk::Generic( ERS_HERE, mk_set_error_text("attribute", name, m_obj).c_str(), ex);
     892            0 :             }
     893              : 
     894            0 :           d.data.LIST->push_back(d2);
     895              :         }
     896            0 :     }
     897              : 
     898            0 :   set_attr_value(name, d);
     899            0 : }
     900              : 
     901              : void
     902            0 : OksConfigObject::set_date(const std::string& name, const std::vector<std::string>& value)
     903              : {
     904            0 :   OksData d(new OksData::List());
     905              : 
     906            0 :   for (const auto& i : value)
     907              :     {
     908            0 :       OksData * d2 = new OksData();
     909            0 :       d2->type = OksData::date_type;
     910            0 :       try
     911              :         {
     912            0 :           d2->SetValue(i.c_str(), nullptr);
     913              :         }
     914            0 :       catch (oks::exception& ex)
     915              :         {
     916            0 :           throw dunedaq::conffwk::Generic( ERS_HERE, mk_set_error_text("attribute", name, m_obj).c_str(), ex);
     917            0 :         }
     918            0 :       d.data.LIST->push_back(d2);
     919              :     }
     920              : 
     921            0 :   set_attr_value(name, d);
     922            0 : }
     923              : 
     924              : void
     925            0 : OksConfigObject::set_time(const std::string& name, const std::vector<std::string>& value)
     926              : {
     927            0 :   OksData d(new OksData::List());
     928              : 
     929            0 :   for (const auto& i : value)
     930              :     {
     931            0 :       OksData * d2 = new OksData();
     932            0 :       d2->type = OksData::time_type;
     933            0 :       try
     934              :         {
     935            0 :           d2->SetValue(i.c_str(), 0);
     936              :         }
     937            0 :       catch (oks::exception& ex)
     938              :         {
     939            0 :           throw dunedaq::conffwk::Generic( ERS_HERE, mk_set_error_text("attribute", name, m_obj).c_str(), ex);
     940            0 :         }
     941            0 :       d.data.LIST->push_back(d2);
     942              :     }
     943              : 
     944            0 :   set_attr_value(name, d);
     945            0 : }
     946              : 
     947              : void
     948            1 : OksConfigObject::set(const std::string& name, const conffwk::ConfigObject * value, bool skip_non_null_check)
     949              : {
     950            1 :   OksData d((value != nullptr) ? static_cast<const OksConfigObject*>(value->implementation())->m_obj : (OksObject *) nullptr);
     951            1 :   set_rel_value(name, d, skip_non_null_check);
     952            1 : }
     953              : 
     954              : void
     955            8 : OksConfigObject::set(const std::string& name, const std::vector<const conffwk::ConfigObject*>& value, bool skip_non_null_check)
     956              : {
     957            8 :   OksData d(new OksData::List());
     958              : 
     959           26 :   for (const auto& i : value)
     960              :     {
     961           18 :       d.data.LIST->push_back(new OksData(static_cast<const OksConfigObject*>(i->implementation())->m_obj));
     962              :     }
     963              : 
     964            8 :   set_rel_value(name, d, skip_non_null_check);
     965            8 : }
     966              : 
     967              : //void OksConfigObject::test_checkout_needs()
     968              : //{
     969              : ////  static_cast<OksConfiguration *>(m_impl)->test_and_checkout(m_obj->get_file());
     970              : //}
     971              : 
     972              : void
     973            0 : OksConfigObject::move(const std::string& at)
     974              : {
     975            0 :   std::lock_guard<std::mutex> scoped_lock(m_mutex);
     976              : 
     977            0 :   throw_if_deleted();
     978              : 
     979            0 :   if (OksFile * new_file_h = m_obj->GetClass()->get_kernel()->find_data_file(at))
     980              :     {
     981            0 :       OksFile * old_file_h = m_obj->get_file();
     982            0 :       if (old_file_h != new_file_h)
     983              :         {
     984            0 :           try
     985              :             {
     986              : //              static_cast<OksConfiguration *>(m_impl)->test_and_checkout(old_file_h);
     987              : //              static_cast<OksConfiguration *>(m_impl)->test_and_checkout(new_file_h);
     988            0 :               m_obj->set_file(new_file_h, false);
     989              :             }
     990            0 :           catch (oks::exception& ex)
     991              :             {
     992            0 :               throw dunedaq::conffwk::Generic(ERS_HERE, ex.what());
     993            0 :             }
     994              :         }
     995              :     }
     996              :   else
     997              :     {
     998            0 :       std::ostringstream text;
     999            0 :       text << "file \"" << at << "\" is not loaded";
    1000            0 :       throw dunedaq::conffwk::Generic(ERS_HERE, text.str().c_str());
    1001            0 :     }
    1002            0 : }
    1003              : 
    1004              : 
    1005              : void
    1006            0 : OksConfigObject::rename(const std::string& new_id)
    1007              : {
    1008            0 :   try
    1009              :     {
    1010            0 :       throw_if_deleted();
    1011              : 
    1012              : //      std::set<OksFile *> files;
    1013              : //
    1014              : //      files.insert(m_obj->get_file());
    1015              : //
    1016              : //      if (OksObject::FList * objs = m_obj->get_all_rels())
    1017              : //        {
    1018              : //          for (auto & f : *objs)
    1019              : //            {
    1020              : //              files.insert(f->get_file());
    1021              : //            }
    1022              : //
    1023              : //          delete objs;
    1024              : //        }
    1025              : //
    1026              : //      for (auto & f : files)
    1027              : //        {
    1028              : //          static_cast<OksConfiguration *>(m_impl)->test_and_checkout(f);
    1029              : //        }
    1030              : 
    1031            0 :       m_obj->set_id(new_id);
    1032              :     }
    1033            0 :   catch (oks::exception& ex)
    1034              :     {
    1035            0 :       std::ostringstream text;
    1036            0 :       text << "cannot rename object " << m_obj << " to new name \'" << new_id << "\' because " << ex.what();
    1037            0 :       throw dunedaq::conffwk::Generic(ERS_HERE, text.str().c_str());
    1038            0 :     }
    1039            0 : }
    1040              : 
    1041              : void
    1042            0 : OksConfigObject::reset()
    1043              : {
    1044            0 :   if (OksClass * c = static_cast<OksConfiguration *>(m_impl)->m_kernel->find_class(*m_class_name))
    1045              :     {
    1046            0 :       m_obj = c->get_object(m_id);
    1047              :     }
    1048              :   else
    1049              :     {
    1050            0 :       m_obj = nullptr;
    1051              :     }
    1052              : 
    1053            0 :   m_state = (m_obj ? dunedaq::conffwk::Valid : dunedaq::conffwk::Deleted);
    1054            0 : }
        

Generated by: LCOV version 2.0-1