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 print "Obtain a reference to the root naming context"
42 # --------------------------------------------------------------------------
44 def initNS(self,args):
45 print "Obtain a reference to the root naming context"
46 # Obtain a reference to the root naming context
47 obj = self.orb.resolve_initial_references("NameService")
49 self.rootContext = obj._narrow(CosNaming.NamingContext)
51 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
52 self.rootContext = None
53 print "Lancement du Naming Service",
55 # On lance le Naming Server (doit etre dans le PATH)
56 NamingServer(args).run()
57 print "Searching Naming Service ",
63 obj = self.orb.resolve_initial_references("NameService")
64 self.rootContext = obj._narrow(CosNaming.NamingContext)
66 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
67 self.rootContext = None
72 if self.rootContext is None:
73 print "Failed to narrow the root naming context"
75 print " found in %s seconds " % ((ncount-1)*delta)
77 # --------------------------------------------------------------------------
79 def showNScontext(self,context,dec=''):
84 for s in b.binding_name :
85 print "%s%s.%s" %(dec,s.id,s.kind)
87 obj=context.resolve([s])
88 scontext = obj._narrow(CosNaming.NamingContext)
89 self.showNScontext(scontext,dec=dec+' ')
92 # --------------------------------------------------------------------------
95 """ Show the content of NS"""
96 self.showNScontext(self.rootContext)
98 # --------------------------------------------------------------------------
100 def Resolve(self, Path):
101 resolve_path=string.split(Path,'/')
102 if resolve_path[0] == '': del resolve_path[0]
103 dir_path=resolve_path[:-1]
106 context_name.append(CosNaming.NameComponent(e,"dir"))
107 context_name.append(CosNaming.NameComponent(resolve_path[-1],"object"))
110 obj = self.rootContext.resolve(context_name)
111 except CosNaming.NamingContext.NotFound, ex:
113 except CosNaming.NamingContext.InvalidName, ex:
115 except CosNaming.NamingContext.CannotProceed, ex:
117 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
121 # --------------------------------------------------------------------------
123 def waitNS(self,name,typobj=None,maxcount=60):
126 print "Searching %s in Naming Service " % name,
129 if count > maxcount : raise "Impossible de trouver %s" % name
130 obj=self.Resolve(name)
132 print " found in %s seconds " % ((count-1)*delta)
135 sys.stdout.write('+')
139 if typobj is None:return obj
141 nobj = obj._narrow(typobj)
143 print "%s exists but is not a %s" % (name,typobj)
146 if sys.platform != "win32":
147 def waitNSPID(self, theName, thePID, theTypObj = None):
151 print "Searching %s in Naming Service " % theName,
154 aPid, aStatus = os.waitpid(thePID,os.WNOHANG)
155 except Exception, exc:
156 raise "Impossible de trouver %s" % theName
158 anObj = self.Resolve(theName)
160 print " found in %s seconds " % ((aCount-1)*aDelta)
163 sys.stdout.write('+')
169 if theTypObj is None:
172 anObject = anObj._narrow(theTypObj)
174 print "%s exists but is not a %s" % (theName,theTypObj)
178 # --------------------------------------------------------------------------
180 def ResolveLogger(self, name):
182 context_name.append(CosNaming.NameComponent(name,""))
185 obj = self.rootContext.resolve(context_name)
186 except CosNaming.NamingContext.NotFound, ex:
188 except CosNaming.NamingContext.InvalidName, ex:
190 except CosNaming.NamingContext.CannotProceed, ex:
192 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
196 # --------------------------------------------------------------------------
198 def waitLogger(self,name,typobj=None,maxcount=40):
201 print "Searching %s in Naming Service " % name,
204 if count > maxcount : raise "Impossible de trouver %s" % name
205 obj=self.ResolveLogger(name)
207 print " found in %s seconds " % ((count-1)*delta)
210 sys.stdout.write('+')
214 if typobj is None:return obj
216 nobj = obj._narrow(typobj)
218 print "%s exists but is not a %s" % (name,typobj)