4 #ifndef DGPY_SIGNAL_WRAPPER 5 #define DGPY_SIGNAL_WRAPPER 7 #include <dynamic-graph/linear-algebra.h> 8 #include <dynamic-graph/signal.h> 9 #include <dynamic-graph/entity.h> 14 namespace signalWrapper {
15 void convert(PyObject* o,
int& v);
16 void convert(PyObject* o,
bool& v);
17 void convert(PyObject* o,
float& v);
18 void convert(PyObject* o,
double& v);
20 void convert(PyObject* o, Vector& v);
26 DYNAMIC_GRAPH_ENTITY_DECL();
31 void signalRegistration(
const SignalArray<int>& signals);
33 void rmSignal(
const std::string& name);
36 template <
class T,
class Time>
41 static bool checkCallable(PyObject* c, std::string& error);
43 SignalWrapper(std::string name, PyObject* _callable) : parent_t(name), callable(_callable) {
44 typedef boost::function2<T&, T&, Time> function_t;
46 function_t f = boost::bind(&SignalWrapper::call,
this, _1, _2);
53 T& call(T& value, Time t) {
54 PyGILState_STATE gstate;
55 gstate = PyGILState_Ensure();
56 if (PyGILState_GetThisThreadState() == NULL) {
57 dgDEBUG(10) <<
"python thread not initialized" << std::endl;
60 PyObject* obj = PyObject_CallFunction(callable, format, t);
62 dgERROR <<
"Could not call callable" << std::endl;
67 PyGILState_Release(gstate);
Definition: signal-wrapper.hh:25
Definition: signal-wrapper.hh:37
SignalWrapper(std::string name, PyObject *_callable)
Definition: signal-wrapper.hh:43
Signal< T, Time > parent_t
Definition: signal-wrapper.hh:39
virtual ~SignalWrapper()
Definition: signal-wrapper.hh:50
Definition: convert-dg-to-py.hh:7
void convert(PyObject *o, int &v)
Definition: signal-wrapper.cc:13