2 # Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
4 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 # SALOME Container : implementation of container and engine for Kernel
24 # File : SALOME_ComponentPy.py
25 # Author : Paul RASCLE, EDF
29 ## @package SALOME_ComponentPy
30 # \brief python implementation of component interface for Kernel
39 from omniORB import CORBA, PortableServer
40 import Engines, Engines__POA
42 from Utils_Identity import *
43 from SALOME_NamingServicePy import *
44 from libNOTIFICATION import *
46 from SALOME_utilities import *
50 #=============================================================================
54 ## define an implementation of the component interface Engines::Component
57 class SALOME_ComponentPy_i (Engines__POA.Component):
63 #-------------------------------------------------------------------------
65 def __init__ (self, orb, poa, contID, containerName,
66 instanceName, interfaceName, notif=0):
67 # Notif for notification services
69 MESSAGE( "SALOME_ComponentPy_i::__init__" + " " + str (containerName) + " " + str(instanceName) + " " + str(interfaceName) )
72 self._instanceName = instanceName
73 self._interfaceName = interfaceName
74 self._containerName = containerName
76 self._myConnexionToRegistry = 0
79 self._serviceName = ''
82 self._ThreadCpuUsed = 0
86 naming_service = SALOME_NamingServicePy_i(self._orb)
87 myMachine=getShortHostName()
88 Component_path = self._containerName + "/" + self._instanceName
89 MESSAGE( 'SALOME_ComponentPy_i Register' + str( Component_path ) )
90 id_o = poa.activate_object(self)
91 compo_o = poa.id_to_reference(id_o)
92 naming_service.Register(compo_o, Component_path)
94 # Add componentinstance to registry
95 obj = naming_service.Resolve('/Registry')
97 MESSAGE( "Registry Reference is invalid" )
99 regist = obj._narrow(Registry.Components)
101 MESSAGE( "Registry Reference is invalid" )
103 ior = orb.object_to_string(contID)
106 lesInfos = Identity(self._instanceName)
107 infos = Registry.Infos(lesInfos._name,
113 int(lesInfos._tc_start),
119 res = regist.add(infos)
121 self._notifSupplier = NOTIFICATION_Supplier_Swig(instanceName, notif)
123 #-------------------------------------------------------------------------
125 def _get_instanceName(self):
126 MESSAGE( "SALOME_ComponentPy_i::_get_instanceName" )
127 return self._instanceName
129 #-------------------------------------------------------------------------
131 def _get_interfaceName(self):
132 MESSAGE( "SALOME_ComponentPy_i::_get_interfaceName" )
133 return self._interfaceName
135 #-------------------------------------------------------------------------
138 MESSAGE( "SALOME_ComponentPy_i::ping() pid " + str(os.getpid()) )
140 #-------------------------------------------------------------------------
142 def setProperties(self, dico):
143 self._fieldsDict = dico
145 #-------------------------------------------------------------------------
147 def getProperties(self):
148 return self._fieldsDict
150 #-------------------------------------------------------------------------
153 MESSAGE( "SALOME_ComponentPy_i::destroy" )
154 #id = self._poa.servant_to_id(self)
155 #self._poa.deactivate_object(id)
158 #-------------------------------------------------------------------------
160 def GetContainerRef(self):
161 MESSAGE( "SALOME_ComponentPy_i::GetContainerRef" )
162 #corbaObj_ptr = self._poa.id_to_reference(self._contId)
163 #return corbaObj_ptr._narrow(Engines.Container)
164 return self._contId._narrow(Engines.Container)
166 #-------------------------------------------------------------------------
168 def beginService(self , serviceName ):
169 MESSAGE( "Send BeginService notification for " + str(serviceName) + " for graph/node " + str(self._graphName) + " " + str(self._nodeName) )
170 MESSAGE( "Component instance : " + str ( self._instanceName ) )
171 self._serviceName = str(serviceName)
172 self._ThreadId = get_ident()
174 self._StartUsed = self.CpuUsed_impl()
175 self._ThreadCpuUsed = 0
177 MESSAGE( "SALOME_ComponentPy_i::beginService _StartUsed " + str( self._ThreadId ) + " " + str( self._StartUsed ) )
180 #-------------------------------------------------------------------------
182 def endService(self , serviceName ):
183 MESSAGE( "Send EndService notification for " + str( self._ThreadId ) + " " + str(serviceName) + " for graph/node " + str(self._graphName) + " " + str(self._nodeName) + " CpuUsed " + str( self.CpuUsed_impl() ) )
184 MESSAGE( "Component instance : " + str(self._instanceName) )
186 #-------------------------------------------------------------------------
188 def sendMessage(self , event_type , message ):
189 self._notifSupplier.Send(self.graphName(), self.nodeName(), event_type, message)
191 #-------------------------------------------------------------------------
193 def Names(self , GraphName , NodeName ):
194 MESSAGE( "SALOME_ComponentPy_i::Names" + str(GraphName) + str(NodeName) )
195 self._graphName = GraphName
196 self._nodeName = NodeName
198 #-------------------------------------------------------------------------
201 return self._graphName
203 #-------------------------------------------------------------------------
206 return self._nodeName
208 #-------------------------------------------------------------------------
210 def Killer(self, ThreadId, signum):
213 #if pthread_cancel(ThreadId): <- from C++
218 #if pthread_kill(ThreadId): <- from C++
224 #-------------------------------------------------------------------------
227 MESSAGE( "SALOME_ComponentPy_i::Kill_impl" )
229 if self._ThreadId > 0 & self._ThreadId != get_ident():
230 RetVal = Killer(self._ThreadId,0)
234 #-------------------------------------------------------------------------
237 MESSAGE( "SALOME_ComponentPy_i::Stop_impl" )
239 if self._ThreadId > 0 & self._ThreadId != get_ident():
240 RetVal = Killer(self._ThreadId,0)
244 #-------------------------------------------------------------------------
246 def Suspend_impl(self):
247 MESSAGE( "SALOME_ComponentPy_i::Suspend_impl" )
250 if self._ThreadId > 0 & self._ThreadId != get_ident():
254 RetVal = Killer(self._ThreadId, signal.SIGINT)
259 #-------------------------------------------------------------------------
261 def Resume_impl(self):
262 MESSAGE( "SALOME_ComponentPy_i::Resume_impl" )
265 if self._ThreadId > 0 & self._ThreadId != get_ident():
273 #-------------------------------------------------------------------------
275 def CpuUsed_impl(self):
276 if ( self._ThreadId | self._Executed ) :
277 if self._ThreadId == get_ident() :
279 self._ThreadCpuUsed = int(cpu) - self._StartUsed
280 MESSAGE( "SALOME_ComponentPy_i::CpuUsed_impl " + self._serviceName + " " + str( int(cpu) ) + " - " + str( self._StartUsed ) + " = " + str( self._ThreadCpuUsed ) )
281 return self._ThreadCpuUsed
282 MESSAGE( "SALOME_ComponentPy_i::CpuUsed_impl " + self._serviceName + " " + str( self._ThreadCpuUsed ) )
283 return self._ThreadCpuUsed
284 MESSAGE( "SALOME_ComponentPy_i::CpuUsed_impl self._StartUsed " + self._serviceName + " " + str(self._StartUsed) )
287 #-------------------------------------------------------------------------
289 def DumpPython(self, theStudy, isPublished):
290 aBuffer = "def RebuildData(theStudy): pass\n\0"
293 #-------------------------------------------------------------------------
295 def getStudyId(self):
298 #-------------------------------------------------------------------------
300 def hasObjectInfo(self):
303 #-------------------------------------------------------------------------
305 def getObjectInfo(self, studyId, entry):