Salome HOME
a8e7f508f8fb15c27c842b2d85ee0b45e58ae5c3
[modules/geom.git] / src / GEOM_I / GEOM_Gen_Session_i.cc
1 // Copyright (C) 2021-2023  CEA/DEN, EDF R&D
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 "GEOM_Gen_Session_i.hh"
21
22 GEOM_Gen_Session_i::GEOM_Gen_Session_i(CORBA::ORB_ptr orb,
23                         PortableServer::POA_ptr poa,
24                         PortableServer::ObjectId *contId,
25                         const char *instanceName,
26                         const char *interfaceName):GEOM_Gen_i(orb,poa,contId,instanceName,interfaceName,true)
27 {
28     name_service = new SALOME_NamingService(_orb);
29 }
30
31 GEOM_Gen_Session_i::~GEOM_Gen_Session_i()
32 {
33   delete name_service;
34 }
35
36 void GEOM_Gen_Session_i::register_name(char * name)
37 {
38   GEOM::GEOM_Gen_var g = _this();
39   name_service->Register(g, name);
40 }
41
42 SALOMEDS::Study_var GEOM_Gen_Session_i::getStudyServant()
43 {
44   static SALOMEDS::Study_var aStudy;
45   if(CORBA::is_nil(aStudy))
46   {
47     CORBA::Object_ptr anObject = name_service->Resolve("/Study");
48     aStudy = SALOMEDS::Study::_narrow(anObject);
49   }
50   return aStudy;
51 }
52
53 #include "GEOM_Gen_No_Session_i.hh"
54
55 extern "C"
56 {
57   GEOM_I_EXPORT  PortableServer::ObjectId* GEOMEngine_factory(CORBA::ORB_ptr orb,
58                                                PortableServer::POA_ptr       poa,
59                                                PortableServer::ObjectId*     contId,
60                                                const char*                   instanceName,
61                                                const char*                   interfaceName)
62   {
63     CORBA::Object_var o = poa->id_to_reference(*contId);
64     Engines::Container_var cont = Engines::Container::_narrow(o);
65     if(cont->is_SSL_mode())
66     {
67       GEOM_Gen_No_Session_i* myGEOM_Gen_i = new GEOM_Gen_No_Session_i(orb, poa, contId, instanceName, interfaceName);
68       return myGEOM_Gen_i->getId();
69     }
70     else
71     {
72       GEOM_Gen_Session_i* myGEOM_Gen_i = new GEOM_Gen_Session_i(orb, poa, contId, instanceName, interfaceName);
73       return myGEOM_Gen_i->getId();
74     }
75   }
76 }