Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

マネージャ起動時のポート接続、アクティベート失敗時に異常終了しないようにする #274

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
Draft
410 changes: 410 additions & 0 deletions OpenRTM_aist/CORBA_RTCUtil.py

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions OpenRTM_aist/CorbaNaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import omniORB.CORBA as CORBA
import CosNaming
import OpenRTM_aist.CORBA_RTCUtil
import string
import sys
import traceback
Expand Down Expand Up @@ -85,7 +86,9 @@ 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()

obj = orb.string_to_object(self._nameServer)
self._rootContext = obj._narrow(CosNaming.NamingContext)
if CORBA.is_nil(self._rootContext):
Expand Down Expand Up @@ -125,7 +128,8 @@ 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):
Expand Down
12 changes: 10 additions & 2 deletions OpenRTM_aist/InPortBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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.")
Expand Down
5 changes: 3 additions & 2 deletions OpenRTM_aist/InPortPullConnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
self._serializer = OpenRTM_aist.SerializerFactories.instance(
).createSerializer(self._marshaling_type, data)
2 changes: 1 addition & 1 deletion OpenRTM_aist/InPortPushConnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
157 changes: 124 additions & 33 deletions OpenRTM_aist/Manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1789,6 +1789,44 @@ 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 "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




##
# @if jp
# @brief エンドポイントの生成
Expand Down Expand Up @@ -1839,11 +1877,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)

Expand Down Expand Up @@ -1882,12 +1923,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

Expand Down Expand Up @@ -3083,9 +3133,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
Expand Down Expand Up @@ -3114,9 +3168,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
Expand Down Expand Up @@ -3170,9 +3228,12 @@ def initPreConnection(self):
if not ("interface_type" in configs.keys()):
configs["interface_type"] = "corba_cdr"

tmp = port0_str.split(".")
tmp.pop()
comp0_name = ".".join([x.strip() for x in 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

Expand All @@ -3191,11 +3252,16 @@ 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 found: " % port0_str)
self._rtcout.RTC_DEBUG("port %s not found: " % port0_str)
continue

if not ports:
Expand All @@ -3206,15 +3272,24 @@ 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:

tmp = port_str.split(".")
tmp.pop()
comp_name = ".".join([x.strip() for x in 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:
Expand All @@ -3232,11 +3307,17 @@ 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 found: " % port_str)
self._rtcout.RTC_DEBUG("port %s not found: " % port_str)
continue

prop = OpenRTM_aist.Properties()
Expand All @@ -3245,10 +3326,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
Expand Down Expand Up @@ -3284,7 +3368,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:
Expand Down
5 changes: 2 additions & 3 deletions OpenRTM_aist/ManagerServant.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1172,9 +1173,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)

Expand Down
Loading
Loading