DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
Command.cpp
Go to the documentation of this file.
1#include "dbe/Command.hpp"
2#include "dbe/config_api_set.hpp" // checked
3#include "dbe/config_api_graph.hpp" // checked
4#include "dbe/confobject_desc.hpp" // checked
8#include "dbe/messenger.hpp"
9
11
12#include <QFileInfo>
13
14#include <algorithm>
15
16//------------------------------------------------------------------------------------------
18 tref object, dunedaq::conffwk::relationship_t const & relation,
19 std::vector<std::string> const & object_names_tolink, QUuid const & src,
20 QUndoCommand * parent )
21 : onobject ( object, parent, src ),
22 this_relation ( relation ),
23 this_current_neighbors (
24 dbe::config::api::graph::linked::through::relation<std::vector<tref>> ( object, relation ) )
25{
26 try
27 {
28 for ( std::string const & oname : object_names_tolink )
29 {
30 try
31 {
33 { oname, relation.p_type } ) );
34 }
35 catch ( daq::dbe::config_object_retrieval_result_is_null const & ex )
36 {
37 // Actually there is no need to handle this error here ,
38 // since the object will not be added to the result list of references,
39 // and can be safely ignored
40 }
41 }
42 }
43 catch ( dunedaq::conffwk::Exception const & e )
44 {
45 failed();
46 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, dbe::config::errors::parse ( e ) );
47 }
48
49 setText (
50 QObject::tr ( "Relation %1 of object %2 was updated." ).arg (
51 this_relation.p_name.c_str() ).arg ( object.UID().c_str() ) );
52}
53//------------------------------------------------------------------------------------------
54
55//------------------------------------------------------------------------------------------
57{
58 try
59 {
60 if ( redoable() )
61 {
62 failed();
63 dbe::config::api::set::noactions::relation ( checkedref(), this_relation,
64 this_target_neighbors );
65 confaccessor::ref().force_emit_object_changed ( source().toString(), checkedref() );
66 toggle();
67 }
68 }
69 catch ( dunedaq::conffwk::Exception const & e )
70 {
71 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, config::errors::parse ( e ) );
72 }
73 catch ( daq::dbe::config_object_retrieval_result_is_null const & ex )
74 {
75 FAIL ( "Operation did not complete because a lookup in the underlying database failed",
76 ex.what() );
77 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, ex );
78 }
79
80}
81//------------------------------------------------------------------------------------------
82
83//------------------------------------------------------------------------------------------
85{
86 try
87 {
88 if ( undoable() )
89 {
90 failed();
91 dbe::config::api::set::noactions::relation ( checkedref(), this_relation,
92 this_current_neighbors );
93 confaccessor::ref().force_emit_object_changed ( source().toString(), checkedref() );
94 toggle();
95 }
96 }
97 catch ( dunedaq::conffwk::Exception const & e )
98 {
99 failed();
100 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, dbe::config::errors::parse ( e ) );
101 }
102 catch ( daq::dbe::config_object_retrieval_result_is_null const & ex )
103 {
104 FAIL ( "Operation did not complete because a lookup in the underlying database failed",
105 ex.what() );
106 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, ex );
107 }
108
109}
110//------------------------------------------------------------------------------------------
111
112//------------------------------------------------------------------------------------------
113dbe::actions::file::add::add ( std::string const & db_file,
114 std::string const & include_file,
115 QUuid const & src, QUndoCommand * parent )
116 : state ( parent, src ),
117 m_db_file ( db_file ),
118 m_include_file ( include_file )
119{
120 setText (
121 QObject::tr ( "Add Include File %1 to %2" ).arg (
122 QFileInfo ( QString ( m_include_file.c_str() ) ).fileName() ).arg (
123 QFileInfo ( QString ( m_db_file.c_str() ) ).fileName() ) );
124}
125//------------------------------------------------------------------------------------------
126
127//------------------------------------------------------------------------------------------
129{
130 try
131 {
132 if ( undoable() )
133 {
134 confaccessor::ref().removefile ( m_db_file, m_include_file );
135 }
136 }
137 catch ( dunedaq::conffwk::Exception const & e )
138 {
139 failed();
140 throw daq::dbe::DatabaseChangeNotSuccessful ( ERS_HERE, dbe::config::errors::parse ( e ) );
141 }
142}
143//------------------------------------------------------------------------------------------
144
145//------------------------------------------------------------------------------------------
147{
148 try
149 {
150 if ( redoable() )
151 {
152 failed();
153 confaccessor::ref().addfile ( m_db_file, m_include_file );
154 toggle();
155 }
156 }
157 catch ( dunedaq::conffwk::Exception const & e )
158 {
159 throw daq::dbe::DatabaseChangeNotSuccessful ( ERS_HERE, dbe::config::errors::parse ( e ) );
160 }
161}
162//------------------------------------------------------------------------------------------
163
164//------------------------------------------------------------------------------------------
165dbe::actions::file::remove::remove ( std::string & db_file, std::string & include_file,
166 QUuid const & src, QUndoCommand * parent )
167 : state ( parent, src ),
168 m_db_file ( db_file ),
169 m_include_file ( include_file )
170{
171 setText (
172 QObject::tr ( "Remove Include File %1 to %2" ).arg (
173 QFileInfo ( QString ( m_include_file.c_str() ) ).fileName() ).arg (
174 QFileInfo ( QString ( m_db_file.c_str() ) ).fileName() ) );
175}
176
178{
179 try
180 {
181 if ( undoable() )
182 {
183 failed();
184 confaccessor::ref().addfile ( m_db_file, m_include_file );
185 toggle();
186 }
187 }
188 catch ( dunedaq::conffwk::Exception const & e )
189 {
190 throw daq::dbe::DatabaseChangeNotSuccessful ( ERS_HERE, dbe::config::errors::parse ( e ) );
191 }
192}
193
195{
196 try
197 {
198 if ( redoable() )
199 {
200 failed();
201 confaccessor::ref().removefile ( m_db_file, m_include_file );
202 toggle();
203 }
204 }
205 catch ( dunedaq::conffwk::Exception const & e )
206 {
207 throw daq::dbe::DatabaseChangeNotSuccessful ( ERS_HERE, dbe::config::errors::parse ( e ) );
208 }
209}
210//------------------------------------------------------------------------------------------
211
212//------------------------------------------------------------------------------------------
214 QUuid const & src, QUndoCommand * parent )
215 : state ( parent, src ),
216 this_object_key ( img )
217{
218 setText (
219 QObject::tr ( "Creation of : Object %2@%1 " ).arg ( this_object_key.ref.this_class.c_str() )
220 .arg ( this_object_key.ref.this_name.c_str() ) );
221}
222
224{
225 try
226 {
227 if ( undoable() )
228 {
229 failed();
230 // notify for the objects that have been actually removed
232 [&] ( dref const obj )
233 {
234 confaccessor::ref().force_emit_object_deleted ( source().toString(), obj );
235 };
236
238 inner::dbcontroller::get ( this_object_key.ref ), deletion );
239 toggle();
240 }
241 }
242 catch ( dunedaq::conffwk::Exception const & e )
243 {
244 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, dbe::config::errors::parse ( e ) );
245 }
246 catch ( daq::dbe::config_object_retrieval_result_is_null const & e )
247 {
248 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, e );
249 }
250}
251
253{
254 try
255 {
256 if ( redoable() )
257 {
258 failed();
261 source().toString(), inner::dbcontroller::get ( this_object_key.ref ) );
262 toggle();
263 }
264 }
265 catch ( dunedaq::conffwk::Exception const & e )
266 {
267 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, dbe::config::errors::parse ( e ) );
268 }
269}
270//------------------------------------------------------------------------------------------
271
272//------------------------------------------------------------------------------------------
273dbe::actions::object::remove::remove ( tref anobject, QUuid const & uuid,
274 QUndoCommand * parent )
275 : onobject ( anobject, parent, uuid )
276{
277 setText (
278 QObject::tr ( "Delete object of class %1 with ID %2" ).arg (
279 ( this->checkedref().class_name() ).c_str() ).arg (
280 ( this->checkedref().UID() ).c_str() ) );
281}
282
286
288{
289 try
290 {
291 if ( undoable() )
292 {
293 failed();
294 gref::config_action_notifiable creation = [&] ( dref obj )
295 {
296 confaccessor::ref().force_emit_object_created ( source().toString(), obj );
297 };
298
299 inner::dbcontroller::create_object_request ( this_remainder, creation );
300 toggle();
301 }
302 }
303 catch ( dunedaq::conffwk::Exception const & e )
304 {
305 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, dbe::config::errors::parse ( e ) );
306 }
307 catch ( daq::dbe::config_object_retrieval_result_is_null const & ex )
308 {
309 FAIL ( "Operation did not complete because a lookup in the underlying database failed",
310 ex.what() );
311 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, ex );
312 }
313
314}
315
317{
318 try
319 {
320 if ( redoable() and not checkedref().is_null() )
321 {
322 failed();
323 // notify for the objects that have been actually removed
324 gref::config_action_notifiable deletion = [&] ( dref const obj )
325 {
326 confaccessor::ref().force_emit_object_deleted ( source().toString(), obj );
327 };
328
330 decltype ( this_remainder ) ::t_extractor > ( checkedref(), deletion );
331 toggle();
332 }
333 }
334 catch ( dunedaq::conffwk::Exception const & e )
335 {
336 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, dbe::config::errors::parse ( e ) );
337 }
338 catch ( daq::dbe::config_object_retrieval_result_is_null const & ex )
339 {
340 FAIL ( "Operation did not complete because a lookup in the underlying database failed",
341 ex.what() );
342 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, ex );
343 }
344
345}
346
347//------------------------------------------------------------------------------------------
348dbe::actions::object::rename::rename ( tref object, std::string const & Id,
349 QUuid const & src,
350 QUndoCommand * parent )
351 : onobject ( object, parent, src ),
352 oldname ( this->checkedref().UID() ),
353 newname ( Id )
354{
355 setText (
356 QObject::tr ( "Object changed ID from %1 to %2" ).arg ( this->checkedref().UID().c_str() )
357 .arg ( newname.c_str() ) );
358}
359//------------------------------------------------------------------------------------------
360
361//------------------------------------------------------------------------------------------
363{
364 try
365 {
366 if ( redoable() )
367 {
368 failed();
369 dref object_before_change ( checkedref() );
370 dbe::inner::dbcontroller::rename_object_request ( checkedref(), newname );
371
372 confaccessor::ref().force_emit_object_renamed ( source().toString(), object_before_change );
373
374 std::vector<tref> tonotify
375 { this->checkedref().referenced_by ( "*", false ) };
376
377 std::for_each ( tonotify.begin(), tonotify.end(), [&] ( tref const & x )
378 {
379 confaccessor::ref().force_emit_object_changed ( source().toString(), x );
380 } );
381 toggle();
382 }
383 }
384 catch ( dunedaq::conffwk::Exception const & e )
385 {
386 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, dbe::config::errors::parse ( e ) );
387 }
388 catch ( daq::dbe::config_object_retrieval_result_is_null const & e )
389 {
390 FAIL ( "Operation did not complete because a lookup in the underlying database failed",
391 e.what() );
392 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, e );
393 }
394
395}
396//------------------------------------------------------------------------------------------
397
398//------------------------------------------------------------------------------------------
400{
401 try
402 {
403 if ( undoable() )
404 {
405 failed();
406 dref object_before_rename ( checkedref() );
407 dbe::inner::dbcontroller::rename_object_request ( checkedref(), oldname );
408 confaccessor::ref().force_emit_object_renamed ( source().toString(), object_before_rename );
409
410 std::vector<tref> tonotify = checkedref().referenced_by ( "*", false );
411
412 std::for_each ( tonotify.begin(), tonotify.end(), [&] ( tref const & x )
413 {
414 confaccessor::ref().force_emit_object_changed ( source().toString(), x );
415 } );
416 toggle();
417 }
418 }
419 catch ( dunedaq::conffwk::Exception const & e )
420 {
421 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, dbe::config::errors::parse ( e ) );
422 }
423 catch ( daq::dbe::config_object_retrieval_result_is_null const & e )
424 {
425 FAIL ( "Operation did not complete because a lookup in the underlying database failed",
426 e.what() );
427 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, e );
428 }
429
430}
431//------------------------------------------------------------------------------------------
432
433//------------------------------------------------------------------------------------------
434dbe::actions::object::move::move ( tref object, std::string const & filename,
435 QUuid const & src, QUndoCommand * parent )
436 : onobject ( object, parent, src ),
437 source_file ( this->checkedref().contained_in() ),
438 destination_file ( filename )
439{
440 setText (
441 QObject::tr ( "Object changed from file %1 to %2" ).arg ( source_file.c_str() ).arg (
442 destination_file.c_str() ) );
443}
444//------------------------------------------------------------------------------------------
445
446//------------------------------------------------------------------------------------------
450//------------------------------------------------------------------------------------------
451
452//------------------------------------------------------------------------------------------
454{
455 try
456 {
457 if ( redoable() )
458 {
459 failed();
460 inner::dbcontroller::move_object_request ( this->checkedref(), destination_file );
461 emit confaccessor::ref().force_emit_object_changed ( source().toString(), this->checkedref() );
462 toggle();
463 }
464 }
465 catch ( dunedaq::conffwk::Exception const & e )
466 {
467 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, dbe::config::errors::parse ( e ) );
468 }
469 catch ( daq::dbe::config_object_retrieval_result_is_null const & e )
470 {
471 FAIL ( "Operation did not complete because a lookup in the underlying database failed",
472 e.what() );
473 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, e );
474 }
475}
476//------------------------------------------------------------------------------------------
477
478//------------------------------------------------------------------------------------------
480{
481 try
482 {
483 if ( undoable() )
484 {
485 failed();
486 inner::dbcontroller::move_object_request ( this->checkedref(), source_file );
487 toggle();
488 }
489 }
490 catch ( dunedaq::conffwk::Exception const & e )
491 {
492 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, dbe::config::errors::parse ( e ) );
493 }
494 catch ( daq::dbe::config_object_retrieval_result_is_null const & e )
495 {
496 FAIL ( "Operation did not complete because a lookup in the underlying database failed",
497 e.what() );
498 throw daq::dbe::ObjectChangeWasNotSuccessful ( ERS_HERE, e );
499 }
500
501}
502//------------------------------------------------------------------------------------------
503
504//------------------------------------------------------------------------------------------
505dbe::actions::onobject::onobject ( tref obj, QUndoCommand * parent, QUuid const & uuid )
506 : dbe::actions::state ( parent, uuid ),
507 this_object ( obj )
508{
509}
510//------------------------------------------------------------------------------------------
511
512//------------------------------------------------------------------------------------------
514{
515 return this_object.ref();
516}
517//------------------------------------------------------------------------------------------
518
519//------------------------------------------------------------------------------------------
520dbe::actions::state::state ( QUndoCommand * parent, QUuid const & uuid )
521 : QUndoCommand ( parent ),
522 uuid ( uuid ),
523 rewind ( true ),
524 forward ( true ),
525 invalid ( false )
526{
527}
528
530{
531 invalid = not invalid;
532 rewind = not rewind;
533 forward = not forward;
534}
535
537{
538 invalid = true;
539 rewind = false;
540 forward = false;
541}
542
544{
545 return not invalid;
546}
547
549{
550 rewind = state;
551}
552
554{
555 forward = state;
556}
557
559{
560 return rewind and not invalid;
561}
562
564{
565 return forward and not invalid;
566}
567
568QUuid const & dbe::actions::state::source() const
569{
570 return uuid;
571}
572
574{
575 return redoable();
576}
577
579{
580 return undoable();
581}
582
584{
585 // TODO evaluate: is this command that reloads the configuration object from the database really needed?
586}
587
588//------------------------------------------------------------------------------------------
589
#define ERS_HERE
add(std::string const &db_file, std::string const &include_file, QUuid const &src=0, QUndoCommand *parent=0)
Definition Command.cpp:113
std::string m_include_file
Definition Command.hpp:179
remove(std::string &db_file, std::string &include_file, QUuid const &src=0, QUndoCommand *parent=0)
Definition Command.cpp:165
changerefs(tref object, dunedaq::conffwk::relationship_t const &relation, std::vector< std::string > const &object_names_tolink, QUuid const &src=0, QUndoCommand *Parent=nullptr)
Definition Command.cpp:17
std::vector< tref > this_target_neighbors
Definition Command.hpp:142
dunedaq::conffwk::relationship_t this_relation
Definition Command.hpp:140
create(dbe::t_config_object_preimage const &img, QUuid const &src=0, QUndoCommand *parent=0)
Definition Command.cpp:213
dbe::t_config_object_preimage this_object_key
Definition Command.hpp:95
move(tref ObjectChanged, std::string const &File, QUuid const &src=0, QUndoCommand *parent=nullptr)
Definition Command.cpp:434
remove(tref item, QUuid const &uuid=0, QUndoCommand *parent=0)
Definition Command.cpp:273
rename(tref object, std::string const &Id, QUuid const &src=0, QUndoCommand *parent=nullptr)
Definition Command.cpp:348
tref checkedref() const
Definition Command.cpp:513
onobject(tref obj, QUndoCommand *parent=nullptr, QUuid const &uuid=0)
Definition Command.cpp:505
void setundoable(bool s=true) const
Definition Command.cpp:548
bool canRedo() const
Definition Command.cpp:573
void reload() const
Definition Command.cpp:583
bool undoable() const
Definition Command.cpp:558
bool canUndo() const
Definition Command.cpp:578
bool isvalid() const
Definition Command.cpp:543
void setredoable(bool s=true) const
Definition Command.cpp:553
void failed() const
Definition Command.cpp:536
bool redoable() const
Definition Command.cpp:563
state(QUndoCommand *parent=nullptr, QUuid const &uuid=0)
Definition Command.cpp:520
QUuid const & source() const
Definition Command.cpp:568
void force_emit_object_created(QString const &, dref const)
void removefile(std::string const &db, std::string const &fn)
void force_emit_object_deleted(QString const &, dref const)
void force_emit_object_renamed(QString const &, dref const)
void force_emit_object_changed(QString const &, dref const)
static confaccessor & ref()
void addfile(std::string const &db, std::string const &fn)
dunedaq::conffwk::ConfigObject & ref(bool check_null=true) const
static configobject::gref< T > delete_object_request(configobject::tref const &obj)
static configobject::tref move_object_request(configobject::tref objref, std::string const &destfile)
static configobject::tref get(dbe::cokey const &desc)
static configobject::tref rename_object_request(configobject::tref objref, std::string const &newname)
static configobject::tref create_object_request(dbe::t_config_object_preimage const &rep)
conffwk entry point
#define FAIL(...)
void relation(dbe::inner::configobject::tref src, dunedaq::conffwk::relationship_t const &edge, std::vector< dbe::inner::configobject::tref > const &targets)
std::string const parse(ers::Issue const &)
Include QT Headers.