Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[modules/kernel.git] / src / Container / SALOME_ContainerPy.py
1 #! /usr/bin/env python
2
3 #=============================================================================
4 # File      : SALOME_ContainerPy.py
5 # Created   : lun sep  3 17:54:13 CEST 2001
6 # Author    : Paul RASCLE, EDF
7 # Project   : SALOME
8 # Copyright : EDF 2001
9 # $Header$
10 #=============================================================================
11
12 import os
13 import sys
14 import string
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)
18 import SALOMEDS 
19 import Engines, Engines__POA
20 from SALOME_NamingServicePy import *
21 from SALOME_ComponentPy import *
22
23 from SALOME_utilities import *
24
25 #=============================================================================
26
27 #define an implementation of the container interface
28
29 class SALOME_ContainerPy_i (Engines__POA.Container):
30     _orb = None
31     _poa = None
32     _numInstance = 0
33
34     #-------------------------------------------------------------------------
35
36     def __init__(self, orb, poa, containerName):
37         MESSAGE( "SALOME_ContainerPy_i::__init__" )
38         self._orb = orb
39         self._poa = poa
40         self._containerName = containerName
41
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)
48             
49     #-------------------------------------------------------------------------
50
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
55         try:
56             obj = self._naming_service.Resolve(theContainer)
57         except :
58             obj = None
59             MESSAGE(  "SALOME_ContainerPy_i::start_impl " + str(ContainerName) + ".object not found in Naming Service" )
60         if obj is None:
61             container = None
62         else:
63             container = obj._narrow(Engines.Container)
64             if container is None:
65                 MESSAGE( "SALOME_ContainerPy_i::start_impl " + str(containerName) + ".object exists but is not a Container" )
66             else :
67                 MESSAGE( "SALOME_ContainerPy_i::start_impl " + str(ContainerName) + ".object found without runSession" )
68             return container
69         shstr = os.getenv( "PWD" ) + "/"
70         shstr += "runSession ./SALOME_ContainerPy.py "
71         shstr += ContainerName
72         shstr += " > /tmp/"
73         shstr += ContainerName
74         shstr += ".log 2>&1 &"
75         MESSAGE(  "SALOME_ContainerPy_i::start_impl " + "os.system(" + str(shstr) + ")" )
76         os.system( shstr )
77         count = 21
78         while container is None :
79             time.sleep(1)
80             count = count - 1
81             MESSAGE(  str(count) + ". Waiting for " + str(theContainer) )
82             try :
83                 obj = self._naming_service.Resolve(theContainer)
84             except :
85                 obj = None
86             if obj is None:
87                 container = None
88             else:
89                 container = obj._narrow(Engines.Container)
90                 if container is None:
91                     MESSAGE(  str(containerName) + ".object exists but is not a Container" )
92                 return container
93             if count == 0 :
94                 return container
95
96     #-------------------------------------------------------------------------
97
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) )
107         exec the_command
108         comp_o = comp_i._this()
109         return comp_o
110     
111     #-------------------------------------------------------------------------
112
113     def remove_impl(self, component):
114         MESSAGE( "SALOME_ContainerPy_i::remove_impl" )
115
116     #-------------------------------------------------------------------------
117
118     def finalize_removal(self):
119         MESSAGE( "SALOME_ContainerPy_i::finalize_removal" )
120
121     #-------------------------------------------------------------------------
122
123     def ping(self):
124         MESSAGE( "SALOME_ContainerPy_i::ping" )
125
126     #-------------------------------------------------------------------------
127
128     def _get_name(self):
129         MESSAGE( "SALOME_ContainerPy_i::_get_name" )
130
131     #-------------------------------------------------------------------------
132
133     def _get_machineName(self):
134         MESSAGE( "SALOME_ContainerPy_i::_get_MachineName" )
135         self._machineName = "localhost"
136         return self._machineName
137
138 #=============================================================================
139
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")
143
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()
150
151 #activate the POA
152 poaManager = poa._get_the_POAManager()
153 poaManager.activate()
154
155 #Block for ever
156 orb.run()
157
158
159         
160             
161
162