DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dunedaq::oksconflibs::OksConfiguration Class Reference

#include <OksConfiguration.hpp>

Inheritance diagram for dunedaq::oksconflibs::OksConfiguration:
[legend]
Collaboration diagram for dunedaq::oksconflibs::OksConfiguration:
[legend]

Public Types

typedef std::map< std::string, std::set< std::string > > SMap
 
- Public Types inherited from dunedaq::conffwk::ConfigurationImpl
typedef void(*) notify(std::vector< ConfigurationChange * > &changes, Configuration *)
 Callback to notify database changes.
 
typedef void(*) pre_notify(Configuration *)
 Callback to pre-notify database changes.
 

Public Member Functions

 OksConfiguration () noexcept
 
virtual ~OksConfiguration ()
 
virtual bool test_object (const std::string &class_name, const std::string &name, unsigned long rlevel, const std::vector< std::string > *rclasses)
 Test object existence (used by Python binding)
 
virtual void get (const std::string &class_name, const std::string &name, conffwk::ConfigObject &object, unsigned long rlevel, const std::vector< std::string > *rclasses)
 Get object of class by id.
 
virtual void get (const std::string &class_name, std::vector< conffwk::ConfigObject > &objects, const std::string &query, unsigned long rlevel, const std::vector< std::string > *rclasses)
 
virtual void get (const conffwk::ConfigObject &obj_from, const std::string &query, std::vector< conffwk::ConfigObject > &objects, unsigned long rlevel, const std::vector< std::string > *rclasses)
 
virtual conffwk::class_tget (const std::string &class_name, bool direct_only)
 Get description of class in accordance with parameters.
 
virtual void get_superclasses (conffwk::fmap< conffwk::fset > &schema)
 Get inheritance hierarchy.
 
virtual void create (const std::string &at, const std::string &class_name, const std::string &id, conffwk::ConfigObject &object)
 Create object of class by id at given file.
 
virtual void create (const conffwk::ConfigObject &at, const std::string &class_name, const std::string &id, conffwk::ConfigObject &object)
 Create object of class by id at file identified by object 'at'.
 
virtual void destroy (conffwk::ConfigObject &object)
 Destroy object of class by id.
 
virtual void open_db (const std::string &db_name)
 Open database implementation in accordance with given name.
 
virtual void close_db ()
 Close database implementation.
 
virtual bool loaded () const noexcept
 Check if a database is loaded.
 
virtual void create (const std::string &db_name, const std::list< std::string > &includes)
 Create database.
 
virtual bool is_writable (const std::string &db_name)
 Return write access status.
 
virtual void add_include (const std::string &db_name, const std::string &include)
 Add include file.
 
virtual void remove_include (const std::string &db_name, const std::string &include)
 Remove include file.
 
virtual void get_includes (const std::string &db_name, std::list< std::string > &includes) const
 Get included files.
 
virtual void get_updated_dbs (std::list< std::string > &dbs) const
 Get uncommitted files.
 
virtual void set_commit_credentials (const std::string &user, const std::string &password)
 Set commit credentials.
 
virtual void commit (const std::string &why)
 Commit database changes.
 
virtual void abort ()
 Abort database changes.
 
virtual void prefetch_all_data ()
 Prefetch all data into client cache.
 
virtual std::vector< dunedaq::conffwk::Versionget_changes ()
 Get newly available versions.
 
virtual std::vector< dunedaq::conffwk::Versionget_versions (const std::string &since, const std::string &until, dunedaq::conffwk::Version::QueryType type, bool skip_irrelevant)
 Get archived versions.
 
virtual void subscribe (const std::set< std::string > &class_names, const SMap &objs, ConfigurationImpl::notify cb, ConfigurationImpl::pre_notify pre_cb)
 
virtual void unsubscribe ()
 Remove subscription on database changes.
 
virtual void print_profiling_info () noexcept
 Print implementation specific profiling information.
 
const oks::OksKernelget_oks_kernel () const
 
- Public Member Functions inherited from dunedaq::conffwk::ConfigurationImpl
 ConfigurationImpl () noexcept
 The constructor.
 
virtual ~ConfigurationImpl ()
 Virtual destructor.
 
virtual void get (const std::string &class_name, std::vector< ConfigObject > &objects, const std::string &query, unsigned long rlevel, const std::vector< std::string > *rclasses)=0
 Get objects of class according to query.
 
virtual void get (const ConfigObject &obj_from, const std::string &query, std::vector< ConfigObject > &objects, unsigned long rlevel, const std::vector< std::string > *rclasses)=0
 Get objects according to path.
 
virtual void subscribe (const std::set< std::string > &class_names, const std::map< std::string, std::set< std::string > > &objs, notify cb, pre_notify pre_cb)=0
 Subscribe on database changes.
 
void print_cache_info () noexcept
 Print profiling information about objects in cache.
 
void set (Configuration *db) noexcept
 set configuration object
 
void rename_impl_object (const std::string *class_name, const std::string &old_id, const std::string &new_id) noexcept
 rename object in cache
 

Protected Member Functions

void create (oks::OksFile *at, const std::string &class_name, const std::string &id, conffwk::ConfigObject &object)
 
void init_env ()
 
OksConfigObjectnew_object (oks::OksObject *obj) noexcept
 
void subscribe ()
 
- Protected Member Functions inherited from dunedaq::conffwk::ConfigurationImpl
ConfigObjectImplget_impl_object (const std::string &class_name, const std::string &id) const noexcept
 get object from cache
 
void put_impl_object (const std::string &class_name, const std::string &id, ConfigObjectImpl *obj) noexcept
 put object to cache
 
template<class T , class OBJ >
T * insert_object (OBJ &obj, const std::string &id, const std::string &class_name) noexcept
 insert new object (update cache or create-and-insert)
 
void clean () noexcept
 clean cache (e.g. to be used by destructor)
 
std::mutex & get_conf_impl_mutex () const
 Is required by reload methods.
 

Static Protected Member Functions

static void create_notify (oks::OksObject *, void *) noexcept
 
static void change_notify (oks::OksObject *, void *) noexcept
 
static void delete_notify (oks::OksObject *, void *) noexcept
 

Protected Attributes

oks::OksKernelm_kernel
 
conffwk::ConfigurationImpl::notify m_fn
 
conffwk::ConfigurationImpl::pre_notify m_pre_fn
 
std::set< std::string > m_class_names
 
SMap m_objects
 
bool m_oks_kernel_silence
 
bool m_oks_kernel_no_repo
 
std::list< oks::OksObject * > m_created
 
std::set< oks::OksObject * > m_modified
 
std::map< std::string, std::set< std::string > > m_removed
 
OksConfigurationCheckDBm_check_db_obj
 
std::thread * m_check_db_thread
 
std::string m_user
 
std::string m_password
 
std::set< oks::OksFile * > m_created_files
 
unsigned int m_repo_error_count
 
- Protected Attributes inherited from dunedaq::conffwk::ConfigurationImpl
Configurationm_conf
 Configuration pointer is needed for notification on changes, e.g. in case of subscription or an object deletion.
 

Private Member Functions

virtual void check_db ()
 
void close_database (bool unsubscribe)
 

Friends

class OksConfigObject
 
struct OksConfigurationCheckDB
 
class ResubscribeGuard
 

Detailed Description

Definition at line 32 of file OksConfiguration.hpp.

Member Typedef Documentation

◆ SMap

std::map< std::string , std::set<std::string> > dunedaq::oksconflibs::OksConfiguration::SMap

Definition at line 43 of file OksConfiguration.hpp.

Constructor & Destructor Documentation

◆ OksConfiguration()

dunedaq::oksconflibs::OksConfiguration::OksConfiguration ( )
inlinenoexcept

◆ ~OksConfiguration()

virtual dunedaq::oksconflibs::OksConfiguration::~OksConfiguration ( )
inlinevirtual

Definition at line 41 of file OksConfiguration.hpp.

41{ close_db(); }
virtual void close_db()
Close database implementation.

Member Function Documentation

◆ abort()

void dunedaq::oksconflibs::OksConfiguration::abort ( )
virtual

Abort database changes.

Implements dunedaq::conffwk::ConfigurationImpl.

Definition at line 459 of file OksConfiguration.cpp.

460{
461 // unsubscribe changes; if there are any, re-subscribe on return from this method
462
463 ResubscribeGuard __rg__(*this);
464
465
466 // destroy any newly created files
467 for (const auto& i : m_created_files)
468 {
469 const std::string file_name(i->get_full_file_name());
470
471 TLOG_DEBUG(1) << "destroy created file \'" << file_name << "\')" ;
473
474 if (int result = unlink(file_name.c_str()))
475 {
476 std::ostringstream text;
477 text << "abort changes failed since cannot erase created file \'" << file_name << "\'; unlink failed with code " << result << ": " << dunedaq::oks::strerror(errno);
478 throw(dunedaq::conffwk::Generic( ERS_HERE, text.str().c_str() ) );
479 }
480 }
481
482 m_created_files.clear();
483
484
485
486 // add to "updated" any modified file
487 std::set<OksFile *> updated;
488
489 for (const auto& i : m_kernel->data_files())
490 {
491 if (i.second->is_updated())
492 {
493 updated.insert(i.second);
494 TLOG_DEBUG(2) << "file \'" << i.second->get_full_file_name() << "\' was updated, to be reloaded..." ;
495 }
496 }
497
498 if (!m_kernel->get_user_repository_root().empty())
499 {
500 std::set<OksFile *> mfs, rfs;
501 try
502 {
503 m_kernel->get_modified_files(mfs, rfs, "origin/master");
504 }
505 catch (const oks::exception& ex)
506 {
507 std::ostringstream text;
508 text << "failed to get differences between revisions " << m_kernel->get_repository_version() << " and origin/master: " << ex.what() << '\n';
509 throw(dunedaq::conffwk::Generic(ERS_HERE, text.str().c_str(), ex));
510 }
511 }
512
513 if (!updated.empty())
514 {
515 try
516 {
517 if (!m_kernel->get_user_repository_root().empty())
518 m_kernel->update_repository("origin/master", OksKernel::RepositoryUpdateType::DiscardChanges);
519
520 m_kernel->reload_data(updated);
521 }
522 catch (oks::exception & ex)
523 {
524 throw(dunedaq::conffwk::Generic(ERS_HERE, "cannot reload updated data files", ex));
525 }
526 catch (...)
527 {
528 throw(dunedaq::conffwk::Generic(ERS_HERE, "cannot reload updated data files"));
529 }
530 }
531}
#define ERS_HERE
Generic configuration exception.
const std::string & get_user_repository_root() const
Get user OKS repository root.
Definition kernel.cpp:370
void update_repository(const std::string &hash_val, RepositoryUpdateType update_type)
Update user repository files from origin by hash.
Definition kernel.hpp:1608
void get_modified_files(std::set< OksFile * > &mfs, std::set< OksFile * > &rfs, const std::string &version)
Get modified data files.
Definition kernel.cpp:3017
const OksFile::Map & data_files() const
Get all data files.
Definition kernel.hpp:1493
void reload_data(std::set< OksFile * > &files, bool allow_schema_extension=true)
Reload OKS data files.
Definition kernel.cpp:3211
const std::string & get_repository_version()
Definition kernel.hpp:936
void close_data(OksFile *file_h, bool unbind_objects=true)
Close OKS data file.
Definition kernel.cpp:4183
std::set< oks::OksFile * > m_created_files
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112
const std::string strerror(int error)
Convert C error number to string.
Definition kernel.cpp:114

◆ add_include()

void OksConfiguration::add_include ( const std::string & db_name,
const std::string & include )
virtual

Add include file.

Implements dunedaq::conffwk::ConfigurationImpl.

Definition at line 1150 of file OksConfiguration.cpp.

1151{
1152 if(OksFile * h = m_kernel->find_data_file(db_name)) {
1153 try {
1154 h->add_include_file(include);
1155 }
1156 catch(dunedaq::conffwk::Generic& ex) {
1157 throw ( dunedaq::conffwk::Generic( ERS_HERE, mk_add_include_error_text(db_name, include).c_str() ), ex );
1158 }
1159 catch (oks::exception & ex) {
1160 throw ( dunedaq::conffwk::Generic( ERS_HERE, mk_add_include_error_text(db_name, include, ex.what()).c_str() ) );
1161 }
1162 catch (...) {
1163 throw ( dunedaq::conffwk::Generic( ERS_HERE, mk_add_include_error_text(db_name, include).c_str() ) );
1164 }
1165 }
1166 else {
1167 throw ( dunedaq::conffwk::Generic( ERS_HERE, mk_no_file_error_text(db_name).c_str() ) );
1168 }
1169}
static std::string mk_no_file_error_text(const std::string &db)
static std::string mk_add_include_error_text(const std::string &db, const std::string &include, const char *error=nullptr)
Provides interface to the OKS XML schema and data files.
Definition file.hpp:340
OksFile * find_data_file(const std::string &s) const
Finds OKS data file.
Definition kernel.cpp:2287

◆ change_notify()

void OksConfiguration::change_notify ( oks::OksObject * o,
void * p )
staticprotectednoexcept

Definition at line 930 of file OksConfiguration.cpp.

931{
932 reinterpret_cast<OksConfiguration *>(p)->m_modified.insert(o);
933}
std::set< oks::OksObject * > m_modified

◆ check_db()

void OksConfiguration::check_db ( )
privatevirtual

Definition at line 1242 of file OksConfiguration.cpp.

1243{
1244 static const std::string version("origin/master");
1245
1246 if (m_fn)
1247 {
1248 std::set<OksFile *> ufs, rfs;
1249
1250 try
1251 {
1254 }
1255 catch(const oks::RepositoryOperationFailed& ex)
1256 {
1257 std::ostringstream text;
1258 text << "cannot get modified repository files (attempt " << ++m_repo_error_count << "): " << ex.what();
1259 ers::error(dunedaq::conffwk::Generic( ERS_HERE, text.str().c_str() ) );
1260 }
1261 catch(const oks::exception& ex)
1262 {
1263 std::ostringstream text;
1264 text << "cannot get modified files: " << ex.what();
1265 throw(dunedaq::conffwk::Generic( ERS_HERE, text.str().c_str() ) );
1266 }
1267
1268 for (const auto& x : ufs)
1269 {
1270 if (x->get_oks_format() == "schema")
1271 {
1272 std::ostringstream text;
1273 text << "reload of schema files is not supported (\'" << x->get_well_formed_name() << "\')";
1274 throw(dunedaq::conffwk::Generic( ERS_HERE, text.str().c_str() ) );
1275 }
1276 }
1277
1278 if (ufs.empty() == false)
1279 {
1280 InheritanceData inheritance(*m_kernel);
1281
1282 m_kernel->subscribe_create_object(create_notify, reinterpret_cast<void *>(this));
1283 m_kernel->subscribe_change_object(change_notify, reinterpret_cast<void *>(this));
1284 m_kernel->subscribe_delete_object(delete_notify, reinterpret_cast<void *>(this));
1285
1286 (*m_pre_fn)(m_conf);
1287
1288 try
1289 {
1290 if(!m_kernel->get_user_repository_root().empty())
1291 m_kernel->update_repository(version, OksKernel::RepositoryUpdateType::DiscardChanges);
1292
1293 m_kernel->reload_data(ufs, false);
1294 }
1295 catch (oks::exception & ex)
1296 {
1297 close_database(false);
1298 m_fn = 0;
1299 std::ostringstream text;
1300 text << "failed to reload updated files:\n" << ex.what();
1301 throw(dunedaq::conffwk::Generic( ERS_HERE, text.str().c_str() ) );
1302 }
1303 catch (...)
1304 {
1305 close_database(false);
1306 m_fn = 0;
1307 throw ( dunedaq::conffwk::Generic( ERS_HERE, "failed to reload updated files" ) );
1308 }
1309
1310
1314
1315 std::vector<conffwk::ConfigurationChange *> changes;
1316
1317 {
1318 for (auto& i : m_created)
1319 {
1320 check(changes, inheritance, m_class_names, m_objects, i->GetClass()->get_name(), i->GetId(), '+');
1321
1322 std::set<OksObject *>::iterator j = m_modified.find(i);
1323 if (j != m_modified.end())
1324 {
1325 TLOG_DEBUG(1) << "created object " << i << " appears in \'modified\' set, removing..." ;
1326 m_modified.erase(j);
1327 }
1328 }
1329 }
1330
1331 {
1332 for (auto& i : m_modified)
1333 {
1334 if (m_kernel->is_dangling(i))
1335 {
1336 TLOG_DEBUG(1) << "object " << (void *)(i) << " is dangling, ignore..." ;
1337 }
1338 else
1339 {
1340 check(changes, inheritance, m_class_names, m_objects, i->GetClass()->get_name(), i->GetId(), '~');
1341 }
1342 }
1343 }
1344
1345 {
1346 for (auto& i : m_removed)
1347 {
1348 for (auto& j : i.second)
1349 {
1350 check(changes, inheritance, m_class_names, m_objects, i.first, j, '-');
1351 }
1352 }
1353 }
1354
1355 if (!changes.empty())
1356 {
1357 (*m_fn)(changes, m_conf);
1359 }
1360
1361 m_created.clear();
1362 m_modified.clear();
1363 m_removed.clear();
1364 }
1365 }
1366 else
1367 {
1368 throw(dunedaq::conffwk::Generic( ERS_HERE, "no subscription has been done" ) );
1369 }
1370}
static void check(std::vector< conffwk::ConfigurationChange * > &changes, const InheritanceData &inheritance, const std::set< std::string > &class_names, const OksConfiguration::SMap &objects, const std::string &obj_class, const std::string &obj_id, const char action)
static void clear(std::vector< ConfigurationChange * > &changes)
Helper method to clear vector of changes (pointers).
Configuration * m_conf
Configuration pointer is needed for notification on changes, e.g. in case of subscription or an objec...
void subscribe_change_object(OksObject::notify_obj, void *)
Subscribe on object changing.
Definition kernel.hpp:2183
void subscribe_delete_object(OksObject::notify_obj, void *)
Subscribe on object deleting.
Definition kernel.hpp:2191
bool is_dangling(OksClass *class_ptr) const
Check pointer on oks class.
Definition kernel.cpp:4638
void subscribe_create_object(OksObject::notify_obj cb_f, void *parameter)
Subscribe on object creation.
Definition kernel.hpp:2175
static void change_notify(oks::OksObject *, void *) noexcept
static void delete_notify(oks::OksObject *, void *) noexcept
static void create_notify(oks::OksObject *, void *) noexcept
std::list< oks::OksObject * > m_created
std::map< std::string, std::set< std::string > > m_removed
void error(const Issue &issue)
Definition ers.hpp:81

◆ close_database()

void OksConfiguration::close_database ( bool unsubscribe)
private

Definition at line 227 of file OksConfiguration.cpp.

228{
229 clean(); // clean implementation cache
230
231 if(m_kernel) try {
232 if(m_check_db_obj) {
233 if(call_unsubscribe)
234 unsubscribe();
235 else
236 m_check_db_obj->m_run = false;
237 }
238
242
245
246 delete m_kernel;
247 m_kernel = 0;
248 }
249 catch(oksconflibs::Exception& ex) {
250 throw ( dunedaq::conffwk::Generic( ERS_HERE, "failed to close database", ex ) );
251 }
252 catch(std::exception& ex) {
253 throw ( dunedaq::conffwk::Generic( ERS_HERE, "failed to close database", ex ) );
254 }
255}
void clean() noexcept
clean cache (e.g. to be used by destructor)
void close_all_data()
Close all OKS data files.
Definition kernel.cpp:4243
void close_all_schema()
Close all OKS schema files.
Definition kernel.cpp:2883
virtual void unsubscribe()
Remove subscription on database changes.

◆ close_db()

virtual void dunedaq::oksconflibs::OksConfiguration::close_db ( )
inlinevirtual

Close database implementation.

Implements dunedaq::conffwk::ConfigurationImpl.

Definition at line 59 of file OksConfiguration.hpp.

59{ close_database(true); }

◆ commit()

void OksConfiguration::commit ( const std::string & log_message)
virtual

Commit database changes.

Implements dunedaq::conffwk::ConfigurationImpl.

Definition at line 365 of file OksConfiguration.cpp.

366{
367 try
368 {
369 m_kernel->set_active_data(nullptr);
370 }
371 catch (oks::exception &ex)
372 {
373 throw(dunedaq::conffwk::Generic( ERS_HERE, ex.what()));
374 }
375
376 const bool commit2repo(!m_kernel->get_user_repository_root().empty() && m_kernel->is_user_repository_created());
377 unsigned int count(0);
378
379 for (const auto &i : m_kernel->data_files())
380 {
381 OksFile *file_h = i.second;
382
383 if (file_h->is_updated())
384 {
385 const OksFile::FileStatus file_status = file_h->get_status_of_file();
386
387 if (file_status == OksFile::FileModified)
388 throw_update_exception(file_h, "save", "it was externally modified");
389 else if (file_status == OksFile::FileRemoved)
390 throw_update_exception(file_h, "save", "it was externally removed");
391
392 try
393 {
394 if (!commit2repo && !log_message.empty())
395 file_h->add_comment(log_message, m_kernel->get_user_name());
396
397 m_kernel->save_data(file_h);
398
399 count++;
400 }
401 catch (oks::exception &ex)
402 {
403 std::ostringstream text;
404 text << "cannot save updated data file \'" << *(i.first) << "\':\n" << ex.what();
405 throw(dunedaq::conffwk::Generic( ERS_HERE, text.str().c_str()));
406 }
407 }
408 }
409
410 if (commit2repo && count)
411 {
412 try
413 {
414 m_kernel->commit_repository(log_message);
415 }
416 catch (oks::exception &ex)
417 {
418 throw(dunedaq::conffwk::Generic( ERS_HERE, ex.what()));
419 }
420 }
421
422 m_created_files.clear();
423}
static void throw_update_exception(const OksFile *file_h, const char *action, const char *reason)
void add_comment(const std::string &text, const std::string &author)
Add new comment to file.
Definition file.cpp:669
bool is_updated() const
Return update status of OKS file.
Definition file.hpp:624
FileStatus get_status_of_file() const
Return update status of file.
Definition file.cpp:1413
static std::string & get_user_name()
Get username of given process.
Definition kernel.cpp:468
bool is_user_repository_created() const
Definition kernel.hpp:942
void save_data(OksFile *file_h, bool ignore_bad_objects=false, OksFile *true_file_h=nullptr, bool force_defaults=false)
Save OKS data file.
Definition kernel.cpp:3794
void commit_repository(const std::string &comments, const std::string &credentials="")
Commit user modifications into repository.
Definition kernel.cpp:5057
void set_active_data(OksFile *file_h)
Set active OKS data file.
Definition kernel.cpp:4278

◆ create() [1/4]

void OksConfiguration::create ( const conffwk::ConfigObject & at,
const std::string & class_name,
const std::string & id,
conffwk::ConfigObject & object )
virtual

Create object of class by id at file identified by object 'at'.

Implements dunedaq::conffwk::ConfigurationImpl.

Definition at line 918 of file OksConfiguration.cpp.

919{
920 create((static_cast<const OksConfigObject *>(at.implementation()))->m_obj->get_file(), class_name, id, object);
921}
virtual void create(const std::string &at, const std::string &class_name, const std::string &id, conffwk::ConfigObject &object)
Create object of class by id at given file.

◆ create() [2/4]

void OksConfiguration::create ( const std::string & at,
const std::string & class_name,
const std::string & id,
conffwk::ConfigObject & object )
virtual

Create object of class by id at given file.

Implements dunedaq::conffwk::ConfigurationImpl.

Definition at line 901 of file OksConfiguration.cpp.

902{
903 if(at.empty() == true) {
904 throw ( dunedaq::conffwk::Generic( ERS_HERE, "parameter \'at\' (i.e. filename) cannot be empty" ) );
905 }
906
907 if(OksFile * h = m_kernel->find_data_file(at)) {
908 return create(h, class_name, id, object);
909 }
910 else {
911 std::ostringstream text;
912 text << "file \"" << at << "\" is not loaded";
913 throw ( dunedaq::conffwk::Generic( ERS_HERE, text.str().c_str() ) );
914 }
915}

◆ create() [3/4]

void OksConfiguration::create ( const std::string & db_name,
const std::list< std::string > & includes )
virtual

Create database.

Implements dunedaq::conffwk::ConfigurationImpl.

Definition at line 259 of file OksConfiguration.cpp.

260{
261 // create OKS kernel if it was not created
262
263 if (m_kernel == nullptr)
264 {
265 if (is_repo_name(db_name) == false)
267
269 }
270
271
272 // create new data file
273
274 try {
275 OksFile * h = m_kernel->new_data(db_name);
276 m_created_files.insert(h);
277
278 // add includes
279
280 for(std::list<std::string>::const_iterator i = includes.begin(); i != includes.end(); ++i) {
281 try {
282 h->add_include_file(*i);
283 }
284 catch (oks::exception & e) {
285 std::ostringstream text;
286 text << "cannot add and load include file \'" << *i << "\' to \'" << db_name << "\':\n" << e.what();
287 close_db();
288 throw ( dunedaq::conffwk::Generic( ERS_HERE, text.str().c_str() ) );
289 }
290 catch (...) {
291 std::ostringstream text;
292 text << "cannot add and load include file \'" << *i << "\' to \'" << db_name << '\'';
293 close_db();
294 throw ( dunedaq::conffwk::Generic( ERS_HERE, text.str().c_str() ) );
295 }
296 }
297
299 }
300 catch (oks::exception & ex) {
301 close_db();
302 std::ostringstream text;
303 text << "cannot create new data file \'" << db_name << "\': " << ex.what();
304 throw ( dunedaq::conffwk::Generic( ERS_HERE, text.str().c_str() ) );
305 }
306 catch (dunedaq::conffwk::Generic & ex) {
307 close_db();
308 std::ostringstream text;
309 text << "cannot create new data file \'" << db_name << "\'";
310 throw ( dunedaq::conffwk::Generic( ERS_HERE, text.str().c_str(), ex ) );
311 }
312 catch (...) {
313 close_db();
314 std::ostringstream text;
315 text << "cannot create new data file \'" << db_name << '\'';
316 throw ( dunedaq::conffwk::Generic( ERS_HERE, text.str().c_str() ) );
317 }
318}
bool is_repo_name(const std::string &name)
void add_include_file(const std::string &name)
Add include file.
Definition file.cpp:1194
Provides interface to the OKS kernel.
Definition kernel.hpp:577
OksFile * new_data(const std::string &name, const std::string &logical_name="", const std::string &type="")
Create OKS data file.
Definition kernel.cpp:3718
void bind_objects()
Bind oks objects.
Definition kernel.cpp:4361

◆ create() [4/4]

void OksConfiguration::create ( oks::OksFile * at,
const std::string & class_name,
const std::string & id,
conffwk::ConfigObject & object )
protected

Definition at line 861 of file OksConfiguration.cpp.

862{
863 try {
865 }
866 catch(oks::exception& ex) {
867 throw ( dunedaq::conffwk::Generic( ERS_HERE, ex.what()) );
868 }
869
870 OksClass * c = m_kernel->find_class(class_name);
871
872 if(c == nullptr) {
873 std::ostringstream text;
874 text << "cannot find class \"" << class_name << '\"';
875 throw ( dunedaq::conffwk::Generic( ERS_HERE, text.str().c_str() ) );
876 }
877 else if(id.empty() == false) {
878 if(OksObject * obj = c->get_object(id)) {
879 std::ostringstream text;
880 text << "object \"" << id << '@' << class_name << "\" already exists in file \"" << obj->get_file()->get_full_file_name() << '\"';
881 throw ( dunedaq::conffwk::Generic( ERS_HERE, text.str().c_str() ) );
882 }
883 }
884
886 {
889 }
890
891 try {
892 object = new_object(new OksObject(c, id.c_str()));
893 }
894 catch(oks::exception& ex)
895 {
896 throw ( dunedaq::conffwk::Generic( ERS_HERE, "cannot create configuration object", ex ) );
897 }
898}
The OKS class.
Definition class.hpp:200
void registrate_all_classes(bool skip_registered=false)
The method rebuilds all classes taking into account inheritance.
Definition kernel.cpp:4499
bool get_test_duplicated_objects_via_inheritance_mode() const
Get status of test inherited duplicated objects mode. The method returns true, if the mode is switche...
Definition kernel.hpp:765
void set_test_duplicated_objects_via_inheritance_mode(const bool b)
Set status of test inherited duplicated objects mode. To switch 'On'/'Off' use the method's parameter...
Definition kernel.hpp:756
OksClass * find_class(const std::string &class_name) const
Find class by name (C++ string).
Definition kernel.hpp:1814
OksObject describes instance of OksClass.
Definition object.hpp:836
OksConfigObject * new_object(oks::OksObject *obj) noexcept

◆ create_notify()

void OksConfiguration::create_notify ( oks::OksObject * o,
void * p )
staticprotectednoexcept

Definition at line 924 of file OksConfiguration.cpp.

925{
926 reinterpret_cast<OksConfiguration *>(p)->m_created.push_back(o);
927}

◆ delete_notify()

void OksConfiguration::delete_notify ( oks::OksObject * o,
void * p )
staticprotectednoexcept

Definition at line 936 of file OksConfiguration.cpp.

937{
938 reinterpret_cast<OksConfiguration *>(p)->m_removed[o->GetClass()->get_name()].insert(o->GetId());
939}

◆ destroy()

void OksConfiguration::destroy ( conffwk::ConfigObject & object)
virtual

Destroy object of class by id.

Implements dunedaq::conffwk::ConfigurationImpl.

Definition at line 1077 of file OksConfiguration.cpp.

1078{
1079 OksObject * o((static_cast<const OksConfigObject *>(obj.implementation()))->m_obj);
1080
1081 DestroyGuard2 dg2(m_removed); // => on exit from method, call m_removed.clear();
1082
1083 InheritanceData inheritance(*m_kernel);
1084
1085 try {
1086 m_kernel->subscribe_delete_object(delete_notify, reinterpret_cast<void *>(this));
1087 DestroyGuard1 dg1(*m_kernel); // => on exit from try block, call m_kernel->subscribe_delete_object(0, 0);
1089 }
1090 catch(oks::exception& ex) {
1091 throw ( dunedaq::conffwk::Generic( ERS_HERE, ex.what()) );
1092 }
1093
1094 if(m_conf) {
1095 std::vector<conffwk::ConfigurationChange *> changes;
1096
1097 for(SMap::iterator i = m_removed.begin(); i != m_removed.end(); ++i) {
1098 for(std::set<std::string>::const_iterator j = i->second.begin(); j != i->second.end(); ++j) {
1099 check(changes, inheritance, m_class_names, m_objects, i->first, *j, '-');
1100 }
1101 }
1102
1103 if(!changes.empty()) {
1104 m_conf->update_cache(changes);
1106 }
1107 }
1108}
void update_cache(std::vector< ConfigurationChange * > &changes) noexcept
System function invoked in case of modifications.
static void destroy(OksObject *obj, bool fast=false)
Destroy OKS object.
Definition object.cpp:1301

◆ get() [1/4]

void OksConfiguration::get ( const conffwk::ConfigObject & obj_from,
const std::string & query,
std::vector< conffwk::ConfigObject > & objects,
unsigned long rlevel,
const std::vector< std::string > * rclasses )
virtual

Definition at line 710 of file OksConfiguration.cpp.

711{
712 if(obj_from.is_null()) {
713 throw ( dunedaq::conffwk::Generic( ERS_HERE, "parameter \'obj_from\' is (null)" ) );
714 }
715
716 OksObject * o = (static_cast<const OksConfigObject *>(obj_from.implementation()))->m_obj;
717
718 try {
719 oks::QueryPath q(query, *m_kernel);
720 if(OksObject::List * objs = o->find_path(q)) {
721 for(OksObject::List::iterator i = objs->begin(); i != objs->end(); ++i) {
722 objects.push_back(new_object(*i));
723 }
724 delete objs;
725 }
726 }
727 catch ( oks::bad_query_syntax& e ) {
728 std::ostringstream text;
729 text << "bad path-query \"" << query << "\" to object " << o;
730 throw ( dunedaq::conffwk::Generic( ERS_HERE, text.str().c_str() ) );
731 }
732}
std::list< OksObject * > List
Definition object.hpp:875
OksObject::List * find_path(const oks::QueryPath &query) const
Definition query.cpp:936

◆ get() [2/4]

dunedaq::conffwk::class_t * OksConfiguration::get ( const std::string & class_name,
bool direct_only )
virtual

Get description of class in accordance with parameters.

Implements dunedaq::conffwk::ConfigurationImpl.

Definition at line 736 of file OksConfiguration.cpp.

737{
738 OksClass * c = m_kernel->find_class(class_name);
739
740 if(c == 0) {
741 throw dunedaq::conffwk::NotFound(ERS_HERE, "class", class_name.c_str());
742 }
743
744 dunedaq::conffwk::class_t * d = new dunedaq::conffwk::class_t(c->get_name(), c->get_description(), c->get_file()->get_full_file_name(), c->get_is_abstract());
745
746 if(direct_only) {
747 if(const std::list<std::string *> * classes = c->direct_super_classes()) {
748 for(const auto& i : *classes) {
749 const_cast< std::vector<std::string>& >(d->p_superclasses).push_back(*i);
750 }
751 }
752 }
753 else {
754 if(const OksClass::FList * classes = c->all_super_classes()) {
755 for(const auto& i : *classes) {
756 const_cast< std::vector<std::string>& >(d->p_superclasses).push_back(i->get_name());
757 }
758 }
759 }
760
761 if(const OksClass::FList * subclasses = c->all_sub_classes()) {
762 for(const auto& i : *subclasses) {
763 if(direct_only == false || i->has_direct_super_class(c->get_name()) == true) {
764 const_cast< std::vector<std::string>& >(d->p_subclasses).push_back(i->get_name());
765 }
766 }
767 }
768
769 if(const std::list<OksAttribute *> * attrs = (direct_only ? c->direct_attributes() : c->all_attributes())) {
770 for(const auto& i : *attrs) {
771 OksAttribute::Format format = i->get_format();
772 OksData::Type type = i->get_data_type();
773
774 const_cast< std::vector<dunedaq::conffwk::attribute_t>& >(d->p_attributes).push_back(
776 i->get_name(),
777 (
794 ),
795 i->get_range(),
796 (
797 i->is_integer() == false ? dunedaq::conffwk::na_int_format :
798 (
802 )
803 ),
804 i->get_is_no_null(),
805 i->get_is_multi_values(),
806 i->get_init_value(),
807 i->get_description()
808 )
809 );
810
811 }
812 }
813
814 if(const std::list<OksRelationship *> * rels = (direct_only ? c->direct_relationships() : c->all_relationships())) {
815 for(const auto& i : *rels) {
816 const_cast< std::vector<dunedaq::conffwk::relationship_t>& >(d->p_relationships).push_back(
818 i->get_name(),
819 i->get_type(),
820 (i->get_low_cardinality_constraint() == OksRelationship::Zero),
821 (i->get_high_cardinality_constraint() == OksRelationship::Many),
822 i->get_is_composite(),
823 i->get_description()
824 )
825 );
826 }
827 }
828
829 return d;
830}
Try to access non-existent object or class.
Definition Errors.hpp:47
std::list< OksClass *, boost::fast_pool_allocator< OksClass * > > FList
Definition class.hpp:235

◆ get() [3/4]

void dunedaq::oksconflibs::OksConfiguration::get ( const std::string & class_name,
const std::string & id,
conffwk::ConfigObject & object,
unsigned long rlevel,
const std::vector< std::string > * rclasses )
virtual

Get object of class by id.

Implements dunedaq::conffwk::ConfigurationImpl.

Definition at line 636 of file OksConfiguration.cpp.

638{
639 if (OksClass * cl = m_kernel->find_class(class_name))
640 {
641 OksObject * obj = cl->get_object(name);
642 if (obj == nullptr)
643 {
644 // try all subclasses
645 if (const OksClass::FList *subclasses = cl->all_sub_classes())
646 {
647 for (const auto& it : *subclasses)
648 {
649 obj = it->get_object(name);
650 if (obj != nullptr)
651 break;
652 }
653 }
654 if (obj == nullptr)
655 {
656 const std::string id(name + '@' + class_name);
657 throw dunedaq::conffwk::NotFound(ERS_HERE, "object", id.c_str());
658 }
659 }
660
661 object = new_object(obj);
662 }
663 else
664 {
665 throw dunedaq::conffwk::NotFound(ERS_HERE, "class", class_name.c_str());
666 }
667}

◆ get() [4/4]

void OksConfiguration::get ( const std::string & class_name,
std::vector< conffwk::ConfigObject > & objects,
const std::string & query,
unsigned long rlevel,
const std::vector< std::string > * rclasses )
virtual

Definition at line 670 of file OksConfiguration.cpp.

671{
672 if(OksClass * cl = m_kernel->find_class(class_name)) {
673 objects.clear();
674
675 OksObject::List * objs = 0;
676
677 if(query.empty()) {
678 objs = cl->create_list_of_all_objects();
679 }
680 else {
681 try {
682 std::unique_ptr<OksQuery> qe(new OksQuery(cl, query.c_str()));
683 if(qe->good() == false) {
684 std::ostringstream text;
685 text << "bad query syntax \"" << query << "\" in scope of class \"" << class_name << '\"';
686 throw dunedaq::conffwk::Generic( ERS_HERE, text.str().c_str());
687 }
688 objs = cl->execute_query(qe.get()); // FIXME: check .get()
689 }
690 catch(oks::exception& ex) {
691 std::ostringstream text;
692 text << "failed to execute query:\n" << ex.what();
693 throw dunedaq::conffwk::Generic(ERS_HERE, text.str().c_str());
694 }
695 }
696
697 if(objs) {
698 for(OksObject::List::iterator i = objs->begin(); i != objs->end(); ++i) {
699 objects.push_back(new_object(*i));
700 }
701 delete objs;
702 }
703 }
704 else {
705 throw dunedaq::conffwk::NotFound(ERS_HERE, "class", class_name.c_str());
706 }
707}
OKS query class.
Definition query.hpp:36

◆ get_changes()

std::vector< dunedaq::conffwk::Version > dunedaq::oksconflibs::OksConfiguration::get_changes ( )
virtual

Get newly available versions.

Implements dunedaq::conffwk::ConfigurationImpl.

Definition at line 547 of file OksConfiguration.cpp.

548{
549 if (!m_kernel->get_repository_root().empty())
550 {
551 try
552 {
554 }
555 catch (const oks::exception& ex)
556 {
557 throw(dunedaq::conffwk::Generic(ERS_HERE, "cannot get new versions", ex));
558 }
559 }
560 else
561 {
562 std::vector<dunedaq::conffwk::Version> out;
563
564 std::set<OksFile *> oks_files;
565 m_kernel->get_modified_files(oks_files, oks_files, "");
566
567 if (!oks_files.empty())
568 {
569 std::vector<std::string> files;
570
571 for(const auto& x : oks_files)
572 files.push_back(x->get_well_formed_name());
573
574 out.emplace_back("", "", 0, "", files);
575 }
576
577 return out;
578 }
579}
static const std::string & get_repository_root()
Get OKS repository root.
Definition kernel.cpp:304
std::vector< OksRepositoryVersion > get_repository_versions_by_hash(bool skip_irrelevant=true, const std::string &sha1="", const std::string &sha2="")
Return repository versions between hash keys.
Definition kernel.cpp:5450
static std::vector< dunedaq::conffwk::Version > oks2config(const std::vector< OksRepositoryVersion > &in)
FELIX Initialization std::string initerror FELIX queue timed out

◆ get_includes()

void OksConfiguration::get_includes ( const std::string & db_name,
std::list< std::string > & includes ) const
virtual

Get included files.

Implements dunedaq::conffwk::ConfigurationImpl.

Definition at line 1214 of file OksConfiguration.cpp.

1215{
1216 if (db_name.empty())
1217 {
1218 for (auto& i : m_kernel->data_files())
1219 {
1220 if(i.second->get_parent() == nullptr)
1221 includes.push_back(*i.first);
1222 }
1223 }
1224 else
1225 {
1226 if (OksFile * h = m_kernel->find_data_file(db_name))
1227 {
1228 for (auto& i : h->get_include_files())
1229 {
1230 includes.push_back(i);
1231 }
1232 }
1233 else
1234 {
1235 throw(dunedaq::conffwk::Generic( ERS_HERE, mk_no_file_error_text(db_name).c_str() ) );
1236 }
1237 }
1238}

◆ get_oks_kernel()

const oks::OksKernel & dunedaq::oksconflibs::OksConfiguration::get_oks_kernel ( ) const
inline

Definition at line 93 of file OksConfiguration.hpp.

93{ return *m_kernel; } // required by Java oksconflibs

◆ get_superclasses()

void OksConfiguration::get_superclasses ( conffwk::fmap< conffwk::fset > & schema)
virtual

Get inheritance hierarchy.

Implements dunedaq::conffwk::ConfigurationImpl.

Definition at line 833 of file OksConfiguration.cpp.

834{
835 schema.clear();
836
837 if(!m_kernel) {
838 return; // throw ( dunedaq::conffwk::Generic( ERS_HERE, "database is not loaded" ) );
839 }
840
841 schema.reserve(m_kernel->classes().size() * 3);
842
843 for(OksClass::Map::const_iterator i = m_kernel->classes().begin(); i != m_kernel->classes().end(); ++i) {
844 if(const OksClass::FList * scl = i->second->all_super_classes()) {
845 const std::string* name = &conffwk::DalFactory::instance().get_known_class_name_ref(i->second->get_name());
846
847 auto& subclasses = schema[name];
848
849 if(!scl->empty()) {
850 subclasses.reserve(scl->size() * 3);
851 for(OksClass::FList::const_iterator j = scl->begin(); j != scl->end(); ++j) {
852 subclasses.insert(&conffwk::DalFactory::instance().get_known_class_name_ref((*j)->get_name()));
853 }
854 }
855 }
856 }
857}
const OksClass::Map & classes() const
Get classes.
Definition kernel.hpp:1767

◆ get_updated_dbs()

void OksConfiguration::get_updated_dbs ( std::list< std::string > & dbs) const
virtual

Get uncommitted files.

Implements dunedaq::conffwk::ConfigurationImpl.

Definition at line 340 of file OksConfiguration.cpp.

341{
342 for (const auto& i : m_kernel->data_files())
343 {
344 if (i.second->is_updated())
345 dbs.push_back(i.second->get_full_file_name());
346 }
347}

◆ get_versions()

std::vector< dunedaq::conffwk::Version > dunedaq::oksconflibs::OksConfiguration::get_versions ( const std::string & since,
const std::string & until,
dunedaq::conffwk::Version::QueryType type,
bool skip_irrelevant )
virtual

Get archived versions.

Implements dunedaq::conffwk::ConfigurationImpl.

Definition at line 583 of file OksConfiguration.cpp.

584{
585 if (!m_kernel->get_repository_root().empty())
586 {
587 try
588 {
589 return oks2config(type == dunedaq::conffwk::Version::query_by_date ? m_kernel->get_repository_versions_by_date(skip_irrelevant, since, until) : m_kernel->get_repository_versions_by_hash(skip_irrelevant, since, until));
590 }
591 catch (const oks::exception& ex)
592 {
593 throw(dunedaq::conffwk::Generic(ERS_HERE, "cannot get repository versions", ex));
594 }
595 }
596 else
597 {
598 throw(dunedaq::conffwk::Generic(ERS_HERE, "cannot get versions, repository is not set"));
599 }
600}
std::vector< OksRepositoryVersion > get_repository_versions_by_date(bool skip_irrelevant=true, const std::string &since="", const std::string &until="")
Return repository versions between timestamps.
Definition kernel.cpp:5486

◆ init_env()

void OksConfiguration::init_env ( )
protected

Definition at line 1438 of file OksConfiguration.cpp.

1439{
1440 m_oks_kernel_silence = (getenv("OKSCONFLIBS_NO_KERNEL_SILENCE") == nullptr);
1441}

◆ is_writable()

bool OksConfiguration::is_writable ( const std::string & db_name)
virtual

Return write access status.

Implements dunedaq::conffwk::ConfigurationImpl.

Definition at line 1111 of file OksConfiguration.cpp.

1112{
1113 if (OksFile * h = m_kernel->find_data_file(db_name))
1114 {
1115 try
1116 {
1117 if (!m_kernel->get_user_repository_root().empty())
1118 {
1120 }
1121 else
1122 {
1123 return !OksKernel::check_read_only(h);
1124 }
1125 }
1126 catch (const std::exception& ex)
1127 {
1128 std::ostringstream text;
1129 text << "cannot check access status of file \'" << db_name << "\': " << ex.what();
1130 throw ( dunedaq::conffwk::Generic( ERS_HERE, text.str().c_str() ) );
1131 }
1132 }
1133 else
1134 {
1135 throw ( dunedaq::conffwk::Generic( ERS_HERE, mk_no_file_error_text(db_name).c_str() ) );
1136 }
1137}
static bool check_read_only(OksFile *f)
Check if the OKS file is read-only.
Definition kernel.cpp:1532
bool is_writable(const oks::OksFile &file, const std::string &user=oks::OksKernel::get_user_name())
Definition oks_access.cpp:8

◆ loaded()

virtual bool dunedaq::oksconflibs::OksConfiguration::loaded ( ) const
inlinevirtualnoexcept

Check if a database is loaded.

Implements dunedaq::conffwk::ConfigurationImpl.

Definition at line 60 of file OksConfiguration.hpp.

60{ return (m_kernel != 0); }

◆ new_object()

dunedaq::oksconflibs::OksConfigObject * dunedaq::oksconflibs::OksConfiguration::new_object ( oks::OksObject * obj)
protectednoexcept

Definition at line 605 of file OksConfiguration.cpp.

606{
607 return insert_object<dunedaq::oksconflibs::OksConfigObject>(obj, obj->GetId(), obj->GetClass()->get_name());
608}
T * insert_object(OBJ &obj, const std::string &id, const std::string &class_name) noexcept
insert new object (update cache or create-and-insert)

◆ open_db()

void OksConfiguration::open_db ( const std::string & db_name)
virtual

Open database implementation in accordance with given name.

Implements dunedaq::conffwk::ConfigurationImpl.

Definition at line 155 of file OksConfiguration.cpp.

156{
157 // separate parameters first
158
159 std::string::size_type idx = spec_params.find_first_of('&');
160
161 std::string data, params;
162
163 if (idx == std::string::npos)
164 {
165 data = spec_params;
166 }
167 else
168 {
169 data = spec_params.substr(0, idx);
170 params = spec_params.substr(idx + 1);
171 }
172
173 std::string token;
174
175 // guess about oks kernel mode based on the file names
176
177 {
178 Oks::Tokenizer t(data, ":");
179
180 while (!(token = t.next()).empty())
181 {
182 if (is_repo_name(token) == false)
184 }
185 }
186
187 // create OKS kernel if it was not created
188
189 if (m_kernel == nullptr)
190 {
191 if (!params.empty())
192 {
193 Oks::Tokenizer t(params, ";");
194
195 while (!(token = t.next()).empty())
196 {
197 if(token == "norepo")
199 }
200 }
201
203 }
204
205 Oks::Tokenizer t(data, ":");
206
207 while(!(token = t.next()).empty()) {
208 try {
209 m_kernel->load_file(token);
210 }
211 catch (oks::exception & e) {
212 std::ostringstream text;
213 text << "cannot load file \'" << token << "\':\n" << e.what();
214 close_db();
215 throw ( dunedaq::conffwk::Generic( ERS_HERE, text.str().c_str() ) );
216 }
217 catch (...) {
218 std::ostringstream text;
219 text << "cannot load file \'" << token << '\'';
220 close_db();
221 throw ( dunedaq::conffwk::Generic( ERS_HERE, text.str().c_str() ) );
222 }
223 }
224}
OksFile * load_file(const std::string &name, bool bind=true)
Load OKS database file.
Definition kernel.cpp:1788
String tokenizer.
Definition defs.hpp:58

◆ prefetch_all_data()

virtual void dunedaq::oksconflibs::OksConfiguration::prefetch_all_data ( )
inlinevirtual

Prefetch all data into client cache.

Implements dunedaq::conffwk::ConfigurationImpl.

Definition at line 70 of file OksConfiguration.hpp.

70{ ; } // nothing to do with OKS data already in-memory

◆ print_profiling_info()

void OksConfiguration::print_profiling_info ( )
virtualnoexcept

Print implementation specific profiling information.

Implements dunedaq::conffwk::ConfigurationImpl.

Definition at line 1424 of file OksConfiguration.cpp.

1425{
1426 std::cout <<
1427 "OksConfiguration profiler report:\n"
1428 " number of loaded schema files: " << (m_kernel ? m_kernel->schema_files().size() : 0) << "\n"
1429 " number of loaded data files: " << (m_kernel ? m_kernel->data_files().size() : 0) << "\n"
1430 " number of loaded classes: " << (m_kernel ? m_kernel->classes().size() : 0) << "\n"
1431 " number of loaded objects: " << (m_kernel ? m_kernel->objects().size() : 0) << std::endl;
1432}
const OksObject::Set & objects() const
Get objects.
Definition kernel.hpp:1790
const OksFile::Map & schema_files() const
Get all schema files.
Definition kernel.hpp:1223
FELIX Initialization std::string initerror FELIX queue timed std::string queuename Unexpected chunk size

◆ remove_include()

void OksConfiguration::remove_include ( const std::string & db_name,
const std::string & include )
virtual

Remove include file.

Implements dunedaq::conffwk::ConfigurationImpl.

Definition at line 1172 of file OksConfiguration.cpp.

1173{
1174 InheritanceData inheritance(*m_kernel);
1175
1176 DestroyGuard2 dg2(m_removed); // => on exit from method, call m_removed.clear();
1177
1178 if(OksFile * h = m_kernel->find_data_file(db_name)) {
1179 try {
1180 m_kernel->subscribe_delete_object(delete_notify, reinterpret_cast<void *>(this));
1181 DestroyGuard1 dg1(*m_kernel); // => on exit from try block, call m_kernel->subscribe_delete_object(0, 0);
1182 h->remove_include_file(include);
1183 }
1184 catch(dunedaq::conffwk::Generic& ex) {
1185 throw ( dunedaq::conffwk::Generic( ERS_HERE, mk_rm_include_error_text(db_name, include).c_str() ), ex );
1186 }
1187 catch (oks::exception & ex) {
1188 throw ( dunedaq::conffwk::Generic( ERS_HERE, mk_rm_include_error_text(db_name, include, ex.what()).c_str() ) );
1189 }
1190 catch (...) {
1191 throw ( dunedaq::conffwk::Generic( ERS_HERE, mk_rm_include_error_text(db_name, include).c_str() ) );
1192 }
1193 }
1194 else {
1195 throw ( dunedaq::conffwk::Generic( ERS_HERE, mk_no_file_error_text(db_name).c_str() ) );
1196 }
1197
1198 std::vector<conffwk::ConfigurationChange *> changes;
1199
1200 for(SMap::iterator i = m_removed.begin(); i != m_removed.end(); ++i) {
1201 for(std::set<std::string>::const_iterator j = i->second.begin(); j != i->second.end(); ++j) {
1202 check(changes, inheritance, m_class_names, m_objects, i->first, *j, '-');
1203 }
1204 }
1205
1206 if(!changes.empty()) {
1207 m_conf->update_cache(changes);
1209 }
1210}
static std::string mk_rm_include_error_text(const std::string &db, const std::string &include, const char *error=0)

◆ set_commit_credentials()

void OksConfiguration::set_commit_credentials ( const std::string & user,
const std::string & password )
virtual

Set commit credentials.

Implements dunedaq::conffwk::ConfigurationImpl.

Definition at line 351 of file OksConfiguration.cpp.

◆ subscribe() [1/2]

void OksConfiguration::subscribe ( )
protected

Definition at line 1394 of file OksConfiguration.cpp.

1395{
1396 if(m_check_db_obj == 0) {
1397 TLOG_DEBUG( 2) << "starting CheckDB thread ..." ;
1399 m_check_db_thread = new std::thread(std::ref(*m_check_db_obj));
1400 }
1401}

◆ subscribe() [2/2]

void OksConfiguration::subscribe ( const std::set< std::string > & class_names,
const SMap & objs,
ConfigurationImpl::notify cb,
ConfigurationImpl::pre_notify pre_cb )
virtual

Definition at line 1378 of file OksConfiguration.cpp.

1382{
1383 m_fn = cb;
1384 m_pre_fn = pre_cb;
1385 m_class_names = class_names;
1386 m_objects = objs;
1387
1388 subscribe();
1389}
conffwk::ConfigurationImpl::pre_notify m_pre_fn

◆ test_object()

bool OksConfiguration::test_object ( const std::string & class_name,
const std::string & id,
unsigned long rlevel,
const std::vector< std::string > * rclasses )
virtual

Test object existence (used by Python binding)

Implements dunedaq::conffwk::ConfigurationImpl.

Definition at line 611 of file OksConfiguration.cpp.

612{
613 // Looking for the class. If it does not exist, we return false.
614 OksClass * cl = m_kernel->find_class(class_name);
615 if (!cl)
616 return false;
617
618 // The object exist for this class?
619 if (cl->get_object(name))
620 return true;
621
622 // Trying all subclasses
623 if (const OksClass::FList * subclasses = cl->all_sub_classes())
624 {
625 for (OksClass::FList::const_iterator it = subclasses->begin(); it != subclasses->end(); ++it)
626 {
627 if ((*it)->get_object(name))
628 return true;
629 }
630 }
631 // If we get here, we found the class, but not the object.
632 return false;
633}
const FList * all_sub_classes() const noexcept
Definition class.hpp:466
OksObject * get_object(const std::string &id) const noexcept
Get object by ID.
Definition class.cpp:1521

◆ unsubscribe()

void OksConfiguration::unsubscribe ( )
virtual

Remove subscription on database changes.

Implements dunedaq::conffwk::ConfigurationImpl.

Definition at line 1409 of file OksConfiguration.cpp.

1410{
1411 if(m_check_db_obj) {
1412 TLOG_DEBUG( 2) << "stopping CheckDB thread ..." ;
1413 m_check_db_obj->m_run = false;
1414 m_check_db_thread->join(); // wait thread termination
1415 delete m_check_db_thread;
1417 m_check_db_obj = 0;
1418 TLOG_DEBUG( 2) << "the CheckDB thread has been terminated" ;
1419 }
1420}

Friends And Related Symbol Documentation

◆ OksConfigObject

friend class OksConfigObject
friend

Definition at line 34 of file OksConfiguration.hpp.

◆ OksConfigurationCheckDB

friend struct OksConfigurationCheckDB
friend

Definition at line 35 of file OksConfiguration.hpp.

◆ ResubscribeGuard

friend class ResubscribeGuard
friend

Definition at line 36 of file OksConfiguration.hpp.

Member Data Documentation

◆ m_check_db_obj

OksConfigurationCheckDB* dunedaq::oksconflibs::OksConfiguration::m_check_db_obj
protected

Definition at line 127 of file OksConfiguration.hpp.

◆ m_check_db_thread

std::thread* dunedaq::oksconflibs::OksConfiguration::m_check_db_thread
protected

Definition at line 128 of file OksConfiguration.hpp.

◆ m_class_names

std::set<std::string> dunedaq::oksconflibs::OksConfiguration::m_class_names
protected

Definition at line 101 of file OksConfiguration.hpp.

◆ m_created

std::list<oks::OksObject *> dunedaq::oksconflibs::OksConfiguration::m_created
protected

Definition at line 117 of file OksConfiguration.hpp.

◆ m_created_files

std::set<oks::OksFile *> dunedaq::oksconflibs::OksConfiguration::m_created_files
protected

Definition at line 136 of file OksConfiguration.hpp.

◆ m_fn

conffwk::ConfigurationImpl::notify dunedaq::oksconflibs::OksConfiguration::m_fn
protected

Definition at line 99 of file OksConfiguration.hpp.

◆ m_kernel

oks::OksKernel* dunedaq::oksconflibs::OksConfiguration::m_kernel
protected

Definition at line 98 of file OksConfiguration.hpp.

◆ m_modified

std::set<oks::OksObject *> dunedaq::oksconflibs::OksConfiguration::m_modified
protected

Definition at line 118 of file OksConfiguration.hpp.

◆ m_objects

SMap dunedaq::oksconflibs::OksConfiguration::m_objects
protected

Definition at line 102 of file OksConfiguration.hpp.

◆ m_oks_kernel_no_repo

bool dunedaq::oksconflibs::OksConfiguration::m_oks_kernel_no_repo
protected

Definition at line 104 of file OksConfiguration.hpp.

◆ m_oks_kernel_silence

bool dunedaq::oksconflibs::OksConfiguration::m_oks_kernel_silence
protected

Definition at line 103 of file OksConfiguration.hpp.

◆ m_password

std::string dunedaq::oksconflibs::OksConfiguration::m_password
protected

Definition at line 131 of file OksConfiguration.hpp.

◆ m_pre_fn

conffwk::ConfigurationImpl::pre_notify dunedaq::oksconflibs::OksConfiguration::m_pre_fn
protected

Definition at line 100 of file OksConfiguration.hpp.

◆ m_removed

std::map<std::string, std::set<std::string> > dunedaq::oksconflibs::OksConfiguration::m_removed
protected

Definition at line 119 of file OksConfiguration.hpp.

◆ m_repo_error_count

unsigned int dunedaq::oksconflibs::OksConfiguration::m_repo_error_count
protected

Definition at line 141 of file OksConfiguration.hpp.

◆ m_user

std::string dunedaq::oksconflibs::OksConfiguration::m_user
protected

Definition at line 130 of file OksConfiguration.hpp.


The documentation for this class was generated from the following files: