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/Command.hpp"
14#include "dbe/Exceptions.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"
20#include "dbe/confaccessor.hpp"
21#include "dbe/config_api.hpp"
24#include "dbe/dbcontroller.hpp"
25#include "dbe/messenger.hpp"
26
27#include "conffwk/Schema.hpp"
28#include "ers/Issue.hpp"
29
30#include <QString>
31#include <QUuid>
32
33#include <stack>
34#include <string>
35#include <vector>
36
37//------------------------------------------------------------------------------------------
38// NAMESPACE DBE::CONFIG::API::COMMANDS
39//------------------------------------------------------------------------------------------
40/*
41 * Purpose of this namespace is to group all commands that generate undo/redo objects
42 * that acts on config related structures and objects .
43 *
44 * DBE user interface should access the database by appropriately calling methods in this
45 * namespace. Direct access by accessing that database and retrieving ConfigObject directly
46 * is strongly discouraged.
47 */
48namespace dbe {
49namespace config {
50namespace api {
51namespace commands {
52
53//------------------------------------------------------------------------------------------
54void
55newobj(std::string const& fn,
56 std::string const& cn,
57 std::string const& name,
60 QUuid const& src)
61{
62 std::string description{ "Object created : " + name + "@" + cn };
63
64 config_internal_change request{ 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
75delobj(tref obj, QUuid const& src)
76{
77 try {
78 std::string const description{ "Object deleted : " + obj.UID() + "@" + obj.class_name() };
79 config_internal_change request{ config_internal_change::DELETED, description, obj.UID(), obj.class_name(), "" };
82 } catch (daq::dbe::ObjectChangeWasNotSuccessful const& dbe_err) {
83 INFO("Delete Object: The object could not be deleted!\n\n", dbe::config::errors::parse(dbe_err).c_str());
84 return false;
85 }
86
87 return true;
88}
89//------------------------------------------------------------------------------------------
90
91//------------------------------------------------------------------------------------------
92bool
93renobj(tref obj, std::string const& newuuid, QUuid const& src)
94{
95 try {
96 std::string const description = { "Object renamed : " + obj.UID() + "@" + obj.class_name() + " to " + newuuid +
97 "@" + obj.class_name() };
98
99 config_internal_change request{ config_internal_change::RENAMED, description, obj.UID(), obj.class_name(), "" };
100
101 confaccessor::get_commands()->push(new dbe::actions::object::rename(obj, newuuid, src));
102
104
105 return true;
106 } catch (daq::dbe::ObjectChangeWasNotSuccessful const& dbe_err) {
107 INFO("It was not possible to rename object ",
108 dbe::config::errors::parse(dbe_err).c_str(),
109 "\n\nObject UID:",
110 obj.UID().c_str());
111 return false;
112 }
113}
114//------------------------------------------------------------------------------------------
115
116//------------------------------------------------------------------------------------------
117bool
118movobj(tref obj, std::string const& destination, QUuid const& src)
119{
120 try {
121 std::string const description{ "Object " + obj.UID() + "@" + obj.class_name() + " contained in " +
122 obj.contained_in() + " moved to " + destination };
123
124 config_internal_change request{ config_internal_change::MOVED, description, obj.UID(), obj.class_name(), "" };
125
126 confaccessor::get_commands()->push(new dbe::actions::object::move(obj, destination, src));
128
129 return true;
130 } catch (daq::dbe::ObjectChangeWasNotSuccessful const& dbe_err) {
131 INFO("It was not possible to move object ",
132 dbe::config::errors::parse(dbe_err).c_str(),
133 "\n\nObject UID:",
134 obj.UID().c_str());
135 return false;
136 }
137}
138//------------------------------------------------------------------------------------------
139
140//------------------------------------------------------------------------------------------
141void
142modobj(tref object, const dunedaq::conffwk::relationship_t& linkinfo, std::vector<std::string> const& others_names)
143{
144 try {
145 confaccessor::get_commands()->push(new dbe::actions::object::changerefs(object, linkinfo, others_names));
146 std::string const description(others_names.size() != 1 ? "Multi Relationship : " + linkinfo.p_name
147 : "Single Relationship : " + linkinfo.p_name);
148
149 config_internal_change const change{
150 config_internal_change::MODIFIED, description, object.UID(), object.class_name(), ""
151 };
152
154 } catch (daq::dbe::ObjectChangeWasNotSuccessful const& dbe_err) {
155 WARN("The object reference could not be changed", dbe::config::errors::parse(dbe_err).c_str());
156 }
157}
158//------------------------------------------------------------------------------------------
159
160//------------------------------------------------------------------------------------------
161template<>
162void
163modobj<std::string>(tref Object, const dunedaq::conffwk::attribute_t& AttributeData, std::string Value)
164{
165 try {
167 Change.uid = Object.UID();
168 Change.classname = Object.class_name();
170 Change.description = QString("Attribute ").append(AttributeData.p_name.c_str()).toStdString();
171
172 if (AttributeData.p_type == dunedaq::conffwk::string_type) {
173 confaccessor::get_commands()->push(new dbe::actions::ChangeAttribute<std::string>(Object, AttributeData, Value));
174 } else if (AttributeData.p_type == dunedaq::conffwk::enum_type) {
175 confaccessor::get_commands()->push(new dbe::actions::ChangeEnum<std::string>(Object, AttributeData, Value));
176 } else if (AttributeData.p_type == dunedaq::conffwk::class_type) {
177 confaccessor::get_commands()->push(new dbe::actions::ChangeClass<std::string>(Object, AttributeData, Value));
178 } else if (AttributeData.p_type == dunedaq::conffwk::date_type) {
179
180 confaccessor::get_commands()->push(new dbe::actions::ChangeDate<std::string>(Object, AttributeData, Value));
181 } else if (AttributeData.p_type == dunedaq::conffwk::time_type) {
182 confaccessor::get_commands()->push(new dbe::actions::ChangeTime<std::string>(Object, AttributeData, Value));
183 }
184
186 } catch (daq::dbe::ObjectChangeWasNotSuccessful const& dbe_err) {
187 WARN("The object attribute could not be changed", dbe::config::errors::parse(dbe_err).c_str());
188 }
189}
190//------------------------------------------------------------------------------------------
191
192//------------------------------------------------------------------------------------------
193template<>
194void
196 const dunedaq::conffwk::attribute_t& AttributeData,
197 std::vector<std::string> Value)
198{
199 try {
201 Change.uid = Object.UID();
202 Change.classname = Object.class_name();
204 Change.description = QString("Attribute ").append(AttributeData.p_name.c_str()).toStdString();
205
206 if (AttributeData.p_type == dunedaq::conffwk::string_type) {
208 new dbe::actions::ChangeAttribute<std::vector<std::string>>(Object, AttributeData, Value));
209 } else if (AttributeData.p_type == dunedaq::conffwk::enum_type) {
211 new dbe::actions::ChangeEnum<std::vector<std::string>>(Object, AttributeData, Value));
212 } else if (AttributeData.p_type == dunedaq::conffwk::class_type) {
214 new dbe::actions::ChangeClass<std::vector<std::string>>(Object, AttributeData, Value));
215 } else if (AttributeData.p_type == dunedaq::conffwk::date_type) {
217 new dbe::actions::ChangeDate<std::vector<std::string>>(Object, AttributeData, Value));
218 } else if (AttributeData.p_type == dunedaq::conffwk::time_type) {
220 new dbe::actions::ChangeTime<std::vector<std::string>>(Object, AttributeData, Value));
221 }
222
224 } catch (daq::dbe::ObjectChangeWasNotSuccessful const& dbe_err) {
225 WARN("The object attribute could not be changed", dbe::config::errors::parse(dbe_err).c_str());
226 }
227}
228//------------------------------------------------------------------------------------------
229
230//------------------------------------------------------------------------------------------
231
232//------------------------------------------------------------------------------------------
233namespace file {
234void
235remove(QString const& db, QString const& fn)
236{
237 std::string dbname = db.toStdString();
238 std::string sinclude = fn.toStdString();
239
240 try {
242 Change.filename = fn.toStdString();
244 Change.description = QString("File(deleted) : ").append(fn).toStdString();
245
246 confaccessor::get_commands()->push(new dbe::actions::file::remove(dbname, sinclude));
248 } catch (daq::dbe::DatabaseChangeNotSuccessful const& dbe_err) {
249 WARN("File removal failure", dbe::config::errors::parse(dbe_err).c_str());
250 }
251}
252
253void
254add(const QString& Database, const QString& IncludedFile)
255{
256 std::string dbname = Database.toStdString();
257 std::string sinclude = IncludedFile.toStdString();
258
259 try {
261 Change.filename = IncludedFile.toStdString();
263 Change.description = QString("File(included) : ").append(IncludedFile).toStdString();
264
265 confaccessor::get_commands()->push(new dbe::actions::file::add(dbname, sinclude));
267 } catch (daq::dbe::DatabaseChangeNotSuccessful const& dbe_err) {
268 WARN("File inclusion did not succeed", dbe::config::errors::parse(dbe_err).c_str());
269 }
270}
271
272}
273
274}
275}
276}
277}
278//------------------------------------------------------------------------------------------
static t_undo_stack_cptr get_commands()
static t_internal_changes_stack_cptr get_internal_change_stack()
#define WARN(...)
Definition messenger.hpp:82
#define INFO(...)
Definition messenger.hpp:98
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:36
modification request
Type of modification.
std::string uid
Object Identification.