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 omniORB import CORBA
23 # Import the stubs for the Naming service
26 # -----------------------------------------------------------------------------
29 XTERM="/usr/bin/X11/xterm -iconic -e "
33 commande=self.XTERM+self.CMD
35 ier=os.system(commande)
36 if ier:print "Commande failed"
38 # -----------------------------------------------------------------------------
40 class NamingServer(Server):
42 USER=os.getenv('USER')
45 os.system("mkdir -m 777 -p /tmp/logs")
46 LOGDIR="/tmp/logs/" + USER
47 os.system("mkdir -m 777 -p " + LOGDIR)
48 CMD="runNS.sh > " + LOGDIR + "/salomeNS.log 2>&1"
50 # -----------------------------------------------------------------------------
55 #set GIOP message size for bug 10560: impossible to get field values in TUI mode
56 sys.argv.extend(["-ORBgiopMaxMsgSize", "104857600"]) ## = 100 * 1024 * 1024
58 self.orb=CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
59 # Initialise the Naming Service
62 # --------------------------------------------------------------------------
65 # Obtain a reference to the root naming context
66 obj = self.orb.resolve_initial_references("NameService")
68 self.rootContext = obj._narrow(CosNaming.NamingContext)
70 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
71 self.rootContext = None
72 print "Lancement du Naming Service",
74 # On lance le Naming Server (doit etre dans le PATH)
76 print "Searching Naming Service ",
82 obj = self.orb.resolve_initial_references("NameService")
83 self.rootContext = obj._narrow(CosNaming.NamingContext)
85 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
86 self.rootContext = None
91 if self.rootContext is None:
92 print "Failed to narrow the root naming context"
94 print " found in %s seconds " % ((ncount-1)*delta)
96 # --------------------------------------------------------------------------
98 def showNScontext(self,context,dec=''):
103 for s in b.binding_name :
104 print "%s%s.%s" %(dec,s.id,s.kind)
106 obj=context.resolve([s])
107 scontext = obj._narrow(CosNaming.NamingContext)
108 self.showNScontext(scontext,dec=dec+' ')
111 # --------------------------------------------------------------------------
114 """ Show the content of NS"""
115 self.showNScontext(self.rootContext)
117 # --------------------------------------------------------------------------
119 def Resolve(self, Path):
120 resolve_path=string.split(Path,'/')
121 if resolve_path[0] == '': del resolve_path[0]
122 dir_path=resolve_path[:-1]
125 context_name.append(CosNaming.NameComponent(e,"dir"))
126 context_name.append(CosNaming.NameComponent(resolve_path[-1],"object"))
129 obj = self.rootContext.resolve(context_name)
130 except CosNaming.NamingContext.NotFound, ex:
132 except CosNaming.NamingContext.InvalidName, ex:
134 except CosNaming.NamingContext.CannotProceed, ex:
136 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
140 # --------------------------------------------------------------------------
142 def waitNS(self,name,typobj=None,maxcount=60):
145 print "Searching %s in Naming Service " % name,
148 if count > maxcount : raise "Impossible de trouver %s" % name
149 obj=self.Resolve(name)
151 print " found in %s seconds " % ((count-1)*delta)
154 sys.stdout.write('+')
158 if typobj is None:return obj
160 nobj = obj._narrow(typobj)
162 print "%s exists but is not a %s" % (name,typobj)
164 def waitNSPID(self, theName, thePID, theTypObj = None):
168 print "Searching %s in Naming Service " % theName,
171 aPid, aStatus = os.waitpid(thePID,os.WNOHANG)
172 except Exception, exc:
173 raise "Impossible de trouver %s" % theName
175 anObj = self.Resolve(theName)
177 print " found in %s seconds " % ((aCount-1)*aDelta)
180 sys.stdout.write('+')
186 if theTypObj is None:
189 anObject = anObj._narrow(theTypObj)
191 print "%s exists but is not a %s" % (theName,theTypObj)
195 # --------------------------------------------------------------------------
197 def ResolveLogger(self, name):
199 context_name.append(CosNaming.NameComponent(name,""))
202 obj = self.rootContext.resolve(context_name)
203 except CosNaming.NamingContext.NotFound, ex:
205 except CosNaming.NamingContext.InvalidName, ex:
207 except CosNaming.NamingContext.CannotProceed, ex:
209 except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
213 # --------------------------------------------------------------------------
215 def waitLogger(self,name,typobj=None,maxcount=40):
218 print "Searching %s in Naming Service " % name,
221 if count > maxcount : raise "Impossible de trouver %s" % name
222 obj=self.ResolveLogger(name)
224 print " found in %s seconds " % ((count-1)*delta)
227 sys.stdout.write('+')
231 if typobj is None:return obj
233 nobj = obj._narrow(typobj)
235 print "%s exists but is not a %s" % (name,typobj)