1 // Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "SALOME_Launcher.hxx"
24 #include "SALOMESDS_DataServerManager.hxx"
25 #include "SALOME_ExternalServerLauncher.hxx"
26 #include "SALOME_CPythonHelper.hxx"
27 #include "utilities.h"
31 #include <libxml/parser.h>
33 void AttachDebugger();
34 void terminateHandler(void);
35 void unexpectedHandler(void);
40 if(getenv ("DEBUGGER"))
42 std::stringstream exec;
43 exec << "$DEBUGGER SALOME_LauncherServer " << getpid() << "&";
44 MESSAGE ( exec.str() );
45 system(exec.str().c_str());
51 void terminateHandler(void)
53 MESSAGE ( "Terminate: not managed exception !" );
57 void unexpectedHandler(void)
59 MESSAGE ( "Unexpected: unexpected exception !" );
64 int main(int argc, char* argv[])
66 if(getenv ("DEBUGGER"))
68 // setsig(SIGSEGV,&Handler);
69 std::set_terminate(&terminateHandler);
70 std::set_unexpected(&unexpectedHandler);
73 * To avoid memory leak, need to call xmlInitParser in the main thread
74 * and not call xmlCleanupParser later (cause implicit reinitialization in thread)
78 PortableServer::POA_var root_poa;
79 PortableServer::POAManager_var pman;
80 CORBA::Object_var obj;
84 char **myArgv(new char *[myArgc]);
85 for(int i=0;i<argc;i++)
86 myArgv[i]=strdup(argv[i]);
87 myArgv[argc+0]=strdup("-ORBsupportCurrent");
88 myArgv[argc+1]=strdup("0");
89 orb = CORBA::ORB_init( myArgc , myArgv ) ;
90 for(int i=0;i<myArgc;i++)
94 // LocalTraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
98 obj = orb->resolve_initial_references("RootPOA");
99 if(!CORBA::is_nil(obj))
100 root_poa = PortableServer::POA::_narrow(obj);
101 if(!CORBA::is_nil(root_poa))
103 pman = root_poa->the_POAManager();
107 catch(CORBA::COMM_FAILURE&){
108 MESSAGE( "Container: CORBA::COMM_FAILURE: Unable to contact the Naming Service" );
112 CORBA::PolicyList policies;
114 PortableServer::ThreadPolicy_var threadPol(root_poa->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL));
115 policies[0] = PortableServer::ThreadPolicy::_duplicate(threadPol);
116 PortableServer::POA_var safePOA = root_poa->create_POA("SingleThreadPOA",pman,policies);
117 threadPol->destroy();
118 SALOME_CPythonHelper cPyh;
119 cPyh.initializePython(argc,argv);
120 SALOME_Launcher *lServ(new SALOME_Launcher(orb,safePOA));
121 lServ->_remove_ref();
123 SALOMESDS::DataServerManager *dsm(new SALOMESDS::DataServerManager(&cPyh,orb,root_poa));
126 SALOME_ExternalServerLauncher *esm(new SALOME_ExternalServerLauncher(&cPyh,orb,safePOA));
132 catch(CORBA::SystemException&){
133 MESSAGE("Caught CORBA::SystemException.");
134 }catch(PortableServer::POA::WrongPolicy&){
135 MESSAGE("Caught CORBA::WrongPolicyException.");
136 }catch(PortableServer::POA::ServantAlreadyActive&){
137 MESSAGE("Caught CORBA::ServantAlreadyActiveException");
138 }catch(CORBA::Exception&){
139 MESSAGE("Caught CORBA::Exception.");
140 }catch(std::exception& exc){
141 MESSAGE("Caught std::exception - "<<exc.what());
143 MESSAGE("Caught unknown exception.");
146 // delete myThreadTrace;