Salome HOME
Merge branch 'gdd_env_modules_in_config_appli'
[modules/kernel.git] / src / SALOMESDS / SALOME_DataScopeServer.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony GEAY (EDF R&D)
20
21 #include "SALOMESDS_DataScopeServer.hxx"
22 #include "SALOMESDS_DataServerManager.hxx"
23 #include "SALOMESDS_Exception.hxx"
24
25 #include "SALOME_NamingService.hxx"
26
27 #include <string>
28 #include <sstream>
29
30 int main(int argc, char *argv[])
31 {
32   std::string scopeName;
33   if(argc<=1)
34     throw SALOMESDS::Exception("In the main of SALOME_DataScopeServer.cxx !");
35   scopeName=argv[1];
36   std::istringstream isTransacSS(argv[2]);
37   int isTransac(0);
38   isTransacSS >> isTransac;
39   CORBA::ORB_var orb(CORBA::ORB_init(argc,argv));
40   CORBA::Object_var obj(orb->resolve_initial_references("RootPOA"));
41   PortableServer::POA_var poa(PortableServer::POA::_narrow(obj));
42   PortableServer::POAManager_var mgr(poa->the_POAManager());
43   mgr->activate();
44   //
45   SALOMESDS::DataScopeKiller *killer(new SALOMESDS::DataScopeKiller(orb));
46   SALOME::DataScopeKiller_var killerObj(killer->_this());
47   //
48   SALOMESDS::DataScopeServerBase *server(0);
49   if(!isTransac)
50     server=new SALOMESDS::DataScopeServer(orb,killerObj,scopeName);
51   else
52     server=new SALOMESDS::DataScopeServerTransaction(orb,killerObj,scopeName);
53   //
54   CORBA::PolicyList policies;
55   policies.length(3);
56   PortableServer::ThreadPolicy_var threadPol(poa->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL));
57   policies[0]=PortableServer::ThreadPolicy::_duplicate(threadPol);
58   policies[1]=poa->create_implicit_activation_policy(PortableServer::NO_IMPLICIT_ACTIVATION);
59   policies[2]=poa->create_id_uniqueness_policy(PortableServer::UNIQUE_ID);
60   PortableServer::POA_var poa2(poa->create_POA("SingleThPOA4SDS",mgr,policies));
61   threadPol->destroy();
62   server->initializePython(argc,argv);// agy : Very important ! invoke this method BEFORE activation !
63   server->registerToSalomePiDict();
64   //
65   server->setPOA(poa2);
66   obj=server->activate();
67   SALOME::DataScopeServerBase_var serverPtr(SALOME::DataScopeServerBase::_narrow(obj));
68   server->registerInNS(serverPtr);
69   //
70   orb->run();
71   delete killer;
72   return 0;
73 }
74