1 // Copyright (C) 2015-2016 CEA/DEN, EDF R&D, OPEN CASCADE
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: Adrien Bruneton (CEA)
21 #include "PVServer_ServiceLoader.h"
22 #include "PVServer_ServiceWrapper.h"
24 #include <SALOME_LifeCycleCORBA.hxx>
25 #include <SALOME_NamingService.hxx>
26 #include <utilities.h> // MESSAGE() macro
28 PVServer_ServiceLoader::PVServer_ServiceLoader():
31 _lcc = new SALOME_LifeCycleCORBA();
32 _ns = _lcc->namingService();
33 _cm = _lcc->getContainerManager();
38 PVServer_ServiceLoader::~PVServer_ServiceLoader()
45 std::string PVServer_ServiceLoader::findOrLoadService(const char * containerName)
47 std::string ior = findService(containerName);
49 ior = loadService(containerName);
53 std::string PVServer_ServiceLoader::findService(const char * containerName)
55 std::string path = "/Containers";
56 path += containerName;
58 CORBA::Object_ptr obj = _ns->Resolve(path.c_str());
59 if(!CORBA::is_nil(obj))
61 MESSAGE("PVServer_ServiceLoader::findService(): Service found! ");
62 char * ior = _orb->object_to_string(obj);
63 return std::string(ior);
67 MESSAGE("PVServer_ServiceLoader::findService(): Service NOT found! ");
68 return std::string("");
73 std::string PVServer_ServiceLoader::loadService(const char * containerName)
75 // Get the requested container
76 Engines::ContainerParameters params;
77 params.container_name = CORBA::string_dup(containerName);
79 params.mode = "getorstart";
80 Engines::Container_ptr contain = _cm->GiveContainer(params);
82 if (!CORBA::is_nil(contain))
85 char * ior = contain->create_python_service_instance("PVSERVER", reason);
86 std::string reas(reason);
87 CORBA::string_free(reason);
90 MESSAGE("PVServer_ServiceLoader::loadService(): Python service instance could not be created! ");
91 MESSAGE("PVServer_ServiceLoader::loadService(): " << reas);
92 return std::string("");
96 MESSAGE("PVServer_ServiceLoader::loadService(): Container and service loaded! ");
97 return std::string(ior);
102 MESSAGE("PVServer_ServiceLoader::loadService(): Container could not be retrieved! ");
103 return std::string("");