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_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 #-------------------------------------------------------------------------
125 MESSAGE( "SALOME_ComponentPy_i::ping() pid " + str(os.getpid()) )
127 #-------------------------------------------------------------------------
129 def setProperties(self, dico):
130 self._fieldsDict = dico
132 #-------------------------------------------------------------------------
134 def getProperties(self):
135 return self._fieldsDict
137 #-------------------------------------------------------------------------
140 MESSAGE( "SALOME_ComponentPy_i::destroy" )
141 self._poa.deactivate_object(self)
142 CORBA.release(self._poa)
144 #-------------------------------------------------------------------------
146 def GetContainerRef(self):
147 MESSAGE( "SALOME_ComponentPy_i::GetContainerRef" )
148 corbaObj_ptr = self._poa.id_to_reference(self._contId)
149 return corbaObj_ptr._narrow(Engines.Container)
151 #-------------------------------------------------------------------------
153 def beginService(self , serviceName ):
154 MESSAGE( "Send BeginService notification for " + str(serviceName) + " for graph/node " + str(self._graphName) + " " + str(self._nodeName) )
155 MESSAGE( "Component instance : " + str ( self._instanceName ) )
156 self._serviceName = str(serviceName)
157 self._ThreadId = get_ident()
159 self._StartUsed = self.CpuUsed_impl()
160 self._ThreadCpuUsed = 0
162 MESSAGE( "SALOME_ComponentPy_i::beginService _StartUsed " + str( self._ThreadId ) + " " + str( self._StartUsed ) )
165 #-------------------------------------------------------------------------
167 def endService(self , serviceName ):
168 MESSAGE( "Send EndService notification for " + str( self._ThreadId ) + " " + str(serviceName) + " for graph/node " + str(self._graphName) + " " + str(self._nodeName) + " CpuUsed " + str( self.CpuUsed_impl() ) )
169 MESSAGE( "Component instance : " + str(self._instanceName) )
171 #-------------------------------------------------------------------------
173 def sendMessage(self , event_type , message ):
174 self._notifSupplier.Send(self.graphName(), self.nodeName(), event_type, message)
176 #-------------------------------------------------------------------------
178 def Names(self , GraphName , NodeName ):
179 MESSAGE( "SALOME_ComponentPy_i::Names" + str(GraphName) + str(NodeName) )
180 self._graphName = GraphName
181 self._nodeName = NodeName
183 #-------------------------------------------------------------------------
186 return self._graphName
188 #-------------------------------------------------------------------------
191 return self._nodeName
193 #-------------------------------------------------------------------------
195 def Killer(self, ThreadId, signum):
198 #if pthread_cancel(ThreadId): <- from C++
203 #if pthread_kill(ThreadId): <- from C++
209 #-------------------------------------------------------------------------
212 MESSAGE( "SALOME_ComponentPy_i::Kill_impl" )
214 if self._ThreadId > 0 & self._ThreadId != get_ident():
215 RetVal = Killer(self._ThreadId,0)
219 #-------------------------------------------------------------------------
222 MESSAGE( "SALOME_ComponentPy_i::Stop_impl" )
224 if self._ThreadId > 0 & self._ThreadId != get_ident():
225 RetVal = Killer(self._ThreadId,0)
229 #-------------------------------------------------------------------------
231 def Suspend_impl(self):
232 MESSAGE( "SALOME_ComponentPy_i::Suspend_impl" )
235 if self._ThreadId > 0 & self._ThreadId != get_ident():
239 RetVal = Killer(self._ThreadId, signal.SIGINT)
244 #-------------------------------------------------------------------------
246 def Resume_impl(self):
247 MESSAGE( "SALOME_ComponentPy_i::Resume_impl" )
250 if self._ThreadId > 0 & self._ThreadId != get_ident():
258 #-------------------------------------------------------------------------
260 def CpuUsed_impl(self):
261 if ( self._ThreadId | self._Executed ) :
262 if self._ThreadId == get_ident() :
264 self._ThreadCpuUsed = int(cpu) - self._StartUsed
265 MESSAGE( "SALOME_ComponentPy_i::CpuUsed_impl " + self._serviceName + " " + str( int(cpu) ) + " - " + str( self._StartUsed ) + " = " + str( self._ThreadCpuUsed ) )
266 return self._ThreadCpuUsed
267 MESSAGE( "SALOME_ComponentPy_i::CpuUsed_impl " + self._serviceName + " " + str( self._ThreadCpuUsed ) )
268 return self._ThreadCpuUsed
269 MESSAGE( "SALOME_ComponentPy_i::CpuUsed_impl self._StartUsed " + self._serviceName + " " + str(self._StartUsed) )
272 #-------------------------------------------------------------------------
274 def DumpPython(self, theStudy, isPublished):
275 aBuffer = "def RebuildData(theStudy): pass\n\0"
278 #-------------------------------------------------------------------------
280 def getStudyId(self):