2 # -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
5 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
6 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
8 # This library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2.1 of the License.
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # Lesser General Public License for more details.
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this library; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
25 # \brief Module that provides a client for %SALOME
31 from nameserver import *
32 from omniORB import CORBA
33 from launchConfigureParser import verbose
35 # Import the stubs for the Naming service
39 # -----------------------------------------------------------------------------
42 """Client for SALOME"""
44 def __init__(self,args=None):
45 #set GIOP message size for bug 10560: impossible to get field values in TUI mode
46 sys.argv.extend(["-ORBgiopMaxMsgSize", "104857600"]) ## = 100 * 1024 * 1024
48 self.orb=CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
49 # Initialise the Naming Service
50 self.initNS(args or {})
52 # --------------------------------------------------------------------------
54 def initNS(self,args):
55 # Obtain a reference to the root naming context
56 obj = self.orb.resolve_initial_references("NameService")
58 self.rootContext = obj._narrow(CosNaming.NamingContext)
60 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
61 self.rootContext = None
62 if verbose(): print "Launch Naming Service++",
64 # On lance le Naming Server (doit etre dans le PATH)
65 NamingServer(args).run()
66 print "Searching Naming Service ",
72 obj = self.orb.resolve_initial_references("NameService")
73 self.rootContext = obj._narrow(CosNaming.NamingContext)
75 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
76 self.rootContext = None
81 if self.rootContext is None:
82 print "Failed to narrow the root naming context"
84 print " found in %s seconds " % ((ncount-1)*delta)
86 # --------------------------------------------------------------------------
88 def showNScontext(self,context,dec=''):
93 for s in b.binding_name :
94 print "%s%s.%s" %(dec,s.id,s.kind)
96 obj=context.resolve([s])
97 scontext = obj._narrow(CosNaming.NamingContext)
98 self.showNScontext(scontext,dec=dec+' ')
101 # --------------------------------------------------------------------------
104 """ Show the content of SALOME naming service """
105 self.showNScontext(self.rootContext)
107 # --------------------------------------------------------------------------
109 def Resolve(self, Path):
110 resolve_path=string.split(Path,'/')
111 if resolve_path[0] == '': del resolve_path[0]
112 dir_path=resolve_path[:-1]
115 context_name.append(CosNaming.NameComponent(e,"dir"))
116 context_name.append(CosNaming.NameComponent(resolve_path[-1],"object"))
119 obj = self.rootContext.resolve(context_name)
120 except CosNaming.NamingContext.NotFound, ex:
122 except CosNaming.NamingContext.InvalidName, ex:
124 except CosNaming.NamingContext.CannotProceed, ex:
126 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
130 # --------------------------------------------------------------------------
132 def waitNS(self,name,typobj=None,maxcount=240):
135 print "Searching %s in Naming Service " % name,
138 if count > maxcount : raise RuntimeError, "Impossible de trouver %s" % name
139 obj=self.Resolve(name)
141 print " found in %s seconds " % ((count-1)*delta)
144 sys.stdout.write('+')
148 if typobj is None:return obj
150 nobj = obj._narrow(typobj)
152 print "%s exists but is not a %s" % (name,typobj)
155 if sys.platform != "win32":
156 def waitNSPID(self, theName, thePID, theTypObj = None):
160 print "Searching %s in Naming Service " % theName,
165 raise RuntimeError, "Process %d for %s not found" % (thePID,theName)
167 anObj = self.Resolve(theName)
169 print " found in %s seconds " % ((aCount-1)*aDelta)
172 sys.stdout.write('+')
178 if theTypObj is None:
181 anObject = anObj._narrow(theTypObj)
183 print "%s exists but is not a %s" % (theName,theTypObj)
187 # --------------------------------------------------------------------------
189 def ResolveLogger(self, name):
191 context_name.append(CosNaming.NameComponent(name,""))
194 obj = self.rootContext.resolve(context_name)
195 except CosNaming.NamingContext.NotFound, ex:
197 except CosNaming.NamingContext.InvalidName, ex:
199 except CosNaming.NamingContext.CannotProceed, ex:
201 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
205 # --------------------------------------------------------------------------
207 def waitLogger(self,name,typobj=None,maxcount=40):
210 print "Searching %s in Naming Service " % name,
213 if count > maxcount : raise RuntimeError, "Impossible de trouver %s" % name
214 obj=self.ResolveLogger(name)
216 print " found in %s seconds " % ((count-1)*delta)
219 sys.stdout.write('+')
223 if typobj is None:return obj
225 nobj = obj._narrow(typobj)
227 print "%s exists but is not a %s" % (name,typobj)