9#ifndef CONFFWK_CONFIGURATION_H_
10#define CONFFWK_CONFIGURATION_H_
23#include <boost/property_tree/ptree.hpp>
41class ConfigurationImpl;
42class ConfigurationChange;
400 template<
class T>
bool is_valid(
const T *
object)
noexcept;
422 template<
class T>
void update(
const std::vector<std::string>& modified,
423 const std::vector<std::string>& removed,
424 const std::vector<std::string>& created)
noexcept;
434 void update_cache(std::vector<ConfigurationChange *>& changes)
noexcept;
612 template<class T> const T *
create(const
std::
string& at, const
std::
string&
id,
bool init_object = false);
629 template<class T> const T *
create(const
DalObject& at, const
std::
string&
id,
bool init_object = false);
655 template<class T>
void destroy(T& obj);
674 bool test_object(const
std::
string& class_name, const
std::
string&
id,
unsigned long rlevel = 0, const
std::vector<
std::
string> * rclasses = 0);
691 void get(const
std::
string& class_name, const
std::
string&
id,
ConfigObject&
object,
unsigned long rlevel = 0, const
std::vector<
std::
string> * rclasses = 0);
708 void get(const
std::
string& class_name,
std::vector<
ConfigObject>& objects, const
std::
string& query = "",
unsigned long rlevel = 0, const
std::vector<
std::
string> * rclasses = 0);
747 get(const
std::
string&
id,
bool init_children = false,
bool init = true,
unsigned long rlevel = 0, const
std::vector<
std::
string> * rclasses = 0)
750 return _get<T>(
id, init_children,
init, rlevel, rclasses);
796 get(std::vector<const T*>& objects,
bool init_children =
false,
bool init =
true,
const std::string& query =
"",
unsigned long rlevel = 0,
const std::vector<std::string> * rclasses = 0)
799 _get<T>(objects, init_children,
init, query, rlevel, rclasses);
881 template<
class T>
void ref(
ConfigObject& obj,
const std::string& name, std::vector<const T*>& objects,
bool init =
false) {
908 template<
class T,
class V>
void referenced_by(
const T& obj, std::vector<const V*>& objects,
const std::string& relationship_name =
"*",
bool check_composite_only =
true,
bool init =
false,
unsigned long rlevel = 0,
const std::vector<std::string> * rclasses =
nullptr);
937 std::vector<const DalObject*>
938 referenced_by(
const DalObject& obj,
const std::string& relationship_name =
"*",
bool check_composite_only =
true,
bool upcast_unregistered =
true,
bool init =
false,
unsigned long rlevel = 0,
const std::vector<std::string> * rclasses =
nullptr);
950 template<
class TARGET,
class SOURCE>
const TARGET *
cast(
const SOURCE *s)
noexcept {
958 void _get(
const std::string& class_name,
const std::string&
id,
ConfigObject&
object,
unsigned long rlevel,
const std::vector<std::string> * rclasses);
961 template<
class T>
const T *
_get(
const std::string&
id,
bool init_children =
false,
bool init =
true,
unsigned long rlevel = 0,
const std::vector<std::string> * rclasses = 0);
964 template<
class T>
const T *
_get(
ConfigObject& obj,
bool init_children =
false,
bool init =
true);
970 template<
class T>
void _get(std::vector<const T*>& objects,
bool init_children =
false,
bool init =
true,
const std::string& query =
"",
unsigned long rlevel = 0,
const std::vector<std::string> * rclasses = 0);
976 return const_cast<T*
>(
_get<T>(obj, uid));
991 bool , std::vector<const DalObject*>& result)
1002 result.push_back(obj);
1011 template<
class T>
const T *
_find(
const std::string&
id);
1020 template<
class T>
const T *
_ref(
ConfigObject& obj,
const std::string& name,
bool read_children);
1029 template<
class T>
void _ref(
ConfigObject& obj,
const std::string& name, std::vector<const T*>& results,
bool read_children);
1041 bool try_cast(
const std::string& target,
const std::string& source)
noexcept;
1043 bool try_cast(
const std::string* target,
const std::string* source)
noexcept;
1053 static std::string
mk_ref_ex_text(
const char * what,
const std::string& cname,
const std::string& rname,
const ConfigObject& obj)
noexcept;
1073 bool loaded() const noexcept;
1084 void load(const
std::
string& db_name);
1113 void create(const
std::
string& db_name, const
std::list<
std::
string>& includes);
1210 void commit(const
std::
string& log_message = "");
1308 export_schema(
boost::property_tree::ptree& tree, const
std::
string& classes = "",
bool direct_only = false);
1324 export_data(
boost::property_tree::ptree& tree, const
std::
string& classes = "", const
std::
string& objects = "", const
std::
string& files = "", const
std::
string& empty_array_item = "");
1395 template<
class T>
void convert(T& value,
const ConfigObject& obj,
const std::string& attr_name)
noexcept;
1404 template<
class T>
void convert2(std::vector<T>& value,
const ConfigObject& obj,
const std::string& attr_name)
noexcept;
1654 void print(std::ostream&)
const noexcept;
1677 typedef std::set< CallbackSubscription * , std::less<CallbackSubscription *> >
CallbackSet;
1678 typedef std::set< CallbackPreSubscription * , std::less<CallbackPreSubscription *> >
PreCallbackSet;
1725 std::unordered_map<std::string, std::unordered_map<std::string, std::string>>
attributes_pybind(
const std::string& class_name,
bool all);
1730 std::vector<ConfigObject>*
get_objs_pybind(
const std::string& class_name,
const std::string& query=
"");
1731 std::unordered_map<std::string, std::unordered_map<std::string, std::string>>
relations_pybind(
const std::string& class_name,
bool all);
1733 std::vector<std::string>
subclasses_pybind(
const std::string& class_name,
bool all);
Represents database objects.
Describes changes inside a class returned by the notification mechanism.
Provides pure virtual interface used by the Configuration class.
Describes a subscription criteria.
virtual ~AttributeConverterBase()
virtual void convert(T &value, const Configuration &conf, const ConfigObject &obj, const std::string &attr_name)=0
Defines base class for cache of template objects.
void register_converter(AttributeConverter< T > *object) noexcept
Register user function for attribute conversion.
const std::string & get_impl_name() const noexcept
const T * _find(const std::string &id)
Multi-thread unsafe version of find(const std::string&) method.
void update_cache(std::vector< ConfigurationChange * > &changes) noexcept
System function invoked in case of modifications.
std::vector< ConfigObject > * get_objs_pybind(const std::string &class_name, const std::string &query="")
void _get(const std::string &class_name, const std::string &id, ConfigObject &object, unsigned long rlevel, const std::vector< std::string > *rclasses)
const conffwk::fmap< conffwk::fset > & superclasses() const noexcept
static void update_impl_objects(conffwk::pmap< conffwk::map< ConfigObjectImpl * > * > &cache, ConfigurationChange &change, const std::string *class_name)
void set_subclasses() noexcept
conffwk::map< std::list< AttributeConverterBase * > * > m_convert_map
void get(const std::string &class_name, const std::string &id, ConfigObject &object, unsigned long rlevel=0, const std::vector< std::string > *rclasses=0)
Get object by class name and object id (multi-thread safe).
void(*) pre_notify(void *parameter)
The user notification callback function which is invoked before changes are going to be applied.
void _unread_implementation_objects(dunedaq::conffwk::ObjectState state) noexcept
ConfigurationImpl * m_impl
const TARGET * cast(const SOURCE *s) noexcept
Cast objects from one class to another (multi-thread safe).
static void system_cb(std::vector< ConfigurationChange * > &, Configuration *) noexcept
System callback function invoked in case of modifications.
std::unordered_map< std::string, std::unordered_map< std::string, std::string > > attributes_pybind(const std::string &class_name, bool all)
void destroy_obj(ConfigObject &object)
Destroy object.
std::unordered_map< std::string, std::unordered_map< std::string, std::string > > relations_pybind(const std::string &class_name, bool all)
void reset_subscription()
void remove_include(const std::string &db_name, const std::string &include)
Remove include file.
void get_updated_dbs(std::list< std::string > &dbs) const
Get list of updated files to be committed.
PreCallbackSet m_pre_callbacks
std::vector< std::string > classes_in_python() const
void prefetch_all_data()
Prefetch all data into client cache.
void load(const std::string &db_name)
Load database according to the name. If name is empty, take it from TDAQ_DB_NAME and TDAQ_DB_DATA env...
void action_on_update(const ConfigObject &obj, const std::string &name)
void remove_action(ConfigAction *ac)
Configuration & operator=(const Configuration &)
bool is_writable(const std::string &db_name) const
Get write access status.
std::list< ConfigAction * > m_actions
void update(const std::vector< std::string > &modified, const std::vector< std::string > &removed, const std::vector< std::string > &created) noexcept
Update cache of objects in case of modification.
void set_commit_credentials(const std::string &user, const std::string &password)
Set commit credentials.
void print(std::ostream &) const noexcept
Prints out details of configuration object.
~Configuration() noexcept
Destructor to destroy a configuration object.
std::vector< const DalObject * > referenced_by(const DalObject &obj, const std::string &relationship_name="*", bool check_composite_only=true, bool upcast_unregistered=true, bool init=false, unsigned long rlevel=0, const std::vector< std::string > *rclasses=nullptr)
Get DAL objects holding references on this object via given relationship (multi-thread safe).
Configuration(const Configuration &)
void add_action(ConfigAction *ac)
std::atomic< uint_least64_t > p_number_of_template_object_created
void unread_template_objects() noexcept
Unread all template (i.e. set their state as uninitialized) objects.
void update_classes() noexcept
const std::string & get_impl_param() const noexcept
static void system_pre_cb(Configuration *) noexcept
System callback function invoked in case of pre-modifications.
conffwk::fmap< conffwk::fset > p_subclasses
void referenced_by(const T &obj, std::vector< const V * > &objects, const std::string &relationship_name="*", bool check_composite_only=true, bool init=false, unsigned long rlevel=0, const std::vector< std::string > *rclasses=nullptr)
Get template DAL objects holding references on this object via given relationship (multi-thread safe)...
std::vector< std::string > superclasses_pybind(const std::string &class_name, bool all)
CallbackSubscription * find_callback(CallbackId cb_handler) const
void create(const std::string &at, const std::string &class_name, const std::string &id, ConfigObject &object)
Create new object by class name and object id.
static std::string mk_ref_ex_text(const char *what, const std::string &cname, const std::string &rname, const ConfigObject &obj) noexcept
const dunedaq::conffwk::class_t & _get_class_info(const std::string &class_name, bool direct_only=false)
std::vector< std::string > subclasses_pybind(const std::string &class_name, bool all)
const T * _ref(ConfigObject &obj, const std::string &name, bool read_children)
Multi-thread unsafe version of ref(ConfigObject&, const std::string&, bool); The method should not be...
std::list< std::string > * return_includes_pybind(const std::string &db_name)
bool loaded() const noexcept
Check if database is correctly loaded.
DalObject * _make_instance(ConfigObject &obj, const std::string &uid)
std::vector< std::string > get_class_list() const
const conffwk::fmap< conffwk::fset > & subclasses() const
conffwk::map< dunedaq::conffwk::class_t * > p_all_classes_desc_cache
void _reset_objects() noexcept
Update state of objects after abort operations.
void set_class_domain_map()
void unread_all_objects(bool unread_implementation_objs=false) noexcept
Mark object of given template class as unread (multi-thread unsafe).
std::deque< std::set< std::string > > find_class_domains()
CallbackSubscription * CallbackId
Callback identifier.
const std::string & get_impl_spec() const noexcept
const dunedaq::conffwk::class_t & get_class_info(const std::string &class_name, bool direct_only=false)
The method provides access to description of class.
void destroy(T &obj)
Destroy object of given class.
void get_includes(const std::string &db_name, std::list< std::string > &includes) const
Get include files.
std::set< CallbackPreSubscription *, std::less< CallbackPreSubscription * > > PreCallbackSet
conffwk::fmap< conffwk::fset > p_superclasses
std::vector< dunedaq::conffwk::Version > get_changes()
Get new conffwk versions.
conffwk::map< dunedaq::conffwk::class_t * > p_direct_classes_desc_cache
void commit(const std::string &log_message="")
Commit database changes.
void ref(ConfigObject &obj, const std::string &name, std::vector< const T * > &objects, bool init=false)
Get multiple values of object's relation and instantiate result with them (multi-thread safe).
void downcast_dal_object(const T *obj, bool, std::vector< const DalObject * > &result)
conffwk::fmap< uint > p_class_domain_map
bool is_superclass_of(const std::string &target, const std::string &source) noexcept
const T * get(ConfigObject &obj, const std::string &id)
Generate object of given class by object reference and instantiate the template parameter with it (mu...
void _unread_template_objects() noexcept
void export_data(boost::property_tree::ptree &tree, const std::string &classes="", const std::string &objects="", const std::string &files="", const std::string &empty_array_item="")
Export configuration data into ptree.
static std::string mk_ref_by_ex_text(const std::string &cname, const std::string &rname, const ConfigObject &obj) noexcept
void unread_implementation_objects(dunedaq::conffwk::ObjectState state) noexcept
Unread implementation objects (i.e. clear their cache).
ConfigObject * get_obj_pybind(const std::string &class_name, const std::string &id)
void downcast_dal_objects(const std::vector< const T * > &objs, bool, std::vector< const DalObject * > &result)
CallbackId subscribe(pre_notify user_cb, void *user_param=nullptr)
Subscribe on pre-notification on configuration changes.
void export_schema(boost::property_tree::ptree &tree, const std::string &classes="", bool direct_only=false)
Export configuration schema into ptree.
void unsubscribe(CallbackId cb_handler=0)
Remove callback function.
void(*) notify(const std::vector< ConfigurationChange * > &changed_classes, void *parameter)
The user notification callback function which is invoked in case of changes.
void print_profiling_info() noexcept
Print out profiling information.
std::vector< dunedaq::conffwk::Version > get_versions(const std::string &since, const std::string &until, dunedaq::conffwk::Version::QueryType type=dunedaq::conffwk::Version::query_by_date, bool skip_irrelevant=true)
Get repository versions in interval.
const T * ref(ConfigObject &obj, const std::string &name, bool init=false)
Get signle value of object's relation and instantiate result with it (multi-thread safe).
std::atomic< uint_least64_t > p_number_of_template_object_read
void abort()
Abort database changes.
void unload()
Unload database.
bool test_object(const std::string &class_name, const std::string &id, unsigned long rlevel=0, const std::vector< std::string > *rclasses=0)
Test the object existence.
void add_include(const std::string &db_name, const std::string &include)
Add include file to existing database.
std::atomic< uint_least64_t > p_number_of_cache_hits
void convert(T &value, const ConfigObject &obj, const std::string &attr_name) noexcept
Converts single value.
std::set< CallbackSubscription *, std::less< CallbackSubscription * > > CallbackSet
ConfigObject * create_and_return_obj_pybind(const std::string &at, const std::string &class_name, const std::string &id)
CallbackId subscribe(const ConfigurationSubscriptionCriteria &criteria, notify user_cb, void *user_param=nullptr)
Subscribe on configuration changes.
const T * get(ConfigObject &obj, bool init_children=false, bool init=true)
Get object of given class by object reference and instantiate the template parameter with it (multi-t...
bool try_cast(const std::string &target, const std::string &source) noexcept
Checks if cast from source class to target class is allowed.
void get(std::vector< const T * > &objects, bool init_children=false, bool init=true, const std::string &query="", unsigned long rlevel=0, const std::vector< std::string > *rclasses=0)
Get all objects of given class and instantiate a vector of the template parameters object with it (mu...
const T * find(const std::string &id)
Find object of given class (multi-thread safe).
void convert2(std::vector< T > &value, const ConfigObject &obj, const std::string &attr_name) noexcept
Converts vector of single values.
void rename_object(ConfigObject &obj, const std::string &new_id)
Cache of template object of given type.
bool is_valid(const T *object) noexcept
Checks validity of pointer to an objects of given user class.
bool is_superclass_of(const std::string *target, const std::string *source) noexcept
The base class for any generated DAL object.
DalRegistry: A registry of DalObjects It provides a single interface to create, cache and manage DalO...
Represents configuration version.
void init(unordered_map< std::string, std::string > params)
std::unordered_set< const std::string *, string_ptr_hash > fset
std::unordered_set< std::string > set
std::ostream & operator<<(std::ostream &, const ConfigurationChange &)
ConfigurationSubscriptionCriteria m_criteria