15 PyObject * type_ptr = NULL, *value_ptr = NULL, *traceback_ptr = NULL;
17 PyErr_Fetch(&type_ptr, &value_ptr, &traceback_ptr);
24 handle<> h_type(type_ptr);
25 str type_pstr(h_type);
27 extract<std::string> e_type_pstr(type_pstr);
31 if (e_type_pstr.check())
32 { ret = e_type_pstr(); }
35 { ret =
"Unknown exception type"; }
39 if (value_ptr != NULL)
41 handle<> h_val(value_ptr);
43 extract<std::string> returned(a);
46 { ret +=
": " + returned(); }
49 { ret +=
std::string(
": Unparseable Python error: "); }
53 if (traceback_ptr != NULL)
55 handle<> h_tb(traceback_ptr);
57 object tb(
import(
"traceback"));
58 object fmt_tb(tb.attr(
"format_tb"));
60 object tb_list(fmt_tb(h_tb));
62 object tb_str(str(
"\n").join(tb_list));
64 extract<std::string> returned(tb_str);
67 { ret +=
": " + returned(); }
70 { ret +=
std::string(
": Unparseable Python traceback"); }
82 PyGILState_STATE state = PyGILState_Ensure();
86 call_method<void>(
self,
"data_change",
handle, node, val , attribute);
89 catch (
const error_already_set & ex)
92 std::cout <<
"Error in 'data_change' method handler: " << perror_str << std::endl;
95 PyGILState_Release(state);
100 PyGILState_STATE state = PyGILState_Ensure();
104 call_method<void>(
self,
"event",
handle, event);
107 catch (
const error_already_set & ex)
110 std::cout <<
"Error in 'event' method handler: " << perror_str << std::endl;
113 PyGILState_Release(state);
118 PyGILState_STATE state = PyGILState_Ensure();
122 call_method<void>(
self,
"status_change", status);
125 catch (
const error_already_set & ex)
128 std::cout <<
"Error in 'status_change' method handler: " << perror_str << std::endl;
131 PyGILState_Release(state);
136 std::cout <<
"'data_change' virtual in this context" << std::endl;
141 std::cout <<
"'event' virtual in this context" << std::endl;
146 std::cout <<
"'status_change' virtual in this context" << std::endl;
static void DefaultDataChange(const SubscriptionHandler &self_, uint32_t handle, const Node &node, const object &val, uint32_t attribute)
void Event(uint32_t handle, const OpcUa::Event &event) override
static void DefaultEvent(const SubscriptionHandler &self_, uint32_t handle, const OpcUa::Event &event)
void DataChange(uint32_t handle, const Node &node, const Variant &val, AttributeId attribute) override
static void DefaultStatusChange(const SubscriptionHandler &self_, StatusCode status)
void StatusChange(StatusCode status) override
A Node object represent an OPC-UA node. It is high level object intended for developper who want to e...
static std::string parse_python_exception()
Python bindings for freeopcua. GNU LGPL.
PySubscriptionHandler(PyObject *p)