[openrtm-commit:03065] r3160 - branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm
openrtm @ openrtm.org
openrtm @ openrtm.org
2018年 1月 17日 (水) 10:09:28 JST
Author: miyamoto
Date: 2018-01-17 10:09:28 +0900 (Wed, 17 Jan 2018)
New Revision: 3160
Added:
branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/NamingServiceNumberingPolicy.cpp
branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/NamingServiceNumberingPolicy.h
branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/NodeNumberingPolicy.cpp
branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/NodeNumberingPolicy.h
Modified:
branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/FactoryInit.cpp
branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/NumberingPolicy.h
branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/NumberingPolicyBase.cpp
Log:
[compat,->RELENG_1_2] refs #3273
Modified: branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/FactoryInit.cpp
===================================================================
--- branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/FactoryInit.cpp 2018-01-17 01:06:34 UTC (rev 3159)
+++ branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/FactoryInit.cpp 2018-01-17 01:09:28 UTC (rev 3160)
@@ -44,6 +44,8 @@
// RTC name numbering policy
#include <rtm/NumberingPolicy.h>
+#include <rtm/NamingServiceNumberingPolicy.h>
+#include <rtm/NodeNumberingPolicy.h>
void FactoryInit()
{
@@ -75,6 +77,6 @@
// Naming Policy
ProcessUniquePolicyInit();
- // NodeUniquePolicyInit();
- // NamingServiceUniquePolicyInit();
+ NamingServiceNumberingPolicyInit();
+ NodeNumberingPolicyInit();
}
Added: branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/NamingServiceNumberingPolicy.cpp
===================================================================
--- branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/NamingServiceNumberingPolicy.cpp (rev 0)
+++ branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/NamingServiceNumberingPolicy.cpp 2018-01-17 01:09:28 UTC (rev 3160)
@@ -0,0 +1,128 @@
+// -*- C++ -*-
+/*!
+* @file NamingServiceNumberingPolicy.cpp
+* @brief Object numbering policy class
+* @date $Date: 2018-1-11 03:08:04 $
+* @author Nobuhiko Miyamoto <n-miyamoto at aist.go.jp>
+*
+* Copyright (C) 2018
+* Intelligent Systems Research Institute,
+* National Institute of
+* Advanced Industrial Science and Technology (AIST), Japan
+* All rights reserved.
+*
+*
+*/
+
+#include <rtm/NamingServiceNumberingPolicy.h>
+#include <rtm/Manager.h>
+#include <coil/stringutil.h>
+#include <rtm/NamingManager.h>
+#include <rtm/RTObject.h>
+
+namespace RTM
+{
+ //============================================================
+ // NamingServiceNumberingPolicy
+ //============================================================
+ NamingServiceNumberingPolicy::NamingServiceNumberingPolicy()
+ : m_num(0)
+ {
+ m_mgr = &RTC::Manager::instance();
+ }
+ /*!
+ * @if jp
+ * @brief オブジェクト生成時の名称作成
+ * @else
+ * @brief Create the name when creating objects
+ * @endif
+ */
+ std::string NamingServiceNumberingPolicy::onCreate(void* obj)
+ {
+ int num = 0;
+ while (true)
+ {
+ std::string num_str = coil::otos<int>(num);
+ RTC::RTObject_impl *rtobj = (RTC::RTObject_impl *)obj;
+
+
+ std::string name = rtobj->getTypeName() + num_str;
+
+ if (!find(name))
+ {
+ return num_str;
+ }
+ else
+ {
+ num++;
+ }
+ }
+ return coil::otos<int>(num);
+ }
+
+ /*!
+ * @if jp
+ * @brief オブジェクト削除時の名称解放
+ * @else
+ * @brief Delete the name when deleting objects
+ * @endif
+ */
+ void NamingServiceNumberingPolicy::onDelete(void* obj)
+ {
+ }
+
+ /*!
+ * @if jp
+ *
+ * @brief オブジェクトの検索
+ *
+ * 指定名のインスタンス名のRTCを検索し、
+ * 一致するRTCが存在する場合はTrueを返す
+ *
+ * @param name 検索対象オブジェクトの名前
+ *
+ * @return 判定
+ *
+ * @else
+ *
+ * @brief
+ *
+ *
+ * @param name
+ *
+ * @return
+ *
+ * @endif
+ */
+ bool NamingServiceNumberingPolicy::find(std::string name)
+ {
+ RTC::RTCList rtcs;
+ std::string rtc_name = "rtcname://*/*/";
+ rtc_name += name;
+
+ rtcs = m_mgr->getNaming()->string_to_component(rtc_name);
+
+ if (rtcs.length() > 0)
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+}; //namespace RTM
+
+extern "C"
+{
+ void NamingServiceNumberingPolicyInit()
+ {
+ ::RTM::NumberingPolicyFactory::
+ instance().addFactory("ns_unique",
+ ::coil::Creator< ::RTM::NumberingPolicyBase,
+ ::RTM::NamingServiceNumberingPolicy>,
+ ::coil::Destructor< ::RTM::NumberingPolicyBase,
+ ::RTM::NamingServiceNumberingPolicy>);
+ }
+};
+
Added: branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/NamingServiceNumberingPolicy.h
===================================================================
--- branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/NamingServiceNumberingPolicy.h (rev 0)
+++ branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/NamingServiceNumberingPolicy.h 2018-01-17 01:09:28 UTC (rev 3160)
@@ -0,0 +1,173 @@
+// -*- C++ -*-
+/*!
+ * @file NamingServiceNumberingPolicy.h
+ * @brief Object numbering policy class
+ * @date $Date: 2018-1-11 03:08:04 $
+ * @author Nobuhiko Miyamoto <n-miyamoto at aist.go.jp>
+ *
+ * Copyright (C) 2018
+ * Intelligent Systems Research Institute,
+ * National Institute of
+ * Advanced Industrial Science and Technology (AIST), Japan
+ * All rights reserved.
+ *
+ *
+ */
+
+#ifndef RTC_NAMINGSERVICENUMBERINGPOLICY_H
+#define RTC_NAMINGSERVICENUMBERINGPOLICY_H
+
+#include <string>
+#include <vector>
+#include <rtm/RTC.h>
+#include <rtm/NumberingPolicyBase.h>
+#include <rtm/Manager.h>
+
+namespace RTM
+{
+ /*!
+ * @if jp
+ *
+ * @class NamingServiceNumberingPolicy
+ * @brief オブジェクト生成時ネーミング・ポリシー(命名規則)管理用クラス
+ *
+ * ネーミングサービスからRTCを検索してナンバリングを行う
+ *
+ * @since 1.2.0
+ *
+ * @else
+ *
+ * @class NamingServiceNumberingPolicy
+ * @brief
+ *
+ *
+ *
+ * @since 1.2.0
+ *
+ * @endif
+ */
+ class NamingServiceNumberingPolicy
+ : public NumberingPolicyBase
+ {
+ public:
+ /*!
+ * @if jp
+ *
+ * @brief コンストラクタ
+ *
+ * コンストラクタ
+ *
+ * @else
+ *
+ * @brief Constructor
+ *
+ * Constructor
+ *
+ * @endif
+ */
+ NamingServiceNumberingPolicy();
+
+ /*!
+ * @if jp
+ *
+ * @brief デストラクタ
+ *
+ * @else
+ *
+ * @brief Destractor
+ *
+ * @endif
+ */
+ virtual ~NamingServiceNumberingPolicy(void){};
+
+ /*!
+ * @if jp
+ *
+ * @brief オブジェクト生成時の名称作成
+ *
+ * オブジェクト生成時の名称を生成する。
+ * 生成済みインスタンスの数に応じた名称を生成する。
+ *
+ * @param obj 名称生成対象オブジェクト
+ *
+ * @return 生成したオブジェクト名称
+ *
+ * @else
+ *
+ * @brief Create the name when creating object
+ *
+ * Create the name when creating object.
+ * Create the name corresponding to the number of generated instances.
+ *
+ * @param obj The target object for the name creation
+ *
+ * @return Names of the created object
+ *
+ * @endif
+ */
+ virtual std::string onCreate(void* obj);
+
+ /*!
+ * @if jp
+ *
+ * @brief オブジェクト削除時の名称解放
+ *
+ * オブジェクト削除時に名称を解放する。
+ * オブジェクト削除時に生成済みインスタンス数を減算する。
+ *
+ * @param obj 名称解放対象オブジェクト
+ *
+ * @else
+ *
+ * @brief Delete the name when deleting object
+ *
+ * Delete the name when deleting object.
+ * Substract the generated number of instances when deleting the object.
+ *
+ * @param obj The target object for the name delete
+ *
+ * @endif
+ */
+ virtual void onDelete(void* obj);
+
+
+
+ protected:
+ /*!
+ * @if jp
+ *
+ * @brief オブジェクトの検索
+ *
+ * 指定名のインスタンス名のRTCを検索し、
+ * 一致するRTCが存在する場合はTrueを返す
+ *
+ * @param name 検索対象オブジェクトの名前
+ *
+ * @return 判定
+ *
+ * @else
+ *
+ * @brief
+ *
+ *
+ * @param name
+ *
+ * @return
+ *
+ * @endif
+ */
+ virtual bool find(std::string name);
+
+ private:
+ int m_num;
+ std::vector<void*> m_objects;
+ RTC::Manager *m_mgr;
+ };
+}; // namespace RTM
+
+extern "C"
+{
+ void DLL_EXPORT NamingServiceNumberingPolicyInit();
+};
+
+#endif // RTC_NAMINGSERVICENUMBERINGPOLICY_H
Added: branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/NodeNumberingPolicy.cpp
===================================================================
--- branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/NodeNumberingPolicy.cpp (rev 0)
+++ branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/NodeNumberingPolicy.cpp 2018-01-17 01:09:28 UTC (rev 3160)
@@ -0,0 +1,130 @@
+// -*- C++ -*-
+/*!
+* @file NodeNumberingPolicy.cpp
+* @brief Object numbering policy class
+* @date $Date: 2018-1-11 03:08:04 $
+* @author Nobuhiko Miyamoto <n-miyamoto at aist.go.jp>
+*
+* Copyright (C) 2018
+* Intelligent Systems Research Institute,
+* National Institute of
+* Advanced Industrial Science and Technology (AIST), Japan
+* All rights reserved.
+*
+*
+*/
+
+#include <rtm/NodeNumberingPolicy.h>
+#include <rtm/Manager.h>
+#include <coil/stringutil.h>
+#include <rtm/NamingManager.h>
+#include <rtm/RTObject.h>
+
+namespace RTM
+{
+ //============================================================
+ // NodeNumberingPolicy
+ //============================================================
+ NodeNumberingPolicy::NodeNumberingPolicy()
+ : m_num(0)
+ {
+ m_mgr = &RTC::Manager::instance();
+ }
+ /*!
+ * @if jp
+ * @brief オブジェクト生成時の名称作成
+ * @else
+ * @brief Create the name when creating objects
+ * @endif
+ */
+ std::string NodeNumberingPolicy::onCreate(void* obj)
+ {
+ int num = 0;
+ while (true)
+ {
+ std::string num_str = coil::otos<int>(num);
+ RTC::RTObject_impl *rtobj = (RTC::RTObject_impl *)obj;
+
+
+ std::string name = rtobj->getTypeName() + num_str;
+
+ if (!find(name))
+ {
+ return num_str;
+ }
+ else
+ {
+ num++;
+ }
+ }
+ return coil::otos<int>(num);
+ }
+
+ /*!
+ * @if jp
+ * @brief オブジェクト削除時の名称解放
+ * @else
+ * @brief Delete the name when deleting objects
+ * @endif
+ */
+ void NodeNumberingPolicy::onDelete(void* obj)
+ {
+ }
+
+ /*!
+ * @if jp
+ *
+ * @brief オブジェクトの検索
+ *
+ * マスターマネージャ、およびスレーブマネージャに登録されたRTCを検索し、
+ * 名前が一致するRTCが存在する場合はTrueを返す
+ * このプロセスで起動したマネージャがマスターマネージャではなく、
+ * さらにマスターマネージャが1つも登録されていない場合はこのプロセスのマネージャから検索
+ *
+ * @param name 検索対象オブジェクトの名前
+ *
+ * @return 判定
+ *
+ * @else
+ *
+ * @brief
+ *
+ *
+ * @param name
+ *
+ * @return
+ *
+ * @endif
+ */
+ bool NodeNumberingPolicy::find(std::string name)
+ {
+ RTC::RTCList rtcs;
+ std::string rtc_name = "rtcloc://*/*/";
+ rtc_name += name;
+
+ rtcs = m_mgr->getNaming()->string_to_component(rtc_name);
+
+ if (rtcs.length() > 0)
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+}; //namespace RTM
+
+extern "C"
+{
+ void NodeNumberingPolicyInit()
+ {
+ ::RTM::NumberingPolicyFactory::
+ instance().addFactory("node_unique",
+ ::coil::Creator< ::RTM::NumberingPolicyBase,
+ ::RTM::NodeNumberingPolicy>,
+ ::coil::Destructor< ::RTM::NumberingPolicyBase,
+ ::RTM::NodeNumberingPolicy>);
+ }
+};
+
Added: branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/NodeNumberingPolicy.h
===================================================================
--- branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/NodeNumberingPolicy.h (rev 0)
+++ branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/NodeNumberingPolicy.h 2018-01-17 01:09:28 UTC (rev 3160)
@@ -0,0 +1,174 @@
+// -*- C++ -*-
+/*!
+* @file NodeNumberingPolicy.h
+* @brief Object numbering policy class
+* @date $Date: 2018-1-11 03:08:04 $
+* @author Nobuhiko Miyamoto <n-miyamoto at aist.go.jp>
+*
+* Copyright (C) 2018
+* Intelligent Systems Research Institute,
+* National Institute of
+* Advanced Industrial Science and Technology (AIST), Japan
+* All rights reserved.
+*
+*
+*/
+
+#ifndef RTC_NODENUMBERINGPOLICY_H
+#define RTC_NODENUMBERINGPOLICY_H
+
+#include <string>
+#include <vector>
+#include <rtm/RTC.h>
+#include <rtm/NumberingPolicyBase.h>
+#include <rtm/Manager.h>
+
+
+namespace RTM
+{
+ /*!
+ * @if jp
+ *
+ * @class NodeNumberingPolicy
+ * @brief オブジェクト生成時ネーミング・ポリシー(命名規則)管理用クラス
+ *
+ * マスターマネージャ、スレーブマネージャからRTCを検索してナンバリングを行う
+ *
+ * @since 1.2.0
+ *
+ * @else
+ *
+ * @class NodeNumberingPolicy
+ * @brief Class for naming policy management when creating objects
+ *
+ *
+ *
+ * @since 1.2.0
+ *
+ * @endif
+ */
+ class NodeNumberingPolicy
+ : public NumberingPolicyBase
+ {
+ public:
+ /*!
+ * @if jp
+ *
+ * @brief コンストラクタ
+ *
+ * コンストラクタ
+ *
+ * @else
+ *
+ * @brief Constructor
+ *
+ * Constructor
+ *
+ * @endif
+ */
+ NodeNumberingPolicy();
+
+ /*!
+ * @if jp
+ *
+ * @brief デストラクタ
+ *
+ * @else
+ *
+ * @brief Destractor
+ *
+ * @endif
+ */
+ virtual ~NodeNumberingPolicy(void){};
+
+ /*!
+ * @if jp
+ *
+ * @brief オブジェクト生成時の名称作成
+ *
+ * オブジェクト生成時の名称を生成する。
+ * 生成済みインスタンスの数に応じた名称を生成する。
+ *
+ * @param obj 名称生成対象オブジェクト
+ *
+ * @return 生成したオブジェクト名称
+ *
+ * @else
+ *
+ * @brief Create the name when creating object
+ *
+ * Create the name when creating object.
+ * Create the name corresponding to the number of generated instances.
+ *
+ * @param obj The target object for the name creation
+ *
+ * @return Names of the created object
+ *
+ * @endif
+ */
+ virtual std::string onCreate(void* obj);
+
+ /*!
+ * @if jp
+ *
+ * @brief オブジェクト削除時の名称解放
+ *
+ * オブジェクト削除時に名称を解放する。
+ * オブジェクト削除時に生成済みインスタンス数を減算する。
+ *
+ * @param obj 名称解放対象オブジェクト
+ *
+ * @else
+ *
+ * @brief Delete the name when deleting object
+ *
+ * Delete the name when deleting object.
+ * Substract the generated number of instances when deleting the object.
+ *
+ * @param obj The target object for the name delete
+ *
+ * @endif
+ */
+ virtual void onDelete(void* obj);
+
+ protected:
+ /*!
+ * @if jp
+ *
+ * @brief オブジェクトの検索
+ *
+ * マスターマネージャ、およびスレーブマネージャに登録されたRTCを検索し、
+ * 名前が一致するRTCが存在する場合はTrueを返す
+ * このプロセスで起動したマネージャがマスターマネージャではなく、
+ * さらにマスターマネージャが1つも登録されていない場合はこのプロセスのマネージャから検索
+ *
+ * @param name 検索対象オブジェクトの名前
+ *
+ * @return 判定
+ *
+ * @else
+ *
+ * @brief
+ *
+ *
+ * @param name
+ *
+ * @return
+ *
+ * @endif
+ */
+ virtual bool find(std::string name);
+
+ private:
+ int m_num;
+ std::vector<void*> m_objects;
+ RTC::Manager *m_mgr;
+ };
+}; // namespace RTM
+
+extern "C"
+{
+ void DLL_EXPORT NodeNumberingPolicyInit();
+};
+
+#endif // RTC_NODENUMBERINGPOLICY_H
Modified: branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/NumberingPolicy.h
===================================================================
--- branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/NumberingPolicy.h 2018-01-17 01:06:34 UTC (rev 3159)
+++ branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/NumberingPolicy.h 2018-01-17 01:09:28 UTC (rev 3160)
@@ -30,7 +30,7 @@
/*!
* @if jp
*
- * @class DefaultNumberingPolicy
+ * @class ProcessUniquePolicy
* @brief ¥ª¥Ö¥¸¥§¥¯¥ÈÀ¸À®»þ¥Í¡¼¥ß¥ó¥°¡¦¥Ý¥ê¥·¡¼(̿̾µ¬Â§)´ÉÍýÍÑ¥¯¥é¥¹
*
* ¥ª¥Ö¥¸¥§¥¯¥È¤òÀ¸À®¤¹¤ëºÝ¤Î¥Í¡¼¥ß¥ó¥°¡¦¥Ý¥ê¥·¡¼(̿̾µ¬Â§)¤ò´ÉÍý¤¹¤ë¤¿¤á¤Î
@@ -40,7 +40,7 @@
*
* @else
*
- * @class DefaultNumberingPolicy
+ * @class ProcessUniquePolicy
* @brief Class for naming policy management when creating objects
*
* This is a class to manage the naming policy when creating objects.
Modified: branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/NumberingPolicyBase.cpp
===================================================================
--- branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/NumberingPolicyBase.cpp 2018-01-17 01:06:34 UTC (rev 3159)
+++ branches/RELENG_1_2/OpenRTM-aist/src/lib/rtm/NumberingPolicyBase.cpp 2018-01-17 01:09:28 UTC (rev 3160)
@@ -20,70 +20,5 @@
#include <rtm/NumberingPolicy.h>
#include <coil/stringutil.h>
-//============================================================
-// DefaultNumberingPolicy
-//============================================================
-/*!
- * @if jp
- * @brief ¥ª¥Ö¥¸¥§¥¯¥ÈÀ¸À®»þ¤Î̾¾ÎºîÀ®
- * @else
- * @brief Create the name when creating objects
- * @endif
- */
-std::string DefaultNumberingPolicy::onCreate(void* obj)
-{
- std::vector<void*>::size_type pos;
-
- ++m_num;
-
- try
- {
- pos = find(NULL);
- m_objects[pos] = obj;
- return coil::otos(pos);
- }
- catch (ObjectNotFound& e)
- {
- (void)(e);
- m_objects.push_back(obj);
- return coil::otos((int)(m_objects.size() - 1));
- }
-}
-/*!
- * @if jp
- * @brief ¥ª¥Ö¥¸¥§¥¯¥Èºï½ü»þ¤Î̾¾Î²òÊü
- * @else
- * @brief Delete the name when deleting objects
- * @endif
- */
-void DefaultNumberingPolicy::onDelete(void* obj)
-{
- std::vector<void*>::size_type pos;
- pos = find(obj);
- if (pos < m_objects.size())
- {
- m_objects[pos] = NULL;
- }
- --m_num;
-}
-/*!
- * @if jp
- * @brief ¥ª¥Ö¥¸¥§¥¯¥È¤Î¸¡º÷
- * @else
- * @brief Find the object
- * @endif
- */
-long int DefaultNumberingPolicy::find(void* obj)
-{
- std::vector<void*>::size_type len(m_objects.size());
- std::vector<void*>::size_type i(0);
- for (i = 0; i < len; ++i)
- {
- if (m_objects[i] == obj) return i;
- }
- throw ObjectNotFound();
- return i;
-}
-
More information about the openrtm-commit
mailing list