]> SALOME platform Git repositories - modules/gui.git/blob - src/Session/Session_NS_wrapper.cxx
Salome HOME
GUI evolutions for salome gui without neither NS nor other servers.
[modules/gui.git] / src / Session / Session_NS_wrapper.cxx
1 // Copyright (C) 2021  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
20 #include "Session_NS_wrapper.hxx"
21
22 #include "SALOME_Fake_NamingService.hxx"
23 #include "SALOME_Container_i.hxx"
24 #include "SALOME_Launcher.hxx"
25 #include "SALOMEDSClient_ClientFactory.hxx"
26
27 #include "Session_Session_i.hxx"
28 #include "Session_Promises.hxx"
29 #include "utilities.h"
30
31 const char OldStyleNS::LibName[]="SalomeApp";
32 const char NewStyleNS::LibName[]="SalomeAppSL";
33
34 void CommonActivateSession(CORBA::ORB_var orb, PortableServer::POA_var poa, QMutex *GUIMutex, QWaitCondition *GUILauncher, SALOME_NamingService_Abstract *ns, int argc, char ** argv)
35 {
36   try {
37     MESSAGE("Session thread started");
38     SALOME_Session_i * mySALOME_Session = nullptr;
39     if(!ns)
40       mySALOME_Session = new SALOME_Session_i(argc, argv, orb, poa, GUIMutex, GUILauncher);
41     else
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)");
45     
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();
51     
52     mySALOME_Session->NSregister();
53   }
54   catch (CORBA::SystemException&) {
55     INFOS("Caught CORBA::SystemException.");
56   }
57   catch (CORBA::Exception&) {
58     INFOS("Caught CORBA::Exception.");
59   }
60   catch (...) {
61     INFOS("Caught unknown exception.");
62   }
63 }
64
65 Engines_Container_i *OldStyleNS::activateContainer(CORBA::ORB_var orb, PortableServer::POA_var poa, int argc, char **argv)
66 {
67   Engines_Container_i *_container = nullptr;
68   try
69   {
70     MESSAGE("Container thread started");
71
72     // get or create the child POA
73
74     PortableServer::POA_var factory_poa;
75     try
76     {
77       factory_poa = poa->find_POA("factory_poa", 0);
78       // 0 = no activation (already done if exists)
79     }
80     catch (PortableServer::POA::AdapterNonExistent &)
81     {
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
90
91       // create policy list
92       CORBA::PolicyList policyList;
93       policyList.length(2);
94       policyList[0] = PortableServer::ImplicitActivationPolicy::
95           _duplicate(implicitActivation);
96       policyList[1] = PortableServer::ThreadPolicy::
97           _duplicate(threadPolicy);
98
99       PortableServer::POAManager_var nil_mgr = PortableServer::POAManager::_nil();
100       factory_poa = poa->create_POA("factory_poa",
101                                     nil_mgr,
102                                     policyList);
103       //with nil_mgr instead of pman,
104       //a new POA manager is created with the new POA
105
106       // destroy policy objects
107       implicitActivation->destroy();
108       threadPolicy->destroy();
109
110       // obtain the factory poa manager
111       PortableServer::POAManager_var pmanfac = factory_poa->the_POAManager();
112       pmanfac->activate();
113       MESSAGE("pmanfac->activate()");
114     }
115
116     char *containerName = (char *)"";
117     if (argc > 1)
118     {
119       containerName = argv[1];
120     }
121     _container = new Engines_Container_i(orb, poa, containerName, argc, argv, nullptr, false);
122   }
123   catch (CORBA::SystemException &)
124   {
125     INFOS("Caught CORBA::SystemException.");
126   }
127   catch (PortableServer::POA::WrongPolicy &)
128   {
129     INFOS("Caught CORBA::WrongPolicyException.");
130   }
131   catch (PortableServer::POA::ServantAlreadyActive &)
132   {
133     INFOS("Caught CORBA::ServantAlreadyActiveException");
134   }
135   catch (CORBA::Exception &)
136   {
137     INFOS("Caught CORBA::Exception.");
138   }
139   catch (...)
140   {
141     INFOS("Caught unknown exception.");
142   }
143   return _container;
144 }
145
146 void OldStyleNS::activateContainerManager(CORBA::ORB_var orb)
147 {
148   try {
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);
152   }
153   catch(CORBA::SystemException&) {
154     INFOS("Caught CORBA::SystemException.");
155   }
156   catch(PortableServer::POA::WrongPolicy&) {
157     INFOS("Caught CORBA::WrongPolicyException.");
158   }
159   catch(PortableServer::POA::ServantAlreadyActive&) {
160     INFOS("Caught CORBA::ServantAlreadyActiveException");
161   }
162   catch(CORBA::Exception&) {
163     INFOS("Caught CORBA::Exception.");
164   }
165   catch(...) {
166     INFOS("Caught unknown exception.");
167   }
168 }
169
170 void OldStyleNS::activateSession(CORBA::ORB_var orb, PortableServer::POA_var poa, QMutex *GUIMutex, QWaitCondition *GUILauncher, int argc, char ** argv)
171 {
172   CommonActivateSession(orb,poa,GUIMutex,GUILauncher,nullptr,argc,argv);
173 }
174
175 void OldStyleNS::activateSALOMEDS(CORBA::ORB_var orb, PortableServer::POA_var poa)
176 {
177   try {
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
181     // longer needed.    
182     
183     ClientFactory::createStudy(orb,poa);
184   }
185   catch(CORBA::SystemException&) {
186     INFOS( "Caught CORBA::SystemException." );
187   }
188   catch(CORBA::Exception&) {
189     INFOS( "Caught CORBA::Exception." );
190   }
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() );
196   }
197   catch(...) {
198     INFOS( "Caught unknown exception." );
199   }
200 }
201
202 #include "Utils_ORB_INIT.hxx"
203 #include "Utils_SINGLETON.hxx"
204
205 CORBA::Object_var OldStyleNS::forServerChecker(const char *NSName, int argc, char **argv)
206 {
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() );
211   NS.init_orb( orb );
212   CORBA::Object_var obj = NS.Resolve( NSName );
213   return obj;
214 }
215
216 CosNaming::NamingContext_var OldStyleNS::checkTrueNamingServiceIfExpected(int argc, char **argv, bool& forceOK)
217 {
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;
224 }
225
226 #include "SALOME_KernelServices.hxx"
227
228 void NewStyleNS::defineDefaultSALOMEKERNELNamingService()
229 {
230   KERNEL::assignNamingServiceSL();
231 }
232
233 Engines_Container_i *NewStyleNS::activateContainer(CORBA::ORB_var orb, PortableServer::POA_var poa, int argc, char **argv)
234 {
235   return KERNEL::getContainerSA();
236 }
237
238 void NewStyleNS::activateContainerManager(CORBA::ORB_var orb)
239 {
240   KERNEL::getLauncherSA();
241 }
242
243 void NewStyleNS::activateSession(CORBA::ORB_var orb, PortableServer::POA_var poa, QMutex *GUIMutex, QWaitCondition *GUILauncher, int argc, char ** argv)
244 {
245   SALOME_Fake_NamingService *ns=new SALOME_Fake_NamingService;
246   CommonActivateSession(orb,poa,GUIMutex,GUILauncher,ns,argc,argv);
247 }
248
249 void NewStyleNS::activateSALOMEDS(CORBA::ORB_var orb, PortableServer::POA_var poa)
250 {
251   ClientFactory::createStudyWithoutNS(orb,poa);
252 }
253
254 CORBA::Object_var NewStyleNS::forServerChecker(const char *NSName, int argc, char **argv)
255 {
256   SALOME_Fake_NamingService ns;
257   return ns.Resolve(NSName);
258 }
259
260 CosNaming::NamingContext_var NewStyleNS::checkTrueNamingServiceIfExpected(int argc, char **argv, bool& forceOK)
261 {
262   forceOK = true;//tell checker : forget it's always OK
263   return CosNaming::NamingContext::_nil();
264 }