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/Configuration.hpp"
10 : #include "conffwk/ConfigObject.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, "Add include file to existing database.", py::arg("db_name"), py::arg("include"))
35 0 : .def("attributes",
36 0 : &Configuration::attributes_pybind, "Get the properties of each attribute in a given class", py::arg("class_name"), py::arg("all"))
37 0 : .def("classes",
38 0 : &Configuration::get_class_list, "Get the names of the superclasses for each class")
39 0 : .def("commit",
40 0 : &Configuration::commit, "Commit database changes.", py::arg("log_message") = "")
41 0 : .def("create_db",
42 0 : static_cast<void (Configuration::*)(const std::string&, const std::list<std::string>&)>(&Configuration::create), "Create a database from a list of files", py::arg("db_name"), py::arg("includes"))
43 0 : .def("create_obj",
44 0 : py::overload_cast<const std::string&, const std::string&, const std::string&>(&Configuration::create_and_return_obj_pybind), "Create new object by class name and object id.", py::arg("at"), py::arg("class_name"), py::arg("id"))
45 0 : .def("create_obj",
46 0 : py::overload_cast<const ConfigObject&, const std::string&, const std::string&>(&Configuration::create_and_return_obj_pybind), "Create new object by class name and object id.", py::arg("at"), py::arg("class_name"), py::arg("id"))
47 0 : .def("destroy_obj",
48 0 : &Configuration::destroy_obj, "The method tries to destroy given object.", py::arg("object"))
49 0 : .def("get_impl_param",
50 0 : &Configuration::get_impl_param, "Get implementation plug-in parameter used to build conffwk object")
51 0 : .def("get_impl_spec",
52 0 : &Configuration::get_impl_spec, "Get implementation plug-in and its parameter used to build conffwk object")
53 0 : .def("get_includes",
54 0 : &Configuration::return_includes_pybind, "Returns list of files included by given database.", py::arg("db_name"))
55 0 : .def("get_schema_path",
56 0 : &Configuration::get_schema_path_pybind, "Get path to schema file with definition of the given class", py::arg("class_name"))
57 0 : .def("get_obj",
58 0 : &Configuration::get_obj_pybind, "Create a configuration object containing the desired entity from the database", py::arg("class_name"), py::arg("id"))
59 0 : .def("get_objs",
60 0 : &Configuration::get_objs_pybind, "Create a list of configuration objects of a given class from the database", py::arg("class_name"), py::arg("query") = "")
61 0 : .def("load",
62 0 : &Configuration::load, "Load database according to the name.", py::arg("db_name"))
63 0 : .def("loaded",
64 0 : &Configuration::loaded, "Check if database is correctly loaded.")
65 0 : .def("remove_include",
66 0 : &Configuration::remove_include, "Remove include file.", py::arg("db_name"), py::arg("include"))
67 0 : .def("relations",
68 0 : &Configuration::relations_pybind, "Get the properties of each relation in a given class", py::arg("class_name"), py::arg("all"))
69 0 : .def("superclasses",
70 0 : &Configuration::superclasses_pybind, "Get the superclasses of a single class", py::arg("class_name"), py::arg("all"))
71 0 : .def("subclasses",
72 0 : &Configuration::subclasses_pybind, "Get the subclasses of a single class", py::arg("class_name"), py::arg("all"))
73 0 : .def("test_object",
74 0 : &Configuration::test_object, "Test the existence of the object", py::arg("class_name"), py::arg("id"), py::arg("rlevel"), py::arg("rclasses"))
75 0 : .def("unload",
76 0 : &Configuration::unload, "Unload previously-loaded database")
77 : ;
78 0 : }
79 :
80 :
81 : void
82 0 : register_conffwkobject(py::module& m)
83 : {
84 :
85 0 : py::class_<ConfigObject>(m, "_ConfigObject")
86 0 : .def(py::init<>())
87 0 : .def(py::init<const ConfigObject&>())
88 0 : .def("class_name",
89 0 : &ConfigObject::class_name, "Return object's class name")
90 0 : .def("contained_in",
91 0 : &ConfigObject::contained_in, "Return the name of the database file this object belongs to.")
92 0 : .def("full_name",
93 0 : &ConfigObject::full_name, "Return full object name")
94 0 : .def("get_obj",
95 0 : &ConfigObject::get_obj_pybind, "Get a copy of an object", py::arg("attrname"))
96 0 : .def("get_objs",
97 0 : &ConfigObject::get_list_pybind<ConfigObject>, "Getter function for a list", py::arg("attr"))
98 0 : .def("get_string",
99 0 : &ConfigObject::get_value_pybind<std::string>, "Simple getter function", py::arg("attr"))
100 0 : .def("get_bool",
101 0 : &ConfigObject::get_value_pybind<bool>, "Simple getter function", py::arg("attr"))
102 0 : .def("get_s8",
103 0 : &ConfigObject::get_value_pybind<int8_t>, "Simple getter function", py::arg("attr"))
104 0 : .def("get_u8",
105 0 : &ConfigObject::get_value_pybind<uint8_t>, "Simple getter function", py::arg("attr"))
106 0 : .def("get_s16",
107 0 : &ConfigObject::get_value_pybind<int16_t>, "Simple getter function", py::arg("attr"))
108 0 : .def("get_u16",
109 0 : &ConfigObject::get_value_pybind<uint16_t>, "Simple getter function", py::arg("attr"))
110 0 : .def("get_s32",
111 0 : &ConfigObject::get_value_pybind<int32_t>, "Simple getter function", py::arg("attr"))
112 0 : .def("get_u32",
113 0 : &ConfigObject::get_value_pybind<uint32_t>, "Simple getter function", py::arg("attr"))
114 0 : .def("get_s64",
115 0 : &ConfigObject::get_value_pybind<int64_t>, "Simple getter function", py::arg("attr"))
116 0 : .def("get_u64",
117 0 : &ConfigObject::get_value_pybind<uint64_t>, "Simple getter function", py::arg("attr"))
118 0 : .def("get_float",
119 0 : &ConfigObject::get_value_pybind<float>, "Simple getter function", py::arg("attr"))
120 0 : .def("get_double",
121 0 : &ConfigObject::get_value_pybind<double>, "Simple getter function", py::arg("attr"))
122 0 : .def("get_string_vec",
123 0 : &ConfigObject::get_list_pybind<std::string>, "Getter function for a list", py::arg("attr"))
124 0 : .def("get_bool_vec",
125 0 : &ConfigObject::get_list_pybind<bool>, "Getter function for a list", py::arg("attr"))
126 0 : .def("get_s8_vec",
127 0 : &ConfigObject::get_list_pybind<int8_t>, "Getter function for a list", py::arg("attr"))
128 0 : .def("get_u8_vec",
129 0 : &ConfigObject::get_list_pybind<uint8_t>, "Getter function for a list", py::arg("attr"))
130 0 : .def("get_s16_vec",
131 0 : &ConfigObject::get_list_pybind<int16_t>, "Getter function for a list", py::arg("attr"))
132 0 : .def("get_u16_vec",
133 0 : &ConfigObject::get_list_pybind<uint16_t>, "Getter function for a list", py::arg("attr"))
134 0 : .def("get_s32_vec",
135 0 : &ConfigObject::get_list_pybind<int32_t>, "Getter function for a list", py::arg("attr"))
136 0 : .def("get_u32_vec",
137 0 : &ConfigObject::get_list_pybind<uint32_t>, "Getter function for a list", py::arg("attr"))
138 0 : .def("get_s64_vec",
139 0 : &ConfigObject::get_list_pybind<int64_t>, "Getter function for a list", py::arg("attr"))
140 0 : .def("get_u64_vec",
141 0 : &ConfigObject::get_list_pybind<uint64_t>, "Getter function for a list", py::arg("attr"))
142 0 : .def("get_float_vec",
143 0 : &ConfigObject::get_list_pybind<float>, "Getter function for a list", py::arg("attr"))
144 0 : .def("get_double_vec",
145 0 : &ConfigObject::get_list_pybind<double>, "Getter function for a list", py::arg("attr"))
146 0 : .def("rename",
147 0 : &ConfigObject::rename, "Rename object", py::arg("new_id"))
148 0 : .def("set_obj",
149 0 : &ConfigObject::set_obj, "Set relationship single-value", py::arg("name"), py::arg("o"), py::arg("skip_non_null_check") = false)
150 0 : .def("set_objs",
151 0 : &ConfigObject::set_objs, "Set relationship multi-value.", py::arg("name"), py::arg("o"), py::arg("skip_non_null_check") = false)
152 0 : .def("set_class",
153 0 : py::overload_cast<const std::string&, const std::string&>(&ConfigObject::set_class), "Set the class name", py::arg("name"), py::arg("value"))
154 0 : .def("set_date",
155 0 : py::overload_cast<const std::string&, const std::string&>(&ConfigObject::set_date), "Set the date", py::arg("name"), py::arg("value"))
156 0 : .def("set_enum",
157 0 : py::overload_cast<const std::string&, const std::string&>(&ConfigObject::set_enum), "Set the enum", py::arg("name"), py::arg("value"))
158 0 : .def("set_string",
159 0 : &ConfigObject::set_by_val<std::string>, "Simple setter function", py::arg("name"), py::arg("value"))
160 0 : .def("set_time",
161 0 : py::overload_cast<const std::string&, const std::string&>(&ConfigObject::set_time), "Set the time", py::arg("name"), py::arg("value"))
162 0 : .def("set_bool",
163 0 : &ConfigObject::set_by_val<bool>, "Simple setter function", py::arg("name"), py::arg("value"))
164 0 : .def("set_s8",
165 0 : &ConfigObject::set_by_val<int8_t>, "Simple setter function", py::arg("name"), py::arg("value"))
166 0 : .def("set_u8",
167 0 : &ConfigObject::set_by_val<uint8_t>, "Simple setter function", py::arg("name"), py::arg("value"))
168 0 : .def("set_s16",
169 0 : &ConfigObject::set_by_val<int16_t>, "Simple setter function", py::arg("name"), py::arg("value"))
170 0 : .def("set_u16",
171 0 : &ConfigObject::set_by_val<uint16_t>, "Simple setter function", py::arg("name"), py::arg("value"))
172 0 : .def("set_s32",
173 0 : &ConfigObject::set_by_val<int32_t>, "Simple setter function", py::arg("name"), py::arg("value"))
174 0 : .def("set_u32",
175 0 : &ConfigObject::set_by_val<uint32_t>, "Simple setter function", py::arg("name"), py::arg("value"))
176 0 : .def("set_s64",
177 0 : &ConfigObject::set_by_val<int64_t>, "Simple setter function", py::arg("name"), py::arg("value"))
178 0 : .def("set_u64",
179 0 : &ConfigObject::set_by_val<uint64_t>, "Simple setter function", py::arg("name"), py::arg("value"))
180 0 : .def("set_float",
181 0 : &ConfigObject::set_by_val<float>, "Simple setter function", py::arg("name"), py::arg("value"))
182 0 : .def("set_double",
183 0 : &ConfigObject::set_by_val<double>, "Simple setter function", py::arg("name"), py::arg("value"))
184 0 : .def("set_bool_vec",
185 0 : &ConfigObject::set_list_pybind<bool>, "Setter function for list", py::arg("attrname"), py::arg("l"))
186 0 : .def("set_s8_vec",
187 0 : &ConfigObject::set_list_pybind<int8_t>, "Setter function for list", py::arg("attrname"), py::arg("l"))
188 0 : .def("set_u8_vec",
189 0 : &ConfigObject::set_list_pybind<uint8_t>, "Setter function for list", py::arg("attrname"), py::arg("l"))
190 0 : .def("set_s16_vec",
191 0 : &ConfigObject::set_list_pybind<int16_t>, "Setter function for list", py::arg("attrname"), py::arg("l"))
192 0 : .def("set_u16_vec",
193 0 : &ConfigObject::set_list_pybind<uint16_t>, "Setter function for list", py::arg("attrname"), py::arg("l"))
194 0 : .def("set_s32_vec",
195 0 : &ConfigObject::set_list_pybind<int32_t>, "Setter function for list", py::arg("attrname"), py::arg("l"))
196 0 : .def("set_u32_vec",
197 0 : &ConfigObject::set_list_pybind<uint32_t>, "Setter function for list", py::arg("attrname"), py::arg("l"))
198 0 : .def("set_s64_vec",
199 0 : &ConfigObject::set_list_pybind<int64_t>, "Setter function for list", py::arg("attrname"), py::arg("l"))
200 0 : .def("set_u64_vec",
201 0 : &ConfigObject::set_list_pybind<uint64_t>, "Setter function for list", py::arg("attrname"), py::arg("l"))
202 0 : .def("set_float_vec",
203 0 : &ConfigObject::set_list_pybind<float>, "Setter function for list", py::arg("attrname"), py::arg("l"))
204 0 : .def("set_double_vec",
205 0 : &ConfigObject::set_list_pybind<double>, "Setter function for list", py::arg("attrname"), py::arg("l"))
206 0 : .def("set_class_vec",
207 0 : &ConfigObject::set_list_pybind<std::string>, "Set list of classes", py::arg("attrname"), py::arg("l"))
208 0 : .def("set_date_vec",
209 0 : &ConfigObject::set_list_pybind<std::string>, "Set list of dates", py::arg("attrname"), py::arg("l"))
210 0 : .def("set_enum_vec",
211 0 : &ConfigObject::set_list_pybind<std::string>, "Set list of enums", py::arg("attrname"), py::arg("l"))
212 0 : .def("set_string_vec",
213 0 : &ConfigObject::set_list_pybind<std::string>, "Set list of strings", py::arg("attrname"), py::arg("l"))
214 0 : .def("set_time_vec",
215 0 : &ConfigObject::set_list_pybind<std::string>, "Set list of times", py::arg("attrname"), py::arg("l"))
216 0 : .def("UID",
217 0 : &ConfigObject::UID, "Return object identity")
218 : ;
219 :
220 0 : }
221 :
222 :
223 : } // namespace dunedaq::conffwk::python
|