3 #=============================================================================
4 # File : SALOME_ContainerPy.py
5 # Created : lun sep 3 17:54:13 CEST 2001
6 # Author : Paul RASCLE, EDF
10 #=============================================================================
15 from omniORB import CORBA, PortableServer
16 # import SALOMEDS before other SALOME modules
17 # (if not, incomplete import done by SALOME module: no load of SALOMEDS_attributes)
19 import Engines, Engines__POA
20 from SALOME_NamingServicePy import *
21 from SALOME_ComponentPy import *
23 from SALOME_utilities import *
25 #=============================================================================
27 #define an implementation of the container interface
29 class SALOME_ContainerPy_i (Engines__POA.Container):
34 #-------------------------------------------------------------------------
36 def __init__(self, orb, poa, containerName):
37 MESSAGE( "SALOME_ContainerPy_i::__init__" )
40 self._containerName = containerName
42 myMachine=string.split(os.getenv( "HOSTNAME" ),'.')
43 naming_service = SALOME_NamingServicePy_i(self._orb)
44 self._naming_service = naming_service
45 Container_path = "/Containers/" + myMachine[0] + "/" + self._containerName
46 MESSAGE( str(Container_path) )
47 naming_service.Register(self._this(), Container_path)
49 #-------------------------------------------------------------------------
51 def start_impl(self, ContainerName):
52 MESSAGE( "SALOME_ContainerPy_i::start_impl " + str(ContainerName) )
53 myMachine=string.split(os.getenv( "HOSTNAME" ),'.')
54 theContainer = "/Containers/" + myMachine[0] + "/" + ContainerName
56 obj = self._naming_service.Resolve(theContainer)
59 MESSAGE( "SALOME_ContainerPy_i::start_impl " + str(ContainerName) + ".object not found in Naming Service" )
63 container = obj._narrow(Engines.Container)
65 MESSAGE( "SALOME_ContainerPy_i::start_impl " + str(containerName) + ".object exists but is not a Container" )
67 MESSAGE( "SALOME_ContainerPy_i::start_impl " + str(ContainerName) + ".object found without runSession" )
69 shstr = os.getenv( "PWD" ) + "/"
70 shstr += "runSession ./SALOME_ContainerPy.py "
71 shstr += ContainerName
73 shstr += ContainerName
74 shstr += ".log 2>&1 &"
75 MESSAGE( "SALOME_ContainerPy_i::start_impl " + "os.system(" + str(shstr) + ")" )
78 while container is None :
81 MESSAGE( str(count) + ". Waiting for " + str(theContainer) )
83 obj = self._naming_service.Resolve(theContainer)
89 container = obj._narrow(Engines.Container)
91 MESSAGE( str(containerName) + ".object exists but is not a Container" )
96 #-------------------------------------------------------------------------
98 def load_impl(self, nameToRegister, componentName):
99 MESSAGE( "SALOME_ContainerPy_i::load_impl " + str(nameToRegister) + ' ' + str(componentName) )
100 self._numInstance = self._numInstance +1
101 instanceName = nameToRegister + "_inst_" + `self._numInstance`
102 interfaceName = nameToRegister
103 the_command = "import " + nameToRegister + "\n"
104 the_command = the_command + "comp_i = " + nameToRegister + "." + nameToRegister
105 the_command = the_command + "(self._orb, self._poa, self._this(), self._containerName, instanceName, interfaceName)\n"
106 MESSAGE( "SALOME_ContainerPy_i::load_impl :" + str (the_command) )
108 comp_o = comp_i._this()
111 #-------------------------------------------------------------------------
113 def remove_impl(self, component):
114 MESSAGE( "SALOME_ContainerPy_i::remove_impl" )
116 #-------------------------------------------------------------------------
118 def finalize_removal(self):
119 MESSAGE( "SALOME_ContainerPy_i::finalize_removal" )
121 #-------------------------------------------------------------------------
124 MESSAGE( "SALOME_ContainerPy_i::ping" )
126 #-------------------------------------------------------------------------
129 MESSAGE( "SALOME_ContainerPy_i::_get_name" )
131 #-------------------------------------------------------------------------
133 def _get_machineName(self):
134 MESSAGE( "SALOME_ContainerPy_i::_get_MachineName" )
135 self._machineName = "localhost"
136 return self._machineName
138 #=============================================================================
140 #initialise the ORB and find the root POA
141 orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
142 poa = orb.resolve_initial_references("RootPOA")
144 #create an instance of SALOME_ContainerPy_i and a Container reference
145 #containerName = "FactoryServerPy"
146 MESSAGE( str(sys.argv) )
147 containerName = sys.argv[1]
148 cpy_i = SALOME_ContainerPy_i(orb, poa, containerName)
149 cpy_o = cpy_i._this()
152 poaManager = poa._get_the_POAManager()
153 poaManager.activate()