Commit 332fba6d authored by Olivier Stasse's avatar Olivier Stasse

[Entity] Add setLoggerVerbosityLevel and getLoggerVerbosityLevel bindings.

parent 2cac3dcd
......@@ -170,7 +170,7 @@ static PyMethodDef dynamicGraphMethods[] = {
{"signal_base_display_dependencies", dynamicgraph::python::signalBase::displayDependencies,
METH_VARARGS, "Print the signal dependencies in a string"},
{"signal_base_get_value", dynamicgraph::python::signalBase::getValue,
METH_VARARGS, "Read the value of a signal"},
METH_VARARGS, "Read the value of a signal"},
{"signal_base_set_value", dynamicgraph::python::signalBase::setValue,
METH_VARARGS, "Set the value of a signal"},
{"signal_base_recompute", dynamicgraph::python::signalBase::recompute,
......@@ -236,7 +236,7 @@ static PyMethodDef dynamicGraphMethods[] = {
{"entity_get_logger_verbosity",
dynamicgraph::python::entity::getLoggerVerbosityLevel,
METH_VARARGS,
"get the verbosity level of the entity"},
"get the verbosity level of the entity"},
{NULL, NULL, 0, NULL} /* Sentinel */
};
......
......@@ -256,12 +256,11 @@ class Entity (object) :
for cmd in cmdList:
self.boundNewCommand( cmd )
def setLoggerVerbosityLevel(self, verbosity):
def setLoggerVerbosityLevel(self,verbosity):
"""
Specify for the entity the verbosity level
"""
#return
wrap.entity_set_logger_verbosity(self.obj,verbosity)
return wrap.entity_set_logger_verbosity(self.obj, verbosity)
def getLoggerVerbosityLevel(self):
"""
......
// Copyright 2010, Florent Lamiraux, Thomas Moulard, LAAS-CNRS.
//
// This file is part of dynamic-graph-python.
......@@ -415,60 +414,31 @@ namespace dynamicgraph {
return Py_BuildValue("s", oss.str().c_str());
}
/**
\brief Get verbosity Level
*/
PyObject* getLoggerVerbosityLevel(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(PyExc_TypeError,
"first argument is not an object");
return NULL;
}
void *pointer = PyCObject_AsVoidPtr(object);
Entity* entity = (Entity*)pointer;
LoggerVerbosity alv ;
try {
alv = entity->getLoggerVerbosityLevel();
} CATCH_ALL_EXCEPTIONS();
int ares= (int)alv;
return Py_BuildValue("i",ares);
}
/**
\brief Set verbosity Level
*/
PyObject* setLoggerVerbosityLevel(PyObject* /*self*/, PyObject* /* args */)
PyObject* setLoggerVerbosityLevel(PyObject* /*self*/, PyObject* args )
{
#if 0
PyObject* object = NULL;
PyObject* objectVerbosityLevel = NULL;
if (!PyArg_ParseTuple(args, "OO", &object,&objectVerbosityLevel))
return NULL;
// Retrieve the entity instance
if (!PyCObject_Check(object)) {
PyErr_SetString(PyExc_TypeError,
"First argument should be an object");
return NULL;
}
void *pointer = PyCObject_AsVoidPtr(object);
Entity* entity = (Entity*)pointer;
// Retrieve object verbosity level
PyObject* valueOfVerbosityLevel = PyObject_GetAttrString(objectVerbosityLevel, "value");
long verbosityLevel = PyLong_AsLong(valueOfVerbosityLevel);//*((int*) lpointer);
try {
switch(verbosityLevel)
{
......@@ -482,21 +452,50 @@ namespace dynamicgraph {
break;
default: entity->setLoggerVerbosityLevel(VERBOSITY_NONE);
break;
}
} catch (const std::exception& exc) {
PyErr_SetString(dgpyError, exc.what());
return NULL;
} catch (const char* s) {
PyErr_SetString(dgpyError, s);
return NULL;
} catch (...) {
PyErr_SetString(dgpyError, "Unknown exception");
return NULL;
}
} catch (const std::exception& exc) {
PyErr_SetString(dgpyError, exc.what());
return NULL;
} catch (const char* s) {
PyErr_SetString(dgpyError, s);
return NULL;
} catch (...) {
PyErr_SetString(dgpyError, "Unknown exception");
return NULL;
}
#endif
return NULL;
return Py_BuildValue("");
}
/**
\brief Get verbosity Level
*/
PyObject* getLoggerVerbosityLevel(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(PyExc_TypeError,
"first argument is not an object");
return NULL;
}
void *pointer = PyCObject_AsVoidPtr(object);
Entity* entity = (Entity*)pointer;
LoggerVerbosity alv ;
try {
alv = entity->getLoggerVerbosityLevel();
} CATCH_ALL_EXCEPTIONS();
int ares= (int)alv;
return Py_BuildValue("i",ares);
}
}
}
}
# Olivier Stasse
# 2019 CNRS
#
import sys, os
# Put local python module at first priority
sys.path.insert(0,os.getcwd()+'/../src')
......@@ -8,11 +11,16 @@ from dynamic_graph_tests.custom_entity import *
from dynamic_graph.entity import VerbosityLevel
aCustomEntity = CustomEntity("a_custom_entity")
print(dir(aCustomEntity))
aCustomEntity.signals()
aCustomEntity.setLoggerVerbosityLevel(VerbosityLevel.VERBOSITY_INFO_WARNING_ERROR)
print(aCustomEntity.getLoggerVerbosityLevel())
aCustomEntity.setLoggerVerbosityLevel(VerbosityLevel.VERBOSITY_WARNING_ERROR)
print(aCustomEntity.getLoggerVerbosityLevel())
aCustomEntity.setLoggerVerbosityLevel(VerbosityLevel.VERBOSITY_ERROR)
print(aCustomEntity.getLoggerVerbosityLevel())
aCustomEntity.setLoggerVerbosityLevel(VerbosityLevel.VERBOSITY_NONE)
print(aCustomEntity.getLoggerVerbosityLevel())
aCustomEntity.setLoggerVerbosityLevel(VerbosityLevel.VERBOSITY_ALL)
print(aCustomEntity.getLoggerVerbosityLevel())
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