Salome HOME
Merge branch 'V7_dev'
[modules/kernel.git] / src / Launcher / SALOME_LauncherServer.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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, or (at your option) any later version.
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "SALOME_Launcher.hxx"
24 #include "SALOMESDS_DataServerManager.hxx"
25 #include "utilities.h"
26 #include <sstream>
27 #include <iostream>
28 #include <stdexcept>
29 #include <libxml/parser.h>
30
31 void AttachDebugger();
32 void terminateHandler(void);
33 void unexpectedHandler(void);
34
35 void AttachDebugger()
36 {
37 #ifndef WIN32
38   if(getenv ("DEBUGGER"))
39     {
40       std::stringstream exec;
41       exec << "$DEBUGGER SALOME_LauncherServer " << getpid() << "&";
42       MESSAGE ( exec.str() );
43       system(exec.str().c_str());
44       while(1);
45     }
46 #endif
47 }
48
49 void terminateHandler(void)
50 {
51   MESSAGE ( "Terminate: not managed exception !"  );
52   AttachDebugger();
53 }
54
55 void unexpectedHandler(void)
56 {
57   MESSAGE ( "Unexpected: unexpected exception !"  );
58   AttachDebugger();
59 }
60
61
62 int main(int argc, char* argv[])
63 {
64   if(getenv ("DEBUGGER"))
65     {
66 //       setsig(SIGSEGV,&Handler);
67       std::set_terminate(&terminateHandler);
68       std::set_unexpected(&unexpectedHandler);
69     }
70   /* Init libxml 
71    * To avoid memory leak, need to call xmlInitParser in the main thread
72    * and not call xmlCleanupParser later (cause implicit reinitialization in thread)
73    */
74   xmlInitParser();
75
76   PortableServer::POA_var root_poa;
77   PortableServer::POAManager_var pman;
78   CORBA::Object_var obj;
79
80   CORBA::ORB_var orb = CORBA::ORB_init( argc , argv ) ;
81   //  LocalTraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
82   INFOS_COMPILATION;
83   BEGIN_OF(argv[0]);
84   try{ 
85     obj = orb->resolve_initial_references("RootPOA");
86     if(!CORBA::is_nil(obj))
87       root_poa = PortableServer::POA::_narrow(obj);
88     if(!CORBA::is_nil(root_poa))
89       {
90         pman = root_poa->the_POAManager();
91         pman->activate();
92       }
93   }
94   catch(CORBA::COMM_FAILURE&){
95     MESSAGE( "Container: CORBA::COMM_FAILURE: Unable to contact the Naming Service" );
96   }
97   try
98     {
99       SALOME_Launcher *lServ(new SALOME_Launcher(orb,root_poa));
100       lServ->_remove_ref();
101       //
102       SALOMESDS::DataServerManager *dsm(new SALOMESDS::DataServerManager(argc,argv,orb,root_poa));
103       dsm->_remove_ref();
104       //
105       orb->run();
106       orb->destroy();
107     }
108   catch(CORBA::SystemException&){
109     MESSAGE("Caught CORBA::SystemException.");
110   }catch(PortableServer::POA::WrongPolicy&){
111     MESSAGE("Caught CORBA::WrongPolicyException.");
112   }catch(PortableServer::POA::ServantAlreadyActive&){
113     MESSAGE("Caught CORBA::ServantAlreadyActiveException");
114   }catch(CORBA::Exception&){
115     MESSAGE("Caught CORBA::Exception.");
116   }catch(std::exception& exc){
117     MESSAGE("Caught std::exception - "<<exc.what()); 
118   }catch(...){
119     MESSAGE("Caught unknown exception.");
120   }
121   END_OF(argv[0]);
122   //  delete myThreadTrace;
123 }
124