#include "YACSEvalSession.hxx"
#include "YACSEvalSessionInternal.hxx"
-#include "AutoGIL.hxx"
+#include "PythonCppUtils.hxx"
#include "Exception.hxx"
#include <Python.h>
YACSEvalSession::YACSEvalSession():_isAttached(false),_isLaunched(false),_isForcedPyThreadSaved(false),_port(-1),_salomeInstanceModule(0),_salomeInstance(0),_internal(new YACSEvalSessionInternal)
{
- YACS::ENGINE::AutoGIL gal;
+ AutoGIL gal;
_salomeInstanceModule=PyImport_ImportModule(const_cast<char *>("salome_instance"));
}
YACSEvalSession::~YACSEvalSession()
{
delete _internal;
- YACS::ENGINE::AutoGIL gal;
+ AutoGIL gal;
if(isLaunched() && !isAttached())
{
- YACS::ENGINE::AutoPyRef terminateSession(PyObject_GetAttrString(_salomeInstance,const_cast<char *>("stop")));//new
- YACS::ENGINE::AutoPyRef res(PyObject_CallObject(terminateSession,0));
+ AutoPyRef terminateSession(PyObject_GetAttrString(_salomeInstance,const_cast<char *>("stop")));//new
+ AutoPyRef res(PyObject_CallObject(terminateSession,0));
}
Py_XDECREF(_salomeInstance);
Py_XDECREF(_salomeInstanceModule);
{
if(isLaunched())
return ;
- YACS::ENGINE::AutoGIL gal;
+ AutoGIL gal;
PyObject *salomeInstance(PyObject_GetAttrString(_salomeInstanceModule,const_cast<char *>("SalomeInstance")));//new
PyObject *startMeth(PyObject_GetAttrString(salomeInstance,const_cast<char *>("start")));
Py_XDECREF(salomeInstance);
- YACS::ENGINE::AutoPyRef myArgs(PyTuple_New(0));//new
- YACS::ENGINE::AutoPyRef myKWArgs(PyDict_New());//new
+ AutoPyRef myArgs(PyTuple_New(0));//new
+ AutoPyRef myKWArgs(PyDict_New());//new
PyDict_SetItemString(myKWArgs,"shutdown_servers",Py_True);//Py_True ref not stolen
_salomeInstance=PyObject_Call(startMeth,myArgs,myKWArgs);//new
- YACS::ENGINE::AutoPyRef getPortMeth(PyObject_GetAttrString(_salomeInstance,const_cast<char *>("get_port")));//new
- YACS::ENGINE::AutoPyRef portPy(PyObject_CallObject(getPortMeth,0));//new
+ AutoPyRef getPortMeth(PyObject_GetAttrString(_salomeInstance,const_cast<char *>("get_port")));//new
+ AutoPyRef portPy(PyObject_CallObject(getPortMeth,0));//new
_port=PyLong_AsLong(portPy);
//
int dummy;
{
if(isLaunched())
return ;
- YACS::ENGINE::AutoGIL gal;
+ AutoGIL gal;
_corbaConfigFileName=GetConfigAndPort(_port);
_isAttached=true; _isLaunched=true;
}
std::string YACSEvalSession::GetPathToAdd()
{
std::string ret;
- YACS::ENGINE::AutoGIL gal;
- YACS::ENGINE::AutoPyRef osPy(PyImport_ImportModule(const_cast<char *>("os")));//new
+ AutoGIL gal;
+ AutoPyRef osPy(PyImport_ImportModule(const_cast<char *>("os")));//new
PyObject *kernelRootDir(0);// os.environ["KERNEL_ROOT_DIR"]
{
- YACS::ENGINE::AutoPyRef environPy(PyObject_GetAttrString(osPy,const_cast<char *>("environ")));//new
- YACS::ENGINE::AutoPyRef kernelRootDirStr(PyBytes_FromString(const_cast<char *>(KERNEL_ROOT_DIR)));//new
+ AutoPyRef environPy(PyObject_GetAttrString(osPy,const_cast<char *>("environ")));//new
+ AutoPyRef kernelRootDirStr(PyBytes_FromString(const_cast<char *>(KERNEL_ROOT_DIR)));//new
kernelRootDir=PyObject_GetItem(environPy,kernelRootDirStr);//new
}
{
- YACS::ENGINE::AutoPyRef pathPy(PyObject_GetAttrString(osPy,const_cast<char *>("path")));//new
- YACS::ENGINE::AutoPyRef joinPy(PyObject_GetAttrString(pathPy,const_cast<char *>("join")));//new
- YACS::ENGINE::AutoPyRef myArgs(PyTuple_New(4));
+ AutoPyRef pathPy(PyObject_GetAttrString(osPy,const_cast<char *>("path")));//new
+ AutoPyRef joinPy(PyObject_GetAttrString(pathPy,const_cast<char *>("join")));//new
+ AutoPyRef myArgs(PyTuple_New(4));
Py_XINCREF(kernelRootDir); PyTuple_SetItem(myArgs,0,kernelRootDir);
PyTuple_SetItem(myArgs,1,PyBytes_FromString(const_cast<char *>("bin")));
PyTuple_SetItem(myArgs,2,PyBytes_FromString(const_cast<char *>("salome")));
PyTuple_SetItem(myArgs,3,PyBytes_FromString(const_cast<char *>("appliskel")));
- YACS::ENGINE::AutoPyRef res(PyObject_CallObject(joinPy,myArgs));
+ AutoPyRef res(PyObject_CallObject(joinPy,myArgs));
ret=PyBytes_AsString(res);
}
Py_XDECREF(kernelRootDir);
#include "YACSEvalSession.hxx"
#include "PyStdout.hxx"
-#include "AutoGIL.hxx"
+#include "PythonCppUtils.hxx"
#include "Exception.hxx"
YACSEvalSession::YACSEvalSessionInternal::YACSEvalSessionInternal():_orb(CORBA::ORB::_nil()),_sl(Engines::SalomeLauncher::_nil())
//
const char methName[]="goFetchingSalomeLauncherInNS";
const char fetchPyCmd[]="import salome,CORBA\nsalome.salome_init()\nsl=salome.naming_service.Resolve(\"/SalomeLauncher\")\nif not CORBA.is_nil(sl):\n return salome.orb.object_to_string(sl)\nelse:\n raise Exception(\"Impossible to locate salome launcher !\")";
- YACS::ENGINE::AutoPyRef func(YACS::ENGINE::evalPy(methName,fetchPyCmd));
- YACS::ENGINE::AutoPyRef val(YACS::ENGINE::evalFuncPyWithNoParams(func));
+ AutoPyRef func(YACS::ENGINE::evalPy(methName,fetchPyCmd));
+ AutoPyRef val(YACS::ENGINE::evalFuncPyWithNoParams(func));
std::string ior;
if (PyUnicode_Check(val))
ior = PyUnicode_AsUTF8(val);
#include "InlineNode.hxx"
#include "ServiceNode.hxx"
#include "PyStdout.hxx"
-#include "AutoGIL.hxx"
+#include "PythonCppUtils.hxx"
#include "ResourcesManager.hxx"
void YACSEvalYFXGraphGenCluster::generateGraph()
{
- YACS::ENGINE::AutoGIL agil;
+ AutoGIL agil;
//
const char EFXGenFileName[]="EFXGenFileName";
const char EFXGenContent[]="import getpass,datetime,os\nn=datetime.datetime.now()\nreturn os.path.join(os.path.sep,\"tmp\",\"EvalYFX_%s_%s_%s.xml\"%(getpass.getuser(),n.strftime(\"%d%m%y\"),n.strftime(\"%H%M%S\")))";
const char EFXGenContent2[]="import getpass,datetime\nn=datetime.datetime.now()\nreturn \"EvalYFX_%s_%s_%s\"%(getpass.getuser(),n.strftime(\"%d%m%y\"),n.strftime(\"%H%M%S\"))";
//
- YACS::ENGINE::AutoPyRef func(YACS::ENGINE::evalPy(EFXGenFileName,EFXGenContent));
- YACS::ENGINE::AutoPyRef val(YACS::ENGINE::evalFuncPyWithNoParams(func));
+ AutoPyRef func(YACS::ENGINE::evalPy(EFXGenFileName,EFXGenContent));
+ AutoPyRef val(YACS::ENGINE::evalFuncPyWithNoParams(func));
if (PyUnicode_Check(val))
_locSchemaFile = PyUnicode_AsUTF8(val);
else
bool YACSEvalYFXGraphGenCluster::go(const YACSEvalExecParams& params, YACSEvalSession *session) const
{
- YACS::ENGINE::AutoGIL agil;
+ AutoGIL agil;
_errors = "";
getUndergroundGeneratedGraph()->saveSchema(_locSchemaFile);
YACSEvalListOfResources *rss(getBoss()->getResourcesInternal());
oss << "f=open(p,\"r\")" << std::endl;
oss << "return eval(f.read())";
std::string zeInput(oss.str());
- YACS::ENGINE::AutoPyRef func(YACS::ENGINE::evalPy("fetch",zeInput));
- YACS::ENGINE::AutoPyRef val(YACS::ENGINE::evalFuncPyWithNoParams(func));
+ AutoPyRef func(YACS::ENGINE::evalPy("fetch",zeInput));
+ AutoPyRef val(YACS::ENGINE::evalFuncPyWithNoParams(func));
if(!PyList_Check(val))
throw YACS::Exception("Fetched file does not contain a list !");
Py_ssize_t sz(PyList_Size(val));
#include "RuntimeSALOME.hxx"
#include "Proc.hxx"
#include "InlineNode.hxx"
-#include "AutoGIL.hxx"
+#include "PythonCppUtils.hxx"
#include "InputPort.hxx"
#include "Container.hxx"
_global_errors.clear();
// Py_Initialize();
- YACS::ENGINE::AutoGIL agil;
+ AutoGIL agil;
pValue = PyUnicode_FromString(_python_parser_module.c_str());
pModule = PyImport_Import(pValue);
Py_DECREF(pValue);
buffer << "Function " << functionName << " not found." << std::endl;
}
return buffer.str();
-}
\ No newline at end of file
+}
SET(YACSRuntimeSALOME_HEADERS
YACSRuntimeSALOMEExport.hxx
- AutoGIL.hxx
CalStreamPort.hxx
CORBAComponent.hxx
CORBACORBAConv.hxx
#include "PythonNode.hxx"
#include "SalomeHPContainer.hxx"
#include "SalomeContainerTmpForHP.hxx"
-#include "AutoGIL.hxx"
+#include "PythonCppUtils.hxx"
#include "PythonPorts.hxx"
#include "YacsTrace.hxx"
#include "PyStdout.hxx"
#include "Exception.hxx"
-#include "AutoGIL.hxx"
+#include "PythonCppUtils.hxx"
#include <structmember.h>
#include "PythonNode.hxx"
#include "PythonPorts.hxx"
#include "TypeCode.hxx"
-#include "AutoGIL.hxx"
+#include "PythonCppUtils.hxx"
#include "Container.hxx"
#include "SalomeContainer.hxx"
#include "SalomeHPContainer.hxx"
#include <QApplication>
-#include "AutoGIL.hxx"
+#include "PythonCppUtils.hxx"
#include "YDFXGUIWrap.hxx"
#include "YDFXGUIPyThreadSaver.hxx"
const char YDFXGUIStatus::OK_STR[]="OK !";
-class AutoPyRef
-{
-public:
- AutoPyRef(PyObject *pyobj=0):_pyobj(pyobj) { }
- ~AutoPyRef() { release(); }
- AutoPyRef(const AutoPyRef& other):_pyobj(other._pyobj) { if(_pyobj) Py_XINCREF(_pyobj); }
- AutoPyRef& operator=(const AutoPyRef& other) { if(_pyobj==other._pyobj) return *this; release(); _pyobj=other._pyobj; Py_XINCREF(_pyobj); return *this; }
- operator PyObject *() { return _pyobj; }
- void set(PyObject *pyobj) { if(pyobj==_pyobj) return ; release(); _pyobj=pyobj; }
- PyObject *get() { return _pyobj; }
- bool isNull() const { return _pyobj==0; }
- PyObject *retn() { if(_pyobj) Py_XINCREF(_pyobj); return _pyobj; }
-private:
- void release() { if(_pyobj) Py_XDECREF(_pyobj); _pyobj=0; }
-private:
- PyObject *_pyobj;
-};
-
////////////////////////////
void YDFXGUIDoubleVectHolder::applyOnInput(YACSEvalInputPort *inp) const
std::string txt(toPlainText().toStdString());
YDFXGUIPyThreadSaver::SaveContext(QApplication::instance()->thread());
{
- YACS::ENGINE::AutoGIL gal;
+ AutoGIL gal;
AutoPyRef code(Py_CompileString(txt.c_str(),TMP_FILENAME, Py_file_input));
if(code.get() == NULL)
{