1 // Copyright (C) 2021 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 "SALOME_Fake_NamingService.hxx"
23 #include "SALOME_Container_i.hxx"
24 #include "SALOME_Launcher.hxx"
25 #include "SALOMEDSClient_ClientFactory.hxx"
27 #include "Session_Session_i.hxx"
28 #include "Session_Promises.hxx"
29 #include "utilities.h"
31 const char OldStyleNS::LibName[]="SalomeApp";
32 const char NewStyleNS::LibName[]="SalomeAppSL";
34 void CommonActivateSession(CORBA::ORB_var orb, PortableServer::POA_var poa, QMutex *GUIMutex, QWaitCondition *GUILauncher, SALOME_NamingService_Abstract *ns, int argc, char ** argv)
37 MESSAGE("Session thread started");
38 SALOME_Session_i * mySALOME_Session = nullptr;
40 mySALOME_Session = new SALOME_Session_i(argc, argv, orb, poa, GUIMutex, GUILauncher);
42 mySALOME_Session = new SALOME_Session_i(argc, argv, orb, poa, GUIMutex, GUILauncher,ns);
43 PortableServer::ObjectId_var mySALOME_Sessionid = poa->activate_object(mySALOME_Session);
44 MESSAGE("poa->activate_object(mySALOME_Session)");
46 CORBA::Object_var obj = mySALOME_Session->_this();
47 SALOME::Session_var objC = SALOME::Session::_narrow(obj);
48 GetSessionRefSingleton()->set_value(objC);
49 CORBA::String_var sior(orb->object_to_string(obj));
50 mySALOME_Session->_remove_ref();
52 mySALOME_Session->NSregister();
54 catch (CORBA::SystemException&) {
55 INFOS("Caught CORBA::SystemException.");
57 catch (CORBA::Exception&) {
58 INFOS("Caught CORBA::Exception.");
61 INFOS("Caught unknown exception.");
65 Engines_Container_i *OldStyleNS::activateContainer(CORBA::ORB_var orb, PortableServer::POA_var poa, int argc, char **argv)
67 Engines_Container_i *_container = nullptr;
70 MESSAGE("Container thread started");
72 // get or create the child POA
74 PortableServer::POA_var factory_poa;
77 factory_poa = poa->find_POA("factory_poa", 0);
78 // 0 = no activation (already done if exists)
80 catch (PortableServer::POA::AdapterNonExistent &)
82 MESSAGE("factory_poa does not exists, create...");
83 // define policy objects
84 PortableServer::ImplicitActivationPolicy_var implicitActivation =
85 poa->create_implicit_activation_policy(PortableServer::NO_IMPLICIT_ACTIVATION);
86 // default = NO_IMPLICIT_ACTIVATION
87 PortableServer::ThreadPolicy_var threadPolicy =
88 poa->create_thread_policy(PortableServer::ORB_CTRL_MODEL);
89 // default = ORB_CTRL_MODEL, other choice SINGLE_THREAD_MODEL
92 CORBA::PolicyList policyList;
94 policyList[0] = PortableServer::ImplicitActivationPolicy::
95 _duplicate(implicitActivation);
96 policyList[1] = PortableServer::ThreadPolicy::
97 _duplicate(threadPolicy);
99 PortableServer::POAManager_var nil_mgr = PortableServer::POAManager::_nil();
100 factory_poa = poa->create_POA("factory_poa",
103 //with nil_mgr instead of pman,
104 //a new POA manager is created with the new POA
106 // destroy policy objects
107 implicitActivation->destroy();
108 threadPolicy->destroy();
110 // obtain the factory poa manager
111 PortableServer::POAManager_var pmanfac = factory_poa->the_POAManager();
113 MESSAGE("pmanfac->activate()");
116 char *containerName = (char *)"";
119 containerName = argv[1];
121 _container = new Engines_Container_i(orb, poa, containerName, argc, argv, nullptr, false);
123 catch (CORBA::SystemException &)
125 INFOS("Caught CORBA::SystemException.");
127 catch (PortableServer::POA::WrongPolicy &)
129 INFOS("Caught CORBA::WrongPolicyException.");
131 catch (PortableServer::POA::ServantAlreadyActive &)
133 INFOS("Caught CORBA::ServantAlreadyActiveException");
135 catch (CORBA::Exception &)
137 INFOS("Caught CORBA::Exception.");
141 INFOS("Caught unknown exception.");
146 void OldStyleNS::activateContainerManager(CORBA::ORB_var orb)
149 PortableServer::POA_var root_poa=PortableServer::POA::_the_root_poa();
150 std::cout << "Activate SalomeLauncher ......!!!! " << std::endl;
151 new SALOME_Launcher(orb,root_poa);
153 catch(CORBA::SystemException&) {
154 INFOS("Caught CORBA::SystemException.");
156 catch(PortableServer::POA::WrongPolicy&) {
157 INFOS("Caught CORBA::WrongPolicyException.");
159 catch(PortableServer::POA::ServantAlreadyActive&) {
160 INFOS("Caught CORBA::ServantAlreadyActiveException");
162 catch(CORBA::Exception&) {
163 INFOS("Caught CORBA::Exception.");
166 INFOS("Caught unknown exception.");
170 void OldStyleNS::activateSession(CORBA::ORB_var orb, PortableServer::POA_var poa, QMutex *GUIMutex, QWaitCondition *GUILauncher, int argc, char ** argv)
172 CommonActivateSession(orb,poa,GUIMutex,GUILauncher,nullptr,argc,argv);
175 void OldStyleNS::activateSALOMEDS(CORBA::ORB_var orb, PortableServer::POA_var poa)
178 MESSAGE("SALOMEDS thread started");
179 // We allocate the objects on the heap. Since these are reference
180 // counted objects, they will be deleted by the POA when they are no
183 ClientFactory::createStudy(orb,poa);
185 catch(CORBA::SystemException&) {
186 INFOS( "Caught CORBA::SystemException." );
188 catch(CORBA::Exception&) {
189 INFOS( "Caught CORBA::Exception." );
191 catch(omniORB::fatalException& fe) {
192 INFOS( "Caught omniORB::fatalException:" );
193 INFOS( " file: " << fe.file() );
194 INFOS( " line: " << fe.line() );
195 INFOS( " mesg: " << fe.errmsg() );
198 INFOS( "Caught unknown exception." );
202 #include "Utils_ORB_INIT.hxx"
203 #include "Utils_SINGLETON.hxx"
205 CORBA::Object_var OldStyleNS::forServerChecker(const char *NSName, int argc, char **argv)
207 ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
208 CORBA::ORB_var orb = init( argc, argv );
209 SALOME_NamingService &NS = *SINGLETON_<SALOME_NamingService>::Instance();
210 ASSERT( SINGLETON_<SALOME_NamingService>::IsAlreadyExisting() );
212 CORBA::Object_var obj = NS.Resolve( NSName );
216 CosNaming::NamingContext_var OldStyleNS::checkTrueNamingServiceIfExpected(int argc, char **argv, bool& forceOK)
218 forceOK = false;//tell checker : do as before
219 ORB_INIT& init = *SINGLETON_<ORB_INIT>::Instance();
220 CORBA::ORB_var orb = init( argc, argv );
221 CORBA::Object_var obj = orb->resolve_initial_references( "NameService" );
222 CosNaming::NamingContext_var _root_context = CosNaming::NamingContext::_narrow( obj );
223 return _root_context;
226 #include "SALOME_KernelServices.hxx"
228 void NewStyleNS::defineDefaultSALOMEKERNELNamingService()
230 KERNEL::assignNamingServiceSL();
233 Engines_Container_i *NewStyleNS::activateContainer(CORBA::ORB_var orb, PortableServer::POA_var poa, int argc, char **argv)
235 return KERNEL::getContainerSA();
238 void NewStyleNS::activateContainerManager(CORBA::ORB_var orb)
240 KERNEL::getLauncherSA();
243 void NewStyleNS::activateSession(CORBA::ORB_var orb, PortableServer::POA_var poa, QMutex *GUIMutex, QWaitCondition *GUILauncher, int argc, char ** argv)
245 SALOME_Fake_NamingService *ns=new SALOME_Fake_NamingService;
246 CommonActivateSession(orb,poa,GUIMutex,GUILauncher,ns,argc,argv);
249 void NewStyleNS::activateSALOMEDS(CORBA::ORB_var orb, PortableServer::POA_var poa)
251 ClientFactory::createStudyWithoutNS(orb,poa);
254 CORBA::Object_var NewStyleNS::forServerChecker(const char *NSName, int argc, char **argv)
256 SALOME_Fake_NamingService ns;
257 return ns.Resolve(NSName);
260 CosNaming::NamingContext_var NewStyleNS::checkTrueNamingServiceIfExpected(int argc, char **argv, bool& forceOK)
262 forceOK = true;//tell checker : forget it's always OK
263 return CosNaming::NamingContext::_nil();