]> SALOME platform Git repositories - modules/kernel.git/blob - src/Launcher/SALOME_LauncherServer.cxx
Salome HOME
Porting functionality on Win32 Platform
[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 #include <libxml/parser.h>
26
27 using namespace std;
28
29 void AttachDebugger()
30 {
31 #ifndef WIN32
32   if(getenv ("DEBUGGER"))
33     {
34       std::stringstream exec;
35       exec << "$DEBUGGER SALOME_LauncherServer " << getpid() << "&";
36       MESSAGE ( exec.str() );
37       system(exec.str().c_str());
38       while(1);
39     }
40 #endif
41 }
42
43 void terminateHandler(void)
44 {
45   MESSAGE ( "Terminate: not managed exception !"  );
46   AttachDebugger();
47 }
48
49 void unexpectedHandler(void)
50 {
51   MESSAGE ( "Unexpected: unexpected exception !"  );
52   AttachDebugger();
53 }
54
55
56 int main(int argc, char* argv[])
57 {
58   if(getenv ("DEBUGGER"))
59     {
60 //       setsig(SIGSEGV,&Handler);
61       set_terminate(&terminateHandler);
62       set_unexpected(&unexpectedHandler);
63     }
64   /* Init libxml 
65    * To avoid memory leak, need to call xmlInitParser in the main thread
66    * and not call xmlCleanupParser later (cause implicit reinitialization in thread)
67    */
68   xmlInitParser();
69
70   PortableServer::POA_var root_poa;
71   PortableServer::POAManager_var pman;
72   CORBA::Object_var obj;
73
74   CORBA::ORB_var orb = CORBA::ORB_init( argc , argv ) ;
75   //  LocalTraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
76   INFOS_COMPILATION;
77   BEGIN_OF(argv[0]);
78   try{ 
79     obj = orb->resolve_initial_references("RootPOA");
80     if(!CORBA::is_nil(obj))
81       root_poa = PortableServer::POA::_narrow(obj);
82     if(!CORBA::is_nil(root_poa))
83       pman = root_poa->the_POAManager();
84   }
85   catch(CORBA::COMM_FAILURE&){
86     MESSAGE( "Container: CORBA::COMM_FAILURE: Unable to contact the Naming Service" );
87   }
88   try{
89     SALOME_Launcher *lServ=new SALOME_Launcher(orb,root_poa);
90     pman->activate();
91     lServ->_remove_ref();
92     orb->run();
93     orb->destroy();
94   }catch(CORBA::SystemException&){
95     MESSAGE("Caught CORBA::SystemException.");
96   }catch(PortableServer::POA::WrongPolicy&){
97     MESSAGE("Caught CORBA::WrongPolicyException.");
98   }catch(PortableServer::POA::ServantAlreadyActive&){
99     MESSAGE("Caught CORBA::ServantAlreadyActiveException");
100   }catch(CORBA::Exception&){
101     MESSAGE("Caught CORBA::Exception.");
102   }catch(std::exception& exc){
103     MESSAGE("Caught std::exception - "<<exc.what()); 
104   }catch(...){
105     MESSAGE("Caught unknown exception.");
106   }
107   END_OF(argv[0]);
108   //  delete myThreadTrace;
109 }
110