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.salome-platform.org/ or email : webmaster.salome@opencascade.com
26 # File : SALOME_ComponentPy.py
27 # Author : Paul RASCLE, EDF
36 from omniORB import CORBA, PortableServer
37 import Engines, Engines__POA
39 from Utils_Identity import *
40 from SALOME_NamingServicePy import *
41 from libNOTIFICATION import *
43 from SALOME_utilities import *
47 #=============================================================================
51 #define an implementation of the component interface
53 class SALOME_ComponentPy_i (Engines__POA.Component):
59 #-------------------------------------------------------------------------
61 def __init__ (self, orb, poa, contID, containerName,
62 instanceName, interfaceName, notif=0):
63 # Notif for notification services
65 MESSAGE( "SALOME_ComponentPy_i::__init__" + " " + str (containerName) + " " + str(instanceName) + " " + str(interfaceName) )
68 self._instanceName = instanceName
69 self._interfaceName = interfaceName
70 self._containerName = containerName
72 self._myConnexionToRegistry = 0
75 self._serviceName = ''
78 self._ThreadCpuUsed = 0
82 naming_service = SALOME_NamingServicePy_i(self._orb)
83 myMachine=getShortHostName()
84 Component_path = self._containerName + "/" + self._instanceName
85 MESSAGE( 'SALOME_ComponentPy_i Register' + str( Component_path ) )
86 naming_service.Register(self._this(), Component_path)
88 # Add componentinstance to registry
89 obj = naming_service.Resolve('/Registry')
91 MESSAGE( "Registry Reference is invalid" )
93 regist = obj._narrow(Registry.Components)
95 MESSAGE( "Registry Reference is invalid" )
97 ior = orb.object_to_string(contID)
100 lesInfos = Identity(self._instanceName)
101 infos = Registry.Infos(lesInfos._name,
107 int(lesInfos._tc_start),
113 res = regist.add(infos)
115 self._notifSupplier = NOTIFICATION_Supplier_Swig(instanceName, notif)
117 #-------------------------------------------------------------------------
119 def _get_instanceName(self):
120 MESSAGE( "SALOME_ComponentPy_i::_get_instanceName" )
121 return self._instanceName
123 #-------------------------------------------------------------------------
125 def _get_interfaceName(self):
126 MESSAGE( "SALOME_ComponentPy_i::_get_interfaceName" )
127 return self._interfaceName
129 #-------------------------------------------------------------------------
132 MESSAGE( "SALOME_ComponentPy_i::ping() pid " + str(os.getpid()) )
134 #-------------------------------------------------------------------------
136 def setProperties(self, dico):
137 self._fieldsDict = dico
139 #-------------------------------------------------------------------------
141 def getProperties(self):
142 return self._fieldsDict
144 #-------------------------------------------------------------------------
147 MESSAGE( "SALOME_ComponentPy_i::destroy" )
148 self._poa.deactivate_object(self)
149 CORBA.release(self._poa)
151 #-------------------------------------------------------------------------
153 def GetContainerRef(self):
154 MESSAGE( "SALOME_ComponentPy_i::GetContainerRef" )
155 corbaObj_ptr = self._poa.id_to_reference(self._contId)
156 return corbaObj_ptr._narrow(Engines.Container)
158 #-------------------------------------------------------------------------
160 def beginService(self , serviceName ):
161 MESSAGE( "Send BeginService notification for " + str(serviceName) + " for graph/node " + str(self._graphName) + " " + str(self._nodeName) )
162 MESSAGE( "Component instance : " + str ( self._instanceName ) )
163 self._serviceName = str(serviceName)
164 self._ThreadId = get_ident()
166 self._StartUsed = self.CpuUsed_impl()
167 self._ThreadCpuUsed = 0
169 MESSAGE( "SALOME_ComponentPy_i::beginService _StartUsed " + str( self._ThreadId ) + " " + str( self._StartUsed ) )
172 #-------------------------------------------------------------------------
174 def endService(self , serviceName ):
175 MESSAGE( "Send EndService notification for " + str( self._ThreadId ) + " " + str(serviceName) + " for graph/node " + str(self._graphName) + " " + str(self._nodeName) + " CpuUsed " + str( self.CpuUsed_impl() ) )
176 MESSAGE( "Component instance : " + str(self._instanceName) )
178 #-------------------------------------------------------------------------
180 def sendMessage(self , event_type , message ):
181 self._notifSupplier.Send(self.graphName(), self.nodeName(), event_type, message)
183 #-------------------------------------------------------------------------
185 def Names(self , GraphName , NodeName ):
186 MESSAGE( "SALOME_ComponentPy_i::Names" + str(GraphName) + str(NodeName) )
187 self._graphName = GraphName
188 self._nodeName = NodeName
190 #-------------------------------------------------------------------------
193 return self._graphName
195 #-------------------------------------------------------------------------
198 return self._nodeName
200 #-------------------------------------------------------------------------
202 def Killer(self, ThreadId, signum):
205 #if pthread_cancel(ThreadId): <- from C++
210 #if pthread_kill(ThreadId): <- from C++
216 #-------------------------------------------------------------------------
219 MESSAGE( "SALOME_ComponentPy_i::Kill_impl" )
221 if self._ThreadId > 0 & self._ThreadId != get_ident():
222 RetVal = Killer(self._ThreadId,0)
226 #-------------------------------------------------------------------------
229 MESSAGE( "SALOME_ComponentPy_i::Stop_impl" )
231 if self._ThreadId > 0 & self._ThreadId != get_ident():
232 RetVal = Killer(self._ThreadId,0)
236 #-------------------------------------------------------------------------
238 def Suspend_impl(self):
239 MESSAGE( "SALOME_ComponentPy_i::Suspend_impl" )
242 if self._ThreadId > 0 & self._ThreadId != get_ident():
246 RetVal = Killer(self._ThreadId, signal.SIGINT)
251 #-------------------------------------------------------------------------
253 def Resume_impl(self):
254 MESSAGE( "SALOME_ComponentPy_i::Resume_impl" )
257 if self._ThreadId > 0 & self._ThreadId != get_ident():
265 #-------------------------------------------------------------------------
267 def CpuUsed_impl(self):
268 if ( self._ThreadId | self._Executed ) :
269 if self._ThreadId == get_ident() :
271 self._ThreadCpuUsed = int(cpu) - self._StartUsed
272 MESSAGE( "SALOME_ComponentPy_i::CpuUsed_impl " + self._serviceName + " " + str( int(cpu) ) + " - " + str( self._StartUsed ) + " = " + str( self._ThreadCpuUsed ) )
273 return self._ThreadCpuUsed
274 MESSAGE( "SALOME_ComponentPy_i::CpuUsed_impl " + self._serviceName + " " + str( self._ThreadCpuUsed ) )
275 return self._ThreadCpuUsed
276 MESSAGE( "SALOME_ComponentPy_i::CpuUsed_impl self._StartUsed " + self._serviceName + " " + str(self._StartUsed) )
279 #-------------------------------------------------------------------------
281 def DumpPython(self, theStudy, isPublished):
282 aBuffer = "def RebuildData(theStudy): pass\n\0"
285 #-------------------------------------------------------------------------
287 def getStudyId(self):