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
77 self._ThreadCpuUsed = 0
81 naming_service = SALOME_NamingServicePy_i(self._orb)
82 myMachine=getShortHostName()
83 Component_path = self._containerName + "/" + self._instanceName
84 MESSAGE( 'SALOME_ComponentPy_i Register' + str( Component_path ) )
85 naming_service.Register(self._this(), Component_path)
87 # Add componentinstance to registry
88 obj = naming_service.Resolve('/Registry')
90 MESSAGE( "Registry Reference is invalid" )
92 regist = obj._narrow(Registry.Components)
94 MESSAGE( "Registry Reference is invalid" )
96 ior = orb.object_to_string(contID)
99 lesInfos = Identity(self._instanceName)
100 infos = Registry.Infos(lesInfos._name,
106 int(lesInfos._tc_start),
112 res = regist.add(infos)
114 self._notifSupplier = NOTIFICATION_Supplier_Swig(instanceName, notif)
116 #-------------------------------------------------------------------------
118 def _get_instanceName(self):
119 MESSAGE( "SALOME_ComponentPy_i::_get_instanceName" )
120 return self._instanceName
122 #-------------------------------------------------------------------------
124 def _get_interfaceName(self):
125 MESSAGE( "SALOME_ComponentPy_i::_get_interfaceName" )
126 return self._interfaceName
128 #-------------------------------------------------------------------------
131 MESSAGE( "SALOME_ComponentPy_i::ping() pid " + str(os.getpid()) )
133 #-------------------------------------------------------------------------
135 def setProperties(self, dico):
136 self._fieldsDict = dico
138 #-------------------------------------------------------------------------
140 def getProperties(self):
141 return self._fieldsDict
143 #-------------------------------------------------------------------------
146 MESSAGE( "SALOME_ComponentPy_i::destroy" )
147 self._poa.deactivate_object(self)
148 CORBA.release(self._poa)
150 #-------------------------------------------------------------------------
152 def GetContainerRef(self):
153 MESSAGE( "SALOME_ComponentPy_i::GetContainerRef" )
154 corbaObj_ptr = self._poa.id_to_reference(self._contId)
155 return corbaObj_ptr._narrow(Engines.Container)
157 #-------------------------------------------------------------------------
159 def beginService(self , serviceName ):
160 MESSAGE( "Send BeginService notification for " + str(serviceName) + " for graph/node " + str(self._graphName) + " " + str(self._nodeName) )
161 MESSAGE( "Component instance : " + str ( self._instanceName ) )
162 self._serviceName = str(serviceName)
163 self._ThreadId = get_ident()
165 self._StartUsed = self.CpuUsed_impl()
166 self._ThreadCpuUsed = 0
168 MESSAGE( "SALOME_ComponentPy_i::beginService _StartUsed " + str( self._ThreadId ) + " " + str( self._StartUsed ) )
171 #-------------------------------------------------------------------------
173 def endService(self , serviceName ):
174 MESSAGE( "Send EndService notification for " + str( self._ThreadId ) + " " + str(serviceName) + " for graph/node " + str(self._graphName) + " " + str(self._nodeName) + " CpuUsed " + str( self.CpuUsed_impl() ) )
175 MESSAGE( "Component instance : " + str(self._instanceName) )
177 #-------------------------------------------------------------------------
179 def sendMessage(self , event_type , message ):
180 self._notifSupplier.Send(self.graphName(), self.nodeName(), event_type, message)
182 #-------------------------------------------------------------------------
184 def Names(self , GraphName , NodeName ):
185 MESSAGE( "SALOME_ComponentPy_i::Names" + str(GraphName) + str(NodeName) )
186 self._graphName = GraphName
187 self._nodeName = NodeName
189 #-------------------------------------------------------------------------
192 return self._graphName
194 #-------------------------------------------------------------------------
197 return self._nodeName
199 #-------------------------------------------------------------------------
201 def Killer(self, ThreadId, signum):
204 #if pthread_cancel(ThreadId): <- from C++
209 #if pthread_kill(ThreadId): <- from C++
215 #-------------------------------------------------------------------------
218 MESSAGE( "SALOME_ComponentPy_i::Kill_impl" )
220 if self._ThreadId > 0 & self._ThreadId != get_ident():
221 RetVal = Killer(self._ThreadId,0)
225 #-------------------------------------------------------------------------
228 MESSAGE( "SALOME_ComponentPy_i::Stop_impl" )
230 if self._ThreadId > 0 & self._ThreadId != get_ident():
231 RetVal = Killer(self._ThreadId,0)
235 #-------------------------------------------------------------------------
237 def Suspend_impl(self):
238 MESSAGE( "SALOME_ComponentPy_i::Suspend_impl" )
241 if self._ThreadId > 0 & self._ThreadId != get_ident():
245 RetVal = Killer(self._ThreadId, signal.SIGINT)
250 #-------------------------------------------------------------------------
252 def Resume_impl(self):
253 MESSAGE( "SALOME_ComponentPy_i::Resume_impl" )
256 if self._ThreadId > 0 & self._ThreadId != get_ident():
264 #-------------------------------------------------------------------------
266 def CpuUsed_impl(self):
267 if ( self._ThreadId | self._Executed ) :
268 if self._ThreadId == get_ident() :
270 self._ThreadCpuUsed = int(cpu) - self._StartUsed
271 MESSAGE( "SALOME_ComponentPy_i::CpuUsed_impl " + self._serviceName + " " + str( int(cpu) ) + " - " + str( self._StartUsed ) + " = " + str( self._ThreadCpuUsed ) )
272 return self._ThreadCpuUsed
273 MESSAGE( "SALOME_ComponentPy_i::CpuUsed_impl " + self._serviceName + " " + str( self._ThreadCpuUsed ) )
274 return self._ThreadCpuUsed
275 MESSAGE( "SALOME_ComponentPy_i::CpuUsed_impl self._StartUsed " + self._serviceName + " " + str(self._StartUsed) )
278 #-------------------------------------------------------------------------
280 def DumpPython(self, theStudy, isPublished):
281 aBuffer = "def RebuildData(theStudy): pass\n\0"
284 #-------------------------------------------------------------------------
286 def getStudyId(self):