Skip to content
Snippets Groups Projects
Commit 8cae8bee authored by florent's avatar florent
Browse files

Bind method Entity::getNewStyleCommandMap()

     * src/dynamic-graph-py.cc,
     * src/entity-py.cc.
parent f7ee5e75
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,7 @@ namespace dynamicgraph {
extern PyObject* getSignal(PyObject* self, PyObject* args);
extern PyObject* displaySignals(PyObject* self, PyObject* args);
extern PyObject* executeCommand(PyObject* self, PyObject* args);
extern PyObject* listCommands(PyObject* self, PyObject* args);
}
namespace factory {
......@@ -121,6 +122,10 @@ static PyMethodDef dynamicGraphMethods[] = {
dynamicgraph::python::entity::executeCommand,
METH_VARARGS,
"execute a command"},
{"entity_list_commands",
dynamicgraph::python::entity::listCommands,
METH_VARARGS,
"list the commands of an entity"},
{"factory_get_entity_class_list",
dynamicgraph::python::factory::getEntityClassList,
METH_VARARGS,
......
......@@ -277,6 +277,36 @@ namespace dynamicgraph {
}
return NULL;
}
PyObject* listCommands(PyObject* self, PyObject* args)
{
PyObject* object = NULL;
if (!PyArg_ParseTuple(args, "O", &object)) {
return NULL;
}
// Retrieve the entity instance
if (!PyCObject_Check(object)) {
PyErr_SetString(error, "first argument is not an object");
return NULL;
}
void* pointer = PyCObject_AsVoidPtr(object);
Entity* entity = (Entity*)pointer;
typedef std::map<const std::string, command::Command*> CommandMap;
CommandMap map = entity->getNewStyleCommandMap();
unsigned int nbCommands = map.size();
// Create a tuple of same size as the command map
PyObject* result = PyTuple_New(nbCommands);
unsigned int count = 0;
for (CommandMap::iterator it=map.begin();
it != map.end(); it++) {
std::string commandName = it->first;
PyObject* pyName = Py_BuildValue("s", commandName.c_str());
PyTuple_SET_ITEM(result, count, pyName);
count++;
}
return result;
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment