[openrtm-commit:01622] r2675 - trunk/OpenRTM-aist/src/lib/rtm

openrtm @ openrtm.org openrtm @ openrtm.org
2015年 10月 27日 (火) 16:30:42 JST


Author: n-ando
Date: 2015-10-27 16:30:41 +0900 (Tue, 27 Oct 2015)
New Revision: 2675

Modified:
   trunk/OpenRTM-aist/src/lib/rtm/NamingManager.cpp
   trunk/OpenRTM-aist/src/lib/rtm/NamingManager.h
Log:
[incompat,->RELENG_1_2] Now NamingManager can register a reference of Port (PortBase) to naming service. refs #3263

Modified: trunk/OpenRTM-aist/src/lib/rtm/NamingManager.cpp
===================================================================
--- trunk/OpenRTM-aist/src/lib/rtm/NamingManager.cpp	2015-10-27 07:25:14 UTC (rev 2674)
+++ trunk/OpenRTM-aist/src/lib/rtm/NamingManager.cpp	2015-10-27 07:30:41 UTC (rev 2675)
@@ -69,7 +69,7 @@
    * @endif
    */
   void NamingOnCorba::bindObject(const char* name,
-				 const RTObject_impl* rtobj)
+                                 const RTObject_impl* rtobj)
   {
     RTC_TRACE(("bindObject(name = %s, rtobj)", name));
 #ifdef ORB_IS_OMNIORB
@@ -100,8 +100,39 @@
   }
 
   void NamingOnCorba::bindObject(const char* name,
-				 const RTM::ManagerServant* mgr)
+                                 const PortBase* port)
   {
+    RTC_TRACE(("bindObject(name = %s, rtobj)", name));
+#ifdef ORB_IS_OMNIORB
+    if (!m_endpoint.empty() && m_replaceEndpoint)
+      {
+        CORBA::Object_var obj(PortService::_duplicate(port->getPortRef()));
+        CORBA::String_var ior;
+        ior = RTC::Manager::instance().getORB()->object_to_string(obj.in());
+        std::string iorstr((const char*)ior);
+
+        RTC_DEBUG(("Original IOR information:\n %s",
+                   CORBA_IORUtil::formatIORinfo(iorstr.c_str()).c_str()));
+        CORBA_IORUtil::replaceEndpoint(iorstr, m_endpoint);
+        CORBA::Object_var newobj = RTC::Manager::instance().
+          getORB()->string_to_object(iorstr.c_str());
+
+        RTC_DEBUG(("Modified IOR information:\n %s",
+                   CORBA_IORUtil::formatIORinfo(iorstr.c_str()).c_str()));
+        m_cosnaming.rebindByString(name, newobj.in(), true);
+      }
+    else
+      {
+#endif // ORB_IS_OMNIORB
+        m_cosnaming.rebindByString(name, port->getPortRef(), true);
+#ifdef ORB_IS_OMNIORB
+      }
+#endif // ORB_IS_OMNIORB
+  }
+
+  void NamingOnCorba::bindObject(const char* name,
+                                 const RTM::ManagerServant* mgr)
+  {
     RTC_TRACE(("bindObject(name = %s, mgr)", name));
 #ifdef ORB_IS_OMNIORB
     if (!m_endpoint.empty() && m_replaceEndpoint)
@@ -184,7 +215,7 @@
    * @endif
    */
   void NamingManager::registerNameServer(const char* method,
-					 const char* name_server)
+                                         const char* name_server)
   {
     RTC_TRACE(("NamingManager::registerNameServer(%s, %s)",
 	       method, name_server));
@@ -192,7 +223,7 @@
     name = createNamingObj(method, name_server);
 
     Guard guard(m_namesMutex);
-    m_names.push_back(new Names(method, name_server, name));
+    m_names.push_back(new NamingService(method, name_server, name));
   }
   
   /*!
@@ -202,15 +233,15 @@
    * @brief Bind the specified objects to NamingService
    * @endif
    */
-  void NamingManager::bindObject(const char* name, 
-				 const RTObject_impl* rtobj)
+  void NamingManager::bindObject(const char* name,
+                                 const RTObject_impl* rtobj)
   {
     RTC_TRACE(("NamingManager::bindObject(%s)", name));
     
     Guard guard(m_namesMutex);
     for (int i(0), len(m_names.size()); i < len; ++i)
       {
-	if (m_names[i]->ns != 0)
+        if (m_names[i]->ns != 0)
           {
             try
               {
@@ -225,15 +256,38 @@
       }
     registerCompName(name, rtobj);
   }
+  void NamingManager::bindObject(const char* name,
+                                 const PortBase* port)
+  {
+    RTC_TRACE(("NamingManager::bindObject(%s)", name));
+    
+    Guard guard(m_namesMutex);
+    for (int i(0), len(m_names.size()); i < len; ++i)
+      {
+        if (m_names[i]->ns != 0)
+          {
+            try
+              {
+                m_names[i]->ns->bindObject(name, port);
+              }
+            catch (...)
+              {
+                delete m_names[i]->ns;
+                m_names[i]->ns = 0;
+              }
+          }
+      }
+    registerPortName(name, port);
+  }
   void NamingManager::bindObject(const char* name, 
-				 const RTM::ManagerServant* mgr)
+                                 const RTM::ManagerServant* mgr)
   {
     RTC_TRACE(("NamingManager::bindObject(%s)", name));
     
     Guard guard(m_namesMutex);
     for (int i(0), len(m_names.size()); i < len; ++i)
       {
-	if (m_names[i]->ns != 0)
+        if (m_names[i]->ns != 0)
           {
             try
               {
@@ -454,6 +508,27 @@
     m_compNames.push_back(new Comps(name, rtobj));
     return;
   }
+  /*!
+   * @if jp
+   * @brief NameServer に登録するコンポーネントの設定
+   * @else
+   * @brief Configure the components that will be registered to NameServer
+   * @endif
+   */
+  void NamingManager::registerPortName(const char* name,
+                                       const PortBase* port)
+  {
+    for (int i(0), len(m_portNames.size()); i < len; ++i)
+      {
+        if (m_portNames[i]->name == name)
+          {
+            m_portNames[i]->port = port;
+            return;
+          }
+      }
+    m_portNames.push_back(new Port(name, port));
+    return;
+  }
   void NamingManager::registerMgrName(const char* name,
                                       const RTM::ManagerServant* mgr)
   {
@@ -505,7 +580,7 @@
     return;
   }
 
-  void NamingManager::retryConnection(Names* ns)
+  void NamingManager::retryConnection(NamingService* ns)
   {
     // recreate NamingObj
     NamingBase* nsobj(0);

Modified: trunk/OpenRTM-aist/src/lib/rtm/NamingManager.h
===================================================================
--- trunk/OpenRTM-aist/src/lib/rtm/NamingManager.h	2015-10-27 07:25:14 UTC (rev 2674)
+++ trunk/OpenRTM-aist/src/lib/rtm/NamingManager.h	2015-10-27 07:30:41 UTC (rev 2675)
@@ -110,6 +110,7 @@
      * @endif
      */
     virtual void bindObject(const char* name, const RTObject_impl* rtobj) = 0;
+    virtual void bindObject(const char* name, const PortBase* port) = 0;
 
     /*!
      * @if jp
@@ -169,9 +170,33 @@
     virtual bool isAlive() = 0;
   };
   
-
   /*!
    * @if jp
+   * @brief NameServer 管理用構造体
+   * @else
+   * @brief Structure for NameServer management
+   * @endif
+   */
+  class NamingService
+  {
+  public:
+    NamingService(const char* meth, const char* name, NamingBase* naming)
+      : method(meth), nsname(name), ns(naming)
+    {
+    }
+    
+    ~NamingService()
+    {
+      delete ns;
+    }
+    
+    std::string method;
+    std::string nsname;
+    NamingBase* ns;
+  };
+  
+  /*!
+   * @if jp
    *
    * @class NamingOnCorba
    * @brief CORBA 用 NamingServer 管理クラス
@@ -262,6 +287,8 @@
      * @endif
      */
     virtual void bindObject(const char* name, const RTObject_impl* rtobj);
+    virtual void bindObject(const char* name, const PortBase* port);
+
     /*!
      * @if jp
      *
@@ -280,7 +307,7 @@
      * @endif
      */
     virtual void bindObject(const char* name, const RTM::ManagerServant* mgr);
-    
+
     /*!
      * @if jp
      *
@@ -301,7 +328,7 @@
      * @endif
      */
     virtual void unbindObject(const char* name);
-    
+
     /*!
      * @if jp
      *
@@ -318,13 +345,14 @@
      * @endif
      */
     virtual bool isAlive();
+    CorbaNaming& getCorbaNaming() { return m_cosnaming; }
 
   private:
     Logger rtclog;
     CorbaNaming m_cosnaming;
     std::string m_endpoint;
     bool m_replaceEndpoint;
-    std::map<std::string, RTObject_impl*> m_names;
+    //    std::map<std::string, RTObject_impl*> m_names;
   };
   
   /*!
@@ -437,6 +465,7 @@
      * @endif
      */
     void bindObject(const char* name, const RTObject_impl* rtobj);
+    void bindObject(const char* name, const PortBase* port);
 
     /*!
      * @if jp
@@ -539,6 +568,7 @@
      * @endif
      */
     std::vector<RTObject_impl*> getObjects();
+    std::vector<NamingService*>& getNameServices() { return m_names; }
     
   protected:
     /*!
@@ -615,6 +645,29 @@
     /*!
      * @if jp
      *
+     * @brief NameServer に登録するコンポーネントの設定
+     * 
+     * NameServer に登録するコンポーネントを設定する。
+     *
+     * @param name コンポーネントの登録時名称
+     * @param rtobj 登録対象オブジェクト
+     * 
+     * @else
+     *
+     * @brief Configure the components that will be registered to NameServer
+     * 
+     * Configure the components that will be registered to NameServer.
+     *
+     * @param name Names of components at the registration
+     * @param rtobj The target objects for registration
+     * 
+     * @endif
+     */
+    void registerPortName(const char* name, const PortBase* port);
+
+    /*!
+     * @if jp
+     *
      * @brief NameServer に登録するManagerServantの設定
      * 
      * NameServer に登録するManagerServantを設定する。
@@ -656,6 +709,7 @@
      * @endif
      */
     void unregisterCompName(const char* name);
+    void unregisterPortName(const char* name);
 
     /*!
      * @if jp
@@ -698,43 +752,18 @@
      * 
      * @endif
      */
-    class Names;
-    void retryConnection(Names* ns);
-    
+    void retryConnection(NamingService* ns);
+
   protected:
     // Name Servers' method/name and object
     /*!
      * @if jp
-     * @brief NameServer 管理用構造体
-     * @else
-     * @brief Structure for NameServer management
-     * @endif
-     */
-    class Names
-    {
-    public:
-      Names(const char* meth, const char* name, NamingBase* naming)
-	: method(meth), nsname(name), ns(naming)
-      {
-      }
-      
-      ~Names()
-      {
-        delete ns;
-      }
-      
-      std::string method;
-      std::string nsname;
-      NamingBase* ns;
-    };
-    /*!
-     * @if jp
      * @brief NameServer リスト
      * @else
      * @brief NameServer list
      * @endif
      */
-    std::vector<Names*> m_names;
+    std::vector<NamingService*> m_names;
     /*!
      * @if jp
      * @brief NameServer リストのmutex
@@ -762,6 +791,21 @@
     };
     /*!
      * @if jp
+     * @brief コンポーネント管理用構造体
+     * @else
+     * @brief Structure for component management
+     * @endif
+     */
+    struct Port
+    {
+      Port(const char* n, const PortBase* p)
+	: name(n), port(p)
+      {}
+      std::string name;
+      const PortBase* port;
+    };
+    /*!
+     * @if jp
      * @brief ManagerServant管理用構造体
      * @else
      * @brief Structure for ManagerServant management
@@ -793,6 +837,22 @@
     Mutex m_compNamesMutex;
     /*!
      * @if jp
+     * @brief コンポーネントリスト
+     * @else
+     * @brief Component list
+     * @endif
+     */
+    std::vector<Port*> m_portNames;
+    /*!
+     * @if jp
+     * @brief コンポーネントリストのmutex
+     * @else
+     * @brief Mutex of Port list
+     * @endif
+     */
+    Mutex m_portNamesMutex;
+    /*!
+     * @if jp
      * @brief ManagerServantリスト
      * @else
      * @brief ManagerServant list



More information about the openrtm-commit mailing list