DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dbe::confaccessor Class Reference

#include <confaccessor.hpp>

Inheritance diagram for dbe::confaccessor:
[legend]
Collaboration diagram for dbe::confaccessor:
[legend]

Public Types

typedef config_internal_change t_internal_change
typedef std::stack< t_internal_change, std::vector< t_internal_change > > t_internal_changes_stack
typedef cptr< t_internal_changes_stack > t_internal_changes_stack_cptr
typedef QUndoStack t_undo_stack
typedef cptr< t_undo_stack > t_undo_stack_cptr

Public Slots

void GetFileCache (QList< QStringList > &FileCache)

Signals

void object_created (QString const &source, dref const &obj)
void object_renamed (QString const &source, dref const &obj)
void object_changed (QString const &source, dref const &obj)
void object_deleted (QString const &source, dref const &obj)
void db_committed (const std::list< std::string > &files, const std::string &msg)
void IncludeFileDone ()
void RemoveFileDone ()
void ResetTree ()
void ExternalChangesDetected ()
void ExternalChangesAccepted ()

Public Member Functions

 ~confaccessor ()
void force_emit_object_created (QString const &, dref const)
void force_emit_object_deleted (QString const &, dref const)
void force_emit_object_renamed (QString const &, dref const)
void force_emit_object_changed (QString const &, dref const)
QList< QStringList > GetIncludedFileCache () const
void addfile (std::string const &db, std::string const &fn)
void removefile (std::string const &db, std::string const &fn)

Static Public Member Functions

static confaccessor & ref ()
static void init ()
static bool load (bool subscribeToChanges=true)
static void abort ()
static bool is_database_loaded ()
static bool enabled ()
static std::list< std::string > save (QString const &)
static cptr< datahandler > gethandler ()
static cptr< ui::config::info > guiconfig ()
static t_undo_stack_cptr get_commands ()
static void clear_commands ()
static t_internal_changes_stack_cptr get_internal_change_stack ()
static void setdbinfo (QString const &location, dbinfo const itype=dbinfo::oks)
static void setdblocation (const QString &Implementation)
static bool check_file_rw (const QString &FileName)
static QString dbfullname ()
static QString db_implementation_name ()
static void CallbackFunction (const std::vector< dunedaq::conffwk::ConfigurationChange * > &changes, void *parameter)
static void unsubscribe ()
static std::list< std::string > uncommitted_files ()
static int get_total_objects ()
static void set_total_objects (int const i)
static void increase_total_objects (int const i)

Private Types

typedef std::mutex t_mutex
typedef std::lock_guard< t_mutex > t_lock
typedef std::vector< ConfigWrapperExternalChange > t_external_changes_stack

Private Member Functions

void setenabled ()
void setdisabled ()
template<dbinfo N>
void set_dbinfo (QString const &p)
void docallback (std::vector< dunedaq::conffwk::ConfigurationChange * > const &changes, void *parameter)
 confaccessor ()
 confaccessor (confaccessor const &)=delete
confaccessor & operator= (confaccessor const &)=delete

Private Attributes

QString this_dblocation
QString this_resource_location
dunedaq::conffwk::Configuration::CallbackId CallId
std::shared_ptr< t_internal_changes_stack > internal_change_stack
t_external_changes_stack external_change_stack
t_undo_stack * sequenced_command_stack
datahandler * editconfig
ui::config::info * coreconfig
QList< QStringList > IncludedFileCache
t_mutex this_change_enabled_mutex
t_mutex mut_changes
t_mutex force_mut
bool this_change_enabled
int this_total_objects

Friends

class dbaccessor

Detailed Description

Definition at line 62 of file confaccessor.hpp.

Member Typedef Documentation

◆ t_external_changes_stack

Definition at line 232 of file confaccessor.hpp.

◆ t_internal_change

◆ t_internal_changes_stack

Definition at line 67 of file confaccessor.hpp.

◆ t_internal_changes_stack_cptr

◆ t_lock

typedef std::lock_guard<t_mutex> dbe::confaccessor::t_lock
private

Definition at line 230 of file confaccessor.hpp.

◆ t_mutex

typedef std::mutex dbe::confaccessor::t_mutex
private

Definition at line 229 of file confaccessor.hpp.

◆ t_undo_stack

typedef QUndoStack dbe::confaccessor::t_undo_stack

Definition at line 70 of file confaccessor.hpp.

◆ t_undo_stack_cptr

Constructor & Destructor Documentation

◆ ~confaccessor()

dbe::confaccessor::~confaccessor ( )

Definition at line 57 of file confaccessor.cpp.

58{
59 delete editconfig;
60 delete coreconfig;
61 {
63 delete dbholder::database;
64 }
65}
datahandler * editconfig
ui::config::info * coreconfig
dbe::types::common::type_lock t_lock
static dunedaq::conffwk::Configuration * database
static dbe::types::common::type_mutex database_lock

◆ confaccessor() [1/2]

dbe::confaccessor::confaccessor ( )
private

Definition at line 46 of file confaccessor.cpp.

47 : CallId(nullptr)
49 , sequenced_command_stack(new QUndoStack())
50 , editconfig(new datahandler())
51 , coreconfig(nullptr)
52 , this_change_enabled(false)
54{
55}
std::stack< t_internal_change, std::vector< t_internal_change > > t_internal_changes_stack
t_undo_stack * sequenced_command_stack
std::shared_ptr< t_internal_changes_stack > internal_change_stack
dunedaq::conffwk::Configuration::CallbackId CallId

◆ confaccessor() [2/2]

dbe::confaccessor::confaccessor ( confaccessor const & )
privatedelete

Member Function Documentation

◆ abort()

void dbe::confaccessor::abort ( )
static

Abort all database changes

Definition at line 296 of file confaccessor.cpp.

297{
298 dbaccessor::dbptr()->abort();
299}
static cptr< dunedaq::conffwk::Configuration > dbptr()

◆ addfile()

void dbe::confaccessor::addfile ( std::string const & db,
std::string const & fn )

Definition at line 401 of file confaccessor.cpp.

402{
403 if (not enabled()) {
404 throw daq::dbe::ChangeNotAllowed(ERS_HERE);
405 }
406
407 dbaccessor::dbptr()->add_include(db, fn);
408 emit IncludeFileDone();
409}
#define ERS_HERE
static bool enabled()

◆ CallbackFunction()

void dbe::confaccessor::CallbackFunction ( const std::vector< dunedaq::conffwk::ConfigurationChange * > & changes,
void * parameter )
static

Definition at line 426 of file confaccessor.cpp.

427{
428 dbe::confaccessor::ref().docallback(changes, parameter);
429}
void docallback(std::vector< dunedaq::conffwk::ConfigurationChange * > const &changes, void *parameter)
static confaccessor & ref()

◆ check_file_rw()

bool dbe::confaccessor::check_file_rw ( const QString & FileName)
static

Definition at line 268 of file confaccessor.cpp.

269{
270 try {
271 if (not fn.endsWith(".schema.xml")) {
272 return dbaccessor::dbptr()->is_writable(fn.toStdString());
273 }
274 } catch (dunedaq::conffwk::Generic const& ex) {
275 ERROR("Not possible to operate on file", dbe::config::errors::parse(ex), "\n\nCheck filename:", fn.toStdString());
276 }
277
278 return false;
279}
#define ERROR(...)
Definition messenger.hpp:90
std::string const parse(ers::Issue const &)

◆ clear_commands()

void dbe::confaccessor::clear_commands ( )
static

Clear internal changes commands

Definition at line 283 of file confaccessor.cpp.

284{
285 if (ref().get_commands().get()) {
286 ref().get_commands()->clear();
287 t_internal_changes_stack cleared{};
288 ref().get_internal_change_stack()->swap(cleared);
289 }
290}
static t_undo_stack_cptr get_commands()
static t_internal_changes_stack_cptr get_internal_change_stack()

◆ db_committed

void dbe::confaccessor::db_committed ( const std::list< std::string > & files,
const std::string & msg )
signal

◆ db_implementation_name()

QString dbe::confaccessor::db_implementation_name ( )
static

Definition at line 141 of file confaccessor.cpp.

142{
144}
QString this_resource_location

◆ dbfullname()

QString dbe::confaccessor::dbfullname ( )
static

Definition at line 135 of file confaccessor.cpp.

136{
137 return ref().this_dblocation;
138}

◆ docallback()

void dbe::confaccessor::docallback ( std::vector< dunedaq::conffwk::ConfigurationChange * > const & changes,
void * parameter )
private

Definition at line 432 of file confaccessor.cpp.

433{
434 Q_UNUSED(parameter);
435
437 external_change_stack.clear();
438
439 for (ConfigurationChange* Change : changes) {
440 const auto& cl = Change->get_class_name();
441 const auto& mod = Change->get_modified_objs();
442 const auto& cre = Change->get_created_objs();
443 const auto& rem = Change->get_removed_objs();
444
445 external_change_stack.push_back({ cl, mod, cre, rem });
446 }
447
449}
std::lock_guard< t_mutex > t_lock
void ExternalChangesAccepted()
t_external_changes_stack external_change_stack

◆ enabled()

bool dbe::confaccessor::enabled ( )
static

Check if changes are allowed

Returns
true in case changes are allowed

Definition at line 71 of file confaccessor.cpp.

◆ ExternalChangesAccepted

void dbe::confaccessor::ExternalChangesAccepted ( )
signal

◆ ExternalChangesDetected

void dbe::confaccessor::ExternalChangesDetected ( )
signal

◆ force_emit_object_changed()

void dbe::confaccessor::force_emit_object_changed ( QString const & src,
dref const obj )

Force emit an object changed signal from this object

Parameters
UUIDstring representation of the object causing the creation
theobject that was changed

Definition at line 116 of file confaccessor.cpp.

117{
119 emit object_changed(src, obj);
120}
void object_changed(QString const &source, dref const &obj)

◆ force_emit_object_created()

void dbe::confaccessor::force_emit_object_created ( QString const & src,
dref const obj )

Force emit a creation signal from this object

Definition at line 95 of file confaccessor.cpp.

96{
98 emit object_created(src, obj);
99}
void object_created(QString const &source, dref const &obj)

◆ force_emit_object_deleted()

void dbe::confaccessor::force_emit_object_deleted ( QString const & src,
dref const obj )

Force emit that an object has been deleted

Parameters must be passed by value, because this signal may be emitted from other than QThreads threads, which may cause a temporary to die prematurely in the other thread.

Parameters
UUIDstring representation of the object causing the creation
adescription of the object having be created

Definition at line 109 of file confaccessor.cpp.

110{
112 emit object_deleted(src, obj);
113}
void object_deleted(QString const &source, dref const &obj)

◆ force_emit_object_renamed()

void dbe::confaccessor::force_emit_object_renamed ( QString const & src,
dref const obj )

Force emit that an object has been renamed

Parameters
UUIDstring representation of the object causing the creation
adescription of the object having be changed, actually contains the original name

Definition at line 102 of file confaccessor.cpp.

103{
105 emit object_renamed(src, obj);
106}
void object_renamed(QString const &source, dref const &obj)

◆ get_commands()

dbe::confaccessor::t_undo_stack_cptr dbe::confaccessor::get_commands ( )
static

Get a thread safe pointer to the internal command stack

Returns

Definition at line 164 of file confaccessor.cpp.

165{
167 return rp;
168}
cptr< t_undo_stack > t_undo_stack_cptr

◆ get_internal_change_stack()

dbe::confaccessor::t_internal_changes_stack_cptr dbe::confaccessor::get_internal_change_stack ( )
static

Get a thread safe pointer to the internal change stack

Returns

Definition at line 463 of file confaccessor.cpp.

464{
466 return rp;
467}
cptr< t_internal_changes_stack > t_internal_changes_stack_cptr

◆ get_total_objects()

int dbe::confaccessor::get_total_objects ( )
static

Definition at line 174 of file confaccessor.cpp.

175{
176 return ref().this_total_objects;
177}

◆ GetFileCache

void dbe::confaccessor::GetFileCache ( QList< QStringList > & FileCache)
slot

Definition at line 126 of file confaccessor.cpp.

127{
128 IncludedFileCache = FileCache;
129}
QList< QStringList > IncludedFileCache

◆ gethandler()

cptr< dbe::datahandler > dbe::confaccessor::gethandler ( )
static

Get a thread safe pointer to the data handler

Returns
returns a thread safe pointer

Definition at line 150 of file confaccessor.cpp.

151{
152 static cptr<datahandler> r(ref().editconfig);
153 return r;
154}

◆ GetIncludedFileCache()

QList< QStringList > dbe::confaccessor::GetIncludedFileCache ( ) const

Definition at line 392 of file confaccessor.cpp.

393{
394 return IncludedFileCache;
395}

◆ guiconfig()

cptr< dbe::ui::config::info > dbe::confaccessor::guiconfig ( )
static

Access the default oks configuration type information

Returns

Definition at line 157 of file confaccessor.cpp.

158{
159 static cptr<dbe::ui::config::info> r(confaccessor::ref().coreconfig);
160 return r;
161}

◆ IncludeFileDone

void dbe::confaccessor::IncludeFileDone ( )
signal

◆ increase_total_objects()

void dbe::confaccessor::increase_total_objects ( int const i)
static

Definition at line 180 of file confaccessor.cpp.

181{
182 ref().this_total_objects += i;
183}

◆ init()

void dbe::confaccessor::init ( )
static

Must be called to read default OKS configuration type information

Definition at line 364 of file confaccessor.cpp.

365{
366 QString DUNEDAQ_DB_PATH = getenv("DUNEDAQ_DB_PATH");
367 QString GUI_DATA = getenv("OKS_GUI_INIT_DATA");
368
369 QStringList CONFIG_DATABASE = GUI_DATA.split(":", Qt::SkipEmptyParts);
370 QStringList DUNEDAQ_DB_PATH_SPLIT = DUNEDAQ_DB_PATH.split(":", Qt::SkipEmptyParts);
371
372 // We need to read the current configuration ( to retrieve parameters affecting dbe )
373
374 std::vector<std::string> full_path_names;
375
376 for (QString& FileName : CONFIG_DATABASE) {
377
378 for (QString& PATH : DUNEDAQ_DB_PATH_SPLIT) {
379 QFileInfo CheckFile(PATH + "/" + FileName);
380
381 if (CheckFile.exists() and CheckFile.isFile()) {
382 QString fullpathname = PATH + "/" + FileName;
383 full_path_names.push_back(fullpathname.toStdString());
384 }
385 }
386 }
387
388 confaccessor::ref().coreconfig = new ui::config::info(full_path_names);
389}

◆ is_database_loaded()

bool dbe::confaccessor::is_database_loaded ( )
static

Check if the underlying database is actually loaded

Returns
true when the database is loaded

Definition at line 259 of file confaccessor.cpp.

260{
261 return dbaccessor::dbptr().get() != nullptr;
262}
T * get()
Definition cptr.hpp:87

◆ load()

bool dbe::confaccessor::load ( bool subscribeToChanges = true)
static

Load the database from the already specified source

Returns
true when the database has been loaded

Definition at line 312 of file confaccessor.cpp.

313{
314 try {
316
317 if (dbholder::database == nullptr) {
319
320 if (subscribeToChanges == true) {
321 ref().CallId = dbholder::database->subscribe(ConfigurationSubscriptionCriteria(),
323 reinterpret_cast<void*>(dbholder::database));
324 }
325 } else {
327 delete dbholder::database;
329 }
330
332
334 return true;
335 } catch (dunedaq::conffwk::Exception const& e) {
336 FAIL("Database loading failed", dbe::config::errors::parse(e).c_str());
337 return false;
338 }
339}
cptr(T *p)
Definition cptr.hpp:63
static void CallbackFunction(const std::vector< dunedaq::conffwk::ConfigurationChange * > &changes, void *parameter)
static cptr< dunedaq::conffwk::Configuration > database_concurrent_ptr
void prefetch_all_data()
Prefetch all data into client cache.
CallbackId subscribe(const ConfigurationSubscriptionCriteria &criteria, notify user_cb, void *user_param=nullptr)
Subscribe on configuration changes.
#define FAIL(...)

◆ object_changed

void dbe::confaccessor::object_changed ( QString const & source,
dref const & obj )
signal

◆ object_created

void dbe::confaccessor::object_created ( QString const & source,
dref const & obj )
signal

◆ object_deleted

void dbe::confaccessor::object_deleted ( QString const & source,
dref const & obj )
signal

◆ object_renamed

void dbe::confaccessor::object_renamed ( QString const & source,
dref const & obj )
signal

◆ operator=()

confaccessor & dbe::confaccessor::operator= ( confaccessor const & )
privatedelete

◆ ref()

dbe::confaccessor & dbe::confaccessor::ref ( )
static

Retrieve a reference to this singleton

Returns
a reference to this

Definition at line 37 of file confaccessor.cpp.

38{
39 static confaccessor me;
40 return me;
41}

◆ removefile()

void dbe::confaccessor::removefile ( std::string const & db,
std::string const & fn )

Definition at line 412 of file confaccessor.cpp.

413{
414 if (not enabled()) {
415 throw daq::dbe::ChangeNotAllowed(ERS_HERE);
416 }
417
418 dbaccessor::dbptr()->remove_include(db, fn);
419 emit RemoveFileDone();
420}

◆ RemoveFileDone

void dbe::confaccessor::RemoveFileDone ( )
signal

◆ ResetTree

void dbe::confaccessor::ResetTree ( )
signal

◆ save()

std::list< std::string > dbe::confaccessor::save ( QString const & CommitMessage)
static

Commit changes to the database

Parameters
CommitMessageto enter for the database

Definition at line 342 of file confaccessor.cpp.

343{
344 try {
345 std::list<std::string> tobecommited{};
346
347 if (ref().is_database_loaded()) {
348 dbaccessor::dbptr()->get_updated_dbs(tobecommited);
349 dbaccessor::dbptr()->commit(CommitMessage.toStdString());
350 confaccessor::ref().db_committed(tobecommited, CommitMessage.toStdString());
351 }
352
353 return tobecommited;
354 } catch (dunedaq::conffwk::Exception const& e) {
355 // throw daq::dbe::CouldNotCommitChanges ( ERS_HERE, dbe::config::errors::parse ( e ) );
356 throw daq::dbe::CouldNotCommitChanges(ERS_HERE, "confaccessor", e);
357 }
358}
static bool is_database_loaded()
void db_committed(const std::list< std::string > &files, const std::string &msg)

◆ set_dbinfo()

template<dbinfo N>
template void dbe::confaccessor::set_dbinfo< dbinfo::rdb > ( QString const & p)
private

Set database information

Parameters
pthe location string

◆ set_total_objects()

void dbe::confaccessor::set_total_objects ( int const i)
static

Definition at line 186 of file confaccessor.cpp.

187{
189}

◆ setdbinfo()

void dbe::confaccessor::setdbinfo ( QString const & location,
dbinfo const itype = dbinfo::oks )
static

Definition at line 230 of file confaccessor.cpp.

231{
232 switch (itype) {
233
234 case dbinfo::oks:
235 ref().set_dbinfo<dbinfo::oks>(location);
236 break;
237
238 case dbinfo::roks:
239 ref().set_dbinfo<dbinfo::roks>(location);
240 break;
241
242 case dbinfo::rdb:
243 ref().set_dbinfo<dbinfo::rdb>(location);
244 break;
245
246 default:
247 ref().setenabled();
248 break;
249 }
250}
void set_dbinfo(QString const &p)

◆ setdblocation()

void dbe::confaccessor::setdblocation ( const QString & Implementation)
static

Definition at line 253 of file confaccessor.cpp.

254{
255 ref().this_resource_location = Implementation;
256}

◆ setdisabled()

void dbe::confaccessor::setdisabled ( )
private

Definition at line 85 of file confaccessor.cpp.

◆ setenabled()

void dbe::confaccessor::setenabled ( )
private

Definition at line 78 of file confaccessor.cpp.

◆ uncommitted_files()

std::list< std::string > dbe::confaccessor::uncommitted_files ( )
static

Definition at line 302 of file confaccessor.cpp.

303{
304 std::list<std::string> dbs;
305 dbaccessor::dbptr()->get_updated_dbs(dbs);
306 return dbs;
307}

◆ unsubscribe()

void dbe::confaccessor::unsubscribe ( )
static

Definition at line 455 of file confaccessor.cpp.

456{
457 if (dbaccessor::dbptr().get() && ref().CallId != nullptr) {
458 dbaccessor::dbptr()->unsubscribe(ref().CallId);
459 }
460}

◆ dbaccessor

friend class dbaccessor
friend

Definition at line 273 of file confaccessor.hpp.

Member Data Documentation

◆ CallId

dunedaq::conffwk::Configuration::CallbackId dbe::confaccessor::CallId
private

Definition at line 237 of file confaccessor.hpp.

◆ coreconfig

ui::config::info* dbe::confaccessor::coreconfig
private

Definition at line 244 of file confaccessor.hpp.

◆ editconfig

datahandler* dbe::confaccessor::editconfig
private

Definition at line 243 of file confaccessor.hpp.

◆ external_change_stack

t_external_changes_stack dbe::confaccessor::external_change_stack
private

Definition at line 240 of file confaccessor.hpp.

◆ force_mut

t_mutex dbe::confaccessor::force_mut
mutableprivate

Definition at line 250 of file confaccessor.hpp.

◆ IncludedFileCache

QList<QStringList> dbe::confaccessor::IncludedFileCache
private

Definition at line 246 of file confaccessor.hpp.

◆ internal_change_stack

std::shared_ptr<t_internal_changes_stack> dbe::confaccessor::internal_change_stack
private

Definition at line 239 of file confaccessor.hpp.

◆ mut_changes

t_mutex dbe::confaccessor::mut_changes
mutableprivate

Definition at line 249 of file confaccessor.hpp.

◆ sequenced_command_stack

t_undo_stack* dbe::confaccessor::sequenced_command_stack
private

Definition at line 241 of file confaccessor.hpp.

◆ this_change_enabled

bool dbe::confaccessor::this_change_enabled
private

Definition at line 252 of file confaccessor.hpp.

◆ this_change_enabled_mutex

t_mutex dbe::confaccessor::this_change_enabled_mutex
mutableprivate

Definition at line 248 of file confaccessor.hpp.

◆ this_dblocation

QString dbe::confaccessor::this_dblocation
private

Definition at line 234 of file confaccessor.hpp.

◆ this_resource_location

QString dbe::confaccessor::this_resource_location
private

Definition at line 235 of file confaccessor.hpp.

◆ this_total_objects

int dbe::confaccessor::this_total_objects
private

Definition at line 254 of file confaccessor.hpp.


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