Back to index

salome-kernel  6.5.0
SALOME_LauncherServer.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include "SALOME_Launcher.hxx"
00024 #include "utilities.h"
00025 #include <sstream>
00026 #include <iostream>
00027 #include <stdexcept>
00028 #include <libxml/parser.h>
00029 
00030 void AttachDebugger();
00031 void terminateHandler(void);
00032 void unexpectedHandler(void);
00033 
00034 void AttachDebugger()
00035 {
00036 #ifndef WIN32
00037   if(getenv ("DEBUGGER"))
00038     {
00039       std::stringstream exec;
00040       exec << "$DEBUGGER SALOME_LauncherServer " << getpid() << "&";
00041       MESSAGE ( exec.str() );
00042       system(exec.str().c_str());
00043       while(1);
00044     }
00045 #endif
00046 }
00047 
00048 void terminateHandler(void)
00049 {
00050   MESSAGE ( "Terminate: not managed exception !"  );
00051   AttachDebugger();
00052 }
00053 
00054 void unexpectedHandler(void)
00055 {
00056   MESSAGE ( "Unexpected: unexpected exception !"  );
00057   AttachDebugger();
00058 }
00059 
00060 
00061 int main(int argc, char* argv[])
00062 {
00063   if(getenv ("DEBUGGER"))
00064     {
00065 //       setsig(SIGSEGV,&Handler);
00066       std::set_terminate(&terminateHandler);
00067       std::set_unexpected(&unexpectedHandler);
00068     }
00069   /* Init libxml 
00070    * To avoid memory leak, need to call xmlInitParser in the main thread
00071    * and not call xmlCleanupParser later (cause implicit reinitialization in thread)
00072    */
00073   xmlInitParser();
00074 
00075   PortableServer::POA_var root_poa;
00076   PortableServer::POAManager_var pman;
00077   CORBA::Object_var obj;
00078 
00079   CORBA::ORB_var orb = CORBA::ORB_init( argc , argv ) ;
00080   //  LocalTraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
00081   INFOS_COMPILATION;
00082   BEGIN_OF(argv[0]);
00083   try{ 
00084     obj = orb->resolve_initial_references("RootPOA");
00085     if(!CORBA::is_nil(obj))
00086       root_poa = PortableServer::POA::_narrow(obj);
00087     if(!CORBA::is_nil(root_poa))
00088       pman = root_poa->the_POAManager();
00089   }
00090   catch(CORBA::COMM_FAILURE&){
00091     MESSAGE( "Container: CORBA::COMM_FAILURE: Unable to contact the Naming Service" );
00092   }
00093   try{
00094     SALOME_Launcher *lServ=new SALOME_Launcher(orb,root_poa);
00095     pman->activate();
00096     lServ->_remove_ref();
00097     orb->run();
00098     orb->destroy();
00099   }catch(CORBA::SystemException&){
00100     MESSAGE("Caught CORBA::SystemException.");
00101   }catch(PortableServer::POA::WrongPolicy&){
00102     MESSAGE("Caught CORBA::WrongPolicyException.");
00103   }catch(PortableServer::POA::ServantAlreadyActive&){
00104     MESSAGE("Caught CORBA::ServantAlreadyActiveException");
00105   }catch(CORBA::Exception&){
00106     MESSAGE("Caught CORBA::Exception.");
00107   }catch(std::exception& exc){
00108     MESSAGE("Caught std::exception - "<<exc.what()); 
00109   }catch(...){
00110     MESSAGE("Caught unknown exception.");
00111   }
00112   END_OF(argv[0]);
00113   //  delete myThreadTrace;
00114 }
00115