1 // Copyright (C) 2007-2022 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 "ArgvKeeper.hxx"
24 #include "SALOME_Launcher.hxx"
25 #include "SALOMESDS_DataServerManager.hxx"
26 #include "SALOME_ExternalServerLauncher.hxx"
27 #include "SALOME_CPythonHelper.hxx"
29 #include "utilities.h"
35 #include <libxml/parser.h>
37 void AttachDebugger();
38 void terminateHandler(void);
39 void unexpectedHandler(void);
44 if(getenv ("DEBUGGER"))
46 std::stringstream exec;
47 exec << "$DEBUGGER SALOME_LauncherServer " << getpid() << "&";
48 MESSAGE ( exec.str() );
49 system(exec.str().c_str());
55 void terminateHandler(void)
57 MESSAGE ( "Terminate: not managed exception !" );
61 void unexpectedHandler(void)
63 MESSAGE ( "Unexpected: unexpected exception !" );
68 int main(int argc, char* argv[])
70 if(getenv ("DEBUGGER"))
72 // setsig(SIGSEGV,&Handler);
73 std::set_terminate(&terminateHandler);
74 //std::set_unexpected(&unexpectedHandler);
77 * To avoid memory leak, need to call xmlInitParser in the main thread
78 * and not call xmlCleanupParser later (cause implicit reinitialization in thread)
82 PortableServer::POA_var root_poa;
83 PortableServer::POAManager_var pman;
84 CORBA::Object_var obj;
87 std::vector<std::string> args;
88 for(int i=0;i<argc;i++)
89 args.push_back(argv[i]);
90 args.push_back("-ORBsupportCurrent");
93 orb = KERNEL::GetRefToORB();
95 // LocalTraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
99 obj = orb->resolve_initial_references("RootPOA");
100 if(!CORBA::is_nil(obj))
101 root_poa = PortableServer::POA::_narrow(obj);
102 if(!CORBA::is_nil(root_poa))
104 pman = root_poa->the_POAManager();
108 catch(CORBA::COMM_FAILURE&){
109 MESSAGE( "Container: CORBA::COMM_FAILURE: Unable to contact the Naming Service" );
113 CORBA::PolicyList policies;
115 PortableServer::ThreadPolicy_var threadPol(root_poa->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL));
116 policies[0] = PortableServer::ThreadPolicy::_duplicate(threadPol);
117 PortableServer::POA_var safePOA = root_poa->create_POA("SingleThreadPOA",pman,policies);
118 threadPol->destroy();
119 SALOME_CPythonHelper cPyh;
120 cPyh.initializePython(argc,argv);
121 SALOME_Launcher *lServ(new SALOME_Launcher(orb,safePOA));
122 lServ->DeclareUsingSalomeSession();
123 lServ->_remove_ref();
125 SALOMESDS::DataServerManager *dsm(new SALOMESDS::DataServerManager(&cPyh,orb,root_poa));
128 SALOME_ExternalServerLauncher *esm(new SALOME_ExternalServerLauncher(&cPyh,orb,safePOA));
134 catch(CORBA::SystemException&){
135 MESSAGE("Caught CORBA::SystemException.");
136 }catch(PortableServer::POA::WrongPolicy&){
137 MESSAGE("Caught CORBA::WrongPolicyException.");
138 }catch(PortableServer::POA::ServantAlreadyActive&){
139 MESSAGE("Caught CORBA::ServantAlreadyActiveException");
140 }catch(CORBA::Exception&){
141 MESSAGE("Caught CORBA::Exception.");
142 }catch(std::exception& exc){
143 MESSAGE("Caught std::exception - "<<exc.what());
145 MESSAGE("Caught unknown exception.");
148 // delete myThreadTrace;