[openrtm-commit:03343] r3421 - trunk/OpenRTM-aist/src/lib/rtm
openrtm @ openrtm.org
openrtm @ openrtm.org
2018年 10月 9日 (火) 11:34:11 JST
Author: miyamoto
Date: 2018-10-09 11:34:11 +0900 (Tue, 09 Oct 2018)
New Revision: 3421
Added:
trunk/OpenRTM-aist/src/lib/rtm/EventBase.h
Modified:
trunk/OpenRTM-aist/src/lib/rtm/CMakeLists.txt
trunk/OpenRTM-aist/src/lib/rtm/EventPort.h
trunk/OpenRTM-aist/src/lib/rtm/InPortBase.h
trunk/OpenRTM-aist/src/lib/rtm/Manager.cpp
trunk/OpenRTM-aist/src/lib/rtm/StaticFSM.h
trunk/OpenRTM-aist/src/lib/rtm/VxWorksInterruptExecutionContext.cpp
Log:
[incompat, bugfix] fixed bug.
Modified: trunk/OpenRTM-aist/src/lib/rtm/CMakeLists.txt
===================================================================
--- trunk/OpenRTM-aist/src/lib/rtm/CMakeLists.txt 2018-10-09 00:25:52 UTC (rev 3420)
+++ trunk/OpenRTM-aist/src/lib/rtm/CMakeLists.txt 2018-10-09 02:34:11 UTC (rev 3421)
@@ -281,6 +281,8 @@
OutPortDSConsumer.h
InPortDSProvider.h
InPortDSConsumer.h
+ MultilayerCompositeEC.h
+ EventBase.h
${PROJECT_BINARY_DIR}/config_rtc.h
${PROJECT_BINARY_DIR}/version.h
)
@@ -364,6 +366,7 @@
OutPortDSConsumer.cpp
InPortDSProvider.cpp
InPortDSConsumer.cpp
+ MultilayerCompositeEC.cpp
${rtm_headers}
)
Added: trunk/OpenRTM-aist/src/lib/rtm/EventBase.h
===================================================================
--- trunk/OpenRTM-aist/src/lib/rtm/EventBase.h (rev 0)
+++ trunk/OpenRTM-aist/src/lib/rtm/EventBase.h 2018-10-09 02:34:11 UTC (rev 3421)
@@ -0,0 +1,83 @@
+// -*- C++ -*-
+/*!
+ * @file EventInPort.h
+ * @brief EventInPort template class
+ * @date $Date$
+ * @author Noriaki Ando <n-ando at aist.go.jp>
+ *
+ * Copyright (C) 2017
+ * Noriaki Ando
+ * National Institute of
+ * Advanced Industrial Science and Technology (AIST), Japan
+ * All rights reserved.
+ *
+ * $Id$
+ *
+ */
+
+#ifndef RTC_EVENTBASE_H
+#define RTC_EVENTBASE_H
+
+
+
+namespace RTC
+{
+ class EventBinderBase0
+ {
+ public:
+ EventBinderBase0(){};
+ virtual void run() = 0;
+ };
+ template <class P0>class EventBinderBase1
+ {
+ public:
+ EventBinderBase1(){};
+ virtual void run(P0& data) = 0;
+ };
+
+ class EventBase
+ {
+ public:
+ EventBase(){};
+ virtual ~EventBase(){};
+ virtual void operator()()=0;
+ };
+
+ class Event0 : public EventBase
+ {
+ public:
+ Event0(EventBinderBase0 *eb):
+ m_eb(eb)
+ {
+ };
+ virtual ~Event0() {};
+ virtual void operator()()
+ {
+ m_eb->run();
+ };
+ private:
+ EventBinderBase0 *m_eb;
+ };
+
+ template <class P0>
+ class Event1 : public EventBase
+ {
+ public:
+ Event1(EventBinderBase1<P0> *eb, P0 &data):
+ m_eb(eb), m_data(data)
+ {
+ };
+ virtual ~Event1() {};
+ virtual void operator()()
+ {
+ m_eb->run(m_data);
+ };
+ private:
+ EventBinderBase1<P0> *m_eb;
+ P0 m_data;
+ };
+
+
+}; // End of namesepace RTM
+
+#endif // RTC_EVENTBASE_H
Modified: trunk/OpenRTM-aist/src/lib/rtm/EventPort.h
===================================================================
--- trunk/OpenRTM-aist/src/lib/rtm/EventPort.h 2018-10-09 00:25:52 UTC (rev 3420)
+++ trunk/OpenRTM-aist/src/lib/rtm/EventPort.h 2018-10-09 02:34:11 UTC (rev 3421)
@@ -36,19 +36,24 @@
#include <rtm/InPortConnector.h>
#include <rtm/Timestamp.h>
#include <rtm/StaticFSM.h>
+#include <rtm/RingBuffer.h>
+#include <rtm/EventBase.h>
namespace RTC
{
+
+
template <class FSM, class TOP, class R>
class EventBinder0
- : public ConnectorDataListener
+ : public ConnectorDataListener, EventBinderBase0
{
USE_CONNLISTENER_STATUS;
public:
EventBinder0(FSM& fsm,
const char* event_name,
- R (TOP::*handler)())
- : m_fsm(fsm), m_eventName(event_name), m_handler(handler) {}
+ R (TOP::*handler)(),
+ RingBuffer<EventBase*> &buffer)
+ : m_fsm(fsm), m_eventName(event_name), m_handler(handler), m_buffer(buffer) {}
virtual ~EventBinder0() {}
@@ -58,28 +63,38 @@
if (info.properties["fsm_event_name"] == m_eventName ||
info.name == m_eventName)
{
- m_fsm.dispatch(Macho::Event(m_handler));
- std::cout << "Event dispatched: " << m_eventName << std::endl;
+ m_buffer.write(new Event0(this));
+ //m_fsm.dispatch(Macho::Event(m_handler));
+ //std::cout << "Event dispatched: " << m_eventName << std::endl;
return NO_CHANGE;
}
return NO_CHANGE;
}
+ virtual void run()
+ {
+
+ m_fsm.dispatch(Macho::Event(m_handler));
+ }
+
FSM& m_fsm;
std::string m_eventName;
R (TOP::*m_handler)();
+ RingBuffer<EventBase*> &m_buffer;
+
};
template <class FSM, class TOP, class R, class P0>
class EventBinder1
- : public ConnectorDataListenerT<P0>
+ : public ConnectorDataListenerT<P0>, EventBinderBase1<P0>
{
USE_CONNLISTENER_STATUS;
public:
EventBinder1(FSM& fsm,
const char* event_name,
- R (TOP::*handler)(P0))
- : m_fsm(fsm), m_eventName(event_name), m_handler(handler) {}
+ R (TOP::*handler)(P0),
+ RingBuffer<EventBase*> &buffer)
+ : m_fsm(fsm), m_eventName(event_name), m_handler(handler), m_buffer(buffer) {}
virtual ~EventBinder1() {}
@@ -88,19 +103,56 @@
if (info.properties["fsm_event_name"] == m_eventName ||
info.name == m_eventName)
{
- m_fsm.dispatch(Macho::Event(m_handler, data));
- std::cout << "Event dispatched: " << m_eventName << std::endl;
+ m_buffer.write(new Event1<P0>(this, data));
+ //m_fsm.dispatch(Macho::Event(m_handler, data));
+ //std::cout << "Event dispatched: " << m_eventName << std::endl;
return NO_CHANGE;
}
return NO_CHANGE;
}
+ virtual void run(P0& data)
+ {
+ m_fsm.dispatch(Macho::Event(m_handler, data));
+ }
+
FSM& m_fsm;
std::string m_eventName;
R (TOP::*m_handler)(P0);
+ RingBuffer<EventBase*> &m_buffer;
};
+ class EventConnListener
+ : public ConnectorListener
+ {
+ USE_CONNLISTENER_STATUS;
+ public:
+ EventConnListener(RingBuffer<EventBase*>&buffer, CdrBufferBase* m_thebuffer) :
+ m_buffer(buffer), m_thebuffer(m_thebuffer) {}
+ virtual ~EventConnListener()
+ {
+ }
+
+ virtual ReturnCode operator()(ConnectorInfo& info)
+ {
+ coil::Properties prop;
+ prop["write.full_policy"] = "do_nothing";
+ prop["read.empty_policy"] = "do_nothing";
+ m_thebuffer->init(prop);
+
+ coil::Properties prop_(info.properties.getNode("dataport.buffer"));
+ prop_ << info.properties.getNode("inport.buffer");
+
+ m_buffer.init(prop_);
+
+
+ return NO_CHANGE;
+ };
+ RingBuffer<EventBase*>&m_buffer;
+ CdrBufferBase *m_thebuffer;
+ };
+
/*!
* @if jp
*
@@ -211,7 +263,7 @@
bool read_block = false, bool write_block = false,
int read_timeout = 0, int write_timeout = 0)
: InPortBase(name, "any"),
- m_name(name), m_fsm(fsm)
+ m_name(name), m_fsm(fsm), m_buffer(fsm.getBuffer())
{
}
@@ -256,6 +308,14 @@
return m_name.c_str();
}
+ virtual void init(coil::Properties& prop)
+ {
+ InPortBase::init(prop);
+ this->addConnectorListener
+ (ON_CONNECT,
+ new EventConnListener(m_buffer, m_thebuffer));
+ }
+
template <class TOP, class R, class P0>
void bindEvent(const char* name,
R (TOP::*handler)(P0))
@@ -262,7 +322,7 @@
{
this->addConnectorDataListener
(ON_RECEIVED,
- new EventBinder1<FsmType, TOP, R, P0>(m_fsm, name, handler));
+ new EventBinder1<FsmType, TOP, R, P0>(m_fsm, name, handler, m_buffer));
}
template <typename TOP, class R>
void bindEvent(const char* name,
@@ -270,9 +330,9 @@
{
this->addConnectorDataListener
(ON_RECEIVED,
- new EventBinder0<FsmType, TOP, R>(m_fsm, name, handler));
+ new EventBinder0<FsmType, TOP, R>(m_fsm, name, handler, m_buffer));
}
- virtual bool read() { return true; }
+ virtual bool read(std::string name="") { return true; }
private:
/*!
* @if jp
@@ -283,6 +343,7 @@
*/
std::string m_name;
FsmType& m_fsm;
+ RingBuffer<EventBase*> &m_buffer;
};
}; // End of namesepace RTM
Modified: trunk/OpenRTM-aist/src/lib/rtm/InPortBase.h
===================================================================
--- trunk/OpenRTM-aist/src/lib/rtm/InPortBase.h 2018-10-09 00:25:52 UTC (rev 3420)
+++ trunk/OpenRTM-aist/src/lib/rtm/InPortBase.h 2018-10-09 02:34:11 UTC (rev 3421)
@@ -130,7 +130,7 @@
* @param prop Property for setting ports
* @endif
*/
- void init(coil::Properties& prop);
+ virtual void init(coil::Properties& prop);
/*!
* @if jp
@@ -146,7 +146,7 @@
* @return true:Success,false:Failure
* @endif
*/
- virtual bool read() = 0;
+ virtual bool read(std::string name="") = 0;
/*!
* @if jp
Modified: trunk/OpenRTM-aist/src/lib/rtm/Manager.cpp
===================================================================
--- trunk/OpenRTM-aist/src/lib/rtm/Manager.cpp 2018-10-09 00:25:52 UTC (rev 3420)
+++ trunk/OpenRTM-aist/src/lib/rtm/Manager.cpp 2018-10-09 02:34:11 UTC (rev 3421)
@@ -369,7 +369,6 @@
}
if (filename.find_first_of('.') == std::string::npos)
{
- std::cout << m_config["manager.modules.C++.suffixes"] << std::endl;
if (m_config.findNode("manager.modules.C++.suffixes") != 0)
{
filename += "." + m_config["manager.modules.C++.suffixes"];
@@ -2955,7 +2954,6 @@
PortProfile_var prof = ports[i]->get_port_profile();
coil::Properties prop;
NVUtil::copyToProperties(prop, prof->properties);
- std::cout << prop;
if ((prop.hasKey("publish_topic") == 0 ||
prop["publish_topic"] == "") &&
(prop.hasKey("subscribe_topic") == 0 ||
Modified: trunk/OpenRTM-aist/src/lib/rtm/StaticFSM.h
===================================================================
--- trunk/OpenRTM-aist/src/lib/rtm/StaticFSM.h 2018-10-09 00:25:52 UTC (rev 3420)
+++ trunk/OpenRTM-aist/src/lib/rtm/StaticFSM.h 2018-10-09 02:34:11 UTC (rev 3421)
@@ -19,6 +19,8 @@
#include <rtm/RTObject.h>
#include <rtm/Macho.h>
+#include <rtm/RingBuffer.h>
+#include <rtm/EventBase.h>
/*!
* @brief State machine definition macros
@@ -117,6 +119,20 @@
{
}
virtual ~Machine() {}
+ virtual RingBuffer<EventBase*>& getBuffer()
+ {
+ return m_buffer;
+ }
+ virtual void run_event()
+ {
+ while (m_buffer.readable() > 0)
+ {
+ EventBase* ebt = m_buffer.get();
+ (*ebt)();
+ m_buffer.advanceRptr();
+ delete ebt;
+ }
+ }
private:
Machine(const Machine<TOP> & other);
@@ -131,6 +147,7 @@
template<class T> friend class Macho::StateID;
RTObject_impl* rtComponent;
+ RingBuffer<EventBase*> m_buffer;
};
/*!
Modified: trunk/OpenRTM-aist/src/lib/rtm/VxWorksInterruptExecutionContext.cpp
===================================================================
--- trunk/OpenRTM-aist/src/lib/rtm/VxWorksInterruptExecutionContext.cpp 2018-10-09 00:25:52 UTC (rev 3420)
+++ trunk/OpenRTM-aist/src/lib/rtm/VxWorksInterruptExecutionContext.cpp 2018-10-09 02:34:11 UTC (rev 3421)
@@ -651,8 +651,6 @@
int_value = IV_IPI3;
}
#endif
-std::cout << props << std::endl;
-std::cout << int_param << std::endl;
if(int_value >= 0)
{
intConnect(INUM_TO_IVEC(int_value), (VOIDFUNCPTR)tickHandler, (int)this);
openrtm-commit メーリングリストの案内