From 9ba9c95788966aa4743eb1c706ce786b0dc535fc Mon Sep 17 00:00:00 2001
From: florent <florent@laas.fr>
Date: Sat, 23 Oct 2010 21:19:19 +0200
Subject: [PATCH] Implement return value for commands.

	  * src/entity-py.cc.
---
 src/entity-py.cc | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/src/entity-py.cc b/src/entity-py.cc
index aa977d5..3b93e6a 100644
--- a/src/entity-py.cc
+++ b/src/entity-py.cc
@@ -19,6 +19,7 @@ using dynamicgraph::SignalBase;
 using dynamicgraph::ExceptionAbstract;
 using dynamicgraph::command::Command;
 using dynamicgraph::command::Value;
+using dynamicgraph::command::AnyType;
 
 namespace dynamicgraph {
   namespace python {
@@ -30,6 +31,7 @@ namespace dynamicgraph {
       static void destroy (void* self);
       static Value pythonToValue(PyObject* pyObject,
 					const Value::Type& valueType);
+      static PyObject* valueToPython(Value value);
       /**
 	 \brief Create an instance of Entity
       */
@@ -179,6 +181,26 @@ namespace dynamicgraph {
 	return Value();
       }
 
+      PyObject* valueToPython(Value value)
+      {
+	int intValue;
+	double doubleValue;
+	std::string stringValue;
+
+	switch(value.type()) {
+	case (Value::INT) :
+	  intValue = value.value();
+	  return Py_BuildValue("i", intValue);
+	case (Value::DOUBLE) :
+	  doubleValue = value.value();
+	  return Py_BuildValue("d", doubleValue);
+	case (Value::STRING) :
+	  stringValue = (std::string) value.value();
+	  return Py_BuildValue("s", stringValue.c_str());
+	}
+	return Py_BuildValue("");
+      }
+
       PyObject* executeCommand(PyObject* self, PyObject* args)
       {
 	PyObject* object = NULL;
@@ -247,12 +269,13 @@ namespace dynamicgraph {
 	}
 	command->setParameterValues(valueVector);
 	try {
-	  command->execute();
+	  Value result = command->execute();
+	  return valueToPython(result);
 	} catch (const ExceptionAbstract& exc) {
 	  PyErr_SetString(error, exc.what()) ;
 	  return NULL;
 	}
-	return Py_BuildValue("");
+	return NULL;
       }
     }
   }
-- 
GitLab