signal-wrapper.hh
Go to the documentation of this file.
1 // Copyright (c) 2018, Joseph Mirabel
2 // Authors: Joseph Mirabel (joseph.mirabel@laas.fr)
3 
4 #ifndef DGPY_SIGNAL_WRAPPER
5 #define DGPY_SIGNAL_WRAPPER
6 
7 #include <dynamic-graph/entity.h>
9 #include <dynamic-graph/signal.h>
10 
11 #include <boost/bind.hpp>
12 #include <boost/python.hpp>
13 
15 
16 namespace dynamicgraph {
17 namespace python {
18 
19 class PythonSignalContainer : public Entity {
21 
22  public:
23  using Entity::Entity;
24 
25  void signalRegistration(const SignalArray<sigtime_t>& signals);
26 
27  void rmSignal(const std::string& name);
28 };
29 
30 template <class T, class Time>
31 class SignalWrapper : public Signal<T, Time> {
32  public:
34  typedef boost::python::object pyobject;
35 
36  static bool checkCallable(pyobject c, std::string& error);
37 
40  typedef boost::function2<T&, T&, Time> function_t;
41  function_t f = boost::bind(&SignalWrapper::call, this, _1, _2);
42  this->setFunction(f);
43  }
44 
45  virtual ~SignalWrapper(){};
46 
47  private:
48  T& call(T& value, Time t) {
49  PyGILState_STATE gstate;
50  gstate = PyGILState_Ensure();
51  if (PyGILState_GetThisThreadState() == NULL) {
52  dgDEBUG(10) << "python thread not initialized" << std::endl;
53  }
54  pyobject obj = callable(t);
55  value = boost::python::extract<T>(obj);
56  PyGILState_Release(gstate);
57  return value;
58  }
60 };
61 
62 } // namespace python
63 } // namespace dynamicgraph
64 #endif
dynamicgraph::Signal
dynamicgraph::python::PythonSignalContainer::signalRegistration
void signalRegistration(const SignalArray< sigtime_t > &signals)
Definition: signal-wrapper.cc:11
dynamicgraph::python::SignalWrapper
Definition: signal-wrapper.hh:31
dynamicgraph
dynamicgraph::Entity
dgDEBUG
#define dgDEBUG(level)
dynamicgraph::Entity::name
std::string name
dynamicgraph::Signal< T, Time >::setFunction
virtual void setFunction(boost::function2< T &, T &, Time > t, Mutex *mutexref=NULL)
dynamicgraph::python::SignalWrapper::pyobject
boost::python::object pyobject
Definition: signal-wrapper.hh:34
t
t
dynamicgraph::python::SignalWrapper::callable
pyobject callable
Definition: signal-wrapper.hh:59
python
python-compat.hh
value
float value
dynamicgraph::python::SignalWrapper::SignalWrapper
SignalWrapper(std::string name, pyobject callable)
Definition: signal-wrapper.hh:38
setup.name
name
Definition: setup.in.py:179
dynamicgraph::Entity::Entity
Entity(const std::string &name)
dynamicgraph::python::SignalWrapper::~SignalWrapper
virtual ~SignalWrapper()
Definition: signal-wrapper.hh:45
dynamicgraph::python::SignalWrapper::checkCallable
static bool checkCallable(pyobject c, std::string &error)
Definition: signal-wrapper.cc:24
linear-algebra.h
dynamicgraph::python::PythonSignalContainer::rmSignal
void rmSignal(const std::string &name)
Definition: signal-wrapper.cc:16
dynamicgraph::python::SignalWrapper::parent_t
Signal< T, Time > parent_t
Definition: signal-wrapper.hh:33
dynamicgraph::SignalArray
dynamicgraph::python::PythonSignalContainer::DYNAMIC_GRAPH_ENTITY_DECL
DYNAMIC_GRAPH_ENTITY_DECL()
dynamicgraph::python::SignalWrapper::call
T & call(T &value, Time t)
Definition: signal-wrapper.hh:48
dynamicgraph::python::PythonSignalContainer
Definition: signal-wrapper.hh:19


dynamic-graph-python
Author(s): Nicolas Mansard, Olivier Stasse
autogenerated on Fri Oct 27 2023 02:16:36