[openrtm-commit:02314] r2886 - branches/FSM4RTC/OpenRTM-aist/src/lib/rtm

openrtm @ openrtm.org openrtm @ openrtm.org
2017年 1月 22日 (日) 23:07:24 JST


Author: n-ando
Date: 2017-01-22 23:07:24 +0900 (Sun, 22 Jan 2017)
New Revision: 2886

Modified:
   branches/FSM4RTC/OpenRTM-aist/src/lib/rtm/Manager.cpp
   branches/FSM4RTC/OpenRTM-aist/src/lib/rtm/Manager.h
   branches/FSM4RTC/OpenRTM-aist/src/lib/rtm/ManagerServant.cpp
Log:
[FSM4RTC,incompat] setEndpointProperty() function has been added to set endpoints information ro corba.endpoints . refs #3836

Modified: branches/FSM4RTC/OpenRTM-aist/src/lib/rtm/Manager.cpp
===================================================================
--- branches/FSM4RTC/OpenRTM-aist/src/lib/rtm/Manager.cpp	2017-01-22 14:00:28 UTC (rev 2885)
+++ branches/FSM4RTC/OpenRTM-aist/src/lib/rtm/Manager.cpp	2017-01-22 14:07:24 UTC (rev 2886)
@@ -806,7 +806,7 @@
       "os.version",
       "os.arch",
       "os.hostname",
-      "corba.endpoint",
+      "corba.endpoints",
       "corba.id",
       "exec_cxt.periodic.type",
       "exec_cxt.periodic.rate",
@@ -827,6 +827,20 @@
       ""
     };
 
+    RTObject_impl* comp;
+    comp = factory->create(this);
+    if (comp == NULL)
+      {
+        RTC_ERROR(("RTC creation failed: %s",
+                   comp_id["implementation_id"].c_str()));
+        return NULL;
+      }
+
+    if (m_config.getProperty("corba.endpoints_ipv4") == "")
+      {
+        setEndpointProperty(comp->getObjRef());
+      }
+
     for (int i(0); inherit_prop[i][0] != '\0'; ++i)
       {
         const char* key(inherit_prop[i]);
@@ -835,15 +849,7 @@
             prop[key] = m_config[key];
           }
       }
-      
-    RTObject_impl* comp;
-    comp = factory->create(this);
-    if (comp == NULL)
-      {
-	RTC_ERROR(("RTC creation failed: %s",
-                   comp_id["implementation_id"].c_str()));
-	return NULL;
-      }
+
     RTC_TRACE(("RTC created: %s", comp_id["implementation_id"].c_str()));
     m_listeners.rtclifecycle_.postCreate(comp);
     prop << comp_prop;
@@ -1762,7 +1768,6 @@
     return true;
   }
 
-
   bool Manager::initManagerServant()
   {
     RTC_TRACE(("Manager::initManagerServant()"));
@@ -1771,6 +1776,10 @@
         return true;
       }
     m_mgrservant = new ::RTM::ManagerServant();
+    if (m_config.getProperty("corba.endpoints_ipv4") == "")
+      {
+        setEndpointProperty(m_mgrservant->getObjRef());
+      }
     coil::Properties& prop(m_config.getNode("manager"));
     std::vector<std::string> names(coil::split(prop["naming_formats"], ","));
 
@@ -1788,10 +1797,10 @@
       {
         otherref.close();
         std::ofstream reffile(m_config["manager.refstring_path"].c_str());
-	RTM::Manager_var mgr_v(RTM::Manager::
+        RTM::Manager_var mgr_v(RTM::Manager::
                                _duplicate(m_mgrservant->getObjRef()));
         CORBA::String_var str_var = m_pORB->object_to_string(mgr_v);
-	reffile << str_var;
+        reffile << str_var;
         reffile.close();
       }
     else
@@ -2208,5 +2217,114 @@
       }
     return str;
   }
-  
+
+  /*!
+   * @if jp
+   * @brief corba.endpoints にエンドポイント情報を設定する
+   * @else
+   * @brief Setting endpoint info from corba.endpoints
+   * @endif
+   */
+  void Manager::setEndpointProperty(CORBA::Object_ptr objref)
+  {
+    RTC_TRACE(("sedEndpointProperty()"));
+    if (CORBA::is_nil(objref))
+      {
+        RTC_WARN(("Object reference is nil."));
+        return;
+      }
+
+    bool ipv4, ipv6;
+    std::vector<int> ipv4_list, ipv6_list;
+    endpointPropertySwitch("ipv4", ipv4, ipv4_list);
+    endpointPropertySwitch("ipv6", ipv6, ipv6_list);
+
+    CORBA::String_var iorstr = theORB()->object_to_string(objref);
+    IOP::IOR ior;
+    CORBA_IORUtil::toIOR(iorstr, ior);
+    std::vector<IIOP::Address> endpoints;
+    endpoints = CORBA_IORUtil::getEndpoints(ior);
+
+    coil::vstring epstr, epstr_ipv4, epstr_ipv6;
+    size_t ipv4_count(0), ipv6_count(0);
+
+    coil::vstring addrs;
+    for (size_t i(0); i < endpoints.size(); ++i)
+      {
+        std::string addr(endpoints[i].host);
+        if (ipv4 && coil::isIPv4(addr))
+          {
+            std::string tmp(addr + ":" + coil::otos(endpoints[i].port));
+            if (ipv4_list.size() == 0 ||
+                std::find(ipv4_list.begin(), ipv4_list.end(), ipv4_count)
+                != ipv4_list.end())
+              {
+                epstr.push_back(tmp);
+                epstr_ipv4.push_back(tmp);
+              }
+            ipv4_count += 1;
+          }
+        if (ipv6 && coil::isIPv6(addr))
+          {
+            std::string tmp("[" + addr + "]:" + coil::otos(endpoints[i].port));
+            if (ipv6_list.size() == 0 ||
+                std::find(ipv6_list.begin(), ipv6_list.end(), ipv6_count)
+                != ipv6_list.end())
+              {
+                epstr.push_back(tmp);
+                epstr_ipv6.push_back(tmp);
+              }
+            ipv6_count += 1;
+          }
+      }
+    m_config.setProperty("corba.endpoints", coil::flatten(epstr));
+    m_config.setProperty("corba.endpoints_ipv4", coil::flatten(epstr_ipv4));
+    m_config.setProperty("corba.endpoints_ipv6", coil::flatten(epstr_ipv6));
+  }
+
+  /*!
+   * @if jp
+   * @brief corba.endpoint_property からオプション情報を取得する
+   * @else
+   * @brief Getting option info from corba.endpoint_property
+   * @endif
+   */
+  void Manager::endpointPropertySwitch(const std::string& ipver,
+                                       bool& ip, std::vector<int>& ip_list)
+  {
+    ip = false; ip_list.resize(0);
+
+    std::string ep_prop;
+    ep_prop = m_config.getProperty("corba.endpoint_property", "ipv4");
+    coil::toLower(ep_prop);
+
+    std::string::size_type pos = ep_prop.find(ipver);
+    if (pos == std::string::npos) { return; }
+
+    ip = true;
+    pos += ipver.size();
+    if (pos >= ep_prop.size() || ep_prop[pos] != '(') { return; }
+    std::string::size_type par_begin, par_end;
+    par_begin = pos;
+    ++pos;
+    while (pos < ep_prop.size())
+      {
+        if (ep_prop[pos] == ')') { break; }
+        ++pos;
+      }
+    par_end = pos;
+
+    std::string list_num(ep_prop.substr(par_begin + 1, par_end - 1));
+    coil::vstring nums = coil::split(list_num, ",");
+    for (size_t i(0); i < nums.size(); ++i)
+      {
+        int n;
+        if (coil::stringTo(n, nums[i].c_str()))
+          {
+            ip_list.push_back(n);
+          }
+      }
+    return;
+  }
+
 };

Modified: branches/FSM4RTC/OpenRTM-aist/src/lib/rtm/Manager.h
===================================================================
--- branches/FSM4RTC/OpenRTM-aist/src/lib/rtm/Manager.h	2017-01-22 14:00:28 UTC (rev 2885)
+++ branches/FSM4RTC/OpenRTM-aist/src/lib/rtm/Manager.h	2017-01-22 14:07:24 UTC (rev 2886)
@@ -1719,7 +1719,24 @@
     std::string formatString(const char* naming_format,
 			     coil::Properties& prop);
 
+    /*!
+     * @if jp
+     * @brief corba.endpoints にエンドポイント情報を設定する
+     * @else
+     * @brief Setting endpoint info from corba.endpoints
+     * @endif
+     */
+    void setEndpointProperty(CORBA::Object_ptr objref);
 
+    /*!
+     * @if jp
+     * @brief corba.endpoint_property からオプション情報を取得する
+     * @else
+     * @brief Getting option info from corba.endpoint_property
+     * @endif
+     */
+    void endpointPropertySwitch(const std::string& ipver,
+                                bool& ip, std::vector<int>& ip_list);
     
     //============================================================
     // protected 変数

Modified: branches/FSM4RTC/OpenRTM-aist/src/lib/rtm/ManagerServant.cpp
===================================================================
--- branches/FSM4RTC/OpenRTM-aist/src/lib/rtm/ManagerServant.cpp	2017-01-22 14:00:28 UTC (rev 2885)
+++ branches/FSM4RTC/OpenRTM-aist/src/lib/rtm/ManagerServant.cpp	2017-01-22 14:07:24 UTC (rev 2886)
@@ -34,17 +34,17 @@
   {
     rtclog.setName("ManagerServant");
     coil::Properties config(m_mgr.getConfig());    
-    
+
+    if (!createINSManager())
+      {
+        RTC_WARN(("Manager CORBA servant creation failed."));
+        return;
+      }
+
     if (coil::toBool(config["manager.is_master"], "YES", "NO", true))
       { // this is master manager
         RTC_TRACE(("This manager is master."));
 
-        if (!createINSManager())
-          {
-            RTC_WARN(("Manager CORBA servant creation failed."));
-            return;
-            
-          }
         m_isMaster = true;
         RTC_WARN(("Manager CORBA servant was successfully created."));
         return;



More information about the openrtm-commit mailing list