[openrtm-commit:02026] r2765 - in branches/FSM4RTC/OpenRTM-aist: . src/lib/hrtm
openrtm @ openrtm.org
openrtm @ openrtm.org
2016年 10月 7日 (金) 14:42:00 JST
Author: n-ando
Date: 2016-10-07 14:42:00 +0900 (Fri, 07 Oct 2016)
New Revision: 2765
Added:
branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/Makefile.am
branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/component_manager.cpp
branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/data_flow_component.cpp
branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/logger.cpp
branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/properties.cpp
branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/properties.h
branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/statechart.cpp
Modified:
branches/FSM4RTC/OpenRTM-aist/configure.ac
branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/component_manager.h
branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/data_flow_component.h
branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/defs.h
branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/in_port.h
branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/logger.h
branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/out_port.h
Log:
[FSM4RTC,2.0] libRTC wrapper lib for libHRTM has been implemented. It still has some bugs. refs 3653
Modified: branches/FSM4RTC/OpenRTM-aist/configure.ac
===================================================================
--- branches/FSM4RTC/OpenRTM-aist/configure.ac 2016-10-07 01:34:17 UTC (rev 2764)
+++ branches/FSM4RTC/OpenRTM-aist/configure.ac 2016-10-07 05:42:00 UTC (rev 2765)
@@ -1595,6 +1595,7 @@
src/Makefile
src/lib/Makefile
src/lib/rtm/Makefile
+ src/lib/hrtm/Makefile
src/lib/rtm/idl/Makefile
src/lib/rtm/ext/Makefile
src/lib/rtm/idl/device_interfaces/Makefile
@@ -1681,6 +1682,7 @@
examples/ExtTrigger/Makefile
examples/Templates/Makefile
examples/tests/Makefile
+ examples/Fsm/Makefile
docs/Makefile
win32/Makefile
win32/OpenRTM-aist/Makefile
Added: branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/Makefile.am
===================================================================
--- branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/Makefile.am (rev 0)
+++ branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/Makefile.am 2016-10-07 05:42:00 UTC (rev 2765)
@@ -0,0 +1,235 @@
+## -*- Makefile -*-
+##------------------------------------------------------------
+## Makefile.am for libHRTM
+##
+## $Id: Makefile.am 2720 2016-05-20 10:35:25Z n-ando $
+##------------------------------------------------------------
+
+AUTOMAKE_OPTIONS = 1.4
+
+ARTLIB = @ARTLIB@
+
+AM_CPPFLAGS=-I$(top_srcdir)/src/lib -I$(top_srcdir)/src/lib/coil/include -I$(top_srcdir)/src/lib/rtm -I$(top_srcdir)/src/lib/rtm/idl -I$(top_srcdir)/src/lib/hrtm
+AM_LDFLAGS=-L$(top_builddir) -L$(top_builddir)/src/lib/rtm -L$(top_builddir)/src/lib/rtm/idl -L$(top_builddir)/src/lib/coil/lib
+
+# version.h would be generated from configure before lib build process.
+BUILT_SOURCES = version.h version.txt
+version.h:
+ echo '// This header file is automatically generated.' > $@
+ echo '// Do not edit this file.' >> $@
+ echo '' >> $@
+ echo 'const char* openrtm_name = "'${PACKAGE}'-'${VERSION}'";' >> $@
+ echo 'const char* openrtm_version = "'${VERSION}'";' >> $@
+ echo 'const char* corba_name = "'${ORB}'";' >> $@
+
+version.txt:
+ echo 'name = '${PACKAGE}'-'${VERSION} >> $@
+ echo 'language = C++' >> $@
+ echo 'version = '${RTM_VERSION}'' >> $@
+ echo 'major_version = '${RTM_MAJOR_VERSION} >> $@
+ echo 'minor_version = '${RTM_MINOR_VERSION} >> $@
+ echo 'revision_num = '${RTM_REVISION_NUM} >> $@
+ echo 'short_version = '${RTM_SHORT_VERSION} >> $@
+ echo 'corba = '${ORB} >> $@
+
+# libHRTM.so, libHRTM.a library build entry
+lib_LTLIBRARIES = libHRTM.la
+
+# sources of libHRTM.la
+
+HRTM_SRC = \
+ component_manager.cpp \
+ data_flow_component.cpp \
+ logger.cpp \
+ properties.cpp \
+ statechart.cpp
+# configuration.cc \
+# corba_object.cc \
+# corba_port.cc
+# event_driven_execution_context.cc \
+# execution_context_base.cc \
+# ext_trig_execution_context.cc \
+# ior_utils.cc \
+# logger_poco.cc \
+# organization.cc \
+# periodic_ec_shared_composite.cc \
+# periodic_execution_context.cc \
+# port.cc
+# utils.cc
+
+
+
+
+libHRTM_la_SOURCES = $(HRTM_SRC)
+# version.h \
+# version.txt \
+# $(HRTM_SRC)
+
+
+libHRTM_la_LIBADD = \
+ $(top_builddir)/src/lib/coil/lib/libcoil.la \
+ $(top_builddir)/src/lib/rtm/idl/libRTCSkel.la \
+ $(top_builddir)/src/lib/rtm/libRTC.la
+
+libHRTM_la_LDFLAGS = \
+ -no-undefined \
+ -L$(top_builddir)/src/lib/rtm/idl \
+ -L$(top_builddir)/src/lib/rtm \
+ -release $(PACKAGE_VERSION)
+
+
+hrtmheaderdir = $(rtm_includedir)/hrtm
+
+hrtmheader_HEADERS = \
+ $(libHRTM_la_SOURCES:.cpp=.h) \
+ defs.h \
+ logger.h \
+ out_port.h \
+ properties.h \
+ version.h
+
+# SDO.h \
+# bind_manager.h \
+# bind_set.h \
+# buffer_policy.h \
+# component_factory.h \
+# consumer.h \
+# consumer_pull.h \
+# consumer_push.h \
+# consumer_push_flush.h \
+# consumer_push_local.h \
+# consumer_push_new-inl.h \
+# consumer_push_new.h \
+# consumer_push_periodic.h \
+# consumer_push_with_buffer.h \
+# corba_consumer.h \
+# data_port_status.h
+# event_driven_execution_context.h \
+# execution_context_base.h \
+# ext_trig_execution_context.h \
+# extended_fsm_service.h \
+# generic_object_interface.h \
+# gtest_utils.h
+# in_port.h \
+# in_port_cdr.h \
+# in_port_cdr_flush.h \
+# in_port_cdr_local.h \
+# in_port_cdr_no_buffer.h
+# marshalizer.h \
+# misc.h \
+# monitoring.h
+# out_port_cdr.h \
+# port_corba.h \
+# port_type.h
+# send_policy.h \
+# simple_deque.h \
+# trace.h
+# vw_main.h \
+# watch.h
+
+
+#------------------------------------------------------------
+# File list for deb/ports packages
+#------------------------------------------------------------
+lst:
+ echo $(HRTM_SRC) > src.lst
+ echo $(hrtmheader_HEADERS) > header.lst
+ echo version.txt >> header.lst
+
+#------------------------------------------------------------
+# Visual Studio Project
+#------------------------------------------------------------
+win32_builddir = $(top_builddir)/win32/OpenRTM-aist/
+
+vcproj: vc8proj vc9proj vc10proj vc11proj vc12proj vc14proj
+
+vc8proj: libHRTM.vcproj.yaml
+ $(top_builddir)/build/vcprojtool.py vcproj \
+ --type DLL \
+ --vcversion "8.00" \
+ --version $(RTM_VERSION) \
+ --out $(win32_builddir)/rtm/libHRTM_vc8.vcproj \
+ --yaml libHRTM.vcproj.yaml \
+ --source $(HRTM_SRC) \
+ --header $(hrtmheader_HEADERS)
+ qkc -O- -sm $(win32_builddir)/rtm/libHRTM_vc8.vcproj
+
+vc9proj: libHRTM.vcproj.yaml
+ $(top_builddir)/build/vcprojtool.py vcproj \
+ --type DLL \
+ --vcversion "9.00" \
+ --version $(RTM_VERSION) \
+ --out $(win32_builddir)/rtm/libHRTM_vc9.vcproj \
+ --yaml libHRTM.vcproj.yaml \
+ --source $(HRTM_SRC) \
+ --header $(hrtmheader_HEADERS)
+ qkc -O- -sm $(win32_builddir)/rtm/libHRTM_vc9.vcproj
+
+vc10proj: libHRTM.vcproj.yaml
+ $(top_builddir)/build/vcxprojtool.py vcxproj \
+ --type DLL \
+ --vcversion "10.00" \
+ --version $(RTM_VERSION) \
+ --out $(win32_builddir)/rtm/libHRTM_vc10.vcxproj \
+ --yaml libHRTM.vcproj.yaml \
+ --source $(HRTM_SRC) \
+ --header $(hrtmheader_HEADERS)
+ qkc -O- -sm $(win32_builddir)/rtm/libHRTM_vc10.vcxproj
+
+vc11proj: libHRTM.vcproj.yaml
+ $(top_builddir)/build/vcxprojtool.py vcxproj \
+ --type DLL \
+ --vcversion "11.00" \
+ --version $(RTM_VERSION) \
+ --out $(win32_builddir)/rtm/libHRTM_vc11.vcxproj \
+ --yaml libHRTM.vcproj.yaml \
+ --source $(HRTM_SRC) \
+ --header $(hrtmheader_HEADERS)
+ qkc -O- -sm $(win32_builddir)/rtm/libHRTM_vc11.vcxproj
+
+vc12proj: libHRTM.vcproj.yaml
+ $(top_builddir)/build/vcxprojtool.py vcxproj \
+ --type DLL \
+ --vcversion "12.00" \
+ --version $(RTM_VERSION) \
+ --out $(win32_builddir)/rtm/libHRTM_vc12.vcxproj \
+ --yaml libHRTM.vcproj.yaml \
+ --source $(HRTM_SRC) \
+ --header $(hrtmheader_HEADERS)
+ qkc -O- -sm $(win32_builddir)/rtm/libHRTM_vc12.vcxproj
+
+vc14proj: libHRTM.vcproj.yaml
+ $(top_builddir)/build/vcxprojtool.py vcxproj \
+ --type DLL \
+ --vcversion "14.00" \
+ --version $(RTM_VERSION) \
+ --out $(win32_builddir)/rtm/libHRTM_vc14.vcxproj \
+ --yaml libHRTM.vcproj.yaml \
+ --source $(HRTM_SRC) \
+ --header $(hrtmheader_HEADERS)
+ qkc -O- -sm $(win32_builddir)/rtm/libHRTM_vc14.vcxproj
+
+#------------------------------------------------------------
+# for wxs file
+#------------------------------------------------------------
+wxs:
+ $(top_srcdir)/build/makewxs.py flist \
+ -c Headers \
+ -o $(win32_builddir)installer/headers.yaml \
+ -p ..\\rtm \
+ *.h version.txt
+
+
+
+dist-hook: lst vcproj wxs
+
+clean-local:
+ rm -f *~ Makefile.old *core
+ rm -f *.lst
+ rm -f *.gch *.bak *.rpo *.sym lib*.*_pure_*
+
+
+EXTRA_DIST = \
+ $(hrtmheader_HEADERS) \
+ libHRTM.vcproj.yaml
+
Property changes on: branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/Makefile.am
___________________________________________________________________
Added: svn:executable
+ *
Added: branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/component_manager.cpp
===================================================================
--- branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/component_manager.cpp (rev 0)
+++ branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/component_manager.cpp 2016-10-07 05:42:00 UTC (rev 2765)
@@ -0,0 +1,84 @@
+// -*- C++ -*-
+/*!
+ * @file component_manager.cpp
+ * @brief RTC::ComponentManager wrapper class for hrtm::ComponentManager
+ * @date $Date$
+ * @author Noriaki Ando <n-ando at aist.go.jp>
+ *
+ * Copyright (C) 2016
+ * Noriaki Ando
+ * National Institute of
+ * Advanced Industrial Science and Technology (AIST), Japan
+ * All rights reserved.
+ *
+ * $Id$
+ *
+ */
+
+//#include <rtm/Manager.h>
+//#include <rtm/Factory.h>
+//#include <rtm/RTObject.h>
+#include <hrtm/data_flow_component.h>
+#include <hrtm/component_manager.h>
+//#include <hrtm/logger.h>
+
+namespace hrtm
+{
+ // static members initialization
+ ModuleInitProc ComponentManager::initProc;
+ ComponentManager* ComponentManager::manager = NULL;
+ coil::Mutex ComponentManager::mutex;
+
+ hrtm::DataFlowComponent*
+ ComponentManager::create_component(const char* component_name)
+ {
+ RTC::RTObject_impl* rtcomp(RTC::Manager::createComponent(component_name));
+ return dynamic_cast<hrtm::DataFlowComponent*>(rtcomp);
+ }
+
+ void
+ ComponentManager::set_init_proc(void(*init_proc)(hrtm::ComponentManager*))
+ {
+ initProc = init_proc;
+ setModuleInitProc(hrtm::ComponentManager::init_proc);
+ }
+ bool ComponentManager::activate()
+ {
+ return activateManager();
+ }
+ void ComponentManager::run(bool non_block)
+ {
+ runManager(non_block);
+ }
+ void ComponentManager::init_proc(RTC::Manager* mgr)
+ {
+ ::hrtm::ComponentManager::initProc(manager);
+ }
+ ComponentManager& ComponentManager::instance(int argc, char** argv)
+ {
+ // DCL for singleton
+ if (!manager)
+ {
+ Guard guard(mutex);
+ if (!manager)
+ {
+ manager = new ComponentManager();
+ manager->initManager(argc, argv);
+ manager->initLogger();
+ manager->initORB();
+ manager->initNaming();
+ manager->initFactories();
+ manager->initExecContext();
+ manager->initComposite();
+ manager->initTimer();
+ manager->initManagerServant();
+ }
+ }
+ return *manager;
+ }
+
+ ComponentManager::ComponentManager()
+ : RTC::Manager()
+ {
+ }
+}; // namespace hrtm
Property changes on: branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/component_manager.cpp
___________________________________________________________________
Added: svn:executable
+ *
Modified: branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/component_manager.h
===================================================================
--- branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/component_manager.h 2016-10-07 01:34:17 UTC (rev 2764)
+++ branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/component_manager.h 2016-10-07 05:42:00 UTC (rev 2765)
@@ -1,3 +1,20 @@
+// -*- C++ -*-
+/*!
+ * @file component_manager.h
+ * @brief RTC::Manager wrapper class for hrtm::ComponentManager
+ * @date $Date$
+ * @author Noriaki Ando <n-ando at aist.go.jp>
+ *
+ * Copyright (C) 2016
+ * Noriaki Ando
+ * National Institute of
+ * Advanced Industrial Science and Technology (AIST), Japan
+ * All rights reserved.
+ *
+ * $Id$
+ *
+ */
+
#ifndef HRTM_COMPONENT_MANAGER_H
#define HRTM_COMPONENT_MANAGER_H
@@ -3,15 +20,19 @@
#include <rtm/Manager.h>
#include <rtm/Factory.h>
-#include <rtm/RTObject.h>
+//#include <rtm/RTObject.h>
#include <coil/Guard.h>
#include <coil/Mutex.h>
//#include <hrtm/data_flow_component.h>
-#include <hrtm/logger.h>
+//#include <hrtm/logger.h>
+namespace RTC
+{
+ class RTObject_impl;
+};
namespace hrtm
{
- class DataFlowComponent;
-
-
+ //------------------------------------------------------------
+ // Creator and Destructor tempaltes for RTC factory
+ //
template <class _New>
RTC::RTObject_impl* Create(RTC::Manager* manager)
@@ -25,37 +46,25 @@
{
delete rtc;
}
+ //------------------------------------------------------------
+
+ // forward decl
+ class DataFlowComponent;
class ComponentManager;
typedef void (*ModuleInitProc)(hrtm::ComponentManager*);
-// class MyModuleInit
-// {
-// ModuleInitProc m_initProc;
-// public:
-// MyModuleInit(ModuleInitProc proc)
-// : m_initProc(proc)
-// {
-// }
-// void operator()(RTC::Manager* mgr)
-// {
-// m_initProc(dynamic_cast<hrtm::ComponentManager*>(mgr));
-// }
-// };
-// ModuleInitProc g_m;
-// void Proc(RTC::Manager* mgr)
-// {
-// g_m(dynamic_cast<hrtm::ComponentManager*>(mgr));
-// }
- //void ModuleInit(hrtm::ComponentManager* manager)
-
+ /*!
+ * @class RTC::Manager wrapper for hrtm::ComponentManager
+ */
class ComponentManager
: public RTC::Manager
{
typedef coil::Mutex Mutex;
typedef coil::Guard<Mutex> Guard;
+
public:
template<typename CompType>
- bool regist(coil::Properties* profile, const char*, const char*)
+ bool regist(coil::Properties* profile, const char*, const char*)
{
return RTC::Manager::
registerFactory(*profile,
@@ -63,54 +72,19 @@
(RTC::RtcDeleteFunc)hrtm::Delete<CompType> );
}
- virtual DataFlowComponent* create_component(const char* component_name)
- {
- return NULL; // createComponent(component_name);
- }
- static void init_proc(RTC::Manager* mgr)
- {
- ::hrtm::ComponentManager::initProc(manager);
- }
- virtual void set_init_proc(void(*init_proc)(hrtm::ComponentManager*))
- {
- initProc = init_proc;
- setModuleInitProc(hrtm::ComponentManager::init_proc);
- }
- virtual bool activate()
- {
- return activateManager();
- }
- virtual void run(bool non_block = false)
- {
- runManager(non_block);
- }
- static ComponentManager& instance(int argc, char** argv)
- {
- // DCL for singleton
- if (!manager)
- {
- Guard guard(mutex);
- if (!manager)
- {
- manager = new ComponentManager();
- manager->initManager(argc, argv);
- manager->initLogger();
- manager->initORB();
- manager->initNaming();
- manager->initFactories();
- manager->initExecContext();
- manager->initComposite();
- manager->initTimer();
- manager->initManagerServant();
- }
- }
- return *manager;
- }
+ virtual DataFlowComponent* create_component(const char* component_name);
+ virtual void set_init_proc(void(*init_proc)(hrtm::ComponentManager*));
+ virtual bool activate();
+ virtual void run(bool non_block = false);
+
+ // static members
+ static void init_proc(RTC::Manager* mgr);
+ static ComponentManager& instance(int argc, char** argv);
+
protected:
- ComponentManager()
- : RTC::Manager()
- {
- }
+ ComponentManager();
+
+ protected:
static ModuleInitProc initProc;
static ComponentManager* manager;
static coil::Mutex mutex;
Added: branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/data_flow_component.cpp
===================================================================
--- branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/data_flow_component.cpp (rev 0)
+++ branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/data_flow_component.cpp 2016-10-07 05:42:00 UTC (rev 2765)
@@ -0,0 +1,39 @@
+// -*- C++ -*-
+/*!
+ * @file data_flow_component.h
+ * @brief RTC::DataFlowComponent wrapper class for hrtm::DataFlowComponent
+ * @date $Date$
+ * @author Noriaki Ando <n-ando at aist.go.jp>
+ *
+ * Copyright (C) 2016
+ * Noriaki Ando
+ * National Institute of
+ * Advanced Industrial Science and Technology (AIST), Japan
+ * All rights reserved.
+ *
+ * $Id$
+ *
+ */
+#include <hrtm/data_flow_component.h>
+
+namespace hrtm
+{
+ DataFlowComponent::DataFlowComponent()
+ : RTC::DataFlowComponentBase(&RTC::Manager::instance())
+ {
+ }
+ DataFlowComponent::~DataFlowComponent()
+ {
+ }
+ RTC::ReturnCode_t DataFlowComponent::initialize(hrtm::ComponentManager* mgr)
+ {
+ std::cout << "########## initialize()" << std::endl;
+ return RTC::RTC_OK;
+ }
+
+ void DataFlowComponent::updateFsmStatus(RTC::StatusKind status_kind,
+ const char* state)
+ {
+ std::cout << "State: " << state << std::endl;
+ }
+}; // namespace hrtm
Property changes on: branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/data_flow_component.cpp
___________________________________________________________________
Added: svn:executable
+ *
Modified: branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/data_flow_component.h
===================================================================
--- branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/data_flow_component.h 2016-10-07 01:34:17 UTC (rev 2764)
+++ branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/data_flow_component.h 2016-10-07 05:42:00 UTC (rev 2765)
@@ -1,3 +1,19 @@
+// -*- C++ -*-
+/*!
+ * @file data_flow_component.h
+ * @brief RTC::DataFlowComponent wrapper class for hrtm::DataFlowComponent
+ * @date $Date$
+ * @author Noriaki Ando <n-ando at aist.go.jp>
+ *
+ * Copyright (C) 2016
+ * Noriaki Ando
+ * National Institute of
+ * Advanced Industrial Science and Technology (AIST), Japan
+ * All rights reserved.
+ *
+ * $Id$
+ *
+ */
#ifndef HRTM_DATA_FLOW_COMPONENT_H
#define HRTM_DATA_FLOW_COMPONENT_H
@@ -2,6 +18,11 @@
#include <rtm/DataFlowComponentBase.h>
+#include <hrtm/defs.h>
+#include <hrtm/properties.h>
+#include <hrtm/logger.h>
#include <hrtm/component_manager.h>
-#include <hrtm/defs.h>
#include <hrtm/in_port.h>
+#include <hrtm/out_port.h>
+#define COMPONENT_NAME(comp_name) #comp_name
+
namespace RTC
@@ -13,32 +34,20 @@
FSM_STATUS
};
};
+
namespace hrtm
{
-#define COMPONENT_NAME(comp_name) #comp_name
-
- // typedef RTC::DataFlowComponent DataFlowComponent;
- // using DataFlowComponent = RTC::DataFlowComponentBase;
+ class ComponentManager;
class DataFlowComponent
: public RTC::DataFlowComponentBase
{
public:
- DataFlowComponent()
- : RTC::DataFlowComponentBase(&RTC::Manager::instance())
- {
- }
-// DataFlowComponent(RTC::Manager* mgr)
-// : RTC::DataFlowComponentBase(mgr)
-// {
-// }
- virtual RTC::ReturnCode_t initialize(hrtm::ComponentManager* mgr)
- {
- return RTC::RTC_OK;
- }
- void updateFsmStatus(RTC::StatusKind status_kind, const char* state)
- {
- }
+ DataFlowComponent();
+ virtual ~DataFlowComponent();
+ virtual RTC::ReturnCode_t initialize(hrtm::ComponentManager* mgr);
+ virtual void updateFsmStatus(RTC::StatusKind status_kind,
+ const char* state);
};
-};
+}; // namespace hrtm
#endif // HRTM_DATA_FLOW_COMPONENT_H
Modified: branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/defs.h
===================================================================
--- branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/defs.h 2016-10-07 01:34:17 UTC (rev 2764)
+++ branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/defs.h 2016-10-07 05:42:00 UTC (rev 2765)
@@ -160,19 +160,6 @@
TypeName(const TypeName&); \
TypeName& operator=(const TypeName&)
-
-namespace coil
-{
- class Properties;
-};
-namespace hrtm
-{
- namespace utils
- {
- using Properties = coil::Properties;
- };
-};
-
//#ifndef hrtm
//#define hrtm RTC
//#endif // hrtmcomp
Modified: branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/in_port.h
===================================================================
--- branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/in_port.h 2016-10-07 01:34:17 UTC (rev 2764)
+++ branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/in_port.h 2016-10-07 05:42:00 UTC (rev 2765)
@@ -1,3 +1,22 @@
+// -*- C++ -*-
+/*!
+ * @file in_port.h
+ * @brief RTC::InPort wrapper class for hrtm::InPort
+ * @date $Date$
+ * @author Noriaki Ando <n-ando at aist.go.jp>
+ *
+ * Copyright (C) 2016
+ * Noriaki Ando
+ * National Institute of
+ * Advanced Industrial Science and Technology (AIST), Japan
+ * All rights reserved.
+ *
+ * $Id$
+ *
+ */
+#ifndef HRTM_IN_PORT_H
+#define HRTM_IN_PORT_H
+
#include <rtm/InPort.h>
namespace hrtm
@@ -2,4 +21,22 @@
{
+#ifndef CXX11
template <class DataType>
+ class InPort
+ : public RTC::InPort<DataType>
+ {
+ public:
+ InPort(const char* name, DataType& data)
+ : RTC::InPort<DataType>(name, data)
+ {
+ }
+ virtual ~InPort()
+ {
+ }
+ };
+#else
+ template<class DataType>
using InPort = RTC::InPort<DataType>;
+#endif
};
+
+#endif // HRTM_IN_PORT_H
Added: branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/logger.cpp
===================================================================
--- branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/logger.cpp (rev 0)
+++ branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/logger.cpp 2016-10-07 05:42:00 UTC (rev 2765)
@@ -0,0 +1,17 @@
+// -*- C++ -*-
+/*!
+ * @file logger.cpp
+ * @brief RTC::Logger wrapper class for hrtm::Logger
+ * @date $Date$
+ * @author Noriaki Ando <n-ando at aist.go.jp>
+ *
+ * Copyright (C) 2016
+ * Noriaki Ando
+ * National Institute of
+ * Advanced Industrial Science and Technology (AIST), Japan
+ * All rights reserved.
+ *
+ * $Id$
+ *
+ */
+#include <hrtm/logger.h>
Property changes on: branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/logger.cpp
___________________________________________________________________
Added: svn:executable
+ *
Modified: branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/logger.h
===================================================================
--- branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/logger.h 2016-10-07 01:34:17 UTC (rev 2764)
+++ branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/logger.h 2016-10-07 05:42:00 UTC (rev 2765)
@@ -1,3 +1,19 @@
+// -*- C++ -*-
+/*!
+ * @file logger.h
+ * @brief RTC::Logger wrapper class for hrtm::Logger
+ * @date $Date$
+ * @author Noriaki Ando <n-ando at aist.go.jp>
+ *
+ * Copyright (C) 2016
+ * Noriaki Ando
+ * National Institute of
+ * Advanced Industrial Science and Technology (AIST), Japan
+ * All rights reserved.
+ *
+ * $Id$
+ *
+ */
#ifndef HRTM_LOGGER_H
#define HRTM_LOGGER_H
@@ -4,8 +20,8 @@
#include <rtm/SystemLogger.h>
#define HRTM_ERROR(name, text)
-//#define HRTM_ERROR_STR RTC_ERROR_STR
-#define HRTM_WARN(name, text)
+#define HRTM_ERROR_STR RTC_ERROR_STR
+#define HRTM_WARNING(name, text)
#define HRTM_WARN_STR RTC_WARN_STR
#define HRTM_NORMAL(name, text)
#define HRTM_NORMAL_STR RTC_NORMAL_STR
@@ -24,7 +40,15 @@
{
namespace utils
{
+#ifndef CXX11
+ class Logger
+ : public RTC::Logger
+ {
+ public:
+ };
+#else
using Logger = RTC::Logger;
+#endif // CXX11
};
};
#endif // HRTM_LOGGER_H
Modified: branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/out_port.h
===================================================================
--- branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/out_port.h 2016-10-07 01:34:17 UTC (rev 2764)
+++ branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/out_port.h 2016-10-07 05:42:00 UTC (rev 2765)
@@ -1,3 +1,22 @@
+// -*- C++ -*-
+/*!
+ * @file out_port.h
+ * @brief RTC::OutPort wrapper class for hrtm::OutPort
+ * @date $Date$
+ * @author Noriaki Ando <n-ando at aist.go.jp>
+ *
+ * Copyright (C) 2016
+ * Noriaki Ando
+ * National Institute of
+ * Advanced Industrial Science and Technology (AIST), Japan
+ * All rights reserved.
+ *
+ * $Id$
+ *
+ */
+#ifndef HRTM_OUT_PORT_H
+#define HRTM_OUT_PORT_H
+
#include <rtm/OutPort.h>
namespace hrtm
@@ -2,4 +21,22 @@
{
+#ifndef CXX11
+ template <class DataType>
+ class OutPort
+ : public RTC::OutPort<DataType>
+ {
+ public:
+ OutPort(const char* name, DataType& data)
+ : RTC::OutPort<DataType>(name, data)
+ {
+ }
+ virtual ~OutPort()
+ {
+ }
+ };
+#else
template<class DataType>
using OutPort = RTC::OutPort<DataType>;
+#endif
};
+
+#endif // HRT_OUT_PORT_H
Added: branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/properties.cpp
===================================================================
--- branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/properties.cpp (rev 0)
+++ branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/properties.cpp 2016-10-07 05:42:00 UTC (rev 2765)
@@ -0,0 +1,36 @@
+// -*- C++ -*-
+/*!
+ * @file properties.cpp
+ * @brief hrtm::Peoperties wrapper class
+ * @date $Date$
+ * @author Noriaki Ando <n-ando at aist.go.jp>
+ *
+ * Copyright (C) 2016
+ * Noriaki Ando
+ * National Institute of
+ * Advanced Industrial Science and Technology (AIST), Japan
+ * All rights reserved.
+ *
+ * $Id$
+ *
+ */
+
+#include <hrtm/properties.h>
+
+namespace hrtm
+{
+namespace utils
+{
+ Properties::Properties()
+ : coil::Properties("", "")
+ {
+ }
+ Properties::Properties(const char* defaults[], long num)
+ : coil::Properties(defaults, num)
+ {
+ }
+ Properties::~Properties()
+ {
+ }
+}; // namespace utils
+}; // namespace hrtm
Property changes on: branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/properties.cpp
___________________________________________________________________
Added: svn:executable
+ *
Added: branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/properties.h
===================================================================
--- branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/properties.h (rev 0)
+++ branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/properties.h 2016-10-07 05:42:00 UTC (rev 2765)
@@ -0,0 +1,38 @@
+// -*- C++ -*-
+/*!
+ * @file properties.h
+ * @brief hrtm::Peoperties wrapper class
+ * @date $Date$
+ * @author Noriaki Ando <n-ando at aist.go.jp>
+ *
+ * Copyright (C) 2016
+ * Noriaki Ando
+ * National Institute of
+ * Advanced Industrial Science and Technology (AIST), Japan
+ * All rights reserved.
+ *
+ * $Id$
+ *
+ */
+
+#ifndef HRTM_PROPERTIES_H
+#define HRTM_PROPERTIES_H
+
+#include <coil/Properties.h>
+
+namespace hrtm
+{
+namespace utils
+{
+ class Properties
+ : public coil::Properties
+ {
+ public:
+ explicit Properties();
+ explicit Properties(const char* defaults[], long num = LONG_MAX);
+ virtual ~Properties();
+ };
+}; // namespace utils
+}; // namespace hrtm
+#endif // HRTM_PROPERTIES_H
+
Property changes on: branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/properties.h
___________________________________________________________________
Added: svn:executable
+ *
Added: branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/statechart.cpp
===================================================================
--- branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/statechart.cpp (rev 0)
+++ branches/FSM4RTC/OpenRTM-aist/src/lib/hrtm/statechart.cpp 2016-10-07 05:42:00 UTC (rev 2765)
@@ -0,0 +1,287 @@
+/**
+ * Copyright 2005 Eduard Etti
+*/
+#include "hrtm/statechart.h"
+#include "hrtm/logger.h"
+
+#define LOGGER "StateChart"
+
+using namespace hrtm; // NOLINT
+using namespace hrtm::sc; // NOLINT
+
+////////////////////////////////////////////////////////////////////////////////
+// Implementation for State
+StateInfo & StateBase::get_info(MachineBase & machine) {
+ // Look first in machine for existing StateInfo.
+ StateInfo * & info = machine.get_info(key());
+ if (!info) {
+ info = new RootStateInfo(machine, 0);
+ }
+ return *info;
+}
+
+void StateBase::shutdown() {
+ state_info_.machine().shutdown();
+}
+
+void StateBase::restore(StateInfo & current) {
+ state_info_.machine().current_state_ = ¤t;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// StateInfo implementation
+StateInfo::StateInfo(MachineBase & machine, StateInfo * parent)
+ : machine_(machine)
+ , instance_(0)
+ , history_(0)
+ , parent_(parent)
+ , data_(0)
+ , data_place(0) {}
+
+StateInfo::~StateInfo() {
+ if (data_place) {
+ ::operator delete(data_place);
+ }
+
+ delete instance_;
+}
+
+void StateInfo::on_entry(StateInfo & previous, bool first) {
+ // Only Root has no parent
+ if (!parent_) {
+ return;
+ }
+ // first entry or previous state is not substate -> perform entry
+ if (first || !previous.is_child(*this)) {
+ parent_->on_entry(previous, false);
+ // Could be set from outside or persistent (or EmptyData)
+ if (!data_) {
+ create_data();
+ }
+ HRTM_DEBUG(LOGGER, name() << ": entry");
+ instance_->on_entry();
+ }
+}
+
+void StateInfo::on_exit(StateInfo & next) {
+ // Only Root has no parent
+ if (!parent_) {
+ return;
+ }
+ // self transition or next state is not substate -> perform exit
+ if (this == &next || !next.is_child(*this)) {
+ HRTM_DEBUG(LOGGER, name() << ": exit");
+ instance_->on_exit();
+ instance_->delete_data(*this);
+ parent_->on_exit(next);
+ }
+}
+
+void StateInfo::on_init(bool history) {
+ if (history && history_) {
+ HRTM_DEBUG(LOGGER, name() << ": history transition to: " <<
+ history_->name());
+ machine_.set_pending_state(*history_, true, 0);
+ } else {
+ HRTM_DEBUG(LOGGER, name() << ": init");
+ instance_->on_init();
+ }
+ history_ = 0;
+}
+
+void StateInfo::copy(StateInfo & original) {
+ if (original.history_) {
+ StateInfo * history = machine_.get_info(original.history_->key());
+ assert(history);
+ set_history(history);
+ }
+
+ if (original.data_) {
+ clone_data(original.data_);
+ }
+}
+
+StateInfo * StateInfo::clone(MachineBase & new_machine) {
+ assert(!new_machine.get_info(key()));
+
+ StateInfo * parent = 0;
+ if (parent_) {
+ // Tell other machine to clone parent first.
+ parent = new_machine.create_clone(parent_->key(), parent_);
+ }
+ StateInfo * clone = create(new_machine, parent);
+ return clone;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// Base class for Machine objects.
+MachineBase::MachineBase()
+ : current_state_(0)
+ , pending_state_(0)
+ , pending_data_(0)
+ , pending_history_(false)
+ , pending_event_(0) {}
+
+MachineBase::~MachineBase() {
+ assert(!pending_data_);
+
+ delete[] states_;
+ delete pending_event_;
+}
+
+void MachineBase::set_state(StateInfo & info, bool history, void * data) {
+ set_pending_state(info, history, data);
+ perform_pending();
+}
+
+void MachineBase::set_state(const StateAlias & state, bool history) {
+ set_pending_state(state.get_info(*this), history, state.take_data());
+ perform_pending();
+}
+
+void MachineBase::start(StateInfo & info, void * data) {
+ HRTM_DEBUG(LOGGER, "Starting Machine");
+
+ // Start with Root state
+ current_state_ = &StateBase::get_info(*this);
+ // Then go to state
+ set_state(info, false, data);
+}
+
+void MachineBase::shutdown() {
+ assert(!pending_state_);
+
+ HRTM_DEBUG(LOGGER, "Shutting down Machine");
+ // Performs exit actions by going to Root (=State) state.
+ set_state(StateBase::get_info(*this), false, 0);
+ current_state_ = 0;
+}
+
+void MachineBase::allocate(unsigned int count) {
+ states_ = new StateInfo *[count];
+ for (unsigned int i = 0; i < count; ++i) {
+ states_[i] = 0;
+ }
+}
+
+void MachineBase::free(unsigned int count) {
+ // Free from end of list, so that child states are freed first
+ unsigned int i = count;
+ while (i > 0) {
+ --i;
+ delete states_[i];
+ states_[i] = 0;
+ }
+}
+
+void MachineBase::copy(StateInfo ** other, unsigned int count) {
+ Key i;
+
+ // Create StateInfo objects
+ for (i = 0; i < count; ++i) {
+ create_clone(i, other[i]);
+ }
+ // Copy StateInfo object's state
+ for (i = 0; i < count; ++i) {
+ StateInfo * state = states_[i];
+ if (state) {
+ assert(other[i]);
+ state->copy(*other[i]);
+ }
+ }
+}
+
+StateInfo * MachineBase::create_clone(Key key, StateInfo * original) {
+ StateInfo * & clone = get_info(key);
+
+ // Object already created?
+ if (!clone && original) {
+ clone = original->clone(*this);
+ }
+ return clone;
+}
+
+void MachineBase::add_deferred_event(EventBase * event,
+ const std::string& name) {
+ assert(event);
+
+ try {
+ EventQueue::iterator queue = deferred_events_.find(name);
+ if (queue != deferred_events_.end()) {
+ HRTM_DEBUG(LOGGER, name << " is already deferred.");
+ return;
+ }
+ deferred_events_[name] = event;
+ deferred_names_.push_back(name);
+ } catch (std::exception& ex) { // NOLINT
+ HRTM_WARNING(LOGGER, "Can't add defferd event by " << ex.what());
+ }
+}
+
+void MachineBase::perform_pending() {
+ assert(current_state_);
+
+ if (pending_state_) {
+ // Loop here because init actions might change state again.
+ while (pending_state_) {
+ HRTM_DEBUG(LOGGER, current_state_->name() << ": transition to: " <<
+ pending_state_->name());
+ // Perform exit actions (which exactly depends on new state).
+ current_state_->on_exit(*pending_state_);
+ // Store history information for previous state now.
+ // Previous state will be used for deep history.
+ current_state_->set_history_super(*current_state_);
+ StateInfo * previous = current_state_;
+ current_state_ = pending_state_;
+ if (pending_data_) {
+ current_state_->set_data(pending_data_);
+ }
+ // Perform entry actions (which exactly depends on previous state).
+ current_state_->on_entry(*previous);
+ // State transition complete.
+ // Clear 'pending' information just now so that set_state would assert
+ // in exits and entries, but not in init.
+ pending_state_ = 0;
+ pending_data_ = 0;
+ bool history = pending_history_;
+ pending_history_ = false;
+ // "init" may change state again.
+ current_state_->on_init(history);
+ assert("Init may only transition to proper substates" &&
+ (!pending_state_ ||
+ (pending_state_->is_child(*current_state_) &&
+ (current_state_ != pending_state_))));
+ // Perform pending event
+ perform_pending_event();
+ // Perform deferred events
+ perform_deferred_events();
+ } // while (pending_state_)
+ } else { // if (pending_state_)
+ // Perform pending event
+ perform_pending_event();
+ }
+}
+
+void MachineBase::perform_pending_event() {
+ if (pending_event_) {
+ EventBase * event = pending_event_;
+ pending_event_ = 0;
+ event->dispatch(*current_state_);
+ delete event;
+ }
+}
+
+void MachineBase::perform_deferred_events() {
+ if (deferred_events_.empty()) {
+ return;
+ }
+ for (EventNames::iterator i = deferred_names_.begin();
+ i != deferred_names_.end(); ++i) {
+ if (current_state_) {
+ deferred_events_[(*i)]->dispatch(*current_state_);
+ delete deferred_events_[(*i)];
+ }
+ }
+ deferred_events_.clear();
+ deferred_names_.clear();
+}
More information about the openrtm-commit
mailing list