X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FContainer%2FSALOME_ContainerPy.py;h=cdc43e64357a6d20cdc8dcd2cb594fe3d699d373;hb=5c16b3e02dbb3afc35daf6b31522a542f4b9c140;hp=417599eb98239f851e815c623d3e94ab777f72d2;hpb=2a9dfb2c5032dc3bfd0c6ac614be64703112f79d;p=modules%2Fkernel.git diff --git a/src/Container/SALOME_ContainerPy.py b/src/Container/SALOME_ContainerPy.py index 417599eb9..cdc43e643 100755 --- a/src/Container/SALOME_ContainerPy.py +++ b/src/Container/SALOME_ContainerPy.py @@ -1,39 +1,38 @@ #! /usr/bin/env python +# -*- coding: iso-8859-1 -*- +# Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE # -# SALOME Container : implementation of container and engine for Kernel +# Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. # -# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. # +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # + +# SALOME Container : implementation of container and engine for Kernel # File : SALOME_ContainerPy.py # Author : Paul RASCLE, EDF # Module : SALOME # $Header$ - +# import os import sys import string + from omniORB import CORBA, PortableServer -# import SALOMEDS before other SALOME modules -# (if not, incomplete import done by SALOME module: no load of SALOMEDS_attributes) import SALOMEDS import Engines, Engines__POA from SALOME_NamingServicePy import * @@ -41,15 +40,17 @@ from SALOME_ComponentPy import * from SALOME_utilities import * from Utils_Identity import getShortHostName +from launchConfigureParser import verbose #============================================================================= -#define an implementation of the container interface +#define an implementation of the container interface for the container implemented in Python class SALOME_ContainerPy_i (Engines__POA.Container): _orb = None _poa = None _numInstance = 0 + _listInstances_map = {} #------------------------------------------------------------------------- @@ -57,12 +58,13 @@ class SALOME_ContainerPy_i (Engines__POA.Container): MESSAGE( "SALOME_ContainerPy_i::__init__" ) self._orb = orb self._poa = poa - self._containerName = containerName - myMachine=getShortHostName() + Container_path = "/Containers/" + myMachine + "/" + containerName + self._containerName = Container_path + if verbose(): print "container name ",self._containerName + naming_service = SALOME_NamingServicePy_i(self._orb) self._naming_service = naming_service - Container_path = "/Containers/" + myMachine + "/" + self._containerName MESSAGE( str(Container_path) ) naming_service.Register(self._this(), Container_path) @@ -133,6 +135,22 @@ class SALOME_ContainerPy_i (Engines__POA.Container): #------------------------------------------------------------------------- + def instance(self, nameToRegister, componentName): + MESSAGE( "SALOME_ContainerPy_i::instance " + str(nameToRegister) + ' ' + str(componentName) ) + self._numInstance = self._numInstance +1 + instanceName = nameToRegister + "_inst_" + `self._numInstance` + + component=__import__(componentName) + factory=getattr(component,componentName) + comp_i=factory(self._orb, self._poa, self._this(), self._containerName, + instanceName, nameToRegister) + + MESSAGE( "SALOME_ContainerPy_i::instance : component created") + comp_o = comp_i._this() + return comp_o + + #------------------------------------------------------------------------- + def load_impl(self, nameToRegister, componentName): MESSAGE( "SALOME_ContainerPy_i::load_impl " + str(nameToRegister) + ' ' + str(componentName) ) self._numInstance = self._numInstance +1 @@ -146,55 +164,168 @@ class SALOME_ContainerPy_i (Engines__POA.Container): comp_o = comp_i._this() return comp_o + #------------------------------------------------------------------------- + + def import_component(self, componentName): + MESSAGE( "SALOME_Container_i::import_component" ) + ret=0 + try: + if verbose(): print "try import ",componentName + module=__import__(componentName) + if verbose(): print "import ",componentName," successful" + ret=1 + except: + import traceback + traceback.print_exc() + print "import ",componentName," not possible" + return ret + + #------------------------------------------------------------------------- + + def load_component_Library(self, componentName): + MESSAGE( "SALOME_ContainerPy_i::load_component_Library " + str(componentName) ) + ret = 0 + instanceName = componentName + "_inst_" + `self._numInstance` + interfaceName = componentName + return self.import_component(componentName), "" + + #------------------------------------------------------------------------- + + def create_component_instance_env(self, componentName, studyId, env): + return self.create_component_instance(componentName, studyId), "" + + def create_component_instance(self, componentName, studyId): + MESSAGE( "SALOME_ContainerPy_i::create_component_instance ==> " + str(componentName) + ' ' + str(studyId) ) + if studyId < 0: + MESSAGE( "Study ID is lower than 0!" ) + return None + else: + self._numInstance = self._numInstance +1 + instanceName = componentName + "_inst_" + `self._numInstance` + comp_iors="" + try: + component=__import__(componentName) + factory=getattr(component,componentName) + comp_i=factory(self._orb, + self._poa, + self._this(), + self._containerName, + instanceName, + componentName) + + MESSAGE( "SALOME_Container_i::create_component_instance : OK") + comp_o = comp_i._this() + self._listInstances_map[instanceName] = comp_i + except: + import traceback + traceback.print_exc() + MESSAGE( "SALOME_Container_i::create_component_instance : NOT OK") + return comp_o + + #------------------------------------------------------------------------- + + def find_component_instance(self, registeredName, studyId): + anEngine = None + keysList = self._listInstances_map.keys() + i = 0 + while i < len(keysList): + instance = keysList[i] + if find(instance,registeredName) == 0: + anEngine = self._listInstances_map[instance] + if studyId == anEngine.getStudyId(): + return anEngine._this() + i = i + 1 + return anEngine._this() + + #------------------------------------------------------------------------- def remove_impl(self, component): MESSAGE( "SALOME_ContainerPy_i::remove_impl" ) + instanceName = component._get_instanceName() + MESSAGE( "unload component " + str(instanceName) ) + self._listInstances_map.remove(instanceName) + component.destroy() + self._naming_service.Destroy_Name(str(instanceName)) #------------------------------------------------------------------------- def finalize_removal(self): MESSAGE( "SALOME_ContainerPy_i::finalize_removal" ) + return None #------------------------------------------------------------------------- def ping(self): - MESSAGE( "SALOME_ContainerPy_i::ping" ) + MESSAGE( "SALOME_ContainerPy_i::ping() pid " + str(os.getpid()) ) + return None + + #------------------------------------------------------------------------- + + def getPID(self): + return os.getpid() #------------------------------------------------------------------------- def _get_name(self): MESSAGE( "SALOME_ContainerPy_i::_get_name" ) + return self._containerName #------------------------------------------------------------------------- - def _get_machineName(self): + def getHostName(self): MESSAGE( "SALOME_ContainerPy_i::_get_MachineName" ) self._machineName = "localhost" return self._machineName -#============================================================================= + #------------------------------------------------------------------------- + + def _get_machineName(self): + MESSAGE( "SALOME_ContainerPy_i::_get_MachineName" ) + self._machineName = "localhost" + return self._machineName -#initialise the ORB and find the root POA -orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID) -poa = orb.resolve_initial_references("RootPOA") + #------------------------------------------------------------------------- -#create an instance of SALOME_ContainerPy_i and a Container reference -#containerName = "FactoryServerPy" -MESSAGE( str(sys.argv) ) -containerName = sys.argv[1] -cpy_i = SALOME_ContainerPy_i(orb, poa, containerName) -cpy_o = cpy_i._this() + def Shutdown(self): + self._naming_service.Destroy_Name(self._containerName); + self._naming_service.Destroy_FullDirectory(self._containerName); + self._orb.shutdown(0) + pass -#activate the POA -poaManager = poa._get_the_POAManager() -poaManager.activate() + def _get_logfilename(self): + return self._logfilename + def _set_logfilename(self,logfilename): + self._logfilename=logfilename + def _get_workingdir(self): + return os.getcwd() -#Block for ever -orb.run() +#============================================================================= +if __name__ == "__main__": + # change the stdout buffering to line buffering (same as C++ cout buffering) + sys.stdout=os.fdopen(1,"w",1) + #initialise the ORB and find the root POA + if verbose():print "Starting ",sys.argv[1] + orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID) + poa = orb.resolve_initial_references("RootPOA") + if verbose():print "ORB and POA initialized" - - + #create an instance of SALOME_ContainerPy_i and a Container reference + #containerName = "FactoryServerPy" + MESSAGE( str(sys.argv) ) + containerName = sys.argv[1] + cpy_i = SALOME_ContainerPy_i(orb, poa, containerName) + if verbose():print "SALOME_ContainerPy_i instance created ",cpy_i + cpy_o = cpy_i._this() + if verbose():print "SALOME_ContainerPy_i instance activated ",cpy_o + sys.stdout.flush() + sys.stderr.flush() + #activate the POA + poaManager = poa._get_the_POAManager() + poaManager.activate() + #Block for ever + orb.run() + if verbose():print "SALOME_ContainerPy_i shutdown"