Salome HOME
Fix compilation pb.
[modules/kernel.git] / src / Launcher / SALOME_LauncherServer.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 #include "SALOME_Launcher.hxx"
21 #include "utilities.h"
22 #include <sstream>
23 #include <iostream>
24 #include <stdexcept>
25 using namespace std;
26
27 void AttachDebugger()
28 {
29   if(getenv ("DEBUGGER"))
30     {
31       std::stringstream exec;
32       exec << "$DEBUGGER SALOME_LauncherServer " << getpid() << "&";
33       std::cerr << exec.str() << std::endl;
34       system(exec.str().c_str());
35       while(1);
36     }
37 }
38
39 void terminateHandler(void)
40 {
41   std::cerr << "Terminate: not managed exception !"  << std::endl;
42   AttachDebugger();
43 }
44
45 void unexpectedHandler(void)
46 {
47   std::cerr << "Unexpected: unexpected exception !"  << std::endl;
48   AttachDebugger();
49 }
50
51
52 int main(int argc, char* argv[])
53 {
54   if(getenv ("DEBUGGER"))
55     {
56 //       setsig(SIGSEGV,&Handler);
57       set_terminate(&terminateHandler);
58       set_unexpected(&unexpectedHandler);
59     }
60   PortableServer::POA_var root_poa;
61   PortableServer::POAManager_var pman;
62   CORBA::Object_var obj;
63
64   CORBA::ORB_ptr orb = CORBA::ORB_init( argc , argv ) ;
65   //  LocalTraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
66   INFOS_COMPILATION;
67   BEGIN_OF(argv[0]);
68   try{ 
69     obj = orb->resolve_initial_references("RootPOA");
70     if(!CORBA::is_nil(obj))
71       root_poa = PortableServer::POA::_narrow(obj);
72     if(!CORBA::is_nil(root_poa))
73       pman = root_poa->the_POAManager();
74   }
75   catch(CORBA::COMM_FAILURE&){
76     MESSAGE( "Container: CORBA::COMM_FAILURE: Unable to contact the Naming Service" );
77   }
78   try{
79     SALOME_Launcher *lServ=new SALOME_Launcher(orb,root_poa);
80     pman->activate();
81     orb->run();
82   }catch(CORBA::SystemException&){
83     MESSAGE("Caught CORBA::SystemException.");
84   }catch(PortableServer::POA::WrongPolicy&){
85     MESSAGE("Caught CORBA::WrongPolicyException.");
86   }catch(PortableServer::POA::ServantAlreadyActive&){
87     MESSAGE("Caught CORBA::ServantAlreadyActiveException");
88   }catch(CORBA::Exception&){
89     MESSAGE("Caught CORBA::Exception.");
90   }catch(std::exception& exc){
91     MESSAGE("Caught std::exception - "<<exc.what()); 
92   }catch(...){
93     MESSAGE("Caught unknown exception.");
94   }
95   END_OF(argv[0]);
96   //  delete myThreadTrace;
97 }
98