70 bHasUpdateCallback(
false),
71 bHasUpdateReplyCallback(
false),
77 yInfo() <<
"Calling Py_Initialize from open()";
91 std::lock_guard<std::recursive_mutex>
guard(m_monitor_mutex);
100 m_pythonScriptName =
scriptPath.stem().string();
101 if (m_pythonScriptName.empty()) {
110 if(!loadPythonModule(m_pythonScriptName, m_pModule)) {
114 bHasAcceptCallback = hasPythonFunction(
"acceptData");
115 bHasUpdateCallback = hasPythonFunction(
"updateData");
116 bHasUpdateReplyCallback = hasPythonFunction(
"updateReply");
117 if(hasPythonFunction(
"create"))
129 return ensureYarpModuleLoaded();
134 std::lock_guard<std::recursive_mutex>
guard(m_monitor_mutex);
136 yDebug() <<
"acceptData called";
137 if (!bHasAcceptCallback) {
141 if (!ensureYarpModuleLoaded()) {
146 if (type ==
nullptr) {
160 if (
pArgs ==
nullptr) {
178 if (!functionWrapper(
"acceptData",
pArgs,
pValue)) {
204 std::lock_guard<std::recursive_mutex>
guard(m_monitor_mutex);
207 if (!ensureYarpModuleLoaded()) {
213 if (type ==
nullptr) {
230 if (
pArgs ==
nullptr) {
241 yError() <<
"Unable to call the " <<
func_name <<
" function from python \n";
249 if (result != &thing) {
282 std::lock_guard<std::recursive_mutex>
guard(m_monitor_mutex);
288 if (
pArgs ==
nullptr) {
328 std::lock_guard<std::recursive_mutex>
guard(m_monitor_mutex);
331 if (!ensureYarpModuleLoaded()) {
337 if (type ==
nullptr) {
354 if (
pArgs ==
nullptr) {
377 std::lock_guard<std::recursive_mutex>
guard(m_monitor_mutex);
380 if (!ensureYarpModuleLoaded()) {
386 if (type ==
nullptr) {
403 if (
pArgs ==
nullptr) {
436 std::lock_guard<std::recursive_mutex>
guard(m_monitor_mutex);
453 if (constraint ==
"") {
478 std::string value = (
record.hasEvent(
token.c_str())) ?
"True" :
"False";
505 if (result ==
nullptr) {
525inline void MonitorPython::searchReplace(std::string& str,
const std::string&
oldStr,
const std::string&
newStr)
528 while((pos = str.find(
oldStr, pos)) != std::string::npos)
535inline void MonitorPython::trimString(std::string& str)
537 std::string::size_type pos = str.find_last_not_of(
' ');
538 if(pos != std::string::npos) {
540 pos = str.find_first_not_of(
' ');
541 if (pos != std::string::npos) {
545 str.erase(str.begin(), str.end());
549inline bool MonitorPython::isKeyword(
const char* str)
555 std::string
token = str;
568bool MonitorPython::loadPythonModule(
const std::string& moduleName,
PyObject* &
pModule)
574 yInfo()<<
"Calling loadPythonModule Py_Initialize";
584 if (
pName ==
nullptr) {
610 yInfo()<<
"Calling functionWrapper Py_Initialize";
616 if (m_pModule !=
NULL)
658bool MonitorPython::hasPythonFunction(
const std::string&
functionName)
661 if (
pFunc ==
nullptr) {
678bool MonitorPython::ensureYarpModuleLoaded()
682 yInfo()<<
"Calling ensureYarpModuleLoaded Py_Initialize";
710 yInfo()<<
"Calling classWrapper Py_Initialize";
A singleton class to record the port monitor events.
static MonitorEventRecord & getInstance()
bool peerTrigged() override
bool setParams(const yarp::os::Property ¶ms) override
bool load(const yarp::os::Property &options) override
yarp::os::Things & updateData(yarp::os::Things &thing) override
bool acceptData(yarp::os::Things &thing) override
bool canAccept() override
bool getParams(yarp::os::Property ¶ms) override
MonitorPython()
Class MonitorPython.
yarp::os::Things & updateReply(yarp::os::Things &thing) override
~MonitorPython() override
A mini-server for performing network communication in the background.
Interface implemented by all objects that can write themselves to the network, such as Bottle objects...
A class for storing options and configuration information.
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
Base class for generic things.
void setPortWriter(yarp::os::PortWriter *writer)
Set the reference to a PortWriter object.
virtual std::string asString() const
Get string value.
#define yCInfo(component,...)
#define yCError(component,...)
#define yCTrace(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
An interface to the operating system, including Port based communication.
The main, catch-all namespace for YARP.
#define SWIG_ConvertPtr(L, idx, ptr, type, flags)
#define SWIG_NewPointerObj(L, ptr, type, owner)
#define SWIG_GetModule(clientdata)
static swig_type_info * SWIG_TypeQuery(lua_State *clientdata, const char *name)