Line data Source code
1 : /*
2 : * config_api_get.cpp
3 : *
4 : * Created on: Apr 19, 2016
5 : * Author: Leonidas Georgopoulos
6 : */
7 :
8 : #include "dbe/config_api_get.hpp"
9 : #include "dbe/Conversion.hpp"
10 : #include "dbe/dbaccessor.hpp"
11 : #include "dbe/messenger.hpp"
12 : #include "dbe/config_api.hpp"
13 :
14 : using namespace dunedaq::conffwk;
15 :
16 :
17 : //------------------------------------------------------------------------------------------
18 : // NAMESPACE DBE::CONFIG::API::GET
19 : //------------------------------------------------------------------------------------------
20 :
21 : namespace dbe
22 : {
23 :
24 : namespace config
25 : {
26 :
27 : namespace api
28 : {
29 :
30 : namespace get
31 : {
32 : //------------------------------------------------------------------------------------------
33 :
34 : template<typename T>
35 0 : inline std::vector<std::string> attribute::read (
36 : ConfigObject & input, dunedaq::conffwk::attribute_t const & attr )
37 : {
38 0 : std::vector<T> attrvalues;
39 :
40 0 : if ( attr.p_is_multi_value )
41 : {
42 0 : attrvalues = direct::attribute<std::vector<T>> ( input, attr );
43 : }
44 : else
45 : {
46 0 : attrvalues =
47 0 : { direct::attribute<T> ( input, attr ) };
48 : }
49 :
50 0 : std::vector<std::string> strings ( attrvalues.size() );
51 0 : std::transform ( attrvalues.begin(), attrvalues.end(),
52 0 : strings.begin(), [&attr] ( T const & x )
53 : {
54 0 : return convert::valtostr ( x, attr.p_int_format );
55 : }
56 :
57 : );
58 :
59 0 : return strings;
60 0 : }
61 :
62 : //------------------------------------------------------------------------------------------
63 :
64 : //------------------------------------------------------------------------------------------
65 : template<typename T>
66 0 : inline T direct::attribute ( ConfigObject & input,
67 : dunedaq::conffwk::attribute_t const & attr )
68 : {
69 0 : T value;
70 0 : input.get ( attr.p_name, value );
71 0 : return value;
72 0 : }
73 :
74 : //------------------------------------------------------------------------------------------
75 :
76 : //------------------------------------------------------------------------------------------
77 : template<>
78 0 : QStringList direct::attribute<QStringList> ( ConfigObject & input,
79 : dunedaq::conffwk::attribute_t const & attr )
80 : {
81 0 : std::vector<std::string> data;
82 :
83 0 : switch ( attr.p_type )
84 : {
85 :
86 0 : case dunedaq::conffwk::bool_type:
87 0 : data = get::attribute::read<bool> ( input, attr );
88 0 : break;
89 :
90 0 : case dunedaq::conffwk::enum_type:
91 :
92 0 : case dunedaq::conffwk::date_type:
93 :
94 0 : case dunedaq::conffwk::time_type:
95 :
96 0 : case dunedaq::conffwk::string_type:
97 :
98 0 : case dunedaq::conffwk::class_type:
99 0 : data = get::attribute::read<std::string> ( input, attr );
100 0 : break;
101 :
102 0 : case dunedaq::conffwk::float_type:
103 0 : data = get::attribute::read<float> ( input, attr );
104 0 : break;
105 :
106 0 : case dunedaq::conffwk::double_type:
107 0 : data = get::attribute::read<double> ( input, attr );
108 0 : break;
109 :
110 0 : case dunedaq::conffwk::s8_type:
111 0 : data = get::attribute::read<int8_t> ( input, attr );
112 0 : break;
113 :
114 0 : case dunedaq::conffwk::u8_type:
115 0 : data = get::attribute::read<u_int8_t> ( input, attr );
116 0 : break;
117 :
118 0 : case dunedaq::conffwk::s16_type:
119 0 : data = get::attribute::read<int16_t> ( input, attr );
120 0 : break;
121 :
122 0 : case dunedaq::conffwk::u16_type:
123 0 : data = get::attribute::read<u_int16_t> ( input, attr );
124 0 : break;
125 :
126 0 : case dunedaq::conffwk::s32_type:
127 0 : data = get::attribute::read<int32_t> ( input, attr );
128 0 : break;
129 :
130 0 : case dunedaq::conffwk::u32_type:
131 0 : data = get::attribute::read<u_int32_t> ( input, attr );
132 0 : break;
133 :
134 0 : case dunedaq::conffwk::s64_type:
135 0 : data = get::attribute::read<int64_t> ( input, attr );
136 0 : break;
137 :
138 0 : case dunedaq::conffwk::u64_type:
139 0 : data = get::attribute::read<u_int64_t> ( input, attr );
140 0 : break;
141 : }
142 :
143 0 : QStringList result;
144 :
145 0 : for ( auto const & x : data )
146 : {
147 0 : result.push_back ( x.c_str() );
148 : }
149 :
150 0 : return result;
151 :
152 0 : }
153 :
154 : template
155 : QStringList direct::attribute<QStringList>
156 : ( ConfigObject &,
157 : dunedaq::conffwk::attribute_t const & );
158 :
159 : template
160 : ConfigObject direct::attribute<ConfigObject>
161 : ( ConfigObject &,
162 : dunedaq::conffwk::attribute_t const & );
163 :
164 : template
165 : std::vector<ConfigObject>
166 : direct::attribute<std::vector<ConfigObject>> (
167 : ConfigObject &, dunedaq::conffwk::attribute_t const & );
168 :
169 : //------------------------------------------------------------------------------------------
170 :
171 : //------------------------------------------------------------------------------------------
172 : template<typename T>
173 0 : inline T attribute::list ( dbe::inner::configobject::tref obj,
174 : dunedaq::conffwk::attribute_t const & Attribute )
175 : {
176 0 : std::vector<std::string> attrvalues;
177 :
178 0 : switch ( Attribute.p_type )
179 : {
180 :
181 0 : case dunedaq::conffwk::bool_type:
182 0 : attrvalues = get::attribute::read<bool> ( obj, Attribute );
183 0 : break;
184 :
185 0 : case dunedaq::conffwk::enum_type:
186 :
187 : case dunedaq::conffwk::date_type:
188 :
189 : case dunedaq::conffwk::time_type:
190 :
191 : case dunedaq::conffwk::string_type:
192 :
193 : case dunedaq::conffwk::class_type:
194 0 : attrvalues = get::attribute::read<std::string> ( obj, Attribute );
195 0 : break;
196 :
197 0 : case dunedaq::conffwk::float_type:
198 0 : attrvalues = get::attribute::read<float> ( obj, Attribute );
199 0 : break;
200 :
201 0 : case dunedaq::conffwk::double_type:
202 0 : attrvalues = get::attribute::read<double> ( obj, Attribute );
203 0 : break;
204 :
205 0 : case dunedaq::conffwk::s8_type:
206 0 : attrvalues = get::attribute::read<int8_t> ( obj, Attribute );
207 0 : break;
208 :
209 0 : case dunedaq::conffwk::u8_type:
210 0 : attrvalues = get::attribute::read<u_int8_t> ( obj, Attribute );
211 0 : break;
212 :
213 0 : case dunedaq::conffwk::s16_type:
214 0 : attrvalues = get::attribute::read<int16_t> ( obj, Attribute );
215 0 : break;
216 :
217 0 : case dunedaq::conffwk::u16_type:
218 0 : attrvalues = get::attribute::read<u_int16_t> ( obj, Attribute );
219 0 : break;
220 :
221 0 : case dunedaq::conffwk::s32_type:
222 0 : attrvalues = get::attribute::read<int32_t> ( obj, Attribute );
223 0 : break;
224 :
225 0 : case dunedaq::conffwk::u32_type:
226 0 : attrvalues = get::attribute::read<u_int32_t> ( obj, Attribute );
227 0 : break;
228 :
229 0 : case dunedaq::conffwk::s64_type:
230 0 : attrvalues = get::attribute::read<int64_t> ( obj, Attribute );
231 0 : break;
232 :
233 0 : case dunedaq::conffwk::u64_type:
234 0 : attrvalues = get::attribute::read<u_int64_t> ( obj, Attribute );
235 0 : break;
236 : }
237 :
238 0 : return dbe::convert::to<T> ( attrvalues );
239 0 : }
240 :
241 : // Template method declaration of attribute::list for type QStringList
242 : template
243 : QStringList attribute::list<QStringList> ( dbe::inner::configobject::tref obj,
244 : dunedaq::conffwk::attribute_t const & );
245 : //------------------------------------------------------------------------------------------
246 :
247 : //------------------------------------------------------------------------------------------
248 0 : QStringList file::inclusions ( QStringList const & candidates, QStringList files )
249 : {
250 0 : if ( candidates.isEmpty() )
251 : {
252 0 : return files;
253 : }
254 : else
255 : {
256 0 : QStringList newcandidates =
257 0 : { };
258 :
259 0 : for ( QString const & fname : candidates )
260 : {
261 0 : if ( not ( fname.endsWith ( "schema.xml" ) or files.contains ( fname ) ) )
262 : {
263 0 : files.push_back ( fname );
264 : // Query the current file for other inclusions
265 0 : std::list<std::string> configfiles;
266 :
267 0 : try
268 : {
269 0 : if ( not ( fname.contains ( "rdbconfig:" ) or fname.contains ( "roksconflibs:" ) ) )
270 : {
271 : // Process file based sources
272 0 : dbaccessor::dbptr()->get_includes ( fname.toStdString(), configfiles );
273 : }
274 : else
275 : {
276 : // Process other sources (e.g. Oracle and RDB )
277 0 : dbaccessor::dbptr()->get_includes ( "", configfiles );
278 0 : files.removeAll ( fname ); // Once used RDB / Oracle sources must be removed
279 : }
280 : }
281 0 : catch ( dunedaq::conffwk::Exception const & ex )
282 : {
283 0 : ERROR ( "Include did not succeed for ", dbe::config::errors::parse ( ex ).c_str(),
284 0 : "filename:", fname.toStdString().c_str() );
285 0 : }
286 :
287 : // Keep only files that have not already been processed
288 : // i.e. they are not in the list of given files.
289 0 : for ( std::string const & configfile : configfiles )
290 : {
291 0 : QString const & qconfigfile = QString::fromStdString ( configfile );
292 :
293 0 : if ( not files.contains ( qconfigfile ) )
294 : {
295 0 : newcandidates.push_back ( qconfigfile );
296 : }
297 0 : }
298 :
299 0 : }
300 :
301 : }
302 :
303 0 : return get::file::inclusions ( newcandidates, files );
304 0 : }
305 : }
306 :
307 : //------------------------------------------------------------------------------------------
308 :
309 : //------------------------------------------------------------------------------------------
310 0 : QStringList file::inclusions_singlefile ( QString const & FileName )
311 : {
312 0 : std::string dbname = FileName.toStdString();
313 0 : std::list<std::string> incList;
314 :
315 0 : QStringList dbfiles;
316 :
317 0 : try
318 : {
319 0 : dbaccessor::dbptr()->get_includes ( dbname, incList );
320 :
321 0 : for ( std::string const & includeName : incList )
322 : {
323 0 : dbfiles.push_back ( QString ( includeName.c_str() ) );
324 : }
325 : }
326 0 : catch ( dunedaq::conffwk::Exception & ex )
327 : {
328 0 : WARN ( "Include : Could not retrieve included files",
329 0 : dbe::config::errors::parse ( ex ).c_str() );
330 0 : }
331 :
332 0 : return dbfiles;
333 0 : }
334 :
335 : //------------------------------------------------------------------------------------------
336 :
337 : //------------------------------------------------------------------------------------------
338 0 : QStringList get::defaults::attribute::value ( dunedaq::conffwk::attribute_t const & attr )
339 : {
340 0 : return QString::fromStdString ( attr.p_default_value ).split ( "," );
341 : }
342 :
343 : //------------------------------------------------------------------------------------------
344 :
345 : //------------------------------------------------------------------------------------------
346 : }
347 : }
348 : }
349 : }
350 :
351 : //------------------------------------------------------------------------------------------
352 :
|