]> SALOME platform Git repositories - modules/kernel.git/blob - src/Container/SALOME_ComponentPy.py
Salome HOME
PR: retour au tag V1_2_1_debug2 (pb dans la branche de merge V1_2c)
[modules/kernel.git] / src / Container / SALOME_ComponentPy.py
1 #! /usr/bin/env python
2 #
3 #  SALOME Container : implementation of container and engine for Kernel
4 #
5 #  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
6 #  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
7
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. 
12
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. 
17
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 
21
22 #  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
23 #
24 #
25 #
26 #  File   : SALOME_ComponentPy.py
27 #  Author : Paul RASCLE, EDF
28 #  Module : SALOME
29 #  $Header$
30
31 import os
32 import sys
33 import time
34 from omniORB import CORBA, PortableServer
35 import Engines, Engines__POA
36 import Registry
37 from Utils_Identity import *
38 from SALOME_NamingServicePy import *
39 from libNOTIFICATION import *
40
41 from SALOME_utilities import *
42
43 #=============================================================================
44
45 #define an implementation of the component interface
46
47 class SALOME_ComponentPy_i (Engines__POA.Component):
48     _orb = None
49     _poa = None
50     
51     #-------------------------------------------------------------------------
52
53     def __init__ (self, orb, poa, contID, containerName,
54                   instanceName, interfaceName, notif):
55         # Notif for notification services
56         # NOT YET IMPLEMENTED
57         MESSAGE(  "SALOME_ComponentPy_i::__init__" + " " + str (containerName) + " " + str(instanceName) + " " + str(interfaceName) )
58         self._orb = orb
59         self._poa = poa
60         self._instanceName = instanceName
61         self._interfaceName = interfaceName
62         self._containerName = containerName
63         self._notif = notif
64         self._myConnexionToRegistry = 0
65         self._graphName = ''
66         self._nodeName = ''
67         self._ThreadId = 0
68         self._StartUsed = 0
69
70         naming_service = SALOME_NamingServicePy_i(self._orb)
71         Component_path = "/Containers/" +  os.getenv( "HOSTNAME" ) + "/" + self._containerName + "/" + self._interfaceName
72         MESSAGE(  'SALOME_ComponentPy_i Register' + str( Component_path ) )
73         naming_service.Register(self._this(), Component_path)
74
75         # Add componentinstance to registry
76         obj = naming_service.Resolve('/Registry')
77         if obj is None:
78             MESSAGE(  "Registry Reference is invalid" )
79         else:
80             regist = obj._narrow(Registry.Components)
81             if regist is None:
82                 MESSAGE(  "Registry Reference is invalid" )
83             else:
84                 ior = orb.object_to_string(contID)
85                 MESSAGE(  ior )
86
87                 lesInfos = Identity(self._instanceName)
88                 infos = Registry.Infos(lesInfos._name,
89                                        lesInfos._pid,
90                                        lesInfos._machine,
91                                        lesInfos._adip,
92                                        lesInfos._uid,
93                                        lesInfos._pwname,
94                                        int(lesInfos._tc_start),
95                                        0,0,0,
96                                        lesInfos._cdir,
97                                        -1,
98                                        ior)
99
100                 res = regist.add(infos)
101
102         self._notifSupplier = NOTIFICATION_Supplier_Swig(instanceName, notif)
103
104     #-------------------------------------------------------------------------
105
106     def _get_instanceName(self):
107         MESSAGE(  "SALOME_ComponentPy_i::_get_instanceName" )
108         return self._instanceName
109     
110     #-------------------------------------------------------------------------
111
112     def ping(self):
113         MESSAGE(  "SALOME_ComponentPy_i::ping" )
114         
115     #-------------------------------------------------------------------------
116
117     def destroy(self):
118         MESSAGE(  "SALOME_ComponentPy_i::destroy" )
119         poa.deactivate_object(self)
120         CORBA.release(_poa)
121         
122     #-------------------------------------------------------------------------
123
124     def GetContainerRef(self):
125         MESSAGE(  "SALOME_ComponentPy_i::GetContainerRef" )
126         
127     #-------------------------------------------------------------------------
128
129     def beginService(self , serviceName ):
130         MESSAGE(  "Send BeginService notification for " + str(serviceName) + "for graph/node" + str(self._graphName) + str(self._nodeName) )
131         MESSAGE(  "Component instance : " + str ( self._instanceName ) )
132         self._StartUsed = 0
133         self._StartUsed = self.CpuUsed_impl()
134
135     #-------------------------------------------------------------------------
136
137     def endService(self , serviceName ):
138         MESSAGE(  "Send EndService notification for " + str(serviceName) + "for graph/node" + str(self._graphName) + str(self._nodeName) )
139         MESSAGE(  "Component instance : " + str(self._instanceName) )
140
141     #-------------------------------------------------------------------------
142
143     def sendMessage(self , event_type , message ):
144         self._notifSupplier.Send(self.graphName(), self.nodeName(), event_type, message)
145
146     #-------------------------------------------------------------------------
147
148     def Names(self , GraphName , NodeName ):
149         MESSAGE(  "SALOME_ComponentPy_i::Names" + str(GraphName) + str(NodeName) )
150         self._graphName = GraphName
151         self._nodeName = NodeName
152         
153     #-------------------------------------------------------------------------
154
155     def graphName(self):
156         return self._graphName
157
158     #-------------------------------------------------------------------------
159
160     def nodeName(self):
161         return self._nodeName
162
163     #-------------------------------------------------------------------------
164
165     def Kill(self):
166         MESSAGE(  "SALOME_ComponentPy_i::Kill not yet implemented" )
167
168     #-------------------------------------------------------------------------
169
170     def Stop(self):
171         MESSAGE(  "SALOME_ComponentPy_i::Stop not yet implemented" )
172
173     #-------------------------------------------------------------------------
174
175     def Suspend(self):
176         MESSAGE(  "SALOME_ComponentPy_i::Suspend not yet implemented" )
177
178     #-------------------------------------------------------------------------
179
180     def Resume(self):
181         MESSAGE(  "SALOME_ComponentPy_i::Resume not yet implemented" )
182
183     #-------------------------------------------------------------------------
184
185     def CpuUsed_impl(self):
186         cpu = time.clock()
187         cpuL = int(cpu) - self._StartUsed
188         print "SALOME_ComponentPy_i::CpuUsed_impl ",cpuL,type(cpuL)
189         return cpuL
190
191     #-------------------------------------------------------------------------
192