DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
OksConfiguration.cpp File Reference
#include <errno.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#include <algorithm>
#include <memory>
#include "ers/ers.hpp"
#include "oks/file.hpp"
#include "oks/kernel.hpp"
#include "oks/object.hpp"
#include "oks/query.hpp"
#include "oks/relationship.hpp"
#include "oksutils/oks/access.hpp"
#include "conffwk/Change.hpp"
#include "conffwk/ConfigObject.hpp"
#include "conffwk/Configuration.hpp"
#include "conffwk/Schema.hpp"
#include "oksconflibs/OksConfigObject.hpp"
#include "oksconflibs/OksConfiguration.hpp"
Include dependency graph for OksConfiguration.cpp:

Go to the source code of this file.

Classes

struct  dunedaq::oksconflibs::OksConfigurationCheckDB
class  dunedaq::oksconflibs::ResubscribeGuard
struct  InheritanceData
class  DestroyGuard1
class  DestroyGuard2

Namespaces

namespace  dunedaq
 The DUNE-DAQ namespace.
namespace  dunedaq::oksconflibs

Functions

conffwk::ConfigurationImpl * _oksconflibs_creator_ (const std::string &spec)
bool is_repo_name (const std::string &name)
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)
static void throw_update_exception (const OksFile *file_h, const char *action, const char *reason)
static std::vector< dunedaq::conffwk::Version > dunedaq::oksconflibs::oks2config (const std::vector< OksRepositoryVersion > &in)
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 std::string mk_rm_include_error_text (const std::string &db, const std::string &include, const char *error=0)

Function Documentation

◆ _oksconflibs_creator_()

conffwk::ConfigurationImpl * _oksconflibs_creator_ ( const std::string & spec)

Definition at line 42 of file OksConfiguration.cpp.

43{
44 try {
45 std::unique_ptr<OksConfiguration> impl(new OksConfiguration());
46 if (!spec.empty()) {
47 impl->open_db(spec);
48 }
49 return impl.release();
50 } catch (dunedaq::conffwk::Exception& ex) {
51 throw dunedaq::conffwk::Generic(ERS_HERE, "oksconflibs initialization error", ex);
52 } catch (...) {
53 throw dunedaq::conffwk::Generic(ERS_HERE,
54 "oksconflibs initialization error:\n***** caught unknown exception *****");
55 }
56}
#define ERS_HERE

◆ check()

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

The function checks if the object satisfies the subscription and adds to changes. The actions could be: '+' - created '~' - changed '-' - deleted

Definition at line 903 of file OksConfiguration.cpp.

910{
911
912 bool any = (class_names.empty() && objects.empty());
913
914 // check subscription on objects
915 //
916 // omi iterator in non-null, if on an object of class 'obj_class'
917 // there is explicit subscription
918
919 OksConfiguration::SMap::const_iterator omi = objects.end();
920
921 if (action != '+') {
922 omi = objects.find(obj_class);
923 if (omi != objects.end()) {
924 std::set<std::string>::const_iterator i = omi->second.find(obj_id);
925
926 if (i != omi->second.end()) {
927 conffwk::ConfigurationChange::add(changes, obj_class, obj_id, action);
928 }
929 }
930 }
931
932 // process the class
933
934 if (action == '+' || omi == objects.end()) {
935 if (any || class_names.find(obj_class) != class_names.end()) {
936 conffwk::ConfigurationChange::add(changes, obj_class, obj_id, action);
937 }
938 }
939
940 // process subclasses
941
942 OksConfiguration::SMap::const_iterator it = inheritance.data().find(obj_class);
943 if (it != inheritance.data().end()) {
944 for (std::set<std::string>::const_iterator j = it->second.begin(); j != it->second.end(); ++j) {
945 omi = (action != '+' ? objects.find(*j) : objects.end());
946
947 // 1. add objects if criteria is 'any'
948 // 2. add object of class which has subscription and has no explicit object subscription
949 // 3. add explicitly subscribed object
950
951 if (any || (omi == objects.end() && class_names.find(*j) != class_names.end()) ||
952 (omi != objects.end() && omi->second.find(obj_id) != omi->second.end())) {
953 conffwk::ConfigurationChange::add(changes, *j, obj_id, action);
954 }
955 }
956 }
957}
static void add(std::vector< ConfigurationChange * > &changes, const std::string &class_name, const std::string &obj_id, const char action)
Helper method to add object to the vector of existing changes.
const OksConfiguration::SMap & data() const

◆ is_repo_name()

bool is_repo_name ( const std::string & name)

Definition at line 108 of file OksConfiguration.cpp.

109{
110 if (!OksKernel::get_repository_root().empty()) {
111 std::string s(name);
112
114
115 bool is_absolute_path = (s[0] == '/');
116
117 if (!is_absolute_path)
118 s = std::string(OksKernel::get_cwd()) + '/' + s;
119
120 // if file system path exists
121 if (Oks::real_path(s, true)) {
123 return true;
124
125 static std::string user_repo_dir;
126 static std::once_flag flag;
127
128 std::call_once(flag, []() {
129 if (const char* s = getenv("TDAQ_DB_USER_REPOSITORY")) {
130 user_repo_dir = s;
131
132 try {
133 Oks::real_path(user_repo_dir, false);
134 } catch (oks::exception& ex) {
135 TLOG_DEBUG(0) << "Failed to read TDAQ_DB_USER_REPOSITORY = \'" << s << "\':\n\tcaused by: " << ex.what();
136 }
137 }
138 });
139
140 if (!user_repo_dir.empty() && s.find(user_repo_dir) == 0)
141 return true;
142
143 return false;
144 } else
145 return true;
146 }
147
148 return false;
149}
static const std::string & get_repository_mapping_dir()
Get OKS repository name.
Definition kernel.cpp:318
static const std::string & get_repository_root()
Get OKS repository root.
Definition kernel.cpp:280
static const char * get_cwd()
Definition kernel.cpp:636
static void substitute_variables(std::string &)
Definition kernel.cpp:525
static bool real_path(std::string &, bool ignore_errors)
Definition kernel.cpp:546
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:116

◆ mk_add_include_error_text()

std::string mk_add_include_error_text ( const std::string & db,
const std::string & include,
const char * error = nullptr )
static

Definition at line 308 of file OksConfiguration.cpp.

309{
310 std::ostringstream text;
311 text << "cannot add and load include file \'" << include << "\' to \'" << db << '\'';
312 if (error)
313 text << ":\n" << error;
314 return text.str();
315}
CIB Buffer std::string descriptor Message from std::string descriptor CIB process error

◆ mk_no_file_error_text()

std::string mk_no_file_error_text ( const std::string & db)
static

Definition at line 300 of file OksConfiguration.cpp.

301{
302 std::ostringstream text;
303 text << "cannot find file \'" << db << '\'';
304 return text.str();
305}

◆ mk_rm_include_error_text()

std::string mk_rm_include_error_text ( const std::string & db,
const std::string & include,
const char * error = 0 )
static

Definition at line 1045 of file OksConfiguration.cpp.

1046{
1047 std::ostringstream text;
1048 text << "cannot remove include file \'" << include << "\' from \'" << db << '\'';
1049 if (error)
1050 text << ":\n" << error;
1051 return text.str();
1052}

◆ throw_update_exception()

void throw_update_exception ( const OksFile * file_h,
const char * action,
const char * reason )
static

Definition at line 334 of file OksConfiguration.cpp.

335{
336 std::ostringstream text;
337 text << "cannot " << action << " file \'" << file_h->get_full_file_name() << "\' since " << reason;
338 throw dunedaq::conffwk::Generic(ERS_HERE, text.str().c_str());
339}
const std::string & get_full_file_name() const
Definition file.hpp:528
std::string const reason(ers::Issue const &)