Salome HOME
a53193848d0b6819bb914a69d7a34ffc3debb0ca
[modules/kernel.git] / src / Session / SALOME_Session_Server.cxx
1 //  SALOME Session : implementation of Session.idl
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SALOME_Session_Server.cxx
25 //  Author : Paul RASCLE, EDF
26 //  Module : SALOME
27 //  $Header$
28
29 # include "Utils_ORB_INIT.hxx"
30 # include "Utils_SINGLETON.hxx"
31
32 #include <iostream>
33 #include <unistd.h>
34 using namespace std;
35
36 #include <SALOMEconfig.h>
37 #include CORBA_SERVER_HEADER(SALOME_Session)
38
39 #include "utilities.h"
40
41 #include "SALOME_Session_i.hxx"
42
43 //! CORBA server for SALOME Session
44 /*!
45  *  SALOME_Session Server launches a SALOME session servant.
46  *  The servant registers to the Naming Service.
47  *  See SALOME_Session.idl for interface specification.
48  *
49  *  Main services offered by the servant are:
50  *   - launch GUI
51  *   - stop Session (must be idle)
52  *   - get session state
53  */
54
55 int main(int argc, char **argv)
56 {
57
58   try
59     {
60     ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
61     ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
62     CORBA::ORB_var &orb = init( argc , argv ) ;
63
64     CORBA::Object_var obj =orb->resolve_initial_references("RootPOA") ;
65     PortableServer::POA_var poa = PortableServer::POA::_narrow(obj) ;
66
67     // servant
68     SALOME_Session_i * mySALOME_Session = new SALOME_Session_i(argc, argv, orb, poa) ;
69     PortableServer::ObjectId_var mySALOME_Sessionid = poa->activate_object(mySALOME_Session) ;
70     MESSAGE("poa->activate_object(mySALOME_Session)")
71
72     obj = mySALOME_Session->_this() ;
73     CORBA::String_var sior(orb->object_to_string(obj)) ;
74
75     mySALOME_Session->NSregister();
76
77     mySALOME_Session->_remove_ref() ;
78
79     PortableServer::POAManager_var pman = poa->the_POAManager() ;
80     pman->activate() ;
81     MESSAGE("pman->activate()")
82
83     orb->run() ;
84     orb->destroy() ;
85     }
86     catch (CORBA::SystemException&)
87     {
88       INFOS("Caught CORBA::SystemException.")
89     }
90     catch (CORBA::Exception&)
91     {
92       INFOS("Caught CORBA::Exception.")
93     }
94     catch (...)
95     {
96       INFOS("Caught unknown exception.")
97     }
98   return 0 ;
99 }