1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/
24 #include "utilities.h"
26 #include <Launchers.hxx>
30 static int Launchers_IsLoaded = 0;
31 static PyObject * Launchers_module = 0;
32 static char * Launchers_name="Launchers";
34 PyThreadState *mainThreadState=0;
36 PyThreadState * getMainThreadState(){
37 PyInterpreterState *interp;
39 interp=PyInterpreterState_Head();
40 for (interp = PyInterpreterState_Head(); interp != NULL; ){
41 if(interp->next == NULL)break;
44 for (p = interp->tstate_head; p != NULL; ){
45 if(p->next == NULL)break;
50 PyThreadState *acquireMainThread(){
52 return PyThreadState_Swap(mainThreadState);
54 void releaseMainThread(PyThreadState *tstate){
55 PyThreadState_Swap(tstate);
59 void Launchers_assertInitialized() {
60 MESSAGE("===========================================================");
61 MESSAGE("Launchers_assertInitialized");
62 MESSAGE("===========================================================");
64 if( !Py_IsInitialized() ) {
65 MESSAGE("===========================================================");
66 MESSAGE("Py_Initialize()");
67 MESSAGE("===========================================================");
72 if( !Launchers_IsLoaded ) {
73 mainThreadState=getMainThreadState();
74 _save=acquireMainThread();
75 Launchers_module=PyImport_ImportModule(Launchers_name);
76 if(!Launchers_module){
80 Py_INCREF(Launchers_module);
81 Launchers_IsLoaded = 1;
82 releaseMainThread(_save);
86 PyObject * getLauncher(char* arg0) {
89 Launchers_assertInitialized();
90 _save=acquireMainThread();
91 v=PyObject_CallMethod(Launchers_module,"getLauncher","s",arg0);
96 releaseMainThread(_save);
101 void Launcher_Slaunch(PyObject *self, char* arg1, char* arg2) {
103 PyThreadState *_save;
104 Launchers_assertInitialized();
105 _save=acquireMainThread();
106 v=PyObject_CallMethod(self,"Slaunch","ss",arg1,arg2);
110 releaseMainThread(_save);