3 # SALOME Container : implementation of container and engine for Kernel
5 # Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
26 # File : SALOME_ContainerPy.py
27 # Author : Paul RASCLE, EDF
34 from omniORB import CORBA, PortableServer
35 # import SALOMEDS before other SALOME modules
36 # (if not, incomplete import done by SALOME module: no load of SALOMEDS_attributes)
38 import Engines, Engines__POA
39 from SALOME_NamingServicePy import *
40 from SALOME_ComponentPy import *
42 from SALOME_utilities import *
44 #=============================================================================
46 #define an implementation of the container interface
48 class SALOME_ContainerPy_i (Engines__POA.Container):
53 #-------------------------------------------------------------------------
55 def __init__(self, orb, poa, containerName):
56 MESSAGE( "SALOME_ContainerPy_i::__init__" )
59 self._containerName = containerName
61 myMachine=string.split(os.getenv( "HOSTNAME" ),'.')
62 naming_service = SALOME_NamingServicePy_i(self._orb)
63 self._naming_service = naming_service
64 Container_path = "/Containers/" + myMachine[0] + "/" + self._containerName
65 MESSAGE( str(Container_path) )
66 naming_service.Register(self._this(), Container_path)
68 #-------------------------------------------------------------------------
70 def start_impl(self, ContainerName):
71 MESSAGE( "SALOME_ContainerPy_i::start_impl " + str(ContainerName) )
72 myMachine=string.split(os.getenv( "HOSTNAME" ),'.')
73 theContainer = "/Containers/" + myMachine[0] + "/" + ContainerName
75 obj = self._naming_service.Resolve(theContainer)
78 MESSAGE( "SALOME_ContainerPy_i::start_impl " + str(ContainerName) + ".object not found in Naming Service" )
82 container = obj._narrow(Engines.Container)
84 MESSAGE( "SALOME_ContainerPy_i::start_impl " + str(containerName) + ".object exists but is not a Container" )
86 MESSAGE( "SALOME_ContainerPy_i::start_impl " + str(ContainerName) + ".object found without runSession" )
88 #shstr = os.getenv( "PWD" ) + "/"
89 #shstr += "runSession ./SALOME_ContainerPy.py "
90 shstr = "runSession SALOME_ContainerPy.py "
91 shstr += ContainerName
93 # mpv: fix for SAL4731 - allways create new file to write log of server
97 fileName = "/tmp/"+ContainerName+"_%i.log"%num
98 if not os.path.exists(fileName):
108 #shstr += ContainerName
109 #shstr += ".log 2>&1 &"
111 MESSAGE( "SALOME_ContainerPy_i::start_impl " + "os.system(" + str(shstr) + ")" )
114 while container is None :
117 MESSAGE( str(count) + ". Waiting for " + str(theContainer) )
119 obj = self._naming_service.Resolve(theContainer)
125 container = obj._narrow(Engines.Container)
126 if container is None:
127 MESSAGE( str(containerName) + ".object exists but is not a Container" )
132 #-------------------------------------------------------------------------
134 def load_impl(self, nameToRegister, componentName):
135 MESSAGE( "SALOME_ContainerPy_i::load_impl " + str(nameToRegister) + ' ' + str(componentName) )
136 self._numInstance = self._numInstance +1
137 instanceName = nameToRegister + "_inst_" + `self._numInstance`
138 interfaceName = nameToRegister
139 the_command = "import " + nameToRegister + "\n"
140 the_command = the_command + "comp_i = " + nameToRegister + "." + nameToRegister
141 the_command = the_command + "(self._orb, self._poa, self._this(), self._containerName, instanceName, interfaceName)\n"
142 MESSAGE( "SALOME_ContainerPy_i::load_impl :" + str (the_command) )
144 comp_o = comp_i._this()
147 #-------------------------------------------------------------------------
149 def remove_impl(self, component):
150 MESSAGE( "SALOME_ContainerPy_i::remove_impl" )
152 #-------------------------------------------------------------------------
154 def finalize_removal(self):
155 MESSAGE( "SALOME_ContainerPy_i::finalize_removal" )
157 #-------------------------------------------------------------------------
160 MESSAGE( "SALOME_ContainerPy_i::ping" )
162 #-------------------------------------------------------------------------
165 MESSAGE( "SALOME_ContainerPy_i::_get_name" )
167 #-------------------------------------------------------------------------
169 def _get_machineName(self):
170 MESSAGE( "SALOME_ContainerPy_i::_get_MachineName" )
171 self._machineName = "localhost"
172 return self._machineName
174 #=============================================================================
176 #initialise the ORB and find the root POA
177 orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
178 poa = orb.resolve_initial_references("RootPOA")
180 #create an instance of SALOME_ContainerPy_i and a Container reference
181 #containerName = "FactoryServerPy"
182 MESSAGE( str(sys.argv) )
183 containerName = sys.argv[1]
184 cpy_i = SALOME_ContainerPy_i(orb, poa, containerName)
185 cpy_o = cpy_i._this()
188 poaManager = poa._get_the_POAManager()
189 poaManager.activate()