Commit b1859161 authored by Florent Lamiraux's avatar Florent Lamiraux Committed by Florent Lamiraux florent@laas.fr
Browse files

Enhance SignalBase API

  - add isPlugged and getPlugged methods,
  - add property getter name.
parent 8019f592
......@@ -40,6 +40,8 @@ namespace dynamicgraph {
extern PyObject* setValue(PyObject* self, PyObject* args);
extern PyObject* recompute(PyObject* self, PyObject* args);
extern PyObject* unplug(PyObject* self, PyObject* args);
extern PyObject* isPlugged(PyObject* self, PyObject* args);
extern PyObject* getPlugged(PyObject* self, PyObject* args);
}
namespace entity {
extern PyObject* create(PyObject* self, PyObject* args);
......@@ -166,6 +168,10 @@ static PyMethodDef dynamicGraphMethods[] = {
METH_VARARGS, "Recompute the signal at given time"},
{"signal_base_unplug", dynamicgraph::python::signalBase::unplug,
METH_VARARGS, "Unplug the signal"},
{"signal_base_isPlugged", dynamicgraph::python::signalBase::isPlugged,
METH_VARARGS, "Whether the signal is plugged"},
{"signal_base_getPlugged", dynamicgraph::python::signalBase::getPlugged,
METH_VARARGS, "To which signal the signal is plugged"},
// Entity
{"create_entity", dynamicgraph::python::entity::create, METH_VARARGS,
"create an Entity C++ object"},
......
......@@ -225,6 +225,13 @@ class SignalBase (object) :
"""
return wrap.signal_base_get_name(self.obj)
@property
def name (self) :
"""
Get name of signal
"""
return wrap.signal_base_get_name(self.obj)
def getClassName(self):
"""
Get class name of signal
......@@ -241,6 +248,16 @@ class SignalBase (object) :
Unplug a PTR signal.
"""
return wrap.signal_base_unplug(self.obj)
def isPlugged(self):
"""
Return whether a signal is plugged.
"""
return wrap.signal_base_isPlugged(self.obj)
def getPlugged(self):
"""
Return the plugged signal.
"""
return SignalBase (obj = wrap.signal_base_getPlugged(self.obj))
def __str__(self):
"""
......
......@@ -319,6 +319,51 @@ namespace dynamicgraph {
} CATCH_ALL_EXCEPTIONS ();
return Py_BuildValue("");
}
}
}
}
PyObject* isPlugged (PyObject*, PyObject* args)
{
void * pointer = NULL;
PyObject* object = NULL;
if (!PyArg_ParseTuple(args,"O", &object))
return NULL;
if (!PyCObject_Check(object))
return NULL;
pointer = PyCObject_AsVoidPtr(object);
SignalBase<int>* signal = (SignalBase<int>*)pointer;
bool plugged = false;
try {
plugged = signal->isPluged();
} CATCH_ALL_EXCEPTIONS ();
if (plugged) return PyBool_FromLong(1); else return PyBool_FromLong(0);
}
PyObject* getPlugged (PyObject*, PyObject* args)
{
void * pointer = NULL;
PyObject* object = NULL;
if (!PyArg_ParseTuple(args,"O", &object))
return NULL;
if (!PyCObject_Check(object))
return NULL;
pointer = PyCObject_AsVoidPtr(object);
SignalBase<int>* signal = (SignalBase<int>*)pointer;
SignalBase<int>* otherSignal = 0;
try {
bool plugged = signal->isPluged ();
otherSignal = signal->getPluged();
if (!plugged || otherSignal == 0) {
std::string msg = std::string ("Signal ") + signal->getName()
+ std::string (" is not plugged.");
throw std::runtime_error (msg);
}
} CATCH_ALL_EXCEPTIONS ();
// Return the pointer to the signal without destructor since the signal
// is not owned by the calling object.
return PyCObject_FromVoidPtr((void*)otherSignal, NULL);
}
} // namespace signalBase
} // namespace python
} // namespace dynamicgraph
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment