1 // Copyright (C) 2012-2016 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (EDF R&D)
21 #include "YACSEvalSessionInternal.hxx"
22 #include "YACSEvalSession.hxx"
24 #include "PyStdout.hxx"
25 #include "AutoGIL.hxx"
26 #include "Exception.hxx"
28 YACSEvalSession::YACSEvalSessionInternal::YACSEvalSessionInternal():_orb(CORBA::ORB::_nil()),_sl(Engines::SalomeLauncher::_nil())
32 void YACSEvalSession::YACSEvalSessionInternal::checkSalomeLauncher()
34 if(CORBA::is_nil(_sl))
35 throw YACS::Exception("YACSEvalSessionInternal::checkSalomeLauncher : salome launcher is null !");
38 Engines::SalomeLauncher_var YACSEvalSession::YACSEvalSessionInternal::goFetchingSalomeLauncherInNS()
40 if(!CORBA::is_nil(_sl))
43 _orb=CORBA::ORB_init(argc,0);
44 if(CORBA::is_nil(_orb))
45 throw YACS::Exception("YACSEvalSessionInternal contrctor : ORB is null !");
47 const char methName[]="goFetchingSalomeLauncherInNS";
48 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 !\")";
49 YACS::ENGINE::AutoPyRef func(YACS::ENGINE::evalPy(methName,fetchPyCmd));
50 YACS::ENGINE::AutoPyRef val(YACS::ENGINE::evalFuncPyWithNoParams(func));
51 std::string ior(PyString_AsString(val));
52 CORBA::Object_var obj(string_to_object(ior));
53 if(CORBA::is_nil(obj))
54 throw YACS::Exception("goFetchingSalomeLauncherInNS : fetched ior is NIL !");
55 _sl=Engines::SalomeLauncher::_narrow(obj);
56 checkSalomeLauncher();
60 Engines::SalomeLauncher_var YACSEvalSession::YACSEvalSessionInternal::getNotNullSL()
62 checkSalomeLauncher();