1 # Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG
2 # PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License.
8 # This library is distributed in the hope that it will be useful
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 from nameserver import *
22 from omniORB import CORBA
24 # Import the stubs for the Naming service
28 # -----------------------------------------------------------------------------
32 def __init__(self,args=None):
33 #set GIOP message size for bug 10560: impossible to get field values in TUI mode
34 sys.argv.extend(["-ORBgiopMaxMsgSize", "104857600"]) ## = 100 * 1024 * 1024
36 self.orb=CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
37 # Initialise the Naming Service
38 self.initNS(args or {})
40 # --------------------------------------------------------------------------
42 def initNS(self,args):
43 # Obtain a reference to the root naming context
44 obj = self.orb.resolve_initial_references("NameService")
46 self.rootContext = obj._narrow(CosNaming.NamingContext)
48 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
49 self.rootContext = None
50 print "Launch Naming Service++",
52 # On lance le Naming Server (doit etre dans le PATH)
53 NamingServer(args).run()
54 print "Searching Naming Service ",
60 obj = self.orb.resolve_initial_references("NameService")
61 self.rootContext = obj._narrow(CosNaming.NamingContext)
63 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
64 self.rootContext = None
69 if self.rootContext is None:
70 print "Failed to narrow the root naming context"
72 print " found in %s seconds " % ((ncount-1)*delta)
74 # --------------------------------------------------------------------------
76 def showNScontext(self,context,dec=''):
81 for s in b.binding_name :
82 print "%s%s.%s" %(dec,s.id,s.kind)
84 obj=context.resolve([s])
85 scontext = obj._narrow(CosNaming.NamingContext)
86 self.showNScontext(scontext,dec=dec+' ')
89 # --------------------------------------------------------------------------
92 """ Show the content of NS"""
93 self.showNScontext(self.rootContext)
95 # --------------------------------------------------------------------------
97 def Resolve(self, Path):
98 resolve_path=string.split(Path,'/')
99 if resolve_path[0] == '': del resolve_path[0]
100 dir_path=resolve_path[:-1]
103 context_name.append(CosNaming.NameComponent(e,"dir"))
104 context_name.append(CosNaming.NameComponent(resolve_path[-1],"object"))
107 obj = self.rootContext.resolve(context_name)
108 except CosNaming.NamingContext.NotFound, ex:
110 except CosNaming.NamingContext.InvalidName, ex:
112 except CosNaming.NamingContext.CannotProceed, ex:
114 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
118 # --------------------------------------------------------------------------
120 def waitNS(self,name,typobj=None,maxcount=60):
123 print "Searching %s in Naming Service " % name,
126 if count > maxcount : raise "Impossible de trouver %s" % name
127 obj=self.Resolve(name)
129 print " found in %s seconds " % ((count-1)*delta)
132 sys.stdout.write('+')
136 if typobj is None:return obj
138 nobj = obj._narrow(typobj)
140 print "%s exists but is not a %s" % (name,typobj)
143 if sys.platform != "win32":
144 def waitNSPID(self, theName, thePID, theTypObj = None):
148 print "Searching %s in Naming Service " % theName,
153 raise "Process %d for %s not found" % (thePID,theName)
155 anObj = self.Resolve(theName)
157 print " found in %s seconds " % ((aCount-1)*aDelta)
160 sys.stdout.write('+')
166 if theTypObj is None:
169 anObject = anObj._narrow(theTypObj)
171 print "%s exists but is not a %s" % (theName,theTypObj)
175 # --------------------------------------------------------------------------
177 def ResolveLogger(self, name):
179 context_name.append(CosNaming.NameComponent(name,""))
182 obj = self.rootContext.resolve(context_name)
183 except CosNaming.NamingContext.NotFound, ex:
185 except CosNaming.NamingContext.InvalidName, ex:
187 except CosNaming.NamingContext.CannotProceed, ex:
189 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
193 # --------------------------------------------------------------------------
195 def waitLogger(self,name,typobj=None,maxcount=40):
198 print "Searching %s in Naming Service " % name,
201 if count > maxcount : raise "Impossible de trouver %s" % name
202 obj=self.ResolveLogger(name)
204 print " found in %s seconds " % ((count-1)*delta)
207 sys.stdout.write('+')
211 if typobj is None:return obj
213 nobj = obj._narrow(typobj)
215 print "%s exists but is not a %s" % (name,typobj)