1 // Copyright (C) 2021-2022 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
20 #include "Session_NS_wrapper.hxx"
22 #include "ArgvKeeper.hxx"
24 #include "SALOME_Fake_NamingService.hxx"
25 #include "SALOME_Container_i.hxx"
26 #include "SALOME_Launcher.hxx"
27 #include "SALOMEDSClient_ClientFactory.hxx"
29 #include "Session_Session_i.hxx"
30 #include "Session_Promises.hxx"
31 #include "utilities.h"
33 const char OldStyleNS::LibName[]="SalomeApp";
34 const char NewStyleNS::LibName[]="SalomeAppSL";
36 void CommonActivateSession(CORBA::ORB_var orb, PortableServer::POA_var poa, QMutex *GUIMutex, QWaitCondition *GUILauncher, SALOME_NamingService_Abstract *ns, int argc, char ** argv)
39 MESSAGE("Session thread started");
40 SALOME_Session_i * mySALOME_Session = nullptr;
42 mySALOME_Session = new SALOME_Session_i(argc, argv, orb, poa, GUIMutex, GUILauncher);
44 mySALOME_Session = new SALOME_Session_i(argc, argv, orb, poa, GUIMutex, GUILauncher,ns);
45 PortableServer::ObjectId_var mySALOME_Sessionid = poa->activate_object(mySALOME_Session);
46 MESSAGE("poa->activate_object(mySALOME_Session)");
48 CORBA::Object_var obj = mySALOME_Session->_this();
49 SALOME::Session_var objC = SALOME::Session::_narrow(obj);
50 GetSessionRefSingleton()->set_value(objC);
51 CORBA::String_var sior(orb->object_to_string(obj));
52 mySALOME_Session->_remove_ref();
54 mySALOME_Session->NSregister();
56 catch (CORBA::SystemException&) {
57 INFOS("Caught CORBA::SystemException.");
59 catch (CORBA::Exception&) {
60 INFOS("Caught CORBA::Exception.");
63 INFOS("Caught unknown exception.");
67 Abstract_Engines_Container_i *OldStyleNS::activateContainer(CORBA::ORB_var orb, PortableServer::POA_var poa, int argc, char **argv)
69 Engines_Container_i *_container = nullptr;
72 MESSAGE("Container thread started");
74 // get or create the child POA
76 PortableServer::POA_var factory_poa;
79 factory_poa = poa->find_POA("factory_poa", 0);
80 // 0 = no activation (already done if exists)
82 catch (PortableServer::POA::AdapterNonExistent &)
84 MESSAGE("factory_poa does not exists, create...");
85 // define policy objects
86 PortableServer::ImplicitActivationPolicy_var implicitActivation =
87 poa->create_implicit_activation_policy(PortableServer::NO_IMPLICIT_ACTIVATION);
88 // default = NO_IMPLICIT_ACTIVATION
89 PortableServer::ThreadPolicy_var threadPolicy =
90 poa->create_thread_policy(PortableServer::ORB_CTRL_MODEL);
91 // default = ORB_CTRL_MODEL, other choice SINGLE_THREAD_MODEL
94 CORBA::PolicyList policyList;
96 policyList[0] = PortableServer::ImplicitActivationPolicy::
97 _duplicate(implicitActivation);
98 policyList[1] = PortableServer::ThreadPolicy::
99 _duplicate(threadPolicy);
101 PortableServer::POAManager_var nil_mgr = PortableServer::POAManager::_nil();
102 factory_poa = poa->create_POA("factory_poa",
105 //with nil_mgr instead of pman,
106 //a new POA manager is created with the new POA
108 // destroy policy objects
109 implicitActivation->destroy();
110 threadPolicy->destroy();
112 // obtain the factory poa manager
113 PortableServer::POAManager_var pmanfac = factory_poa->the_POAManager();
115 MESSAGE("pmanfac->activate()");
118 char *containerName = (char *)"";
121 containerName = argv[1];
123 _container = new Engines_Container_i(orb, poa, containerName, argc, argv, nullptr, false);
125 catch (CORBA::SystemException &)
127 INFOS("Caught CORBA::SystemException.");
129 catch (PortableServer::POA::WrongPolicy &)
131 INFOS("Caught CORBA::WrongPolicyException.");
133 catch (PortableServer::POA::ServantAlreadyActive &)
135 INFOS("Caught CORBA::ServantAlreadyActiveException");
137 catch (CORBA::Exception &)
139 INFOS("Caught CORBA::Exception.");
143 INFOS("Caught unknown exception.");
148 void OldStyleNS::activateContainerManager(CORBA::ORB_var orb)
151 PortableServer::POA_var root_poa=PortableServer::POA::_the_root_poa();
152 std::cout << "Activate SalomeLauncher ......!!!! " << std::endl;
153 new SALOME_Launcher(orb,root_poa);
155 catch(CORBA::SystemException&) {
156 INFOS("Caught CORBA::SystemException.");
158 catch(PortableServer::POA::WrongPolicy&) {
159 INFOS("Caught CORBA::WrongPolicyException.");
161 catch(PortableServer::POA::ServantAlreadyActive&) {
162 INFOS("Caught CORBA::ServantAlreadyActiveException");
164 catch(CORBA::Exception&) {
165 INFOS("Caught CORBA::Exception.");
168 INFOS("Caught unknown exception.");
172 void OldStyleNS::activateSession(CORBA::ORB_var orb, PortableServer::POA_var poa, QMutex *GUIMutex, QWaitCondition *GUILauncher, int argc, char ** argv)
174 CommonActivateSession(orb,poa,GUIMutex,GUILauncher,nullptr,argc,argv);
177 void OldStyleNS::activateSALOMEDS(CORBA::ORB_var orb, PortableServer::POA_var poa)
180 MESSAGE("SALOMEDS thread started");
181 // We allocate the objects on the heap. Since these are reference
182 // counted objects, they will be deleted by the POA when they are no
185 ClientFactory::createStudy(orb,poa);
187 catch(CORBA::SystemException&) {
188 INFOS( "Caught CORBA::SystemException." );
190 catch(CORBA::Exception&) {
191 INFOS( "Caught CORBA::Exception." );
193 catch(omniORB::fatalException& fe) {
194 INFOS( "Caught omniORB::fatalException:" );
195 INFOS( " file: " << fe.file() );
196 INFOS( " line: " << fe.line() );
197 INFOS( " mesg: " << fe.errmsg() );
200 INFOS( "Caught unknown exception." );
204 #include "Utils_SINGLETON.hxx"
206 CORBA::Object_var OldStyleNS::forServerChecker(const char *NSName, int argc, char **argv)
208 SetArgcArgv( argc, argv );
209 CORBA::ORB_var orb = KERNEL::GetRefToORB();
210 SALOME_NamingService &NS = *SINGLETON_<SALOME_NamingService>::Instance();
211 ASSERT( SINGLETON_<SALOME_NamingService>::IsAlreadyExisting() );
213 CORBA::Object_var obj = NS.Resolve( NSName );
217 CosNaming::NamingContext_var OldStyleNS::checkTrueNamingServiceIfExpected(int argc, char **argv, bool& forceOK)
219 forceOK = false;//tell checker : do as before
220 SetArgcArgv( argc, argv );
221 CORBA::ORB_var orb = KERNEL::GetRefToORB();
222 CORBA::Object_var obj = orb->resolve_initial_references( "NameService" );
223 CosNaming::NamingContext_var _root_context = CosNaming::NamingContext::_narrow( obj );
224 return _root_context;
227 #include "SALOME_KernelServices.hxx"
229 void NewStyleNS::defineDefaultSALOMEKERNELNamingService()
231 KERNEL::assignNamingServiceSL();
234 Abstract_Engines_Container_i *NewStyleNS::activateContainer(CORBA::ORB_var orb, PortableServer::POA_var poa, int argc, char **argv)
236 return KERNEL::getContainerSA();
239 void NewStyleNS::activateContainerManager(CORBA::ORB_var orb)
241 KERNEL::getLauncherSA();
244 void NewStyleNS::activateSession(CORBA::ORB_var orb, PortableServer::POA_var poa, QMutex *GUIMutex, QWaitCondition *GUILauncher, int argc, char ** argv)
246 SALOME_Fake_NamingService *ns=new SALOME_Fake_NamingService;
247 CommonActivateSession(orb,poa,GUIMutex,GUILauncher,ns,argc,argv);
250 void NewStyleNS::activateSALOMEDS(CORBA::ORB_var orb, PortableServer::POA_var poa)
252 ClientFactory::createStudyWithoutNS(orb,poa);
255 CORBA::Object_var NewStyleNS::forServerChecker(const char *NSName, int argc, char **argv)
257 SALOME_Fake_NamingService ns;
258 return ns.Resolve(NSName);
261 CosNaming::NamingContext_var NewStyleNS::checkTrueNamingServiceIfExpected(int argc, char **argv, bool& forceOK)
263 forceOK = true;//tell checker : forget it's always OK
264 return CosNaming::NamingContext::_nil();