#include <stdio.h>
#include <dlfcn.h>
#include <unistd.h>
+#include <Python.h>
#include "utilities.h"
using namespace std;
extern "C" {void ActSigIntHandler() ; }
extern "C" {void SigIntHandler(int, siginfo_t *, void *) ; }
+
+static PyMethodDef MethodPyVoidMethod[] = {{ NULL, NULL }};
+PyThreadState *gtstate;
+
+void init_python(int argc, char **argv)
+{
+ if (gtstate)
+ return;
+ Py_SetProgramName(argv[0]);
+ Py_Initialize(); // Initialize the interpreter
+ PySys_SetArgv(argc, argv);
+ PyEval_InitThreads(); // Create (and acquire) the interpreter lock
+ Py_InitModule( "InitPyRunMethod" , MethodPyVoidMethod ) ;
+ //PyOS_setsig(SIGSEGV,&Handler);
+ //PyOS_setsig(SIGINT,&Handler);
+ gtstate = PyEval_SaveThread(); // Release the global thread state
+}
+
const char *Engines_Container_i::_defaultContainerName="FactoryServer";
map<std::string, int> Engines_Container_i::_cntInstances_map;
map<std::string, void *> Engines_Container_i::_library_map;
Engines::Container_var pCont
= Engines::Container::_narrow(obj);
SCRUTE(_containerName);
- _NS->Register(pCont, _containerName.c_str());
+ _NS->Register(pCont, _containerName.c_str());
+
+ // Python:
+ // import SALOME_Container
+ // pycont = SALOME_Container.SALOME_Container_i(containerIORStr)
+
+ init_python(argc,argv);
+
+ CORBA::String_var sior = _orb->object_to_string(pCont);
+ string myCommand="pyCont = SALOME_Container.SALOME_Container_i('";
+ myCommand += sior;
+ myCommand += "')\n";
+ SCRUTE(myCommand);
+
+ PyEval_RestoreThread(gtstate);
+ PyRun_SimpleString("import SALOME_Container\n");
+ PyRun_SimpleString((char*)myCommand.c_str());
+ PyEval_ReleaseThread(gtstate);
}
}
return anEngine._retn();
}
}
+ itm++;
}
return anEngine._retn();
}
extern "C" void HandleServerSideSignals(CORBA::ORB_ptr theORB);
-static PyMethodDef MethodPyVoidMethod[] = {{ NULL, NULL }};
-PyThreadState *gtstate;
-
-void init_python(int argc, char **argv)
-{
- if (gtstate)
- return;
- Py_SetProgramName(argv[0]);
- Py_Initialize(); // Initialize the interpreter
- PySys_SetArgv(argc, argv);
- PyEval_InitThreads(); // Create (and acquire) the interpreter lock
- Py_InitModule( "InitPyRunMethod" , MethodPyVoidMethod ) ;
- //PyOS_setsig(SIGSEGV,&Handler);
- //PyOS_setsig(SIGINT,&Handler);
- gtstate = PyEval_SaveThread(); // Release the global thread state
-}
-
int main(int argc, char* argv[])
{
#ifdef HAVE_MPI2
SALOMETraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
INFOS_COMPILATION;
BEGIN_OF(argv[0]);
-
- init_python(argc,argv);
try{
// Obtain a reference to the root POA.
--- /dev/null
+#! /usr/bin/env python
+#
+# SALOME Container : implementation of container and engine for Kernel
+#
+# 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
+#
+#
+#
+# File : SALOME_Container.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
+reload(Engines)
+reload(Engines__POA)
+from SALOME_NamingServicePy import *
+from SALOME_ComponentPy import *
+
+from SALOME_utilities import *
+from Utils_Identity import getShortHostName
+
+#=============================================================================
+
+#define an implementation of the container interface
+
+class SALOME_Container_i:
+ _orb = None
+ _poa = None
+ _containerName = ""
+ _naming_service = None
+
+ #-------------------------------------------------------------------------
+
+ def __init__(self, containerIORStr ):
+ MESSAGE( "SALOME_Container_i::__init__" )
+ self._orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
+ self._poa = self._orb.resolve_initial_references("RootPOA")
+ self._containerName = sys.argv[1]
+ #self._naming_service = SALOME_NamingServicePy_i(self._orb)
+ self._container = self._orb.string_to_object(containerIORStr)
+
+ #-------------------------------------------------------------------------
+
+ def import_component(self, componentName):
+ MESSAGE( "SALOME_Container_i::import_component" )
+ ret=0
+ try:
+ print "try import ",componentName
+ __import__(componentName)
+ print "import ",componentName," successful"
+ ret=1
+ except:
+ print "import ",componentName," not possible"
+ return ret
+
+ #-------------------------------------------------------------------------
+
+ def create_component_instance(self, componentName, instanceName, studyId):
+ MESSAGE( "SALOME_Container_i::create_component_instance" )
+ comp_iors=""
+ try:
+ component=__import__(componentName)
+ factory=getattr(component,componentName)
+ comp_i=factory(self._orb,
+ self._poa,
+ self._container,
+ self._containerName,
+ instanceName,
+ componentName)
+
+ MESSAGE( "SALOME_Container_i::create_component_instance : OK")
+ comp_o = comp_i._this()
+ comp_iors = self._orb.object_to_string(comp_o)
+ except:
+ import traceback
+ traceback.print_exc()
+ MESSAGE( "SALOME_Container_i::create_component_instance : NOT OK")
+ return comp_iors
+
+