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"
23 #include <SALOME_LifeCycleCORBA.hxx>
24 #include <SALOME_NamingService.hxx>
25 #include <utilities.h> // MESSAGE() macro
26 #include <SALOMEconfig.h>
27 #include CORBA_CLIENT_HEADER(SALOME_ContainerManager)
29 PVServer_ServiceLoader::PVServer_ServiceLoader():
32 myLcc = new SALOME_LifeCycleCORBA();
35 PVServer_ServiceLoader::~PVServer_ServiceLoader()
40 SALOME_LifeCycleCORBA* PVServer_ServiceLoader::lcc()
45 std::string PVServer_ServiceLoader::findOrLoadService( const std::string& containerName )
47 std::string ior = findService( containerName );
49 ior = loadService( containerName );
53 std::string PVServer_ServiceLoader::findService( const std::string& containerName )
57 Engines::Container_var container = getContainer( containerName, "get" );
59 if ( !CORBA::is_nil( container ) )
61 CORBA::String_var hName = container->getHostName();
62 CORBA::Object_var obj = lcc()->namingService()->ResolveComponent( hName.in(),
63 containerName.c_str(),
66 if ( !CORBA::is_nil( obj ) )
68 CORBA::ORB_var orb = lcc()->orb();
69 CORBA::String_var cIor = orb->object_to_string( obj );
76 MESSAGE( "PVServer_ServiceLoader::findService(): Service NOT found!" );
80 MESSAGE( "PVServer_ServiceLoader::findService(): Service found!" );
86 std::string PVServer_ServiceLoader::loadService( const std::string& containerName )
90 Engines::Container_var container = getContainer( containerName, "getorstart" );
92 if ( !CORBA::is_nil( container ) )
94 CORBA::String_var cReason;
95 CORBA::String_var cIor = container->create_python_service_instance( "PVSERVER", cReason.out() );
96 std::string reason = cReason.in();
100 MESSAGE( "PVServer_ServiceLoader::loadService(): Python service instance could not be created!" );
101 MESSAGE( "PVServer_ServiceLoader::loadService(): " << reason );
105 MESSAGE( "PVServer_ServiceLoader::loadService(): Container and service loaded!" );
111 MESSAGE( "PVServer_ServiceLoader::loadService(): Container could not be retrieved!" );
116 Engines::Container_ptr PVServer_ServiceLoader::getContainer( const std::string& containerName,
117 const std::string& mode )
119 Engines::ContainerParameters params;
120 params.isMPI = false;
121 params.mode = CORBA::string_dup( mode.c_str() );
123 int rg = containerName.find( "/" );
126 params.container_name = CORBA::string_dup( containerName.c_str() );
130 params.resource_params.hostname = CORBA::string_dup( containerName.substr(0, rg).c_str() );
131 params.container_name = CORBA::string_dup( containerName.substr(rg+1).c_str() );
134 Engines::ContainerManager_var cm = lcc()->getContainerManager();
135 Engines::Container_var container = cm->GiveContainer( params );
136 return container._retn();