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 new launch" )
88 #shstr = os.getenv( "PWD" ) + "/"
89 #shstr += "runSession ./SALOME_ContainerPy.py "
90 shstr = os.getenv("KERNEL_ROOT_DIR") + "/bin/salome/SALOME_ContainerPy.py ";
91 #shstr = "runSession SALOME_ContainerPy.py "
92 shstr += ContainerName
94 # mpv: fix for SAL4731 - allways create new file to write log of server
98 fileName = "/tmp/"+ContainerName+"_%i.log"%num
99 if not os.path.exists(fileName):
109 #shstr += ContainerName
110 #shstr += ".log 2>&1 &"
112 MESSAGE( "SALOME_ContainerPy_i::start_impl " + "os.system(" + str(shstr) + ")" )
115 while container is None :
118 MESSAGE( str(count) + ". Waiting for " + str(theContainer) )
120 obj = self._naming_service.Resolve(theContainer)
126 container = obj._narrow(Engines.Container)
127 if container is None:
128 MESSAGE( str(containerName) + ".object exists but is not a Container" )
133 #-------------------------------------------------------------------------
135 def load_impl(self, nameToRegister, componentName):
136 MESSAGE( "SALOME_ContainerPy_i::load_impl " + str(nameToRegister) + ' ' + str(componentName) )
137 self._numInstance = self._numInstance +1
138 instanceName = nameToRegister + "_inst_" + `self._numInstance`
139 interfaceName = nameToRegister
140 the_command = "import " + nameToRegister + "\n"
141 the_command = the_command + "comp_i = " + nameToRegister + "." + nameToRegister
142 the_command = the_command + "(self._orb, self._poa, self._this(), self._containerName, instanceName, interfaceName)\n"
143 MESSAGE( "SALOME_ContainerPy_i::load_impl :" + str (the_command) )
145 comp_o = comp_i._this()
148 #-------------------------------------------------------------------------
150 def remove_impl(self, component):
151 MESSAGE( "SALOME_ContainerPy_i::remove_impl" )
153 #-------------------------------------------------------------------------
155 def finalize_removal(self):
156 MESSAGE( "SALOME_ContainerPy_i::finalize_removal" )
158 #-------------------------------------------------------------------------
161 MESSAGE( "SALOME_ContainerPy_i::ping" )
163 #-------------------------------------------------------------------------
166 MESSAGE( "SALOME_ContainerPy_i::_get_name" )
168 #-------------------------------------------------------------------------
170 def _get_machineName(self):
171 MESSAGE( "SALOME_ContainerPy_i::_get_MachineName" )
172 self._machineName = "localhost"
173 return self._machineName
175 #=============================================================================
177 #initialise the ORB and find the root POA
178 orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
179 poa = orb.resolve_initial_references("RootPOA")
181 #create an instance of SALOME_ContainerPy_i and a Container reference
182 #containerName = "FactoryServerPy"
183 MESSAGE( str(sys.argv) )
184 containerName = sys.argv[1]
185 cpy_i = SALOME_ContainerPy_i(orb, poa, containerName)
186 cpy_o = cpy_i._this()
189 poaManager = poa._get_the_POAManager()
190 poaManager.activate()