DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
config_api_commands.cpp
Go to the documentation of this file.
1// DUNE DAQ modification notice:
2// This file has been modified from the original ATLAS dbe source for the DUNE DAQ project.
3// Fork baseline commit: dbe-02-12-17 (2022-05-12).
4// Renamed since fork: no.
5
6/*
7 * config_api_commands.cpp
8 *
9 * Created on: Apr 19, 2016
10 * Author: Leonidas Georgopoulos
11 */
12
13#include "dbe/confaccessor.hpp"
16#include "dbe/Command.hpp"
17#include "dbe/dbcontroller.hpp"
18#include "dbe/Exceptions.hpp"
19#include "dbe/messenger.hpp"
20#include "dbe/config_api.hpp"
21#include "dbe/change_class.hpp"
22#include "dbe/change_date.hpp"
23#include "dbe/change_enum.hpp"
24#include "dbe/change_time.hpp"
26
27
28#include "conffwk/Schema.hpp"
29#include "ers/Issue.hpp"
30
31#include <QString>
32#include <QUuid>
33
34#include <stack>
35#include <string>
36#include <vector>
37
38
39
40//------------------------------------------------------------------------------------------
41// NAMESPACE DBE::CONFIG::API::COMMANDS
42//------------------------------------------------------------------------------------------
43/*
44 * Purpose of this namespace is to group all commands that generate undo/redo objects
45 * that acts on config related structures and objects .
46 *
47 * DBE user interface should access the database by appropriately calling methods in this
48 * namespace. Direct access by accessing that database and retrieving ConfigObject directly
49 * is strongly discouraged.
50 */
51namespace dbe
52{
53namespace config
54{
55namespace api
56{
57namespace commands
58{
59
60//------------------------------------------------------------------------------------------
61void newobj ( std::string const & fn, std::string const & cn, std::string const & name,
63 dbe::t_config_object_preimage::type_relmap const & relations, QUuid const & src )
64{
65 std::string description
66 { "Object created : " + name + "@" + cn };
67
69 { config_internal_change::CREATED, description, name, cn, "" };
70
72 new dbe::actions::object::create ( { attributes, relations, { name, cn}, fn }, src ) );
73
75}
76//------------------------------------------------------------------------------------------
77
78//------------------------------------------------------------------------------------------
79bool delobj ( tref obj, QUuid const & src )
80{
81 try
82 {
83 std::string const description
84 { "Object deleted : " + obj.UID() + "@" + obj.class_name()
85 };
87 { config_internal_change::DELETED, description, obj.UID(), obj.class_name(), "" };
90 }
91 catch ( daq::dbe::ObjectChangeWasNotSuccessful const & dbe_err )
92 {
93 INFO ( "Delete Object: The object could not be deleted!\n\n", dbe::config::errors::parse ( dbe_err ).c_str() );
94 return false;
95 }
96
97 return true;
98}
99//------------------------------------------------------------------------------------------
100
101//------------------------------------------------------------------------------------------
102bool renobj ( tref obj, std::string const & newuuid, QUuid const & src )
103{
104 try
105 {
106 std::string const description =
107 {
108 "Object renamed : " + obj.UID() + "@" + obj.class_name() + " to " + newuuid + "@"
109 + obj.class_name()
110 };
111
113 { config_internal_change::RENAMED, description, obj.UID(), obj.class_name(), "" };
114
116 new dbe::actions::object::rename ( obj, newuuid, src ) );
117
118 confaccessor::get_internal_change_stack()->push ( request );
119
120 return true;
121 }
122 catch ( daq::dbe::ObjectChangeWasNotSuccessful const & dbe_err )
123 {
124 INFO ( "It was not possible to rename object ", dbe::config::errors::parse ( dbe_err ).c_str(), "\n\nObject UID:",
125 obj.UID().c_str() );
126 return false;
127 }
128}
129//------------------------------------------------------------------------------------------
130
131//------------------------------------------------------------------------------------------
132bool movobj ( tref obj, std::string const & destination, QUuid const & src )
133{
134 try
135 {
136 std::string const description
137 { "Object " + obj.UID() + "@" + obj.class_name() + " contained in " + obj.contained_in()
138 + " moved to " + destination
139 };
140
142 { config_internal_change::MOVED, description, obj.UID(), obj.class_name(), "" };
143
145 new dbe::actions::object::move ( obj, destination, src ) );
146 confaccessor::get_internal_change_stack()->push ( request );
147
148 return true;
149 }
150 catch ( daq::dbe::ObjectChangeWasNotSuccessful const & dbe_err )
151 {
152 INFO ( "It was not possible to move object ", dbe::config::errors::parse ( dbe_err ).c_str(), "\n\nObject UID:",
153 obj.UID().c_str() );
154 return false;
155 }
156}
157//------------------------------------------------------------------------------------------
158
159//------------------------------------------------------------------------------------------
160void modobj ( tref object, const dunedaq::conffwk::relationship_t & linkinfo,
161 std::vector<std::string> const & others_names )
162{
163 try
164 {
166 new dbe::actions::object::changerefs ( object, linkinfo, others_names ) );
167 std::string
168 const description (
169 others_names.size() != 1 ? "Multi Relationship : " + linkinfo.p_name :
170 "Single Relationship : " + linkinfo.p_name );
171
172 config_internal_change const change
173 {
174 config_internal_change::MODIFIED, description, object.UID(), object.class_name(), ""
175 };
176
178 }
179 catch ( daq::dbe::ObjectChangeWasNotSuccessful const & dbe_err )
180 {
181 WARN ( "The object reference could not be changed", dbe::config::errors::parse ( dbe_err ).c_str() );
182 }
183}
184//------------------------------------------------------------------------------------------
185
186//------------------------------------------------------------------------------------------
187template<>
188void modobj<std::string> ( tref Object, const dunedaq::conffwk::attribute_t & AttributeData,
189 std::string Value )
190{
191 try
192 {
194 Change.uid = Object.UID();
195 Change.classname = Object.class_name();
197 Change.description = QString ( "Attribute " ).append ( AttributeData.p_name.c_str() )
198 .toStdString();
199
200 if ( AttributeData.p_type == dunedaq::conffwk::string_type )
201 {
203 new dbe::actions::ChangeAttribute<std::string> ( Object, AttributeData, Value ) );
204 }
205 else if ( AttributeData.p_type == dunedaq::conffwk::enum_type )
206 {
208 new dbe::actions::ChangeEnum<std::string> ( Object, AttributeData, Value ) );
209 }
210 else if ( AttributeData.p_type == dunedaq::conffwk::class_type )
211 {
213 new dbe::actions::ChangeClass<std::string> ( Object, AttributeData, Value ) );
214 }
215 else if ( AttributeData.p_type == dunedaq::conffwk::date_type )
216 {
217
219 new dbe::actions::ChangeDate<std::string> ( Object, AttributeData, Value ) );
220 }
221 else if ( AttributeData.p_type == dunedaq::conffwk::time_type )
222 {
224 new dbe::actions::ChangeTime<std::string> ( Object, AttributeData, Value ) );
225 }
226
228 }
229 catch ( daq::dbe::ObjectChangeWasNotSuccessful const & dbe_err )
230 {
231 WARN ( "The object attribute could not be changed", dbe::config::errors::parse ( dbe_err ).c_str() );
232 }
233}
234//------------------------------------------------------------------------------------------
235
236//------------------------------------------------------------------------------------------
237template<>
239 tref Object, const dunedaq::conffwk::attribute_t & AttributeData,
240 std::vector<std::string> Value )
241{
242 try
243 {
245 Change.uid = Object.UID();
246 Change.classname = Object.class_name();
248 Change.description = QString ( "Attribute " ).append ( AttributeData.p_name.c_str() )
249 .toStdString();
250
251 if ( AttributeData.p_type == dunedaq::conffwk::string_type )
252 {
254 new dbe::actions::ChangeAttribute<std::vector<std::string>> ( Object, AttributeData,
255 Value ) );
256 }
257 else if ( AttributeData.p_type == dunedaq::conffwk::enum_type )
258 {
260 new dbe::actions::ChangeEnum<std::vector<std::string>> ( Object, AttributeData,
261 Value ) );
262 }
263 else if ( AttributeData.p_type == dunedaq::conffwk::class_type )
264 {
266 new dbe::actions::ChangeClass<std::vector<std::string>> ( Object, AttributeData,
267 Value ) );
268 }
269 else if ( AttributeData.p_type == dunedaq::conffwk::date_type )
270 {
272 new dbe::actions::ChangeDate<std::vector<std::string>> ( Object, AttributeData,
273 Value ) );
274 }
275 else if ( AttributeData.p_type == dunedaq::conffwk::time_type )
276 {
278 new dbe::actions::ChangeTime<std::vector<std::string>> ( Object, AttributeData,
279 Value ) );
280 }
281
283 }
284 catch ( daq::dbe::ObjectChangeWasNotSuccessful const & dbe_err )
285 {
286 WARN ( "The object attribute could not be changed", dbe::config::errors::parse ( dbe_err ).c_str() );
287 }
288}
289//------------------------------------------------------------------------------------------
290
291
292//------------------------------------------------------------------------------------------
293
294
295
296
297
298//------------------------------------------------------------------------------------------
299namespace file
300{
301void remove ( QString const & db, QString const & fn )
302{
303 std::string dbname = db.toStdString();
304 std::string sinclude = fn.toStdString();
305
306 try
307 {
309 Change.filename = fn.toStdString();
311 Change.description = QString ( "File(deleted) : " ).append ( fn ).toStdString();
312
313 confaccessor::get_commands()->push ( new dbe::actions::file::remove ( dbname, sinclude ) );
315 }
316 catch ( daq::dbe::DatabaseChangeNotSuccessful const & dbe_err )
317 {
318 WARN ( "File removal failure", dbe::config::errors::parse ( dbe_err ).c_str() );
319 }
320}
321
322
323void add ( const QString & Database, const QString & IncludedFile )
324{
325 std::string dbname = Database.toStdString();
326 std::string sinclude = IncludedFile.toStdString();
327
328 try
329 {
331 Change.filename = IncludedFile.toStdString();
333 Change.description = QString ( "File(included) : " ).append ( IncludedFile ).toStdString();
334
335 confaccessor::get_commands()->push ( new dbe::actions::file::add ( dbname, sinclude ) );
337 }
338 catch ( daq::dbe::DatabaseChangeNotSuccessful const & dbe_err )
339 {
340 WARN ( "File inclusion did not succeed", dbe::config::errors::parse ( dbe_err ).c_str() );
341 }
342}
343
344}
345
346}
347}
348}
349}
350//------------------------------------------------------------------------------------------
351
352
353
static t_undo_stack_cptr get_commands()
static t_internal_changes_stack_cptr get_internal_change_stack()
#define WARN(...)
Definition messenger.hpp:85
#define INFO(...)
void remove(QString const &db, QString const &fn)
void add(QString const &db, QString const &fn)
void modobj< std::string >(tref Object, const dunedaq::conffwk::attribute_t &AttributeData, std::string Value)
void newobj(std::string const &fn, std::string const &class_name, std::string const &UID, dbe::t_config_object_preimage::type_attrmap const &attributes, dbe::t_config_object_preimage::type_relmap const &relations, QUuid const &src)
bool renobj(inner::configobject::tref obj, std::string const &newuuid, QUuid const &src)
void modobj(tref Object, dunedaq::conffwk::attribute_t const &AttributeData, T Value)
bool movobj(inner::configobject::tref obj, std::string const &destination, QUuid const &src)
bool delobj(inner::configobject::tref obj, QUuid const &src)
std::string const parse(ers::Issue const &)
Include QT Headers.
inner::configobject::tref tref
Definition tref.hpp:35
modification request
Type of modification.
std::string uid
Object Identification.