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_stackt_internal_changes_stack_cptr
 
typedef QUndoStack t_undo_stack
 
typedef cptr< t_undo_stackt_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 confaccessorref ()
 
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< datahandlergethandler ()
 
static cptr< ui::config::infoguiconfig ()
 
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_mutext_lock
 
typedef std::vector< ConfigWrapperExternalChanget_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
 
confaccessoroperator= (confaccessor const &)=delete
 

Private Attributes

QString this_dblocation
 
QString this_resource_location
 
dunedaq::conffwk::Configuration::CallbackId CallId
 
std::shared_ptr< t_internal_changes_stackinternal_change_stack
 
t_external_changes_stack external_change_stack
 
t_undo_stacksequenced_command_stack
 
datahandlereditconfig
 
ui::config::infocoreconfig
 
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 58 of file confaccessor.hpp.

Member Typedef Documentation

◆ t_external_changes_stack

◆ t_internal_change

◆ t_internal_changes_stack

◆ t_internal_changes_stack_cptr

◆ t_lock

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

Definition at line 230 of file confaccessor.hpp.

◆ t_mutex

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

Definition at line 229 of file confaccessor.hpp.

◆ t_undo_stack

Definition at line 68 of file confaccessor.hpp.

◆ t_undo_stack_cptr

Constructor & Destructor Documentation

◆ ~confaccessor()

dbe::confaccessor::~confaccessor ( )

Definition at line 51 of file confaccessor.cpp.

52{
53 delete editconfig;
54 delete coreconfig;
55 {
57 delete dbholder::database;
58 }
59}
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 40 of file confaccessor.cpp.

41 : CallId ( nullptr ),
43 { } ),
44 sequenced_command_stack ( new QUndoStack() ),
45 editconfig ( new datahandler() ),
46 coreconfig ( nullptr ),
47 this_change_enabled ( false ),
49{}
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 272 of file confaccessor.cpp.

273{
274 dbaccessor::dbptr()->abort();
275}
static cptr< dunedaq::conffwk::Configuration > dbptr()

◆ addfile()

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

Definition at line 386 of file confaccessor.cpp.

387{
388 if ( not enabled() )
389 {
390 throw daq::dbe::ChangeNotAllowed ( ERS_HERE );
391 }
392
393 dbaccessor::dbptr()->add_include ( db, fn );
394 emit IncludeFileDone();
395}
#define ERS_HERE
static bool enabled()

◆ CallbackFunction()

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

Definition at line 411 of file confaccessor.cpp.

414{
415 dbe::confaccessor::ref().docallback ( changes, parameter );
416}
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 240 of file confaccessor.cpp.

241{
242 try
243 {
244 if ( not fn.contains ( "schema" ) )
245 {
246 return dbaccessor::dbptr()->is_writable ( fn.toStdString() );
247 }
248 }
249 catch ( dunedaq::conffwk::Generic const & ex )
250 {
251 ERROR ( "Not possible to operate on file", dbe::config::errors::parse ( ex ),
252 "\n\nCheck filename:", fn.toStdString() );
253 }
254
255 return false;
256}
Generic configuration exception.
#define ERROR(...)
Definition messenger.hpp:88
std::string const parse(ers::Issue const &)

◆ clear_commands()

void dbe::confaccessor::clear_commands ( )
static

Clear internal changes commands

Definition at line 259 of file confaccessor.cpp.

260{
261 if ( ref().get_commands().get() )
262 {
263 ref().get_commands()->clear();
264 t_internal_changes_stack cleared{ };
265 ref().get_internal_change_stack()->swap ( cleared );
266 }
267}
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 125 of file confaccessor.cpp.

126{
128}
QString this_resource_location

◆ dbfullname()

QString dbe::confaccessor::dbfullname ( )
static

Definition at line 120 of file confaccessor.cpp.

121{
122 return ref().this_dblocation;
123}

◆ docallback()

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

Definition at line 418 of file confaccessor.cpp.

420{
421 Q_UNUSED ( parameter );
422
423 t_lock l ( mut_changes );
424 external_change_stack.clear();
425
426 for ( ConfigurationChange * Change : changes )
427 {
428 const auto& cl = Change->get_class_name();
429 const auto& mod = Change->get_modified_objs();
430 const auto& cre = Change->get_created_objs();
431 const auto& rem = Change->get_removed_objs();
432
433 external_change_stack.push_back ( { cl, mod, cre, rem } );
434 }
435
437}
std::lock_guard< t_mutex > t_lock
void ExternalChangesAccepted()
t_external_changes_stack external_change_stack
Describes changes inside a class returned by the notification mechanism.
Definition Change.hpp:35

◆ enabled()

bool dbe::confaccessor::enabled ( )
static

Check if changes are allowed

Returns
true in case changes are allowed

Definition at line 64 of file confaccessor.cpp.

65{
67 return ref().this_change_enabled;
68}
t_mutex this_change_enabled_mutex

◆ 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 103 of file confaccessor.cpp.

104{
105 t_lock l ( force_mut );
106 emit object_changed ( src, obj );
107}
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 85 of file confaccessor.cpp.

86{
87 t_lock l ( force_mut );
88 emit object_created ( src, obj );
89}
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 97 of file confaccessor.cpp.

98{
99 t_lock l ( force_mut );
100 emit object_deleted ( src, obj );
101}
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 91 of file confaccessor.cpp.

92{
93 t_lock l ( force_mut );
94 emit object_renamed ( src, obj );
95}
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 145 of file confaccessor.cpp.

146{
148 return rp;
149}
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 451 of file confaccessor.cpp.

452{
454 return rp;
455}
cptr< t_internal_changes_stack > t_internal_changes_stack_cptr

◆ get_total_objects()

int dbe::confaccessor::get_total_objects ( )
static

Definition at line 154 of file confaccessor.cpp.

155{
156 return ref().this_total_objects;
157}

◆ GetFileCache

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

Definition at line 112 of file confaccessor.cpp.

113{
114 IncludedFileCache = FileCache;
115}
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 133 of file confaccessor.cpp.

134{
135 static cptr<datahandler> r ( ref().editconfig );
136 return r;
137}
Definition cptr.hpp:50

◆ GetIncludedFileCache()

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

Definition at line 378 of file confaccessor.cpp.

379{
380 return IncludedFileCache;
381}

◆ guiconfig()

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

Access the default oks configuration type information

Returns

Definition at line 139 of file confaccessor.cpp.

140{
142 return r;
143}

◆ IncludeFileDone

void dbe::confaccessor::IncludeFileDone ( )
signal

◆ increase_total_objects()

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

Definition at line 159 of file confaccessor.cpp.

160{
161 ref().this_total_objects += i;
162}

◆ init()

void dbe::confaccessor::init ( )
static

Must be called to read default OKS configuration type information

Definition at line 347 of file confaccessor.cpp.

348{
349 QString DUNEDAQ_DB_PATH = getenv ( "DUNEDAQ_DB_PATH" );
350 QString GUI_DATA = getenv ( "OKS_GUI_INIT_DATA" );
351
352 QStringList CONFIG_DATABASE = GUI_DATA.split ( ":", QString::SkipEmptyParts );
353 QStringList DUNEDAQ_DB_PATH_SPLIT = DUNEDAQ_DB_PATH.split ( ":", QString::SkipEmptyParts );
354
355 // We need to read the current configuration ( to retrieve parameters affecting dbe )
356
357 std::vector<std::string> full_path_names;
358
359 for ( QString & FileName : CONFIG_DATABASE )
360 {
361
362 for ( QString & PATH : DUNEDAQ_DB_PATH_SPLIT )
363 {
364 QFileInfo CheckFile ( PATH + "/" + FileName );
365
366 if ( CheckFile.exists() and CheckFile.isFile() )
367 {
368 QString fullpathname = PATH + "/" + FileName;
369 full_path_names.push_back ( fullpathname.toStdString() );
370 }
371 }
372 }
373
374 confaccessor::ref().coreconfig = new ui::config::info ( full_path_names );
375
376}

◆ 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 232 of file confaccessor.cpp.

233{
234 return dbaccessor::dbptr().get() != nullptr;
235}
T * get()
Definition cptr.hpp:83

◆ 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 286 of file confaccessor.cpp.

287{
288 try
289 {
291
292 if ( dbholder::database == nullptr )
293 {
295
296 if ( subscribeToChanges == true ) {
300 reinterpret_cast<void *> ( dbholder::database ) );
301 }
302 }
303 else
304 {
306 delete dbholder::database;
308 }
309
311
313 return true;
314 }
315 catch ( dunedaq::conffwk::Exception const & e )
316 {
317 FAIL ( "Database loading failed", dbe::config::errors::parse ( e ).c_str() );
318 return false;
319 }
320
321}
static void CallbackFunction(const std::vector< dunedaq::conffwk::ConfigurationChange * > &changes, void *parameter)
static cptr< dunedaq::conffwk::Configuration > database_concurrent_ptr
Defines base class for cache of template objects.
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 31 of file confaccessor.cpp.

32{
33 static confaccessor me;
34 return me;
35}

◆ removefile()

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

Definition at line 397 of file confaccessor.cpp.

398{
399 if ( not enabled() )
400 {
401 throw daq::dbe::ChangeNotAllowed ( ERS_HERE );
402 }
403
404 dbaccessor::dbptr()->remove_include ( db, fn );
405 emit RemoveFileDone();
406}

◆ 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 323 of file confaccessor.cpp.

324{
325 try
326 {
327 std::list<std::string> tobecommited{};
328
329 if ( ref().is_database_loaded() )
330 {
331 dbaccessor::dbptr()->get_updated_dbs ( tobecommited );
332 dbaccessor::dbptr()->commit ( CommitMessage.toStdString() );
333 confaccessor::ref().db_committed(tobecommited, CommitMessage.toStdString());
334 }
335
336 return tobecommited;
337 }
338 catch ( dunedaq::conffwk::Exception const & e )
339 {
340 throw daq::dbe::CouldNotCommitChanges ( ERS_HERE, dbe::config::errors::parse ( e ) );
341 }
342}
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 164 of file confaccessor.cpp.

165{
167}

◆ setdbinfo()

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

Definition at line 204 of file confaccessor.cpp.

205{
206 switch ( itype )
207 {
208
209 case dbinfo::oks:
210 ref().set_dbinfo<dbinfo::oks> ( location );
211 break;
212
213 case dbinfo::roks:
214 ref().set_dbinfo<dbinfo::roks> ( location );
215 break;
216
217 case dbinfo::rdb:
218 ref().set_dbinfo<dbinfo::rdb> ( location );
219 break;
220
221 default:
222 ref().setenabled();
223 break;
224 }
225}
void set_dbinfo(QString const &p)

◆ setdblocation()

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

Definition at line 227 of file confaccessor.cpp.

228{
229 ref().this_resource_location = Implementation;
230}

◆ setdisabled()

void dbe::confaccessor::setdisabled ( )
private

Definition at line 76 of file confaccessor.cpp.

◆ setenabled()

void dbe::confaccessor::setenabled ( )
private

Definition at line 70 of file confaccessor.cpp.

◆ uncommitted_files()

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

Definition at line 278 of file confaccessor.cpp.

278 {
279 std::list<std::string> dbs;
280 dbaccessor::dbptr()->get_updated_dbs(dbs);
281 return dbs;
282}

◆ unsubscribe()

void dbe::confaccessor::unsubscribe ( )
static

Definition at line 442 of file confaccessor.cpp.

443{
444 if ( dbaccessor::dbptr().get() && ref().CallId != nullptr )
445 {
446 dbaccessor::dbptr()->unsubscribe ( ref().CallId );
447 }
448}

Friends And Related Symbol Documentation

◆ dbaccessor

friend class dbaccessor
friend

Definition at line 272 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: