Salome HOME
[EDF30399] : Steer directory hosting replay files
[modules/kernel.git] / src / Container / SALOME_ComponentPy.py
old mode 100755 (executable)
new mode 100644 (file)
index a9ce718..f7e01ae
@@ -1,6 +1,5 @@
-#! /usr/bin/env python
 #  -*- coding: iso-8859-1 -*-
-# Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+# Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
 #
 # Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -42,11 +41,12 @@ import Engines, Engines__POA
 import Registry
 from Utils_Identity import *
 from SALOME_NamingServicePy import *
+from SALOME_Embedded_NamingService_ClientPy import SALOME_Embedded_NamingService_ClientPy
 from libNOTIFICATION import *
 
 from SALOME_utilities import *
 
-from thread import *
+from _thread import *
 
 #=============================================================================
 
@@ -55,11 +55,13 @@ _Sleeping = 0
 ## define an implementation of the component interface Engines::Component
 #
 #
-class SALOME_ComponentPy_i (Engines__POA.EngineComponent):
+class SALOME_ComponentPy_Gen_i (Engines__POA.EngineComponent):
+    """
+    Implementation Without naming_service server
+    """
     _orb = None
     _poa = None
     _fieldsDict = []
-    _studyId = -1
 
     #-------------------------------------------------------------------------
 
@@ -84,42 +86,13 @@ class SALOME_ComponentPy_i (Engines__POA.EngineComponent):
         self._Executed = 0
         self._contId = contID
 
-        naming_service = SALOME_NamingServicePy_i(self._orb)
         myMachine=getShortHostName()
-        Component_path = self._containerName + "/" + self._instanceName
-        MESSAGE(  'SALOME_ComponentPy_i Register' + str( Component_path ) )
         id_o = poa.activate_object(self)
-        compo_o = poa.id_to_reference(id_o)
-        naming_service.Register(compo_o, Component_path)
-
-        # Add componentinstance to registry
-        obj = naming_service.Resolve('/Registry')
-        if obj is None:
-            MESSAGE(  "Registry Reference is invalid" )
-        else:
-            regist = obj._narrow(Registry.Components)
-            if regist is None:
-                MESSAGE(  "Registry Reference is invalid" )
-            else:
-                ior = orb.object_to_string(contID)
-                MESSAGE(  ior )
-
-                lesInfos = Identity(self._instanceName)
-                infos = Registry.Infos(lesInfos._name,
-                                       lesInfos._pid,
-                                       lesInfos._machine,
-                                       lesInfos._adip,
-                                       lesInfos._uid,
-                                       lesInfos._pwname,
-                                       int(lesInfos._tc_start),
-                                       0,0,0,
-                                       lesInfos._cdir,
-                                       -1,
-                                       ior)
-
-                res = regist.add(infos)
+        self._compo_o = poa.id_to_reference(id_o)
+        self._notifSupplier = NOTIFICATION_Supplier_Swig(instanceName, self._notif)
 
-        self._notifSupplier = NOTIFICATION_Supplier_Swig(instanceName, notif)
+    def getCorbaRef(self):
+        return self._compo_o
 
     #-------------------------------------------------------------------------
 
@@ -173,7 +146,7 @@ class SALOME_ComponentPy_i (Engines__POA.EngineComponent):
         self._StartUsed = self.CpuUsed_impl()
         self._ThreadCpuUsed = 0
         self._Executed = 1
-        print "beginService for ",serviceName," Component instance : ",self._instanceName
+        print("beginService for ",serviceName," Component instance : ",self._instanceName)
         MESSAGE( "SALOME_ComponentPy_i::beginService _StartUsed " + str( self._ThreadId ) + " " + str( self._StartUsed ) )
         for e in self._fieldsDict:
           key=e.key
@@ -187,7 +160,7 @@ class SALOME_ComponentPy_i (Engines__POA.EngineComponent):
     def endService(self , serviceName ):
         MESSAGE(  "Send EndService notification for " + str( self._ThreadId ) + " " + str(serviceName) + " for graph/node " + str(self._graphName) + " " + str(self._nodeName) + " CpuUsed " + str( self.CpuUsed_impl() ) )
         MESSAGE(  "Component instance : " + str(self._instanceName) )
-        print "endService for",serviceName,"Component instance :",self._instanceName,"Cpu Used:",self.CpuUsed_impl()," (s) "
+        print("endService for",serviceName,"Component instance :",self._instanceName,"Cpu Used:",self.CpuUsed_impl()," (s) ")
 
 
     #-------------------------------------------------------------------------
@@ -282,7 +255,7 @@ class SALOME_ComponentPy_i (Engines__POA.EngineComponent):
     def CpuUsed_impl(self):
         if ( self._ThreadId | self._Executed ) :
             if self._ThreadId == get_ident() :
-                cpu = time.clock()
+                cpu = time.process_time()
                 self._ThreadCpuUsed = cpu - self._StartUsed
                 MESSAGE( "SALOME_ComponentPy_i::CpuUsed_impl " + self._serviceName + " " + str( int(cpu) ) + " - " + str( self._StartUsed ) + " = " + str( self._ThreadCpuUsed ) )
                 return self._ThreadCpuUsed
@@ -293,16 +266,11 @@ class SALOME_ComponentPy_i (Engines__POA.EngineComponent):
 
     #-------------------------------------------------------------------------
 
-    def DumpPython(self, theStudy, isPublished, isMultiFile):
+    def DumpPython(self, isPublished, isMultiFile):
         aBuffer = "\0"
         if isMultiFile :
-            aBuffer = "def RebuildData(theStudy): pass\n\0"
-        return (aBuffer, 1)
-
-    #-------------------------------------------------------------------------
-
-    def getStudyId(self):
-        return self._studyId
+            aBuffer = "def RebuildData(): pass\n\0"
+        return (aBuffer.encode(), 1)
 
     #-------------------------------------------------------------------------
 
@@ -311,7 +279,7 @@ class SALOME_ComponentPy_i (Engines__POA.EngineComponent):
 
     #-------------------------------------------------------------------------
 
-    def getObjectInfo(self, studyId, entry):
+    def getObjectInfo(self, entry):
         return ""
 
     #-------------------------------------------------------------------------
@@ -322,3 +290,46 @@ class SALOME_ComponentPy_i (Engines__POA.EngineComponent):
     #-------------------------------------------------------------------------
 
     pass # end of SALOME_ComponentPy_i
+
+class SALOME_ComponentPy_i(SALOME_ComponentPy_Gen_i):
+    """
+    Implementation with naming_service server
+    """
+    def __init__ (self, orb, poa, contID, containerName, instanceName, interfaceName, notif=False):
+        SALOME_ComponentPy_Gen_i.__init__(self, orb, poa, contID, containerName, instanceName, interfaceName, notif)
+        emb_ns = self._contId.get_embedded_NS_if_ssl()
+        if CORBA.is_nil(emb_ns):
+            self._naming_service = SALOME_NamingServicePy_i(self._orb)
+        else:
+            self._naming_service = SALOME_Embedded_NamingService_ClientPy(emb_ns)
+        Component_path = contID.name + "/" + self._instanceName#self._containerName
+        MESSAGE(  'SALOME_ComponentPy_i Register' + str( Component_path ) )
+        self._naming_service.Register(self._compo_o, Component_path)
+        # Add componentinstance to registry
+        obj = self._naming_service.Resolve('/Registry')
+        if obj is None:
+            MESSAGE(  "Registry Reference is invalid" )
+        else:
+            regist = obj._narrow(Registry.Components)
+            if regist is None:
+                MESSAGE(  "Registry Reference is invalid" )
+            else:
+                ior = orb.object_to_string(contID)
+                MESSAGE(  ior )
+
+                lesInfos = Identity(self._instanceName)
+                infos = Registry.Infos(lesInfos._name,
+                                       lesInfos._pid,
+                                       lesInfos._machine,
+                                       lesInfos._adip,
+                                       lesInfos._uid,
+                                       lesInfos._pwname,
+                                       int(lesInfos._tc_start),
+                                       0,0,0,
+                                       lesInfos._cdir,
+                                       -1,
+                                       ior)
+
+                res = regist.add(infos)
+
+    pass