[openrtm-commit:01757] r658 - trunk/OpenRTM-aist-Python/OpenRTM_aist

openrtm @ openrtm.org openrtm @ openrtm.org
2016年 2月 25日 (木) 14:27:39 JST


Author: miyamoto
Date: 2016-02-25 14:27:39 +0900 (Thu, 25 Feb 2016)
New Revision: 658

Added:
   trunk/OpenRTM-aist-Python/OpenRTM_aist/NamingServiceNumberingPolicy.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/NodeNumberingPolicy.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/NumberingPolicyBase.py
Modified:
   trunk/OpenRTM-aist-Python/OpenRTM_aist/DefaultConfiguration.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/FactoryInit.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/Manager.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/NumberingPolicy.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/__init__.py
Log:
[incompat,new_func,new_file,->RELENG_1_2] add NumberingPolicyBase.py, NodeNumberingPolicy.py, and NamingServiceNumberingPolicy.py. refs #3412

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/DefaultConfiguration.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/DefaultConfiguration.py	2016-02-24 21:26:48 UTC (rev 657)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/DefaultConfiguration.py	2016-02-25 05:27:39 UTC (rev 658)
@@ -77,6 +77,7 @@
                  "manager.command",                  "rtcd",
                  "manager.nameservers",               "default",
                  "manager.language",                 "Python",
+                 "manager.components.naming_policy", "process_unique",
                  "manager.local_service.enabled_services","ALL",
                  "sdo.service.provider.enabled_service",  "ALL",
                  "sdo.service.consumer.enabled_service",  "ALL",

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/FactoryInit.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/FactoryInit.py	2016-02-24 21:26:48 UTC (rev 657)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/FactoryInit.py	2016-02-25 05:27:39 UTC (rev 658)
@@ -42,4 +42,6 @@
     OpenRTM_aist.InPortSHMConsumerInit()
     OpenRTM_aist.OutPortSHMProviderInit()
     OpenRTM_aist.OutPortSHMConsumerInit()
-    
+    OpenRTM_aist.DefaultNumberingPolicyInit()
+    OpenRTM_aist.NodeNumberingPolicyInit()
+    OpenRTM_aist.NamingServiceNumberingPolicyInit()

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/Manager.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/Manager.py	2016-02-24 21:26:48 UTC (rev 657)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/Manager.py	2016-02-25 05:27:39 UTC (rev 658)
@@ -650,7 +650,13 @@
   def registerFactory(self, profile, new_func, delete_func):
     self._rtcout.RTC_TRACE("Manager.registerFactory(%s)", profile.getProperty("type_name"))
     try:
-      factory = OpenRTM_aist.FactoryPython(profile, new_func, delete_func)
+      policy_name = self._config.getProperty("manager.components.naming_policy")
+      
+      if not policy_name:
+        policy_name = "process_unique"
+      policy = OpenRTM_aist.NumberingPolicyFactory.instance().createObject(policy_name)
+      
+      factory = OpenRTM_aist.FactoryPython(profile, new_func, delete_func, policy)
       self._factory.registerObject(factory)
       return True
     except:

Added: trunk/OpenRTM-aist-Python/OpenRTM_aist/NamingServiceNumberingPolicy.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/NamingServiceNumberingPolicy.py	                        (rev 0)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/NamingServiceNumberingPolicy.py	2016-02-25 05:27:39 UTC (rev 658)
@@ -0,0 +1,162 @@
+#!/usr/bin/env python
+# -*- coding: euc-jp -*-
+
+##
+# @file NamingServiceNumberingPolicy.py
+# @brief Object numbering policy class
+# @date $Date: 2016/02/25$
+# @author Nobuhiko Miyamoto
+#
+
+import string
+import OpenRTM_aist
+import CosNaming
+
+
+
+
+
+
+##
+# @if jp
+#
+# @class NamingServiceNumberingPolicy
+# @brief オブジェクト生成時ネーミング・ポリシー(命名規則)管理用クラス
+# ネーミングサービスからRTCを検索してナンバリングを行う
+#
+#
+# @else
+#
+# @endif
+class NamingServiceNumberingPolicy(OpenRTM_aist.NumberingPolicy):
+  """
+  """
+
+  ##
+  # @if jp
+  #
+  # @brief コンストラクタ
+  # 
+  # コンストラクタ
+  # 
+  # @param self
+  # 
+  # @else
+  #
+  # @brief virtual destractor
+  #
+  # @endif
+  def __init__(self):
+    self._num = 0
+    self._objects = []
+    self._mgr = OpenRTM_aist.Manager.instance()
+
+
+  ##
+  # @if jp
+  #
+  # @brief オブジェクト生成時の名称作成
+  #
+  # 
+  # 
+  # @param self
+  # @param obj 名称生成対象オブジェクト
+  #
+  # @return 生成したオブジェクト名称
+  #
+  # @else
+  #
+  # @endif
+  def onCreate(self, obj):
+    num = 0
+    while True:
+      num_str = OpenRTM_aist.otos(num)
+      
+      name = obj.getTypeName() + num_str
+      if not self.find(name):
+        return num_str
+      else:
+        num += 1
+
+  ##
+  # @if jp
+  #
+  # @brief オブジェクト削除時の名称解放
+  #
+  # 
+  # 
+  # @param self
+  # @param obj 名称解放対象オブジェクト
+  #
+  # @else
+  #
+  # @endif
+  def onDelete(self, obj):
+    pass
+
+  ##
+  # @if jp
+  #
+  # @brief RTCの検索
+  #
+  # ネーミングサービスからRTCをインスタンス名から検索し、
+  # 一致するRTCがある場合はTrueを返す
+  # 
+  # @param self
+  # @param context 現在検索中のコンテキスト
+  # @param name RTCのインスタンス名
+  #
+  # @return 判定
+  #
+  # @else
+  #
+  # @endif
+  def find_RTC_by_Name(self, context, name):
+    length = 500
+    bl,bi = context.list(length)
+    for i in bl:
+      if i.binding_type == CosNaming.ncontext:
+        next_context = context.resolve(i.binding_name)
+        if self.find_RTC_by_Name(next_context, name):
+          return True
+      elif i.binding_type == CosNaming.nobject:
+        if i.binding_name[0].id == name and i.binding_name[0].kind == "rtc":
+          return True
+    return False
+        
+    
+
+  ##
+  # @if jp
+  #
+  # @brief オブジェクトの検索
+  #
+  # 指定名のインスタンス名のRTCを検索し、
+  # 一致するRTCが存在する場合はTrueを返す
+  # 
+  # @param self
+  # @param name RTCのインスタンス名
+  #
+  # @return 判定
+  #
+  # @else
+  #
+  # @endif
+  def find(self, name):
+    ns = self._mgr._namingManager._names
+    for n in ns:
+      noc = n.ns
+      if noc is None:
+        continue
+      cns = noc._cosnaming
+      if cns is None:
+        continue
+      root_cxt = cns.getRootContext()
+      return self.find_RTC_by_Name(root_cxt, name)
+
+
+
+def NamingServiceNumberingPolicyInit():
+  OpenRTM_aist.NumberingPolicyFactory.instance().addFactory("ns_unique",
+                                                      OpenRTM_aist.NamingServiceNumberingPolicy,
+                                                      OpenRTM_aist.Delete)

Added: trunk/OpenRTM-aist-Python/OpenRTM_aist/NodeNumberingPolicy.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/NodeNumberingPolicy.py	                        (rev 0)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/NodeNumberingPolicy.py	2016-02-25 05:27:39 UTC (rev 658)
@@ -0,0 +1,149 @@
+#!/usr/bin/env python
+# -*- coding: euc-jp -*-
+
+##
+# @file NodeNumberingPolicy.py
+# @brief Object numbering policy class
+# @date $Date: 2016/02/25$
+# @author Nobuhiko Miyamoto
+#
+
+import string
+import OpenRTM_aist
+
+
+
+
+
+##
+# @if jp
+#
+# @class NodeNumberingPolicy
+# @brief オブジェクト生成時ネーミング・ポリシー(命名規則)管理用クラス
+# マスターマネージャ、スレーブマネージャからRTCを検索してナンバリングを行う
+#
+# 
+#
+# @since 0.4.0
+#
+# @else
+#
+# @endif
+class NodeNumberingPolicy(OpenRTM_aist.NumberingPolicy):
+  """
+  """
+
+  ##
+  # @if jp
+  #
+  # @brief コンストラクタ
+  # 
+  # コンストラクタ
+  # 
+  # @param self
+  # 
+  # @else
+  #
+  # @brief virtual destractor
+  #
+  # @endif
+  def __init__(self):
+    self._mgr = OpenRTM_aist.Manager.instance()
+
+
+  ##
+  # @if jp
+  #
+  # @brief オブジェクト生成時の名称作成
+  #
+  # 
+  # @param self
+  # @param obj 名称生成対象オブジェクト
+  #
+  # @return 生成したオブジェクト名称
+  #
+  # @else
+  #
+  # @endif
+  def onCreate(self, obj):
+    num = 0
+    while True:
+      num_str = OpenRTM_aist.otos(num)
+      
+      name = obj.getTypeName() + num_str
+      if not self.find(name):
+        return num_str
+      else:
+        num += 1
+        
+
+  ##
+  # @if jp
+  #
+  # @brief オブジェクト削除時の名称解放
+  #
+  # 
+  # @param self
+  # @param obj 名称解放対象オブジェクト
+  #
+  # @else
+  #
+  # @endif
+  def onDelete(self, obj):
+    pass
+
+  
+    
+    
+
+  ##
+  # @if jp
+  #
+  # @brief オブジェクトの検索
+  #
+  # マスターマネージャ、およびスレーブマネージャに登録されたRTCを検索し、
+  #     名前が一致するRTCが存在する場合はTrueを返す
+  # このプロセスで起動したマネージャがマスターマネージャではなく、
+  #   さらにマスターマネージャが1つも登録されていない場合はこのプロセスのマネージャから検索
+  # 
+  # @param self
+  # @param name 検索対象オブジェクトの名前
+  #
+  # @return 判定
+  #
+  # @else
+  #
+  # @endif
+  def find(self, name):
+    rtcs = []
+    mgr_servant = self._mgr._mgrservant
+    master_mgr = None
+    if mgr_servant.is_master():
+      master_mgr = mgr_servant.getObjRef()
+    else:
+      masters = mgr_servant.get_master_managers()
+      if len(masters) > 0:
+        master_mgr = masters[0]
+      else:
+        master_mgr = mgr_servant.getObjRef()
+    
+    rtcs = master_mgr.get_components_by_name(name)
+    if len(rtcs) > 0:
+      return True
+    slaves = master_mgr.get_slave_managers()
+    for ms in slaves:
+      rtcs = ms.get_components_by_name(name)
+      if len(rtcs) > 0:
+        return True
+    
+    
+    
+    return False
+
+
+
+
+def NodeNumberingPolicyInit():
+  OpenRTM_aist.NumberingPolicyFactory.instance().addFactory("node_unique",
+                                                      OpenRTM_aist.NodeNumberingPolicy,
+                                                      OpenRTM_aist.Delete)

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/NumberingPolicy.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/NumberingPolicy.py	2016-02-24 21:26:48 UTC (rev 657)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/NumberingPolicy.py	2016-02-25 05:27:39 UTC (rev 658)
@@ -17,6 +17,9 @@
 import string
 import OpenRTM_aist
 
+
+
+
 ##
 # @if jp
 #
@@ -34,7 +37,7 @@
 # @else
 #
 # @endif
-class NumberingPolicy:
+class NumberingPolicy(OpenRTM_aist.NumberingPolicyBase):
   """
   """
 
@@ -87,8 +90,8 @@
   def onDelete(self, obj):
     pass
 
+  
 
-
 ##
 # @if jp
 #
@@ -204,5 +207,10 @@
         return i
       i += 1
     raise NumberingPolicy.ObjectNotFound()
-       
 
+
+def DefaultNumberingPolicyInit():
+  OpenRTM_aist.NumberingPolicyFactory.instance().addFactory("process_unique",
+                                                      OpenRTM_aist.DefaultNumberingPolicy,
+                                                      OpenRTM_aist.Delete)
+

Added: trunk/OpenRTM-aist-Python/OpenRTM_aist/NumberingPolicyBase.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/NumberingPolicyBase.py	                        (rev 0)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/NumberingPolicyBase.py	2016-02-25 05:27:39 UTC (rev 658)
@@ -0,0 +1,48 @@
+#!/usr/bin/env python
+# -*- coding: euc-jp -*-
+
+##
+# @file NumberingPolicyBase.py
+# @brief Object numbering policy base class
+# @date $Date: 2016/02/25$
+# @author Nobuhiko Miyamoto
+#
+
+
+import string
+import OpenRTM_aist
+
+
+##
+# @if jp
+#
+# @class NumberingPolicyBase
+# @brief オブジェクト生成時ネーミング・ポリシー(命名規則)管理用基底クラス
+#
+#
+#
+# @else
+#
+# @endif
+class NumberingPolicyBase:
+  def __init__(self):
+    pass
+  def onCreate(self, obj):
+    pass
+  def onDelete(self, obj):
+    pass
+
+
+
+numberingpolicyfactory = None
+
+class NumberingPolicyFactory(OpenRTM_aist.Factory):
+  def __init__(self):
+    OpenRTM_aist.Factory.__init__(self)
+  def instance():
+    global numberingpolicyfactory
+    if numberingpolicyfactory is None:
+      numberingpolicyfactory = NumberingPolicyFactory()
+    return numberingpolicyfactory
+  instance = staticmethod(instance)
+

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/__init__.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/__init__.py	2016-02-24 21:26:48 UTC (rev 657)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/__init__.py	2016-02-25 05:27:39 UTC (rev 658)
@@ -30,7 +30,6 @@
 from CdrBufferBase import *
 from CdrRingBuffer import *
 from DataPortStatus import *
-from NumberingPolicy import *
 from Listener import *
 from ListenerHolder import *
 from LocalServiceBase import *
@@ -109,3 +108,8 @@
 from OutPortSHMConsumer import *
 from OutPortSHMProvider import *
 from CORBA_RTCUtil import *
+from NumberingPolicyBase import *
+from NumberingPolicy import *
+from NodeNumberingPolicy import *
+from NamingServiceNumberingPolicy import *
+



More information about the openrtm-commit mailing list