Skip to content

Commit 7263626

Browse files
authored
Merge pull request #1255 from ishiguroJSK/multi_name_server
support any RTCmanager port num
2 parents 1810137 + b1b8ef3 commit 7263626

File tree

1 file changed

+53
-14
lines changed

1 file changed

+53
-14
lines changed

python/rtm.py

+53-14
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
rootnc = None
1919
nshost = None
2020
nsport = None
21+
mgrhost = None
22+
mgrport = None
2123

2224
##
2325
# \brief wrapper class of RT component
@@ -311,7 +313,7 @@ def unbindObject(name, kind):
311313
# \brief initialize ORB
312314
#
313315
def initCORBA():
314-
global rootnc, orb, nshost, nsport
316+
global rootnc, orb, nshost, nsport, mgrhost, mgrport
315317

316318
# from omniorb's document
317319
# When CORBA::ORB_init() is called, the value for each configuration
@@ -320,17 +322,55 @@ def initCORBA():
320322
# Environment variables
321323
# so init_CORBA will follow this order
322324
# first check command line argument
323-
try:
324-
n = sys.argv.index('-ORBInitRef')
325-
(nshost, nsport) = re.match(
326-
'NameService=corbaloc:iiop:(\w+):(\d+)/NameService', sys.argv[n + 1]).group(1, 2)
327-
except:
328-
if not nshost:
329-
nshost = socket.gethostname()
330-
if not nsport:
331-
nsport = 15005
332325

333-
print("configuration ORB with %s:%s"%(nshost, nsport))
326+
rtm_argv = [sys.argv[0]] # extract rtm related args only
327+
for i in range(len(sys.argv)):
328+
if sys.argv[i] == '-o':
329+
rtm_argv.extend(['-o', sys.argv[i+1]])
330+
331+
mc = OpenRTM_aist.ManagerConfig();
332+
mc.parseArgs(rtm_argv)
333+
334+
if nshost != None: # these values can be set via other script like "import rtm; rtm.nshost=XXX"
335+
print("\033[34m[rtm.py] nshost already set as " + str(nshost) + "\033[0m")
336+
else:
337+
try:
338+
nshost = mc._argprop.getProperty("corba.nameservers").split(":")[0]
339+
if not nshost:
340+
raise
341+
except:
342+
nshost = socket.gethostname() # default
343+
print("\033[34m[rtm.py] Failed to parse corba.nameservers, use " + str(nshost) + " as nshost \033[0m")
344+
345+
if nsport != None:
346+
print("\033[34m[rtm.py] nsport already set as " + str(nsport) + "\033[0m")
347+
else:
348+
try:
349+
nsport = int(mc._argprop.getProperty("corba.nameservers").split(":")[1])
350+
if not nsport:
351+
raise
352+
except:
353+
nsport = 15005 # default
354+
print("\033[34m[rtm.py] Failed to parse corba.nameservers, use " + str(nsport) + " as nsport \033[0m")
355+
356+
if mgrhost != None:
357+
print("\033[34m[rtm.py] mgrhost already set as " + str(mgrhost) + "\033[0m")
358+
else:
359+
mgrhost = nshost
360+
361+
if mgrport != None:
362+
print("\033[34m[rtm.py] mgrport already set as " + str(mgrport) + "\033[0m")
363+
else:
364+
try:
365+
mgrport = int(mc._argprop.getProperty("corba.master_manager").split(":")[1])
366+
if not mgrport:
367+
raise
368+
except:
369+
mgrport = 2810 # default
370+
print("\033[34m[rtm.py] Failed to parse corba.master_manager, use " + str(mgrport) + "\033[0m")
371+
372+
print("\033[34m[rtm.py] configuration ORB with %s:%s\033[0m"%(nshost, nsport))
373+
print("\033[34m[rtm.py] configuration RTCManager with %s:%s\033[0m"%(mgrhost, mgrport))
334374
os.environ['ORBInitRef'] = 'NameService=corbaloc:iiop:%s:%s/NameService' % \
335375
(nshost, nsport)
336376

@@ -420,10 +460,9 @@ def getManagerFromNS(hostname, mgr=None):
420460
return mgr
421461

422462
def getManagerDirectly(hostname, mgr=None):
423-
global orb
424-
mgrport = int(nsport) + 1 # RTC manager port is set as name server port + 1 traditionally
463+
global orb, mgrport
425464
corbaloc = "corbaloc:iiop:" + hostname + ":" + str(mgrport) + "/manager"
426-
print("\033[34m[rtm.py] tring to findRTCManager on port" + str(mgrport) + "\033[0m")
465+
print("\033[34m[rtm.py] trying to findRTCManager on port" + str(mgrport) + "\033[0m")
427466
try:
428467
obj = orb.string_to_object(corbaloc)
429468
mgr = RTCmanager(obj._narrow(RTM.Manager))

0 commit comments

Comments
 (0)