RtmNSHelper.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 #
4 # @file RtmNSHelper.py
5 # @brief rtc-link name service access helper class
6 # @date $Date: 2005-05-12 09:06:19 $
7 # @author Noriaki Ando <n-ando@aist.go.jp>
8 #
9 # Copyright (C) 2004-2005
10 # Task-intelligence Research Group,
11 # Intelligent Systems Research Institute,
12 # National Institute of
13 # Advanced Industrial Science and Technology (AIST), Japan
14 # All rights reserved.
15 #
16 # $Id$
17 #
18 
19 import sys
20 #sys.path.append("/usr/local/lib/python2.3/site-packages")
21 import omniORB.CORBA as CORBA
22 import CosNaming
23 import RTM
24 from RtmDialog import *
25 
26 
28  def __init__(self):
29  self.orb = None
30 
31  def __del__(self):
32  if self.orb != None:
33  try:
34  self.orb.destroy()
35  except:
36  except_mess('CORBA Name Server: Destroy Error!! <' + name_server + '>')
37 
38  def Connect(self, name_server):
39  try:
40  if self.orb != None:
41  self.orb.destroy()
42  arg = ["-ORBInitRef", "NameService=corbaname::","-ORBclientCallTimeOutPeriod","2000"]
43  arg[1] = arg[1] + name_server
44  self.orb = CORBA.ORB_init(arg)
45  obj = self.orb.resolve_initial_references("NameService")
46  self.root_cxt = obj._narrow(CosNaming.NamingContext)
47  except:
48  self.root_cxt = None
49 # print 'CORBA Name Server: Connect Error!! <',name_server,'>'
50 
51  def GetNSDict(self):
52  ns_dict = None
53  if self.root_cxt != None:
54  ns_dict = self.__GetNameTreeRecursive__(self.root_cxt)
55  return ns_dict
56 
57  def __GetNameTreeRecursive__(self, cxt):
58  ns_dict = {}
59  try:
60  cur_cxt = cxt.list(100)
61  except:
62  except_mess("cxt.list method error!:")
63  return
64 
65  for bc in cur_cxt[0]:
66  if bc != None:
67  try:
68  cur_obj = cxt.resolve(bc.binding_name)
69  dict_key = bc.binding_name[0].id \
70  + "|" \
71  + bc.binding_name[0].kind
72  if bc.binding_type == CosNaming.ncontext:
73  ns_dict[dict_key] = (
74  {
75  "objref":cur_obj,
76  "id":bc.binding_name[0].id,
77  "kind":bc.binding_name[0].kind,
78  "bname":bc.binding_name
79  },
80  self.__GetNameTreeRecursive__(cur_obj))
81  elif bc.binding_type == CosNaming.nobject:
82  ns_dict[dict_key] = (cur_obj, None)
83  ns_dict[dict_key] = (
84  {
85  "objref":cur_obj,
86  "id":bc.binding_name[0].id,
87  "kind":bc.binding_name[0].kind,
88  "bname":bc.binding_name
89  },None)
90  except:
91  except_mess("context method error!:")
92  ns_dict = {}
93  break
94 
95  return ns_dict
96 
97  def DeleteToContext(self,cxt,bname):
98  if cxt != None:
99  try:
100  cxt.unbind(bname)
101  except:
102  except_mess('contex not found:')
103 
104 
105 if __name__ == '__main__':
106  import sys
107  nsh = RtmNSHelper()
108  if len(sys.argv) == 1:
109  print sys.argv[0] + " [CosNameService Host Name]"
110  sys.exit(1)
111 
112  nsh.Connect(sys.argv[1])
113  print nsh.GetNSDict()
114 
def DeleteToContext(self, cxt, bname)
Definition: RtmNSHelper.py:97
def __GetNameTreeRecursive__(self, cxt)
Definition: RtmNSHelper.py:57
def Connect(self, name_server)
Definition: RtmNSHelper.py:38
def except_mess(mess)
Definition: RtmDialog.py:100


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Feb 28 2022 23:00:44