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 63 of file confaccessor.hpp.

Member Typedef Documentation

◆ t_external_changes_stack

Definition at line 237 of file confaccessor.hpp.

◆ t_internal_change

◆ t_internal_changes_stack

Definition at line 70 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 235 of file confaccessor.hpp.

◆ t_mutex

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

Definition at line 234 of file confaccessor.hpp.

◆ t_undo_stack

typedef QUndoStack dbe::confaccessor::t_undo_stack

Definition at line 73 of file confaccessor.hpp.

◆ t_undo_stack_cptr

Constructor & Destructor Documentation

◆ ~confaccessor()

dbe::confaccessor::~confaccessor ( )

Definition at line 56 of file confaccessor.cpp.

57{
58 delete editconfig;
59 delete coreconfig;
60 {
62 delete dbholder::database;
63 }
64}
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 45 of file confaccessor.cpp.

46 : CallId ( nullptr ),
48 { } ),
49 sequenced_command_stack ( new QUndoStack() ),
50 editconfig ( new datahandler() ),
51 coreconfig ( nullptr ),
52 this_change_enabled ( false ),
54{}
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 277 of file confaccessor.cpp.

278{
279 dbaccessor::dbptr()->abort();
280}
static cptr< dunedaq::conffwk::Configuration > dbptr()

◆ addfile()

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

Definition at line 392 of file confaccessor.cpp.

393{
394 if ( not enabled() )
395 {
396 throw daq::dbe::ChangeNotAllowed ( ERS_HERE );
397 }
398
399 dbaccessor::dbptr()->add_include ( db, fn );
400 emit IncludeFileDone();
401}
#define ERS_HERE
static bool enabled()

◆ CallbackFunction()

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

Definition at line 417 of file confaccessor.cpp.

420{
421 dbe::confaccessor::ref().docallback ( changes, parameter );
422}
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 245 of file confaccessor.cpp.

246{
247 try
248 {
249 if ( not fn.endsWith ( ".schema.xml" ) )
250 {
251 return dbaccessor::dbptr()->is_writable ( fn.toStdString() );
252 }
253 }
254 catch ( dunedaq::conffwk::Generic const & ex )
255 {
256 ERROR ( "Not possible to operate on file", dbe::config::errors::parse ( ex ),
257 "\n\nCheck filename:", fn.toStdString() );
258 }
259
260 return false;
261}
#define ERROR(...)
Definition messenger.hpp:93
std::string const parse(ers::Issue const &)

◆ clear_commands()

void dbe::confaccessor::clear_commands ( )
static

Clear internal changes commands

Definition at line 264 of file confaccessor.cpp.

265{
266 if ( ref().get_commands().get() )
267 {
268 ref().get_commands()->clear();
269 t_internal_changes_stack cleared{ };
270 ref().get_internal_change_stack()->swap ( cleared );
271 }
272}
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 130 of file confaccessor.cpp.

131{
133}
QString this_resource_location

◆ dbfullname()

QString dbe::confaccessor::dbfullname ( )
static

Definition at line 125 of file confaccessor.cpp.

126{
127 return ref().this_dblocation;
128}

◆ docallback()

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

Definition at line 424 of file confaccessor.cpp.

426{
427 Q_UNUSED ( parameter );
428
429 t_lock l ( mut_changes );
430 external_change_stack.clear();
431
432 for ( ConfigurationChange * Change : changes )
433 {
434 const auto& cl = Change->get_class_name();
435 const auto& mod = Change->get_modified_objs();
436 const auto& cre = Change->get_created_objs();
437 const auto& rem = Change->get_removed_objs();
438
439 external_change_stack.push_back ( { cl, mod, cre, rem } );
440 }
441
443}
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 69 of file confaccessor.cpp.

70{
72 return ref().this_change_enabled;
73}
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 108 of file confaccessor.cpp.

109{
110 t_lock l ( force_mut );
111 emit object_changed ( src, obj );
112}
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 90 of file confaccessor.cpp.

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

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

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

151{
153 return rp;
154}
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 457 of file confaccessor.cpp.

458{
460 return rp;
461}
cptr< t_internal_changes_stack > t_internal_changes_stack_cptr

◆ get_total_objects()

int dbe::confaccessor::get_total_objects ( )
static

Definition at line 159 of file confaccessor.cpp.

160{
161 return ref().this_total_objects;
162}

◆ GetFileCache

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

Definition at line 117 of file confaccessor.cpp.

118{
119 IncludedFileCache = FileCache;
120}
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 138 of file confaccessor.cpp.

139{
140 static cptr<datahandler> r ( ref().editconfig );
141 return r;
142}

◆ GetIncludedFileCache()

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

Definition at line 384 of file confaccessor.cpp.

385{
386 return IncludedFileCache;
387}

◆ guiconfig()

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

Access the default oks configuration type information

Returns

Definition at line 144 of file confaccessor.cpp.

145{
146 static cptr<dbe::ui::config::info> r ( confaccessor::ref().coreconfig );
147 return r;
148}

◆ IncludeFileDone

void dbe::confaccessor::IncludeFileDone ( )
signal

◆ increase_total_objects()

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

Definition at line 164 of file confaccessor.cpp.

165{
166 ref().this_total_objects += i;
167}

◆ init()

void dbe::confaccessor::init ( )
static

Must be called to read default OKS configuration type information

Definition at line 353 of file confaccessor.cpp.

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

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

238{
239 return dbaccessor::dbptr().get() != nullptr;
240}
T * get()
Definition cptr.hpp:88

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

292{
293 try
294 {
296
297 if ( dbholder::database == nullptr )
298 {
299 dbholder::database = new Configuration ( ref().this_resource_location.toStdString() );
300
301 if ( subscribeToChanges == true ) {
303 ConfigurationSubscriptionCriteria(),
305 reinterpret_cast<void *> ( dbholder::database ) );
306 }
307 }
308 else
309 {
311 delete dbholder::database;
312 dbholder::database = new Configuration ( ref().this_resource_location.toStdString() );
313 }
314
316
318 return true;
319 }
320 catch ( dunedaq::conffwk::Exception const & e )
321 {
322 FAIL ( "Database loading failed", dbe::config::errors::parse ( e ).c_str() );
323 return false;
324 }
325
326}
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 36 of file confaccessor.cpp.

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

◆ removefile()

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

Definition at line 403 of file confaccessor.cpp.

404{
405 if ( not enabled() )
406 {
407 throw daq::dbe::ChangeNotAllowed ( ERS_HERE );
408 }
409
410 dbaccessor::dbptr()->remove_include ( db, fn );
411 emit RemoveFileDone();
412}

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

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

170{
172}

◆ setdbinfo()

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

Definition at line 209 of file confaccessor.cpp.

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

◆ setdblocation()

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

Definition at line 232 of file confaccessor.cpp.

233{
234 ref().this_resource_location = Implementation;
235}

◆ setdisabled()

void dbe::confaccessor::setdisabled ( )
private

Definition at line 81 of file confaccessor.cpp.

◆ setenabled()

void dbe::confaccessor::setenabled ( )
private

Definition at line 75 of file confaccessor.cpp.

◆ uncommitted_files()

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

Definition at line 283 of file confaccessor.cpp.

283 {
284 std::list<std::string> dbs;
285 dbaccessor::dbptr()->get_updated_dbs(dbs);
286 return dbs;
287}

◆ unsubscribe()

void dbe::confaccessor::unsubscribe ( )
static

Definition at line 448 of file confaccessor.cpp.

449{
450 if ( dbaccessor::dbptr().get() && ref().CallId != nullptr )
451 {
452 dbaccessor::dbptr()->unsubscribe ( ref().CallId );
453 }
454}

◆ dbaccessor

friend class dbaccessor
friend

Definition at line 277 of file confaccessor.hpp.

Member Data Documentation

◆ CallId

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

Definition at line 242 of file confaccessor.hpp.

◆ coreconfig

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

Definition at line 249 of file confaccessor.hpp.

◆ editconfig

datahandler* dbe::confaccessor::editconfig
private

Definition at line 248 of file confaccessor.hpp.

◆ external_change_stack

t_external_changes_stack dbe::confaccessor::external_change_stack
private

Definition at line 245 of file confaccessor.hpp.

◆ force_mut

t_mutex dbe::confaccessor::force_mut
mutableprivate

Definition at line 255 of file confaccessor.hpp.

◆ IncludedFileCache

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

Definition at line 251 of file confaccessor.hpp.

◆ internal_change_stack

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

Definition at line 244 of file confaccessor.hpp.

◆ mut_changes

t_mutex dbe::confaccessor::mut_changes
mutableprivate

Definition at line 254 of file confaccessor.hpp.

◆ sequenced_command_stack

t_undo_stack* dbe::confaccessor::sequenced_command_stack
private

Definition at line 246 of file confaccessor.hpp.

◆ this_change_enabled

bool dbe::confaccessor::this_change_enabled
private

Definition at line 257 of file confaccessor.hpp.

◆ this_change_enabled_mutex

t_mutex dbe::confaccessor::this_change_enabled_mutex
mutableprivate

Definition at line 253 of file confaccessor.hpp.

◆ this_dblocation

QString dbe::confaccessor::this_dblocation
private

Definition at line 239 of file confaccessor.hpp.

◆ this_resource_location

QString dbe::confaccessor::this_resource_location
private

Definition at line 240 of file confaccessor.hpp.

◆ this_total_objects

int dbe::confaccessor::this_total_objects
private

Definition at line 259 of file confaccessor.hpp.


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