DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
ConfigurationImpl.hpp
Go to the documentation of this file.
1
8#ifndef CONFFWK_CONFIGURATIONIMPL_H_
9#define CONFFWK_CONFIGURATIONIMPL_H_
10
11#include <string>
12#include <vector>
13#include <list>
14#include <set>
15#include <map>
16
17#include "conffwk/map.hpp"
18#include "conffwk/set.hpp"
20
21class ConfigurationChange;
22class ConfigObject;
23class ConfigObjectImpl;
24
25namespace dunedaq {
26namespace conffwk {
27
28
29struct class_t;
30
31
44
45 friend class ConfigObject;
46 friend class ConfigObjectImpl;
47 friend class Configuration;
48
49 public:
50
52
53 ConfigurationImpl() noexcept;
54
56
57 virtual ~ConfigurationImpl();
58
59
60 // methods to open/close database
61
62 public:
63
65
66 virtual void open_db(const std::string& db_name) = 0;
67
69
70 virtual void close_db() = 0;
71
73
74 virtual bool loaded() const noexcept = 0;
75
77
78 virtual void create(const std::string& db_name, const std::list<std::string>& includes) = 0;
79
81
82 virtual bool is_writable(const std::string& db_name) = 0;
83
85
86 virtual void add_include(const std::string& db_name, const std::string& include)= 0;
87
89
90 virtual void remove_include(const std::string& db_name, const std::string& include)= 0;
91
93
94 virtual void get_includes(const std::string& db_name, std::list<std::string>& includes) const = 0;
95
97
98 virtual void get_updated_dbs(std::list<std::string>& dbs) const = 0;
99
101
102 virtual void set_commit_credentials(const std::string& user, const std::string& password) = 0;
103
105
106 virtual void commit(const std::string& log_message) = 0;
107
109
110 virtual void abort() = 0;
111
113
114 virtual void prefetch_all_data() = 0;
115
117
118 virtual std::vector<dunedaq::conffwk::Version> get_changes() = 0;
119
121
122 virtual std::vector<dunedaq::conffwk::Version> get_versions(const std::string& since, const std::string& until, dunedaq::conffwk::Version::QueryType type, bool skip_irrelevant) = 0;
123
124
125 // methods to get data from database
126
127 public:
128
130
131 virtual void get(const std::string& class_name, const std::string& id, ConfigObject& object, unsigned long rlevel, const std::vector<std::string> * rclasses) = 0;
132
134
135 virtual void get(const std::string& class_name, std::vector<ConfigObject>& objects, const std::string& query, unsigned long rlevel, const std::vector<std::string> * rclasses) = 0;
136
138
139 virtual void get(const ConfigObject& obj_from, const std::string& query, std::vector<ConfigObject>& objects, unsigned long rlevel, const std::vector<std::string> * rclasses) = 0;
140
142
143 virtual bool test_object(const std::string& class_name, const std::string& id, unsigned long rlevel, const std::vector<std::string> * rclasses) = 0;
144
145
146 // methods to create and destroy objects
147
148 public:
149
151
152 virtual void create(const std::string& at, const std::string& class_name, const std::string& id, ConfigObject& object) = 0;
153
155
156 virtual void create(const ConfigObject& at, const std::string& class_name, const std::string& id, ConfigObject& object) = 0;
157
159
160 virtual void destroy(ConfigObject& object) = 0;
161
162
163 // get meta-data
164
165 public:
166
168
169 virtual dunedaq::conffwk::class_t * get(const std::string& class_name, bool direct_only) = 0;
170
172
173 virtual void get_superclasses(conffwk::fmap<conffwk::fset>& schema) = 0;
174
175
176 // notification
177
178 public:
179
181
182 typedef void (*notify)(std::vector<ConfigurationChange *> & changes, Configuration *);
183
185
186 typedef void (*pre_notify)(Configuration *);
187
189
190 virtual void subscribe(const std::set<std::string>& class_names, const std::map< std::string, std::set<std::string> >& objs, notify cb, pre_notify pre_cb) = 0;
191
193
194 virtual void unsubscribe() = 0;
195
197
198 virtual void print_profiling_info() noexcept = 0;
199
201
202 void print_cache_info() noexcept;
203
204
206
207 private:
208
210 std::vector<ConfigObjectImpl *> m_tangled_objects; // deleted and replaced by others as result of rename
211
212 mutable unsigned long p_number_of_cache_hits;
213 mutable unsigned long p_number_of_object_read;
214
215
216 protected:
217
219
220 ConfigObjectImpl * get_impl_object(const std::string& class_name, const std::string& id) const noexcept;
221
222
224
225 void put_impl_object(const std::string& class_name, const std::string& id, ConfigObjectImpl * obj) noexcept;
226
227
229
230 template<class T, class OBJ>
231 T *
232 insert_object(OBJ& obj, const std::string& id, const std::string& class_name) noexcept
233 {
234 ConfigObjectImpl * p = get_impl_object(class_name, id);
235
236 if (p == nullptr)
237 {
238 p = static_cast<ConfigObjectImpl *>(new T(obj, this));
239 put_impl_object(class_name, id, p);
240 }
241 else
242 {
243 static_cast<T *>(p)->set(obj);
245 }
246
247 return static_cast<T *>(p);
248 }
249
250
252
253 void clean() noexcept;
254
255
257
258 protected:
259
261
262
264
265 std::mutex& get_conf_impl_mutex() const;
266
267
268 public:
269
271
272 void set(Configuration * db) noexcept { m_conf = db; }
273
274
275 public:
276
278
279 void rename_impl_object(const std::string * class_name, const std::string& old_id, const std::string& new_id) noexcept;
280
281};
282
283} // namespace conffwk
284} // namespace dunedaq
285
286#endif // CONFFWK_CONFIGURATIONIMPL_H_
Implements database objects.
dunedaq::conffwk::ObjectState m_state
Represents database objects.
Describes changes inside a class returned by the notification mechanism.
Definition Change.hpp:35
Provides pure virtual interface used by the Configuration class.
void(*) notify(std::vector< ConfigurationChange * > &changes, Configuration *)
Callback to notify database changes.
virtual bool test_object(const std::string &class_name, const std::string &id, unsigned long rlevel, const std::vector< std::string > *rclasses)=0
Test object existence (used by Python binding)
void put_impl_object(const std::string &class_name, const std::string &id, ConfigObjectImpl *obj) noexcept
put object to cache
ConfigurationImpl() noexcept
The constructor.
virtual void subscribe(const std::set< std::string > &class_names, const std::map< std::string, std::set< std::string > > &objs, notify cb, pre_notify pre_cb)=0
Subscribe on database changes.
virtual void set_commit_credentials(const std::string &user, const std::string &password)=0
Set commit credentials.
void clean() noexcept
clean cache (e.g. to be used by destructor)
virtual void close_db()=0
Close database implementation.
virtual void get_superclasses(conffwk::fmap< conffwk::fset > &schema)=0
Get inheritance hierarchy.
virtual void abort()=0
Abort database changes.
virtual void get(const std::string &class_name, const std::string &id, ConfigObject &object, unsigned long rlevel, const std::vector< std::string > *rclasses)=0
Get object of class by id.
virtual void get_includes(const std::string &db_name, std::list< std::string > &includes) const =0
Get included files.
virtual void print_profiling_info() noexcept=0
Print implementation specific profiling information.
virtual void prefetch_all_data()=0
Prefetch all data into client cache.
virtual void get_updated_dbs(std::list< std::string > &dbs) const =0
Get uncommitted files.
virtual bool is_writable(const std::string &db_name)=0
Return write access status.
std::vector< ConfigObjectImpl * > m_tangled_objects
virtual std::vector< dunedaq::conffwk::Version > get_changes()=0
Get newly available versions.
ConfigObjectImpl * get_impl_object(const std::string &class_name, const std::string &id) const noexcept
get object from cache
virtual bool loaded() const noexcept=0
Check if a database is loaded.
void rename_impl_object(const std::string *class_name, const std::string &old_id, const std::string &new_id) noexcept
rename object in cache
void(*) pre_notify(Configuration *)
Callback to pre-notify database changes.
virtual void destroy(ConfigObject &object)=0
Destroy object of class by id.
virtual void add_include(const std::string &db_name, const std::string &include)=0
Add include file.
virtual void commit(const std::string &log_message)=0
Commit database changes.
void print_cache_info() noexcept
Print profiling information about objects in cache.
virtual std::vector< dunedaq::conffwk::Version > get_versions(const std::string &since, const std::string &until, dunedaq::conffwk::Version::QueryType type, bool skip_irrelevant)=0
Get archived versions.
virtual void remove_include(const std::string &db_name, const std::string &include)=0
Remove include file.
Configuration * m_conf
Configuration pointer is needed for notification on changes, e.g. in case of subscription or an objec...
std::mutex & get_conf_impl_mutex() const
Is required by reload methods.
virtual void create(const std::string &db_name, const std::list< std::string > &includes)=0
Create database.
conffwk::pmap< conffwk::map< ConfigObjectImpl * > * > m_impl_objects
cache of implementation objects (class-name::->object_id->implementation)
virtual void open_db(const std::string &db_name)=0
Open database implementation in accordance with given name.
virtual void unsubscribe()=0
Remove subscription on database changes.
T * insert_object(OBJ &obj, const std::string &id, const std::string &class_name) noexcept
insert new object (update cache or create-and-insert)
Defines base class for cache of template objects.
Represents configuration version.
std::unordered_set< const std::string *, string_ptr_hash > fset
Definition set.hpp:13
std::unordered_set< std::string > set
Definition set.hpp:10
Including Qt Headers.