From b3bb6bbc37ada44e145f426631e61fd472303a4a Mon Sep 17 00:00:00 2001 From: Nobuhiko Miyamoto Date: Tue, 11 Jan 2022 16:47:28 +0900 Subject: [PATCH 1/8] [incompat] support various protocols. --- OpenRTM_aist/CORBA_RTCUtil.py | 177 +++++++++++++++++++++++++++++++++ OpenRTM_aist/CorbaNaming.py | 5 +- OpenRTM_aist/Manager.py | 58 +++++++++-- OpenRTM_aist/ManagerServant.py | 5 +- OpenRTM_aist/NamingManager.py | 18 +++- 5 files changed, 246 insertions(+), 17 deletions(-) diff --git a/OpenRTM_aist/CORBA_RTCUtil.py b/OpenRTM_aist/CORBA_RTCUtil.py index 4d531a48..f92ef00a 100644 --- a/OpenRTM_aist/CORBA_RTCUtil.py +++ b/OpenRTM_aist/CORBA_RTCUtil.py @@ -1536,3 +1536,180 @@ def set_configuration_parameter(conf, confset, value_name, value): confset.configuration_data = confData conf.set_configuration_set_values(confset) return True + + +## +# @if jp +# @class CorbaURI +# @brief 指定のCORBAオブジェクト参照用URLから参照形式、ホスト名、ポート番号、 +# パス、オブジェクトキーを取得する機能を提供するクラス +# +# @since 2.0.0 +# +# @else +# @class CorbaURI +# @brief +# +# @since 2.0.0 +# +# @endif +class CorbaURI: + ## + # @if jp + # + # @brief コンストラクタ + # + # uriには以下の形式のURLを指定できる + # - corbaloc形式(例:corbaloc:iiop:192.168.11.1:2809/Nameservice) + # - corbaname形式(例:corbaname::192.168.11.1:2809#ConsoleOut0.rtc) + # - HTTP(例:http://192.168.11.1:2809/call#Nameservice) + # - HTTPS(例:https://192.168.11.1:2809/call#Nameservice) + # - WS(例:ws://192.168.11.1:2809/ws#Nameservice) + # - WSS(例:wss://192.168.11.1:2809/ws#Nameservice) + # + # また、giop:ではじまるエンドポイントを指定することもできる + # この場合は上記のcorbaloc形式、corbaname形式、HTTP、HTTPS、WS、WSSのURLに変換する + # - giop::192.168.11.1:2809 -> corbaloc:iiop:192.168.11.1:2809 + # - giop:tcp:192.168.11.1:2809 -> corbaloc:iiop:192.168.11.1:2809 + # - giop:ssl:192.168.11.1:2809 -> corbaloc:ssliop:192.168.11.1:2809 + # - giop:http:http://192.168.11.1:2809/call -> + # http://192.168.11.1:2809/call + # + # アドレス、ポート番号を指定した場合はcorbaloc形式URLに変換する。 + # - 192.168.11.1:2809 -> corbaloc:iiop:192.168.11.1:2809 + # + # objkeyを指定した場合はURIの末尾に追加する。 + # - corbaloc:iiop:192.168.11.1:2809 -> + # corbaloc:iiop:192.168.11.1:2809/Nameservice + # - corbaname::192.168.11.1:2809 -> + # corbaloc:iiop:192.168.11.1:2809#ConsoleOut0.rtc + # - http://192.168.11.1:2809/call -> + # http://192.168.11.1:2809/call#Nameservice + # + # @param self + # @param uri CORBAオブジェクト参照用URL + # @param objkey オブジェクト名 + # + # @else + # + # @brief Consructor + # + # + # @param self + # @param uri + # @param objkey + # + # @endif + def __init__(self, uri, objkey=""): + import urllib.parse + if uri.find("giop:tcp:") == 0: + uri = uri.replace("giop:tcp:", "corbaloc:iiop:") + elif uri.find("giop:ssl:") == 0: + uri = uri.replace("giop:ssl:", "corbaloc:ssliop:") + elif uri.find("giop:http:") == 0: + uri = uri.replace("giop:http:", "") + elif uri.find("giop::") == 0: + uri = uri.replace("giop::", "corbaloc:iiop:") + elif uri.find("iiop://") == 0: + uri = uri.replace("iiop://", "corbaloc:iiop:") + elif uri.find("inet:") == 0: + uri = uri.replace("inet:", "corbaloc:iiop:") + + self._uri = "" + self._port = None + self._addressonly = False + ret = urllib.parse.urlparse(uri) + self._protocol = ret.scheme + + loc = [s.strip() for s in ret.netloc.split(":")] + if len(loc) >= 2: + self._host = loc[0] + self._port = int(loc[1]) + else: + self._host = ret.netloc + self._path = ret.path + self._fragment = ret.fragment + + if self._fragment: + self._uri = uri + return + else: + self._fragment = objkey + if self._protocol == "corbaloc": + self._uri = uri + "/" + self._uri += self._fragment + elif self._protocol: + self._uri = uri + "#" + self._uri += self._fragment + else: + self._uri = "corbaloc:iiop:" + self._uri += uri + "/" + self._uri += self._fragment + self._protocol = "corbaloc" + self._addressonly = True + host_port = [s.strip() for s in uri.split(":")] + if len(host_port) == 2: + self._host = host_port[0] + try: + self._port = int(host_port[1]) + except BaseException: + pass + ## + # @if jp + # + # @brief CORBAオブジェクト参照用URLを取得する + # + # @param self + # @return CORBAオブジェクト参照用URL + # + # @else + # + # @brief Consructor + # + # @param self + # @return + # + # @endif + + def toString(self): + return self._uri + + ## + # @if jp + # + # @brief 参照形式を取得する + # 例:corbaloc、corbaname、http、https、ws、wss + # + # @param self + # @return 参照形式 + # + # @else + # + # @brief + # + # @param self + # @return + # + # @endif + def getProtocol(self): + return self._protocol + + ## + # @if jp + # + # @brief 初期化時にCORBAオブジェクト参照用URLを指定した場合はfalse、 + # ホスト名、ポート番号のみを指定した場合はtrueを返す。 + # + # @param self + # @return 参照先の指定方法 + # + # @else + # + # @brief + # + # @param self + # @return + # + # @endif + def isAddressOnly(self): + return self._addressonly diff --git a/OpenRTM_aist/CorbaNaming.py b/OpenRTM_aist/CorbaNaming.py index 6660a1f7..070e9fb1 100644 --- a/OpenRTM_aist/CorbaNaming.py +++ b/OpenRTM_aist/CorbaNaming.py @@ -17,6 +17,7 @@ import omniORB.CORBA as CORBA import CosNaming +import OpenRTM_aist.CORBA_RTCUtil import string import sys import traceback @@ -85,7 +86,7 @@ def __init__(self, orb, name_server=None): self._blLength = 100 if name_server: - self._nameServer = "corbaloc::" + name_server + "/NameService" + self._nameServer = OpenRTM_aist.CORBA_RTCUtil.CorbaURI(name_server, "NameService").toString() try: obj = orb.string_to_object(self._nameServer) self._rootContext = obj._narrow(CosNaming.NamingContext) @@ -129,7 +130,7 @@ def __del__(self): # @endif def init(self, name_server): - self._nameServer = "corbaloc::" + name_server + "/NameService" + self._nameServer = OpenRTM_aist.CORBA_RTCUtil.CorbaURI(name_server, "NameService").toString() obj = self._orb.string_to_object(self._nameServer) self._rootContext = obj._narrow(CosNaming.NamingContext) if CORBA.is_nil(self._rootContext): diff --git a/OpenRTM_aist/Manager.py b/OpenRTM_aist/Manager.py index 15d9a538..305f5573 100644 --- a/OpenRTM_aist/Manager.py +++ b/OpenRTM_aist/Manager.py @@ -1778,6 +1778,38 @@ def createORBOptions(self): return opt + ## + # @if jp + # @brief giopからはじまるORBエンドポイントでの指定した場合にtrue、 + # それ以外(例えばホスト名:ポート番号の指定)の場合はfalseを返す。 + # + # + # @param endpoint エンドポイント + # @return エンドポイントの指定方法 + # + # @else + # @brief + # + # @param endpoint + # @return + # + # @endif + # + # static bool isORBEndPoint(const std::string& endpoint); + + @staticmethod + def isORBEndPoint(endpoint): + if "giop:" in endpoint: + return True + elif "iiop://" in endpoint: + return True + elif "inet:" in endpoint: + return True + return False + + + + ## # @if jp # @brief エンドポイントの生成 @@ -1828,11 +1860,14 @@ def createORBEndpoints(self): if OpenRTM_aist.toBool(self._config.getProperty( "manager.is_master"), "YES", "NO", False): mm = self._config.getProperty("corba.master_manager", ":2810") - mmm = [s.strip() for s in mm.split(":")] - if len(mmm) == 2: - endpoints.insert(0, ":" + mmm[1]) + if not Manager.isORBEndPoint(mm): + mmm = [s.strip() for s in mm.split(":")] + if len(mmm) == 2: + endpoints.insert(0, ":" + mmm[1]) + else: + endpoints.insert(0, ":2810") else: - endpoints.insert(0, ":2810") + endpoints.insert(0, mm) endpoints = OpenRTM_aist.unique_sv(endpoints) @@ -1871,12 +1906,21 @@ def createORBEndpointOption(self, opt, endpoints): if endpoint == "all:": opt += " -ORBendPointPublish all(addr)" else: - opt += " -ORBendPoint giop:tcp:" + endpoint + if not Manager.isORBEndPoint(endpoint): + opt += " -ORBendPoint giop:tcp:" + endpoint + else: + opt += " -ORBendPoint " + endpoint elif corba == "TAO": - opt += "-ORBEndPoint iiop://" + endpoint + if not Manager.isORBEndPoint(endpoint): + opt += "-ORBEndPoint iiop://" + endpoint + else: + opt += "-ORBEndPoint " + endpoint elif corba == "MICO": - opt += "-ORBIIOPAddr inet:" + endpoint + if not Manager.isORBEndPoint(endpoint): + opt += "-ORBIIOPAddr inet:" + endpoint + else: + opt += "-ORBIIOPAddr " + endpoint endpoints[i] = endpoint diff --git a/OpenRTM_aist/ManagerServant.py b/OpenRTM_aist/ManagerServant.py index 5e5e4159..c8cfc0d5 100644 --- a/OpenRTM_aist/ManagerServant.py +++ b/OpenRTM_aist/ManagerServant.py @@ -20,6 +20,7 @@ import time from omniORB import CORBA import OpenRTM_aist +import OpenRTM_aist.CORBA_RTCUtil import RTC import RTM import RTM__POA @@ -1158,9 +1159,7 @@ def findManager(self, host_port): self._rtcout.RTC_TRACE("findManager(host_port = %s)", host_port) try: config = copy.deepcopy(self._mgr.getConfig()) - mgrloc = "corbaloc:iiop:" - mgrloc += host_port - mgrloc += "/" + config.getProperty("manager.name") + mgrloc = OpenRTM_aist.CORBA_RTCUtil.CorbaURI(host_port, config.getProperty("manager.name")).toString() self._rtcout.RTC_DEBUG("corbaloc: %s", mgrloc) diff --git a/OpenRTM_aist/NamingManager.py b/OpenRTM_aist/NamingManager.py index 530ab2a6..0d695e78 100644 --- a/OpenRTM_aist/NamingManager.py +++ b/OpenRTM_aist/NamingManager.py @@ -19,6 +19,7 @@ import OpenRTM_aist +import OpenRTM_aist.CORBA_RTCUtil from omniORB import CORBA import RTM import RTC @@ -561,11 +562,9 @@ def getManager(self, name): mgr = mgr_sev.getObjRef() return mgr try: - mgrloc = "corbaloc:iiop:" prop = self._mgr.getConfig() manager_name = prop.getProperty("manager.name") - mgrloc += name - mgrloc += "/" + manager_name + mgrloc = OpenRTM_aist.CORBA_RTCUtil.CorbaURI(name, manager_name).toString() mobj = self._orb.string_to_object(mgrloc) mgr = mobj._narrow(RTM.Manager) @@ -783,7 +782,13 @@ def unbindObject(self, name): guard = OpenRTM_aist.ScopedLock(self._namesMutex) for n in self._names: if n.ns: - n.ns.unbindObject(name) + try: + n.ns.unbindObject(name) + except BaseException: + del n.ns + n.ns = None + + self.unregisterCompName(name) self.unregisterMgrName(name) self.unregisterPortName(name) @@ -899,7 +904,10 @@ def createNamingObj(self, method, name_server): def bindCompsTo(self, ns): for comp in self._compNames: - ns.bindObject(comp.name, comp.rtobj) + try: + ns.bindObject(comp.name, comp.rtobj) + except BaseException: + pass ## # @if jp From 7ba5efe1e29a9c1aa8d0d309bcb5c9ba9df38db2 Mon Sep 17 00:00:00 2001 From: Nobuhiko Miyamoto Date: Tue, 11 Jan 2022 16:59:40 +0900 Subject: [PATCH 2/8] [compat] fixed CorbaURI class. --- OpenRTM_aist/CORBA_RTCUtil.py | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/OpenRTM_aist/CORBA_RTCUtil.py b/OpenRTM_aist/CORBA_RTCUtil.py index f92ef00a..988835da 100644 --- a/OpenRTM_aist/CORBA_RTCUtil.py +++ b/OpenRTM_aist/CORBA_RTCUtil.py @@ -1694,6 +1694,44 @@ def toString(self): def getProtocol(self): return self._protocol + ## + # @if jp + # + # @brief ホスト名を取得する + # + # @param self + # @return ホスト名 + # + # @else + # + # @brief + # + # @param self + # @return + # + # @endif + def getHost(self): + return self._protocol + + ## + # @if jp + # + # @brief ポート番号を取得する + # + # @param self + # @return ポート番号 + # + # @else + # + # @brief + # + # @param self + # @return + # + # @endif + def getPort(self): + return self._protocol + ## # @if jp # From 5adab9d82a97dde7be38d3a3c0ce2aebdc92e845 Mon Sep 17 00:00:00 2001 From: Nobuhiko Miyamoto Date: Tue, 11 Jan 2022 17:01:08 +0900 Subject: [PATCH 3/8] [compat] fixed CorbaURI class. --- OpenRTM_aist/CORBA_RTCUtil.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OpenRTM_aist/CORBA_RTCUtil.py b/OpenRTM_aist/CORBA_RTCUtil.py index 988835da..0adf6e62 100644 --- a/OpenRTM_aist/CORBA_RTCUtil.py +++ b/OpenRTM_aist/CORBA_RTCUtil.py @@ -1711,7 +1711,7 @@ def getProtocol(self): # # @endif def getHost(self): - return self._protocol + return self._host ## # @if jp @@ -1730,7 +1730,7 @@ def getHost(self): # # @endif def getPort(self): - return self._protocol + return self._port ## # @if jp From 8ce2652c35e9a1df335216ad66893d0846bb476e Mon Sep 17 00:00:00 2001 From: Nobuhiko Miyamoto Date: Tue, 11 Jan 2022 19:58:30 +0900 Subject: [PATCH 4/8] [compat] support various protocols. --- OpenRTM_aist/CORBA_RTCUtil.py | 6 ++++++ OpenRTM_aist/Manager.py | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/OpenRTM_aist/CORBA_RTCUtil.py b/OpenRTM_aist/CORBA_RTCUtil.py index 0adf6e62..177d956f 100644 --- a/OpenRTM_aist/CORBA_RTCUtil.py +++ b/OpenRTM_aist/CORBA_RTCUtil.py @@ -1612,6 +1612,12 @@ def __init__(self, uri, objkey=""): uri = uri.replace("giop::", "corbaloc:iiop:") elif uri.find("iiop://") == 0: uri = uri.replace("iiop://", "corbaloc:iiop:") + elif uri.find("diop://") == 0: + uri = uri.replace("diop://", "corbaloc:diop:") + elif uri.find("uiop://") == 0: + uri = uri.replace("uiop://", "corbaloc:uiop:") + elif uri.find("shmiop://") == 0: + uri = uri.replace("shmiop://", "corbaloc:shmiop:") elif uri.find("inet:") == 0: uri = uri.replace("inet:", "corbaloc:iiop:") diff --git a/OpenRTM_aist/Manager.py b/OpenRTM_aist/Manager.py index 305f5573..eef7e7d4 100644 --- a/OpenRTM_aist/Manager.py +++ b/OpenRTM_aist/Manager.py @@ -1803,6 +1803,12 @@ def isORBEndPoint(endpoint): return True elif "iiop://" in endpoint: return True + elif "diop://" in endpoint: + return True + elif "uiop://" in endpoint: + return True + elif "shmiop://" in endpoint: + return True elif "inet:" in endpoint: return True return False From 32f578ee90a1a8a67aea1eefd007958ca9424d6e Mon Sep 17 00:00:00 2001 From: Nobuhiko Miyamoto Date: Fri, 21 Jan 2022 19:39:18 +0900 Subject: [PATCH 5/8] [compat] support ssl and http transport. --- OpenRTM_aist/CORBA_RTCUtil.py | 183 +++++++++++++++++++++++++++ OpenRTM_aist/Manager.py | 23 ++-- OpenRTM_aist/NamingManager.py | 127 ++++++++++--------- OpenRTM_aist/ext/http/rtc.http.conf | 4 +- OpenRTM_aist/ext/http/rtc.https.conf | 4 +- OpenRTM_aist/ext/http/rtc.ws.conf | 4 +- OpenRTM_aist/ext/http/rtc.wss.conf | 4 +- OpenRTM_aist/ext/ssl/rtc.ssl.conf | 4 +- 8 files changed, 276 insertions(+), 77 deletions(-) diff --git a/OpenRTM_aist/CORBA_RTCUtil.py b/OpenRTM_aist/CORBA_RTCUtil.py index 177d956f..f2045756 100644 --- a/OpenRTM_aist/CORBA_RTCUtil.py +++ b/OpenRTM_aist/CORBA_RTCUtil.py @@ -1757,3 +1757,186 @@ def getPort(self): # @endif def isAddressOnly(self): return self._addressonly + + +## +# @if jp +# @class RTCURIObject クラス +# @brief RTCURIObject クラス +# rtcname形式、rtcloc形式のURIから通信先のアドレス、RTC名等を +# 取得する機能を提供するクラス +# rtcname形式は以下のようにrtcname.{通信プロトコル}/{アドレス}/{ネームサーバーでの登録パス} +# で指定可能である。通信プロトコルを省略するとiiopに設定する。 +# +# rtcname.ssliop://localhost:2809/test.host_cxt/ConsoleOut0 +# +# ただし、http通信を指定する場合は以下のようにアドレスの後は#で区切る必要がある。 +# +# rtcname.https://localhost:2809/call#test.host_cxt/ConsoleOut0 +# +# rtcloc形式は以下のようにrtcloc.{通信プロトコル}/{アドレス}/{カテゴリ名}/{RTC名} +# で指定可能である。通信プロトコルを省略するとiiopに設定する。 +# +# rtcloc.ssliop://localhost:2810/example/ConsoleOut0 +# +# ただし、http通信を指定する場合は以下のようにアドレスの後は#で区切る必要がある。 +# +# rtcloc.http://localhost:2810/call#example/ConsoleOut0 +# +# @since 2.0.0 +# +# @else +# @class RTCURIObject class +# @brief RTCURIObject class +# @brief +# +# @since 2.0.0 +# +# @endif +class RTCURIObject: + ## + # @if jp + # + # @brief コンストラクタ + # + # @param uri rtcname形式、もしくはrtcloc形式のURI + # @param isrtcname rtcname形式を指定する場合はtrue、それ以外はfalse + # @param isrtcloc rtcloc形式を指定する場合はtrue、それ以外はfalse + # + # @else + # + # @brief Consructor + # + # + # @param uri + # @param isrtcname + # @param isrtcloc + # + # @endif + def __init__(self, uri, isrtcname=False, isrtcloc=False): + self._is_rtcname = False + self._is_rtcloc = False + self._rtcpath = "" + self._address = "" + pos = uri.find("://") + if pos >= 0: + ptype = uri[0:pos] + addrname = uri[pos+3:] + protocol = "" + + if ptype.find("rtcname") == 0: + self._is_rtcname = True + elif ptype.find("rtcloc") == 0: + self._is_rtcloc = True + else: + return + + if isrtcname: + if not self._is_rtcname: + return + + if isrtcloc: + if not self._is_rtcloc: + return + + pos = ptype.find(".") + seprtc = "/" + if pos >= 0: + protocol = ptype[pos+1:] + if protocol == "http" or protocol == "https" or protocol == "ws" or protocol == "wss": + seprtc = "#" + + pos = addrname.find(seprtc) + hostport = "" + + if pos >= 0: + hostport = addrname[0:pos] + self._rtcpath = addrname[pos+1:] + else: + self._rtcpath = addrname + + if protocol == "http" or protocol == "https" or protocol == "ws" or protocol == "wss": + self._address = protocol + self._address += "://" + self._address += hostport + + else: + self._address = "corbaloc:" + self._address += protocol + self._address += ":" + self._address += hostport + + ## + # @if jp + # + # @brief デストラクタ + # + # + # @else + # + # @brief Destructor + # + # + # @endif + def getRTCName(self): + return self._rtcpath + + ## + # @if jp + # + # @brief RTC名を取得する + # + # rtcname形式の場合はネームサーバーに登録したRTCのパスを取得できる。 + # context1.kind1/context2.kind2/..../RTC_name + # + # rtcloc形式の場合はカテゴリ名/RTC名で取得できる。 + # + # @return RTC名 + # + # @else + # + # @brief + # + # @return + # + # @endif + def getAddress(self): + return self._address + + ## + # @if jp + # + # @brief URIがrtcname形式かを判定する + # + # @return true:rtcname形式、false:それ以外 + # + # @return RTC名 + # + # @else + # + # @brief + # + # @return + # + # @endif + def isRTCNameURI(self): + return self._is_rtcname + + ## + # @if jp + # + # @brief URIがrtcname形式かを判定する + # + # @brief URIがrtcloc形式かを判定する + # + # @return true:rtcname形式、false:それ以外 + # + # @else + # + # @brief + # + # @return + # + # @endif + def isRTCLocURI(self): + return self._is_rtcloc diff --git a/OpenRTM_aist/Manager.py b/OpenRTM_aist/Manager.py index eef7e7d4..b2966960 100644 --- a/OpenRTM_aist/Manager.py +++ b/OpenRTM_aist/Manager.py @@ -3209,9 +3209,12 @@ def initPreConnection(self): if not ("interface_type" in configs.keys()): configs["interface_type"] = "corba_cdr" - tmp = port0_str.split(".") - tmp.pop() - comp0_name = OpenRTM_aist.flatten(tmp, ".") + pos_port0 = port0_str.rfind(".") + comp0_name = "" + if pos_port0 >= 0: + comp0_name = port0_str[0:pos_port0] + else: + comp0_name = port0_str port0_name = port0_str @@ -3234,7 +3237,7 @@ def initPreConnection(self): comp0_ref, port0_name) if CORBA.is_nil(port0_var): - self._rtcout.RTC_DEBUG("port %s found: " % port0_str) + self._rtcout.RTC_DEBUG("port %s not found: " % port0_str) continue if not ports: @@ -3251,9 +3254,13 @@ def initPreConnection(self): for port_str in ports: - tmp = port_str.split(".") - tmp.pop() - comp_name = OpenRTM_aist.flatten(tmp, ".") + pos_port = port_str.rfind(".") + comp_name = "" + if pos_port >= 0: + comp_name = port_str[0:pos_port] + else: + comp_name = port_str + port_name = port_str if comp_name.find("://") == -1: @@ -3275,7 +3282,7 @@ def initPreConnection(self): comp_ref, port_name) if CORBA.is_nil(port_var): - self._rtcout.RTC_DEBUG("port %s found: " % port_str) + self._rtcout.RTC_DEBUG("port %s not found: " % port_str) continue prop = OpenRTM_aist.Properties() diff --git a/OpenRTM_aist/NamingManager.py b/OpenRTM_aist/NamingManager.py index 0d695e78..f4c7809a 100644 --- a/OpenRTM_aist/NamingManager.py +++ b/OpenRTM_aist/NamingManager.py @@ -280,6 +280,7 @@ def getCorbaNaming(self): # @endif def getComponentByName(self, context, name, rtcs): + self._rtcout.RTC_TRACE("getComponentByName(name = %s)", name) length = 500 bl, bi = context.list(length) for i in bl: @@ -318,43 +319,51 @@ def getComponentByName(self, context, name, rtcs): # virtual RTCList string_to_component(string name) = 0; def string_to_component(self, name): + self._rtcout.RTC_TRACE("string_to_component(name = %s)", name) rtc_list = [] - tmp = name.split("://") - if len(tmp) > 1: - if tmp[0] == "rtcname": - #tag = tmp[0] - url = tmp[1] - r = url.split("/") - if len(r) > 1: - host = r[0] - rtc_name = url[len(host) + 1:] + rtcuri = OpenRTM_aist.CORBA_RTCUtil.RTCURIObject(name, True, False) - try: - cns = None - if host == "*": - cns = self._cosnaming - else: - orb = OpenRTM_aist.Manager.instance().getORB() - cns = OpenRTM_aist.CorbaNaming(orb, host) - names = rtc_name.split("/") - - if len(names) == 2 and names[0] == "*": - root_cxt = cns.getRootContext() - self.getComponentByName( - root_cxt, names[1], rtc_list) - return rtc_list - else: - rtc_name += ".rtc" - obj = cns.resolveStr(rtc_name) - if CORBA.is_nil(obj): - return [] - if obj._non_existent(): - return [] - rtc_list.append(obj) - return rtc_list - except BaseException: - return [] + if not rtcuri.isRTCNameURI(): + self._rtcout.RTC_WARN("syntax error: %s", name) + return rtc_list + else: + self._rtcout.RTC_INFO("URI: %s, Address: %s, Name: %s", + (name, rtcuri.getAddress(), + rtcuri.getRTCName())) + try: + cns = None + if rtcuri.getAddress() == "*": + cns = self._cosnaming + else: + orb = OpenRTM_aist.Manager.instance().getORB() + cns = OpenRTM_aist.CorbaNaming(orb, rtcuri.getAddress()) + + rtcname = rtcuri.getRTCName() + context = "" + compname = "" + + pos = rtcname.find("/") + if pos >= 0: + context = rtcname[0:pos] + compname = rtcname[pos + 1:] + + if context == "*": + root_cxt = cns.getRootContext() + self.getComponentByName( + root_cxt, compname, rtc_list) + return rtc_list + else: + rtcname += ".rtc" + obj = cns.resolveStr(rtcname) + if CORBA.is_nil(obj): + return rtc_list + if obj._non_existent(): + return rtc_list + rtc_list.append(obj) + return rtc_list + except BaseException: + return rtc_list return rtc_list @@ -501,33 +510,32 @@ def isAlive(self): # # virtual RTCList string_to_component(); def string_to_component(self, name): + self._rtcout.RTC_TRACE("string_to_component(name = %s)", name) rtc_list = [] - tmp = name.split("://") - - if len(tmp) > 1: - if tmp[0] == "rtcloc": - #tag = tmp[0] - url = tmp[1] - r = url.split("/") - if len(r) > 1: - host = r[0] - rtc_name = url[len(host) + 1:] - - mgr = self.getManager(host) - if not CORBA.is_nil(mgr): - rtc_list = mgr.get_components_by_name(rtc_name) - - slaves = mgr.get_slave_managers() - for slave in slaves: - try: - rtc_list.extend( - slave.get_components_by_name(rtc_name)) - except BaseException: - self._rtcout.RTC_DEBUG( - OpenRTM_aist.Logger.print_exception()) - mgr.remove_slave_manager(slave) - return rtc_list + rtcuri = OpenRTM_aist.CORBA_RTCUtil.RTCURIObject(name, False, True) + + if not rtcuri.isRTCLocURI(): + self._rtcout.RTC_WARN("syntax error: %s", name) + return rtc_list + else: + self._rtcout.RTC_INFO("URI: %s, Address: %s, Name: %s", + (name, rtcuri.getAddress(), + rtcuri.getRTCName())) + + mgr = self.getManager(rtcuri.getAddress()) + if not CORBA.is_nil(mgr): + rtc_list = mgr.get_components_by_name(rtcuri.getRTCName()) + slaves = mgr.get_slave_managers() + for slave in slaves: + try: + rtc_list.extend( + slave.get_components_by_name(rtcuri.getRTCName())) + except BaseException: + self._rtcout.RTC_DEBUG( + OpenRTM_aist.Logger.print_exception()) + mgr.remove_slave_manager(slave) + return rtc_list return rtc_list ## @@ -549,6 +557,7 @@ def string_to_component(self, name): # # virtual Manager_ptr getManager(string name); def getManager(self, name): + self._rtcout.RTC_TRACE("getManager(name = %s)", name) if name == "*": mgr_sev = self._mgr.getManagerServant() mgr = None diff --git a/OpenRTM_aist/ext/http/rtc.http.conf b/OpenRTM_aist/ext/http/rtc.http.conf index 38f71370..63fdb0dc 100644 --- a/OpenRTM_aist/ext/http/rtc.http.conf +++ b/OpenRTM_aist/ext/http/rtc.http.conf @@ -6,5 +6,5 @@ manager.modules.load_path: ./ manager.preload.modules: HTTPTransport.py corba.args:-ORBserverTransportRule "* http" -ORBclientTransportRule "* http" -ORBendPoint giop:http:http:///call -corba.nameservers: http://127.0.0.1:2809/call -corba.master_manager: giop:http:http://127.0.0.1:2810/call +corba.nameservers: http://localhost:2809/call +corba.master_manager: giop:http:http://localhost:2810/call diff --git a/OpenRTM_aist/ext/http/rtc.https.conf b/OpenRTM_aist/ext/http/rtc.https.conf index fe9f59f2..471cfa9b 100644 --- a/OpenRTM_aist/ext/http/rtc.https.conf +++ b/OpenRTM_aist/ext/http/rtc.https.conf @@ -10,5 +10,5 @@ corba.http.key_file:../ssl/test/server.pem corba.http.key_file_password:password corba.args:-ORBserverTransportRule "* http" -ORBclientTransportRule "* http" -ORBendPoint giop:http:https:///call -corba.nameservers: https://127.0.0.1:2809/call -corba.master_manager: giop:http:https://127.0.0.1:2810/call +corba.nameservers: https://localhost:2809/call +corba.master_manager: giop:http:https://localhost:2810/call diff --git a/OpenRTM_aist/ext/http/rtc.ws.conf b/OpenRTM_aist/ext/http/rtc.ws.conf index 93aac207..6c191ed1 100644 --- a/OpenRTM_aist/ext/http/rtc.ws.conf +++ b/OpenRTM_aist/ext/http/rtc.ws.conf @@ -6,5 +6,5 @@ manager.modules.load_path: ./ manager.preload.modules: HTTPTransport.py corba.args:-ORBserverTransportRule "* http" -ORBclientTransportRule "* http" -ORBendPoint giop:http:ws:///ws -corba.nameservers: ws://127.0.0.1:2809/ws -corba.master_manager: giop:http:ws://127.0.0.1:2810/ws +corba.nameservers: ws://localhost:2809/ws +corba.master_manager: giop:http:ws://localhost:2810/ws diff --git a/OpenRTM_aist/ext/http/rtc.wss.conf b/OpenRTM_aist/ext/http/rtc.wss.conf index af38d952..4059f311 100644 --- a/OpenRTM_aist/ext/http/rtc.wss.conf +++ b/OpenRTM_aist/ext/http/rtc.wss.conf @@ -10,5 +10,5 @@ corba.http.key_file:../ssl/test/server.pem corba.http.key_file_password:password corba.args:-ORBserverTransportRule "* http" -ORBclientTransportRule "* http" -ORBendPoint giop:http:wss:///ws -corba.nameservers: wss://127.0.0.1:2809/ws -corba.master_manager: giop:http:wss://127.0.0.1:2810/ws +corba.nameservers: wss://localhost:2809/ws +corba.master_manager: giop:http:wss://localhost:2810/ws diff --git a/OpenRTM_aist/ext/ssl/rtc.ssl.conf b/OpenRTM_aist/ext/ssl/rtc.ssl.conf index b0ea8ac8..404ec6d1 100644 --- a/OpenRTM_aist/ext/ssl/rtc.ssl.conf +++ b/OpenRTM_aist/ext/ssl/rtc.ssl.conf @@ -9,5 +9,5 @@ corba.ssl.certificate_authority_file:test/root.crt corba.ssl.key_file:test/server.pem corba.ssl.key_file_password:password corba.args:-ORBserverTransportRule "* ssl" -ORBclientTransportRule "* ssl" -ORBendPoint giop:ssl:: -corba.nameservers: corbaloc:ssliop:127.0.0.1:2809 -corba.master_manager: giop:ssl:127.0.0.1:2810 +corba.nameservers: corbaloc:ssliop:localhost:2809 +corba.master_manager: giop:ssl:localhost:2810 From 18cf2b5a377c354b10f9aa47d72bb3b9d0189335 Mon Sep 17 00:00:00 2001 From: Nobuhiko Miyamoto Date: Sun, 13 Feb 2022 11:13:51 +0900 Subject: [PATCH 6/8] [compat] fixed comment. --- OpenRTM_aist/CORBA_RTCUtil.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/OpenRTM_aist/CORBA_RTCUtil.py b/OpenRTM_aist/CORBA_RTCUtil.py index f2045756..9e62d1dc 100644 --- a/OpenRTM_aist/CORBA_RTCUtil.py +++ b/OpenRTM_aist/CORBA_RTCUtil.py @@ -1869,13 +1869,20 @@ def __init__(self, uri, isrtcname=False, isrtcloc=False): ## # @if jp # - # @brief デストラクタ + # @brief RTC名を取得する + # + # rtcname形式の場合はネームサーバーに登録したRTCのパスを取得できる。 + # context1.kind1/context2.kind2/..../RTC_name # + # rtcloc形式の場合はカテゴリ名/RTC名で取得できる。 + # + # @return RTC名 # # @else # - # @brief Destructor + # @brief # + # @return # # @endif def getRTCName(self): @@ -1884,14 +1891,10 @@ def getRTCName(self): ## # @if jp # - # @brief RTC名を取得する + # @brief 通信先のアドレスを取得する # - # rtcname形式の場合はネームサーバーに登録したRTCのパスを取得できる。 - # context1.kind1/context2.kind2/..../RTC_name # - # rtcloc形式の場合はカテゴリ名/RTC名で取得できる。 - # - # @return RTC名 + # @return 通信先のアドレス # # @else # From 5ff9cee9ea2699bbf8b661ee698c292245bb0a6a Mon Sep 17 00:00:00 2001 From: Nobuhiko Miyamoto Date: Fri, 18 Feb 2022 00:53:00 +0900 Subject: [PATCH 7/8] [compat] fixed bugs. --- OpenRTM_aist/CORBA_RTCUtil.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/OpenRTM_aist/CORBA_RTCUtil.py b/OpenRTM_aist/CORBA_RTCUtil.py index 9e62d1dc..03654344 100644 --- a/OpenRTM_aist/CORBA_RTCUtil.py +++ b/OpenRTM_aist/CORBA_RTCUtil.py @@ -1853,18 +1853,21 @@ def __init__(self, uri, isrtcname=False, isrtcloc=False): hostport = addrname[0:pos] self._rtcpath = addrname[pos+1:] else: - self._rtcpath = addrname - - if protocol == "http" or protocol == "https" or protocol == "ws" or protocol == "wss": - self._address = protocol - self._address += "://" - self._address += hostport + hostport = addrname + if hostport != "*": + if protocol == "http" or protocol == "https" or protocol == "ws" or protocol == "wss": + self._address = protocol + self._address += "://" + self._address += hostport + + else: + self._address = "corbaloc:" + self._address += protocol + self._address += ":" + self._address += hostport else: - self._address = "corbaloc:" - self._address += protocol - self._address += ":" - self._address += hostport + self._address = hostport ## # @if jp From 612006156839402471e22e2af4f291db4346bb69 Mon Sep 17 00:00:00 2001 From: Nobuhiko Miyamoto Date: Fri, 11 Mar 2022 09:45:00 +0900 Subject: [PATCH 8/8] [compat] Fixed to catch CORBA_RTCUtil exception. --- OpenRTM_aist/InPortBase.py | 12 ++++- OpenRTM_aist/InPortPullConnector.py | 5 +- OpenRTM_aist/InPortPushConnector.py | 2 +- OpenRTM_aist/Manager.py | 70 +++++++++++++++++++++------- OpenRTM_aist/OutPortBase.py | 12 ++++- OpenRTM_aist/OutPortPullConnector.py | 5 +- OpenRTM_aist/OutPortPushConnector.py | 9 ++-- 7 files changed, 84 insertions(+), 31 deletions(-) diff --git a/OpenRTM_aist/InPortBase.py b/OpenRTM_aist/InPortBase.py index c02534ac..8af374eb 100644 --- a/OpenRTM_aist/InPortBase.py +++ b/OpenRTM_aist/InPortBase.py @@ -1260,7 +1260,11 @@ def createProvider(self, cprof, prop): if provider is not None: self._rtcout.RTC_DEBUG("provider created") - provider.init(prop.getNode("provider")) + try: + provider.init(prop.getNode("provider")) + except BaseException: + self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception()) + return None if not provider.publishInterface(cprof.properties): self._rtcout.RTC_ERROR( @@ -1304,7 +1308,11 @@ def createConsumer(self, cprof, prop): if consumer is not None: self._rtcout.RTC_DEBUG("consumer created") - consumer.init(prop.getNode("consumer")) + try: + consumer.init(prop.getNode("consumer")) + except BaseException: + self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception()) + return None if not consumer.subscribeInterface(cprof.properties): self._rtcout.RTC_ERROR("interface subscription failed.") diff --git a/OpenRTM_aist/InPortPullConnector.py b/OpenRTM_aist/InPortPullConnector.py index d340ae26..0cb61b7b 100644 --- a/OpenRTM_aist/InPortPullConnector.py +++ b/OpenRTM_aist/InPortPullConnector.py @@ -133,7 +133,7 @@ def __init__(self, info, consumer, listeners, buffer=None): self._buffer = self.createBuffer(self._profile) if not self._buffer or not self._consumer: - raise + raise MemoryError("InPortPullConnector creation failed") self._buffer.init(info.properties.getNode("buffer")) self._consumer.init(info.properties) @@ -414,4 +414,5 @@ def unsubscribeInterface(self, prop): def setDataType(self, data): OpenRTM_aist.InPortConnector.setDataType(self, data) - self._serializer = OpenRTM_aist.SerializerFactories.instance().createSerializer(self._marshaling_type, data) \ No newline at end of file + self._serializer = OpenRTM_aist.SerializerFactories.instance( + ).createSerializer(self._marshaling_type, data) diff --git a/OpenRTM_aist/InPortPushConnector.py b/OpenRTM_aist/InPortPushConnector.py index 07088d48..31f81bea 100644 --- a/OpenRTM_aist/InPortPushConnector.py +++ b/OpenRTM_aist/InPortPushConnector.py @@ -131,7 +131,7 @@ def __init__(self, info, provider, listeners, buffer=None): self._buffer = self.createBuffer(info) if self._buffer is None or not self._provider: - raise + raise MemoryError("InPortPushConnector creation failed") self._buffer.init(info.properties.getNode("buffer")) self._provider.init(info.properties) diff --git a/OpenRTM_aist/Manager.py b/OpenRTM_aist/Manager.py index fda03af6..bd40e058 100644 --- a/OpenRTM_aist/Manager.py +++ b/OpenRTM_aist/Manager.py @@ -3122,9 +3122,13 @@ def connectDataPorts(self, port, target_ports): con_name += ":" con_name += p1.name prop = OpenRTM_aist.Properties() - if RTC.RTC_OK != OpenRTM_aist.CORBA_RTCUtil.connect( - con_name, prop, port, p): - self._rtcout.RTC_ERROR("Connection error in topic connection.") + try: + if RTC.RTC_OK != OpenRTM_aist.CORBA_RTCUtil.connect( + con_name, prop, port, p): + self._rtcout.RTC_ERROR( + "Connection error in topic connection.") + except BaseException: + self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception()) ## # @if jp @@ -3153,9 +3157,13 @@ def connectServicePorts(self, port, target_ports): con_name += ":" con_name += p1.name prop = OpenRTM_aist.Properties() - if RTC.RTC_OK != OpenRTM_aist.CORBA_RTCUtil.connect( - con_name, prop, port, p): - self._rtcout.RTC_ERROR("Connection error in topic connection.") + try: + if RTC.RTC_OK != OpenRTM_aist.CORBA_RTCUtil.connect( + con_name, prop, port, p): + self._rtcout.RTC_ERROR( + "Connection error in topic connection.") + except BaseException: + self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception()) ## # @if jp @@ -3233,8 +3241,13 @@ def initPreConnection(self): comp0_ref = rtcs[0] port0_name = port0_str.split("/")[-1] - port0_var = OpenRTM_aist.CORBA_RTCUtil.get_port_by_name( - comp0_ref, port0_name) + port0_var = None + try: + port0_var = OpenRTM_aist.CORBA_RTCUtil.get_port_by_name( + comp0_ref, port0_name) + except BaseException: + self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception()) + continue if CORBA.is_nil(port0_var): self._rtcout.RTC_DEBUG("port %s not found: " % port0_str) @@ -3248,9 +3261,14 @@ def initPreConnection(self): v = v.strip() prop.setProperty("dataport." + k, v) - if RTC.RTC_OK != OpenRTM_aist.CORBA_RTCUtil.connect( - c, prop, port0_var, RTC.PortService._nil): - self._rtcout.RTC_ERROR("Connection error: %s" % c) + try: + if RTC.RTC_OK != OpenRTM_aist.CORBA_RTCUtil.connect( + c, prop, port0_var, RTC.PortService._nil): + self._rtcout.RTC_ERROR("Connection error: %s" % c) + except BaseException: + self._rtcout.RTC_ERROR( + OpenRTM_aist.Logger.print_exception()) + continue for port_str in ports: @@ -3278,8 +3296,14 @@ def initPreConnection(self): comp_ref = rtcs[0] port_name = port_str.split("/")[-1] - port_var = OpenRTM_aist.CORBA_RTCUtil.get_port_by_name( - comp_ref, port_name) + port_var = None + try: + port_var = OpenRTM_aist.CORBA_RTCUtil.get_port_by_name( + comp_ref, port_name) + except BaseException: + self._rtcout.RTC_ERROR( + OpenRTM_aist.Logger.print_exception()) + continue if CORBA.is_nil(port_var): self._rtcout.RTC_DEBUG("port %s not found: " % port_str) @@ -3291,10 +3315,13 @@ def initPreConnection(self): k = k.strip() v = v.strip() prop.setProperty("dataport." + k, v) - - if RTC.RTC_OK != OpenRTM_aist.CORBA_RTCUtil.connect( - c, prop, port0_var, port_var): - self._rtcout.RTC_ERROR("Connection error: %s" % c) + try: + if RTC.RTC_OK != OpenRTM_aist.CORBA_RTCUtil.connect( + c, prop, port0_var, port_var): + self._rtcout.RTC_ERROR("Connection error: %s" % c) + except BaseException: + self._rtcout.RTC_ERROR( + OpenRTM_aist.Logger.print_exception()) ## # @if jp @@ -3330,7 +3357,14 @@ def initPreActivation(self): self._rtcout.RTC_ERROR("%s not found." % c) continue comp_ref = rtcs[0] - ret = OpenRTM_aist.CORBA_RTCUtil.activate(comp_ref) + ret = RTC.RTC_OK + try: + ret = OpenRTM_aist.CORBA_RTCUtil.activate(comp_ref) + except BaseException: + self._rtcout.RTC_ERROR( + OpenRTM_aist.Logger.print_exception()) + continue + if ret != RTC.RTC_OK: self._rtcout.RTC_ERROR("%s activation failed." % c) else: diff --git a/OpenRTM_aist/OutPortBase.py b/OpenRTM_aist/OutPortBase.py index c6ab706e..43504cd5 100644 --- a/OpenRTM_aist/OutPortBase.py +++ b/OpenRTM_aist/OutPortBase.py @@ -1269,7 +1269,11 @@ def createProvider(self, cprof, prop): if provider is not None: self._rtcout.RTC_DEBUG("provider created") - provider.init(prop.getNode("provider")) + try: + provider.init(prop.getNode("provider")) + except BaseException: + self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception()) + return None if not provider.publishInterface(cprof.properties): self._rtcout.RTC_ERROR( @@ -1311,7 +1315,11 @@ def createConsumer(self, cprof, prop): if consumer is not None: self._rtcout.RTC_DEBUG("consumer created") - consumer.init(prop.getNode("consumer")) + try: + consumer.init(prop.getNode("consumer")) + except BaseException: + self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception()) + return None if not consumer.subscribeInterface(cprof.properties): self._rtcout.RTC_ERROR("interface subscription failed.") diff --git a/OpenRTM_aist/OutPortPullConnector.py b/OpenRTM_aist/OutPortPullConnector.py index ce22588d..83b826a1 100644 --- a/OpenRTM_aist/OutPortPullConnector.py +++ b/OpenRTM_aist/OutPortPullConnector.py @@ -134,7 +134,7 @@ def __init__(self, info, provider, listeners, buffer=None): if not self._provider or not self._buffer: self._rtcout.RTC_ERROR( "Exeption: in OutPortPullConnector.__init__().") - raise + raise MemoryError("OutPortPullConnector creation failed") self._buffer.init(info.properties.getNode("buffer")) self._provider.init(info.properties) @@ -417,7 +417,8 @@ def setDirectMode(self): def setDataType(self, data): OpenRTM_aist.OutPortConnector.setDataType(self, data) - self._serializer = OpenRTM_aist.SerializerFactories.instance().createSerializer(self._marshaling_type, data) + self._serializer = OpenRTM_aist.SerializerFactories.instance( + ).createSerializer(self._marshaling_type, data) class WorkerThreadCtrl: def __init__(self): diff --git a/OpenRTM_aist/OutPortPushConnector.py b/OpenRTM_aist/OutPortPushConnector.py index 03666796..3b906a71 100644 --- a/OpenRTM_aist/OutPortPushConnector.py +++ b/OpenRTM_aist/OutPortPushConnector.py @@ -139,17 +139,17 @@ def __init__(self, info, consumer, listeners, buffer=None): self._buffer = self.createBuffer(info) if not self._publisher or not self._buffer or not self._consumer: - raise + raise MemoryError("OutPortPushConnector creation failed") if self._publisher.init(info.properties) != self.PORT_OK: - raise + raise MemoryError("OutPortPushConnector creation failed") if self._profile.properties.hasKey("serializer"): endian = self._profile.properties.getProperty( "serializer.cdr.endian") if not endian: self._rtcout.RTC_ERROR("write(): endian is not set.") - raise + raise MemoryError("OutPortPushConnector creation failed") # Maybe endian is ["little","big"] endian = OpenRTM_aist.split(endian, ",") @@ -517,4 +517,5 @@ def unsubscribeInterface(self, prop): def setDataType(self, data): OpenRTM_aist.OutPortConnector.setDataType(self, data) - self._serializer = OpenRTM_aist.SerializerFactories.instance().createSerializer(self._marshaling_type, data) + self._serializer = OpenRTM_aist.SerializerFactories.instance( + ).createSerializer(self._marshaling_type, data)