Salome HOME
Copyright update 2020
[modules/kernel.git] / src / SALOMESDS / SALOMESDS_RequestSwitcher.cxx
1 // Copyright (C) 2007-2020  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_RequestSwitcher.hxx"
22
23 #include <sstream>
24
25 using namespace SALOMESDS;
26
27 RequestSwitcherBase::RequestSwitcherBase(CORBA::ORB_ptr orb)
28 {
29   static int iii=0;
30   CORBA::Object_var obj(orb->resolve_initial_references("RootPOA"));
31   PortableServer::POA_var poa(PortableServer::POA::_narrow(obj));
32   _poa_manager_under_control=poa->the_POAManager();
33   //
34   CORBA::PolicyList policies;
35   policies.length(1);
36   PortableServer::ThreadPolicy_var threadPol(poa->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL));
37   policies[0]=PortableServer::ThreadPolicy::_duplicate(threadPol);
38   // all is in PortableServer::POAManager::_nil. By specifying _nil cf Advanced CORBA Programming with C++ p 506
39   // a new POA manager is created. This POA manager is independent from POA manager of the son ones.
40   std::ostringstream poaName;
41   poaName << "4RqstSwitcher_" << iii++;
42   _poa_for_request_control=poa->create_POA(poaName.str().c_str(),PortableServer::POAManager::_nil(),policies);
43   threadPol->destroy();
44   PortableServer::POAManager_var mgr(_poa_for_request_control->the_POAManager());
45   mgr->activate();
46   //obj=orb->resolve_initial_references ("POACurrent");// agy : usage of POACurrent breaks the hold_requests. Why ?
47   //PortableServer::Current_var current(PortableServer::Current::_narrow(obj));
48 }
49
50 void RequestSwitcherBase::holdRequests()
51 {
52   _poa_manager_under_control->hold_requests(true);
53 }
54
55 void RequestSwitcherBase::activeRequests()
56 {
57   _poa_manager_under_control->activate();
58 }