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