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
35 from omniORB import CORBA, PortableServer
36 import Engines, Engines__POA
38 from Utils_Identity import *
39 from SALOME_NamingServicePy import *
40 from libNOTIFICATION import *
42 from SALOME_utilities import *
46 #=============================================================================
48 #define an implementation of the component interface
50 class SALOME_ComponentPy_i (Engines__POA.Component):
55 #-------------------------------------------------------------------------
57 def __init__ (self, orb, poa, contID, containerName,
58 instanceName, interfaceName, notif):
59 # Notif for notification services
61 MESSAGE( "SALOME_ComponentPy_i::__init__" + " " + str (containerName) + " " + str(instanceName) + " " + str(interfaceName) )
64 self._instanceName = instanceName
65 self._interfaceName = interfaceName
66 self._containerName = containerName
68 self._myConnexionToRegistry = 0
73 self._ThreadCpuUsed = 0
76 naming_service = SALOME_NamingServicePy_i(self._orb)
77 myMachine=getShortHostName()
78 Component_path = "/Containers/" + myMachine + "/" + self._containerName + "/" + self._interfaceName
79 MESSAGE( 'SALOME_ComponentPy_i Register' + str( Component_path ) )
80 naming_service.Register(self._this(), Component_path)
82 # Add componentinstance to registry
83 obj = naming_service.Resolve('/Registry')
85 MESSAGE( "Registry Reference is invalid" )
87 regist = obj._narrow(Registry.Components)
89 MESSAGE( "Registry Reference is invalid" )
91 ior = orb.object_to_string(contID)
94 lesInfos = Identity(self._instanceName)
95 infos = Registry.Infos(lesInfos._name,
101 int(lesInfos._tc_start),
107 res = regist.add(infos)
109 self._notifSupplier = NOTIFICATION_Supplier_Swig(instanceName, notif)
111 #-------------------------------------------------------------------------
113 def _get_instanceName(self):
114 MESSAGE( "SALOME_ComponentPy_i::_get_instanceName" )
115 return self._instanceName
117 #-------------------------------------------------------------------------
120 MESSAGE( "SALOME_ComponentPy_i::ping" )
122 #-------------------------------------------------------------------------
124 def setProperties(self, dico):
125 self._fieldsDict = dico
127 #-------------------------------------------------------------------------
129 def getProperties(self):
130 return self._fieldsDict
132 #-------------------------------------------------------------------------
135 MESSAGE( "SALOME_ComponentPy_i::destroy" )
136 poa.deactivate_object(self)
139 #-------------------------------------------------------------------------
141 def GetContainerRef(self):
142 MESSAGE( "SALOME_ComponentPy_i::GetContainerRef" )
144 #-------------------------------------------------------------------------
146 def beginService(self , serviceName ):
147 MESSAGE( "Send BeginService notification for " + str(serviceName) + " for graph/node " + str(self._graphName) + " " + str(self._nodeName) )
148 MESSAGE( "Component instance : " + str ( self._instanceName ) )
149 self._serviceName = str(serviceName)
150 self._ThreadId = get_ident()
152 self._StartUsed = self.CpuUsed_impl()
153 self._ThreadCpuUsed = 0
155 MESSAGE( "SALOME_ComponentPy_i::beginService _StartUsed " + str( self._ThreadId ) + " " + str( self._StartUsed ) )
158 #-------------------------------------------------------------------------
160 def endService(self , serviceName ):
161 MESSAGE( "Send EndService notification for " + str( self._ThreadId ) + " " + str(serviceName) + " for graph/node " + str(self._graphName) + " " + str(self._nodeName) + " CpuUsed " + str( self.CpuUsed_impl() ) )
162 MESSAGE( "Component instance : " + str(self._instanceName) )
164 #-------------------------------------------------------------------------
166 def sendMessage(self , event_type , message ):
167 self._notifSupplier.Send(self.graphName(), self.nodeName(), event_type, message)
169 #-------------------------------------------------------------------------
171 def Names(self , GraphName , NodeName ):
172 MESSAGE( "SALOME_ComponentPy_i::Names" + str(GraphName) + str(NodeName) )
173 self._graphName = GraphName
174 self._nodeName = NodeName
176 #-------------------------------------------------------------------------
179 return self._graphName
181 #-------------------------------------------------------------------------
184 return self._nodeName
186 #-------------------------------------------------------------------------
189 MESSAGE( "SALOME_ComponentPy_i::Kill not yet implemented" )
191 #-------------------------------------------------------------------------
194 MESSAGE( "SALOME_ComponentPy_i::Stop not yet implemented" )
196 #-------------------------------------------------------------------------
199 MESSAGE( "SALOME_ComponentPy_i::Suspend not yet implemented" )
201 #-------------------------------------------------------------------------
204 MESSAGE( "SALOME_ComponentPy_i::Resume not yet implemented" )
206 #-------------------------------------------------------------------------
208 def CpuUsed_impl(self):
209 if ( self._ThreadId | self._Executed ) :
210 if self._ThreadId == get_ident() :
212 self._ThreadCpuUsed = int(cpu) - self._StartUsed
213 MESSAGE( "SALOME_ComponentPy_i::CpuUsed_impl " + self._serviceName + " " + str( int(cpu) ) + " - " + str( self._StartUsed ) + " = " + str( self._ThreadCpuUsed ) )
214 return self._ThreadCpuUsed
215 MESSAGE( "SALOME_ComponentPy_i::CpuUsed_impl " + self._serviceName + " " + str( self._ThreadCpuUsed ) )
216 return self._ThreadCpuUsed
217 MESSAGE( "SALOME_ComponentPy_i::CpuUsed_impl self._StartUsed " + self._serviceName + " " + str(self._StartUsed) )
220 #-------------------------------------------------------------------------
222 def DumpPython(self, theStudy, isPublished):
223 aBuffer = "def RebuildData(theStudy): pass"
226 #-------------------------------------------------------------------------