Line data Source code
1 : /**
2 : * @file conffwk.cpp
3 : *
4 : * This is part of the DUNE DAQ Software Suite, copyright 2020.
5 : * Licensing/copyright details are in the COPYING file that you should have
6 : * received with this code.
7 : */
8 :
9 : #include "conffwk/ConfigObject.hpp"
10 : #include "conffwk/Configuration.hpp"
11 : #include "conffwk/Schema.hpp"
12 : #include "conffwk/set.hpp"
13 :
14 : #include <pybind11/pybind11.h>
15 : #include <pybind11/stl.h>
16 : #include <pybind11/stl_bind.h>
17 :
18 : #include <list>
19 : #include <string>
20 : #include <vector>
21 :
22 : namespace py = pybind11;
23 :
24 : namespace dunedaq::conffwk::python {
25 :
26 : void
27 0 : register_conffwk(py::module& m)
28 : {
29 :
30 0 : py::class_<Configuration>(m, "_Configuration")
31 0 : .def(py::init<>())
32 0 : .def(py::init<std::string>())
33 0 : .def("add_include",
34 0 : &Configuration::add_include,
35 : "Add include file to existing database.",
36 0 : py::arg("db_name"),
37 0 : py::arg("include"))
38 0 : .def("attributes",
39 0 : &Configuration::attributes_pybind,
40 : "Get the properties of each attribute in a given class",
41 0 : py::arg("class_name"),
42 0 : py::arg("all"))
43 0 : .def("classes", &Configuration::get_class_list, "Get the names of the superclasses for each class")
44 0 : .def("commit", &Configuration::commit, "Commit database changes.", py::arg("log_message") = "")
45 0 : .def(
46 : "create_db",
47 0 : static_cast<void (Configuration::*)(const std::string&, const std::list<std::string>&)>(&Configuration::create),
48 : "Create a database from a list of files",
49 0 : py::arg("db_name"),
50 0 : py::arg("includes"))
51 0 : .def("create_obj",
52 0 : py::overload_cast<const std::string&, const std::string&, const std::string&>(
53 : &Configuration::create_and_return_obj_pybind),
54 : "Create new object by class name and object id.",
55 0 : py::arg("at"),
56 0 : py::arg("class_name"),
57 0 : py::arg("id"))
58 0 : .def("create_obj",
59 0 : py::overload_cast<const ConfigObject&, const std::string&, const std::string&>(
60 : &Configuration::create_and_return_obj_pybind),
61 : "Create new object by class name and object id.",
62 0 : py::arg("at"),
63 0 : py::arg("class_name"),
64 0 : py::arg("id"))
65 0 : .def("destroy_obj", &Configuration::destroy_obj, "The method tries to destroy given object.", py::arg("object"))
66 0 : .def("get_impl_param",
67 0 : &Configuration::get_impl_param,
68 : "Get implementation plug-in parameter used to build conffwk object")
69 0 : .def("get_impl_spec",
70 0 : &Configuration::get_impl_spec,
71 : "Get implementation plug-in and its parameter used to build conffwk object")
72 0 : .def("get_includes",
73 0 : &Configuration::return_includes_pybind,
74 : "Returns list of files included by given database.",
75 0 : py::arg("db_name"))
76 0 : .def("get_schema_path",
77 0 : &Configuration::get_schema_path_pybind,
78 : "Get path to schema file with definition of the given class",
79 0 : py::arg("class_name"))
80 0 : .def("get_obj",
81 0 : &Configuration::get_obj_pybind,
82 : "Create a configuration object containing the desired entity from the database",
83 0 : py::arg("class_name"),
84 0 : py::arg("id"))
85 0 : .def("get_objs",
86 0 : &Configuration::get_objs_pybind,
87 : "Create a list of configuration objects of a given class from the database",
88 0 : py::arg("class_name"),
89 0 : py::arg("query") = "")
90 0 : .def("load", &Configuration::load, "Load database according to the name.", py::arg("db_name"))
91 0 : .def("loaded", &Configuration::loaded, "Check if database is correctly loaded.")
92 0 : .def(
93 0 : "remove_include", &Configuration::remove_include, "Remove include file.", py::arg("db_name"), py::arg("include"))
94 0 : .def("relations",
95 0 : &Configuration::relations_pybind,
96 : "Get the properties of each relation in a given class",
97 0 : py::arg("class_name"),
98 0 : py::arg("all"))
99 0 : .def("superclasses",
100 0 : &Configuration::superclasses_pybind,
101 : "Get the superclasses of a single class",
102 0 : py::arg("class_name"),
103 0 : py::arg("all"))
104 0 : .def("subclasses",
105 0 : &Configuration::subclasses_pybind,
106 : "Get the subclasses of a single class",
107 0 : py::arg("class_name"),
108 0 : py::arg("all"))
109 0 : .def("test_object",
110 0 : &Configuration::test_object,
111 : "Test the existence of the object",
112 0 : py::arg("class_name"),
113 0 : py::arg("id"),
114 0 : py::arg("rlevel"),
115 0 : py::arg("rclasses"))
116 0 : .def("unload", &Configuration::unload, "Unload previously-loaded database");
117 0 : }
118 :
119 : void
120 0 : register_conffwkobject(py::module& m)
121 : {
122 :
123 0 : py::class_<ConfigObject>(m, "_ConfigObject")
124 0 : .def(py::init<>())
125 0 : .def(py::init<const ConfigObject&>())
126 0 : .def("class_name", &ConfigObject::class_name, "Return object's class name")
127 0 : .def("contained_in", &ConfigObject::contained_in, "Return the name of the database file this object belongs to.")
128 0 : .def("full_name", &ConfigObject::full_name, "Return full object name")
129 0 : .def("get_obj", &ConfigObject::get_obj_pybind, "Get a copy of an object", py::arg("attrname"))
130 0 : .def("get_objs", &ConfigObject::get_list_pybind<ConfigObject>, "Getter function for a list", py::arg("attr"))
131 0 : .def("get_string", &ConfigObject::get_value_pybind<std::string>, "Simple getter function", py::arg("attr"))
132 0 : .def("get_bool", &ConfigObject::get_value_pybind<bool>, "Simple getter function", py::arg("attr"))
133 0 : .def("get_s8", &ConfigObject::get_value_pybind<int8_t>, "Simple getter function", py::arg("attr"))
134 0 : .def("get_u8", &ConfigObject::get_value_pybind<uint8_t>, "Simple getter function", py::arg("attr"))
135 0 : .def("get_s16", &ConfigObject::get_value_pybind<int16_t>, "Simple getter function", py::arg("attr"))
136 0 : .def("get_u16", &ConfigObject::get_value_pybind<uint16_t>, "Simple getter function", py::arg("attr"))
137 0 : .def("get_s32", &ConfigObject::get_value_pybind<int32_t>, "Simple getter function", py::arg("attr"))
138 0 : .def("get_u32", &ConfigObject::get_value_pybind<uint32_t>, "Simple getter function", py::arg("attr"))
139 0 : .def("get_s64", &ConfigObject::get_value_pybind<int64_t>, "Simple getter function", py::arg("attr"))
140 0 : .def("get_u64", &ConfigObject::get_value_pybind<uint64_t>, "Simple getter function", py::arg("attr"))
141 0 : .def("get_float", &ConfigObject::get_value_pybind<float>, "Simple getter function", py::arg("attr"))
142 0 : .def("get_double", &ConfigObject::get_value_pybind<double>, "Simple getter function", py::arg("attr"))
143 0 : .def("get_string_vec", &ConfigObject::get_list_pybind<std::string>, "Getter function for a list", py::arg("attr"))
144 0 : .def("get_bool_vec", &ConfigObject::get_list_pybind<bool>, "Getter function for a list", py::arg("attr"))
145 0 : .def("get_s8_vec", &ConfigObject::get_list_pybind<int8_t>, "Getter function for a list", py::arg("attr"))
146 0 : .def("get_u8_vec", &ConfigObject::get_list_pybind<uint8_t>, "Getter function for a list", py::arg("attr"))
147 0 : .def("get_s16_vec", &ConfigObject::get_list_pybind<int16_t>, "Getter function for a list", py::arg("attr"))
148 0 : .def("get_u16_vec", &ConfigObject::get_list_pybind<uint16_t>, "Getter function for a list", py::arg("attr"))
149 0 : .def("get_s32_vec", &ConfigObject::get_list_pybind<int32_t>, "Getter function for a list", py::arg("attr"))
150 0 : .def("get_u32_vec", &ConfigObject::get_list_pybind<uint32_t>, "Getter function for a list", py::arg("attr"))
151 0 : .def("get_s64_vec", &ConfigObject::get_list_pybind<int64_t>, "Getter function for a list", py::arg("attr"))
152 0 : .def("get_u64_vec", &ConfigObject::get_list_pybind<uint64_t>, "Getter function for a list", py::arg("attr"))
153 0 : .def("get_float_vec", &ConfigObject::get_list_pybind<float>, "Getter function for a list", py::arg("attr"))
154 0 : .def("get_double_vec", &ConfigObject::get_list_pybind<double>, "Getter function for a list", py::arg("attr"))
155 0 : .def("rename", &ConfigObject::rename, "Rename object", py::arg("new_id"))
156 0 : .def("set_obj",
157 0 : &ConfigObject::set_obj,
158 : "Set relationship single-value",
159 0 : py::arg("name"),
160 0 : py::arg("o"),
161 0 : py::arg("skip_non_null_check") = false)
162 0 : .def("set_objs",
163 0 : &ConfigObject::set_objs,
164 : "Set relationship multi-value.",
165 0 : py::arg("name"),
166 0 : py::arg("o"),
167 0 : py::arg("skip_non_null_check") = false)
168 0 : .def("set_class",
169 0 : py::overload_cast<const std::string&, const std::string&>(&ConfigObject::set_class),
170 : "Set the class name",
171 0 : py::arg("name"),
172 0 : py::arg("value"))
173 0 : .def("set_date",
174 0 : py::overload_cast<const std::string&, const std::string&>(&ConfigObject::set_date),
175 : "Set the date",
176 0 : py::arg("name"),
177 0 : py::arg("value"))
178 0 : .def("set_enum",
179 0 : py::overload_cast<const std::string&, const std::string&>(&ConfigObject::set_enum),
180 : "Set the enum",
181 0 : py::arg("name"),
182 0 : py::arg("value"))
183 0 : .def(
184 0 : "set_string", &ConfigObject::set_by_val<std::string>, "Simple setter function", py::arg("name"), py::arg("value"))
185 0 : .def("set_time",
186 0 : py::overload_cast<const std::string&, const std::string&>(&ConfigObject::set_time),
187 : "Set the time",
188 0 : py::arg("name"),
189 0 : py::arg("value"))
190 0 : .def("set_bool", &ConfigObject::set_by_val<bool>, "Simple setter function", py::arg("name"), py::arg("value"))
191 0 : .def("set_s8", &ConfigObject::set_by_val<int8_t>, "Simple setter function", py::arg("name"), py::arg("value"))
192 0 : .def("set_u8", &ConfigObject::set_by_val<uint8_t>, "Simple setter function", py::arg("name"), py::arg("value"))
193 0 : .def("set_s16", &ConfigObject::set_by_val<int16_t>, "Simple setter function", py::arg("name"), py::arg("value"))
194 0 : .def("set_u16", &ConfigObject::set_by_val<uint16_t>, "Simple setter function", py::arg("name"), py::arg("value"))
195 0 : .def("set_s32", &ConfigObject::set_by_val<int32_t>, "Simple setter function", py::arg("name"), py::arg("value"))
196 0 : .def("set_u32", &ConfigObject::set_by_val<uint32_t>, "Simple setter function", py::arg("name"), py::arg("value"))
197 0 : .def("set_s64", &ConfigObject::set_by_val<int64_t>, "Simple setter function", py::arg("name"), py::arg("value"))
198 0 : .def("set_u64", &ConfigObject::set_by_val<uint64_t>, "Simple setter function", py::arg("name"), py::arg("value"))
199 0 : .def("set_float", &ConfigObject::set_by_val<float>, "Simple setter function", py::arg("name"), py::arg("value"))
200 0 : .def("set_double", &ConfigObject::set_by_val<double>, "Simple setter function", py::arg("name"), py::arg("value"))
201 0 : .def("set_bool_vec",
202 : &ConfigObject::set_list_pybind<bool>,
203 : "Setter function for list",
204 0 : py::arg("attrname"),
205 0 : py::arg("l"))
206 0 : .def("set_s8_vec",
207 : &ConfigObject::set_list_pybind<int8_t>,
208 : "Setter function for list",
209 0 : py::arg("attrname"),
210 0 : py::arg("l"))
211 0 : .def("set_u8_vec",
212 : &ConfigObject::set_list_pybind<uint8_t>,
213 : "Setter function for list",
214 0 : py::arg("attrname"),
215 0 : py::arg("l"))
216 0 : .def("set_s16_vec",
217 : &ConfigObject::set_list_pybind<int16_t>,
218 : "Setter function for list",
219 0 : py::arg("attrname"),
220 0 : py::arg("l"))
221 0 : .def("set_u16_vec",
222 : &ConfigObject::set_list_pybind<uint16_t>,
223 : "Setter function for list",
224 0 : py::arg("attrname"),
225 0 : py::arg("l"))
226 0 : .def("set_s32_vec",
227 : &ConfigObject::set_list_pybind<int32_t>,
228 : "Setter function for list",
229 0 : py::arg("attrname"),
230 0 : py::arg("l"))
231 0 : .def("set_u32_vec",
232 : &ConfigObject::set_list_pybind<uint32_t>,
233 : "Setter function for list",
234 0 : py::arg("attrname"),
235 0 : py::arg("l"))
236 0 : .def("set_s64_vec",
237 : &ConfigObject::set_list_pybind<int64_t>,
238 : "Setter function for list",
239 0 : py::arg("attrname"),
240 0 : py::arg("l"))
241 0 : .def("set_u64_vec",
242 : &ConfigObject::set_list_pybind<uint64_t>,
243 : "Setter function for list",
244 0 : py::arg("attrname"),
245 0 : py::arg("l"))
246 0 : .def("set_float_vec",
247 : &ConfigObject::set_list_pybind<float>,
248 : "Setter function for list",
249 0 : py::arg("attrname"),
250 0 : py::arg("l"))
251 0 : .def("set_double_vec",
252 : &ConfigObject::set_list_pybind<double>,
253 : "Setter function for list",
254 0 : py::arg("attrname"),
255 0 : py::arg("l"))
256 0 : .def("set_class_vec",
257 : &ConfigObject::set_list_pybind<std::string>,
258 : "Set list of classes",
259 0 : py::arg("attrname"),
260 0 : py::arg("l"))
261 0 : .def("set_date_vec",
262 : &ConfigObject::set_list_pybind<std::string>,
263 : "Set list of dates",
264 0 : py::arg("attrname"),
265 0 : py::arg("l"))
266 0 : .def("set_enum_vec",
267 : &ConfigObject::set_list_pybind<std::string>,
268 : "Set list of enums",
269 0 : py::arg("attrname"),
270 0 : py::arg("l"))
271 0 : .def("set_string_vec",
272 : &ConfigObject::set_list_pybind<std::string>,
273 : "Set list of strings",
274 0 : py::arg("attrname"),
275 0 : py::arg("l"))
276 0 : .def("set_time_vec",
277 : &ConfigObject::set_list_pybind<std::string>,
278 : "Set list of times",
279 0 : py::arg("attrname"),
280 0 : py::arg("l"))
281 0 : .def("UID", &ConfigObject::UID, "Return object identity");
282 0 : }
283 :
284 : } // namespace dunedaq::conffwk::python
|