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
41 from SALOME_NamingServicePy import *
42 from SALOME_ComponentPy import *
44 from SALOME_utilities import *
45 from Utils_Identity import getShortHostName
47 #=============================================================================
49 #define an implementation of the container interface
51 class SALOME_ContainerPy_i (Engines__POA.Container):
56 #-------------------------------------------------------------------------
58 def __init__(self, orb, poa, containerName):
59 MESSAGE( "SALOME_ContainerPy_i::__init__" )
62 self._containerName = containerName
64 myMachine=getShortHostName()
65 naming_service = SALOME_NamingServicePy_i(self._orb)
66 self._naming_service = naming_service
67 Container_path = "/Containers/" + myMachine + "/" + self._containerName
68 MESSAGE( str(Container_path) )
69 naming_service.Register(self._this(), Container_path)
71 #-------------------------------------------------------------------------
73 def start_impl(self, ContainerName):
74 MESSAGE( "SALOME_ContainerPy_i::start_impl " + str(ContainerName) )
75 myMachine=getShortHostName()
76 theContainer = "/Containers/" + myMachine + "/" + ContainerName
78 obj = self._naming_service.Resolve(theContainer)
81 MESSAGE( "SALOME_ContainerPy_i::start_impl " + str(ContainerName) + ".object not found in Naming Service" )
85 container = obj._narrow(Engines.Container)
87 MESSAGE( "SALOME_ContainerPy_i::start_impl " + str(containerName) + ".object exists but is not a Container" )
89 MESSAGE( "SALOME_ContainerPy_i::start_impl " + str(ContainerName) + ".object found without new launch" )
91 #shstr = os.getenv( "PWD" ) + "/"
92 #shstr += "runSession ./SALOME_ContainerPy.py "
93 shstr = os.getenv("KERNEL_ROOT_DIR") + "/bin/salome/SALOME_ContainerPy.py ";
94 #shstr = "runSession SALOME_ContainerPy.py "
95 shstr += ContainerName
97 # mpv: fix for SAL4731 - allways create new file to write log of server
101 fileName = "/tmp/"+ContainerName+"_%i.log"%num
102 if not os.path.exists(fileName):
112 #shstr += ContainerName
113 #shstr += ".log 2>&1 &"
115 MESSAGE( "SALOME_ContainerPy_i::start_impl " + "os.system(" + str(shstr) + ")" )
118 while container is None :
121 MESSAGE( str(count) + ". Waiting for " + str(theContainer) )
123 obj = self._naming_service.Resolve(theContainer)
129 container = obj._narrow(Engines.Container)
130 if container is None:
131 MESSAGE( str(containerName) + ".object exists but is not a Container" )
136 #-------------------------------------------------------------------------
138 def instance(self, nameToRegister, componentName):
139 MESSAGE( "SALOME_ContainerPy_i::instance " + str(nameToRegister) + ' ' + str(componentName) )
140 self._numInstance = self._numInstance +1
141 instanceName = nameToRegister + "_inst_" + `self._numInstance`
143 component=__import__(componentName)
144 factory=getattr(component,componentName)
145 comp_i=factory(self._orb, self._poa, self._this(), self._containerName,
146 instanceName, nameToRegister)
148 MESSAGE( "SALOME_ContainerPy_i::instance : component created")
149 comp_o = comp_i._this()
152 #-------------------------------------------------------------------------
154 def load_impl(self, nameToRegister, componentName):
155 MESSAGE( "SALOME_ContainerPy_i::load_impl " + str(nameToRegister) + ' ' + str(componentName) )
156 self._numInstance = self._numInstance +1
157 instanceName = nameToRegister + "_inst_" + `self._numInstance`
158 interfaceName = nameToRegister
159 the_command = "import " + nameToRegister + "\n"
160 the_command = the_command + "comp_i = " + nameToRegister + "." + nameToRegister
161 the_command = the_command + "(self._orb, self._poa, self._this(), self._containerName, instanceName, interfaceName)\n"
162 MESSAGE( "SALOME_ContainerPy_i::load_impl :" + str (the_command) )
164 comp_o = comp_i._this()
167 #-------------------------------------------------------------------------
169 def remove_impl(self, component):
170 MESSAGE( "SALOME_ContainerPy_i::remove_impl" )
173 #-------------------------------------------------------------------------
175 def finalize_removal(self):
176 MESSAGE( "SALOME_ContainerPy_i::finalize_removal" )
179 #-------------------------------------------------------------------------
182 MESSAGE( "SALOME_ContainerPy_i::ping" )
185 #-------------------------------------------------------------------------
188 MESSAGE( "SALOME_ContainerPy_i::_get_name" )
189 return self._containerName
191 #-------------------------------------------------------------------------
193 def _get_machineName(self):
194 MESSAGE( "SALOME_ContainerPy_i::_get_MachineName" )
195 self._machineName = "localhost"
196 return self._machineName
198 #-------------------------------------------------------------------------
201 self._orb.shutdown(0)
204 #=============================================================================
206 #initialise the ORB and find the root POA
207 orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
208 poa = orb.resolve_initial_references("RootPOA")
210 #create an instance of SALOME_ContainerPy_i and a Container reference
211 #containerName = "FactoryServerPy"
212 MESSAGE( str(sys.argv) )
213 containerName = sys.argv[1]
214 cpy_i = SALOME_ContainerPy_i(orb, poa, containerName)
215 cpy_o = cpy_i._this()
218 poaManager = poa._get_the_POAManager()
219 poaManager.activate()