Line data Source code
1 : #include "ers/AnyIssue.hpp"
2 : #include "ers/Context.hpp"
3 : #include "ers/Issue.hpp"
4 : #include "ers/IssueFactory.hpp"
5 : #include "ers/LocalContext.hpp"
6 : #include "ers/OutputStream.hpp"
7 : #include "ers/RemoteContext.hpp"
8 : #include "ers/Severity.hpp"
9 : #include "ers/ers.hpp"
10 :
11 : #include <exception>
12 : #include <pybind11/pybind11.h>
13 : #include <pybind11/stl.h>
14 :
15 : namespace py = pybind11;
16 :
17 0 : PYBIND11_MODULE(_daq_ers_py, module)
18 : {
19 :
20 : // Class inheritence to be included
21 : // std::exception -> ers::Issue -> ers::AnyIssue
22 : // Abstract classes (like ers::Issue) cannot be called with
23 : // pybind11. Line below is only a decleration of ers::Issue.
24 :
25 0 : py::class_<std::exception>(module, "STDException");
26 :
27 0 : py::class_<ers::Issue, std::exception>(module, "Issue");
28 :
29 0 : py::class_<ers::OutputStream>(module, "OutputStream");
30 :
31 : // Concrete Issue class
32 0 : py::class_<ers::AnyIssue, ers::Issue>(module, "AnyIssue")
33 : // constructor 1
34 0 : .def(py::init<const std::string&, const ers::Context&, const std::string&>())
35 : // constructor 2
36 0 : .def(py::init<const std::string&,
37 : const ers::inheritance_type&,
38 : ers::Severity,
39 : const ers::Context&,
40 : const system_clock::time_point&,
41 : const std::string&,
42 : const std::vector<std::string>&,
43 : const std::map<std::string, std::string>&,
44 0 : const ers::Issue*>())
45 0 : .def("get_class_name", &ers::AnyIssue::get_class_name)
46 0 : .def("get_class_inheritance", &ers::AnyIssue::get_class_inheritance)
47 0 : .def("raise", &ers::AnyIssue::raise)
48 0 : .def("what", &ers::AnyIssue::what)
49 0 : .def("cause", &ers::AnyIssue::cause)
50 0 : .def("severity", &ers::AnyIssue::severity)
51 0 : .def("qualifiers", &ers::AnyIssue::qualifiers)
52 0 : .def("parameters", &ers::AnyIssue::parameters);
53 :
54 : // Bindings for Context base class and derived classes
55 :
56 0 : py::class_<ers::Context>(module, "Context")
57 0 : .def("cwd", &ers::Context::cwd)
58 0 : .def("function_name", &ers::Context::function_name)
59 0 : .def("file_name", &ers::Context::file_name)
60 0 : .def("host_name", &ers::Context::host_name)
61 0 : .def("package_name", &ers::Context::package_name)
62 0 : .def("user_name", &ers::Context::user_name)
63 0 : .def("application_name", &ers::Context::application_name)
64 0 : .def("user_id", &ers::Context::user_id)
65 0 : .def("user_name", &ers::Context::user_name)
66 0 : .def("stack_size", &ers::Context::stack_size)
67 0 : .def("stack_symbols", &ers::Context::stack_symbols)
68 0 : .def("line_number", &ers::Context::line_number)
69 0 : .def("process_id", &ers::Context::process_id)
70 0 : .def("thread_id", &ers::Context::thread_id);
71 :
72 : // And now some concrete classes deriving from Context
73 0 : py::class_<ers::LocalContext, ers::Context>(module, "LocalContext")
74 0 : .def(py::init<const char*, const char*, int, const char*, bool>());
75 :
76 0 : py::class_<ers::RemoteProcessContext>(module, "RemoteProcessContext")
77 0 : .def(py::init<const std::string&, int, int, const std::string&, int, const std::string&, const std::string&>());
78 :
79 0 : py::class_<ers::RemoteContext, ers::Context>(module, "RemoteContext")
80 0 : .def(py::init<const std::string&, const std::string&, int, const std::string&, ers::RemoteProcessContext&>());
81 :
82 : // Severity includes both a class and and enum.
83 0 : py::class_<ers::Severity>(module, "Severity")
84 0 : .def(py::init<ers::severity&, int&>())
85 0 : .def_readwrite("type", &ers::Severity::type)
86 0 : .def_readwrite("rank", &ers::Severity::rank);
87 0 : py::enum_<ers::severity>(module, "severity")
88 0 : .value("Debug", ers::severity::Debug)
89 0 : .value("Log", ers::severity::Log)
90 0 : .value("Information", ers::severity::Information)
91 0 : .value("Warning", ers::severity::Warning)
92 0 : .value("Error", ers::severity::Error)
93 0 : .value("Fatal", ers::severity::Fatal)
94 0 : .export_values();
95 :
96 : // Bind the various logging calls
97 0 : module.def("debug", &ers::debug, "sends issue to the debug stream", py::arg("issue"), py::arg("level"));
98 0 : module.def("log", &ers::log, "sends issue to the log stream", py::arg("issue"));
99 0 : module.def("info", &ers::info, "sends issue to the information stream", py::arg("issue"));
100 0 : module.def("warning", &ers::warning, "sends issue to the warning stream", py::arg("issue"));
101 0 : module.def("error", &ers::error, "sends issue to the error stream", py::arg("issue"));
102 0 : module.def("fatal", &ers::fatal, "sends issue to the fatal stream", py::arg("issue"));
103 0 : module.def("debug_level", &ers::debug_level, "returns current debug level for ERS");
104 0 : module.def("verbosity_level", &ers::verbosity_level, "returns current verbosity level for ERS");
105 0 : module.def("enable_core_dump", &ers::enable_core_dump, "does what the name implies");
106 0 : }
|