Salome HOME
PR: merge from branch BR_auto_V310 tag mergefrom_OCC_development_for_3_2_0a2_10mar06
[modules/kernel.git] / src / Container / SALOME_Container.cxx
1 //  SALOME Container : implementation of container and engine for Kernel
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SALOME_Container.cxx
25 //  Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
26 //  Module : SALOME
27 //  $Header$
28
29 #ifdef HAVE_MPI2
30 #include <mpi.h>
31 #endif
32
33 #include <iostream>
34 #include <strstream>
35 #include <string>
36 #include <stdio.h>
37 #include <time.h>
38 #include <sys/time.h>
39 #include <dlfcn.h>
40
41 #ifndef WNT
42 #include <unistd.h>
43 #else
44 #include <process.h>
45 #endif
46 #include "SALOME_Container_i.hxx"
47 #include "utilities.h"
48 #include "Utils_ORB_INIT.hxx"
49 #include "Utils_SINGLETON.hxx"
50 #include "OpUtil.hxx"
51
52 #ifdef CHECKTIME
53 #include <Utils_Timer.hxx>
54 #endif
55
56 #include "Container_init_python.hxx"
57
58 using namespace std;
59
60 extern "C" void HandleServerSideSignals(CORBA::ORB_ptr theORB);
61
62 int main(int argc, char* argv[])
63 {
64 #ifdef HAVE_MPI2
65   MPI_Init(&argc,&argv);
66 #endif
67
68   // Initialise the ORB.
69   //SRN: BugID: IPAL9541, it's necessary to set a size of one message to be at least 100Mb
70   //CORBA::ORB_var orb = CORBA::ORB_init( argc , argv ) ;
71   ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
72   ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
73   CORBA::ORB_ptr orb = init(0 , 0 ) ;
74           
75   //  LocalTraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
76   INFOS_COMPILATION;
77   BEGIN_OF(argv[0]);
78
79   ASSERT(argc > 1);
80   SCRUTE(argv[1]);
81   bool isSupervContainer = false;
82   if (strcmp(argv[1],"SuperVisionContainer") == 0) isSupervContainer = true;
83
84   if (!isSupervContainer)
85     {
86       int _argc = 1;
87       char* _argv[] = {""};
88       KERNEL_PYTHON::init_python(argc,argv);
89     }
90   else
91     {
92       Py_Initialize() ;
93       PySys_SetArgv( argc , argv ) ;
94     }
95     
96   char *containerName = "";
97   if(argc > 1)
98     {
99       containerName = argv[1] ;
100     }
101
102   try
103     {  
104       CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
105       ASSERT(!CORBA::is_nil(obj));
106       PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
107
108       PortableServer::POAManager_var pman = root_poa->the_POAManager();
109
110       // add new container to the kill list
111 #ifndef WNT
112       ostrstream aCommand ;
113       aCommand << "addToKillList.py " << getpid() << " SALOME_Container" << ends ;
114       system(aCommand.str());
115 #endif
116       
117       Engines_Container_i * myContainer 
118         = new Engines_Container_i(orb, root_poa, containerName , argc , argv );
119       
120       pman->activate();
121       
122 #ifdef CHECKTIME
123       Utils_Timer timer;
124       timer.Start();
125       timer.Stop();
126       timer.ShowAbsolute();
127 #endif
128
129       HandleServerSideSignals(orb);
130       
131     }
132   catch(CORBA::SystemException&)
133     {
134       INFOS("Caught CORBA::SystemException.");
135     }
136   catch(PortableServer::POA::ServantAlreadyActive&)
137     {
138       INFOS("Caught CORBA::ServantAlreadyActiveException");
139     }
140   catch(CORBA::Exception&)
141     {
142       INFOS("Caught CORBA::Exception.");
143     }
144   catch(std::exception& exc)
145     {
146       INFOS("Caught std::exception - "<<exc.what()); 
147     }
148   catch(...)
149     {
150       INFOS("Caught unknown exception.");
151     }
152
153 #ifdef HAVE_MPI2
154   MPI_Finalize();
155 #endif
156
157   //END_OF(argv[0]);
158   //LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
159   //bp1->deleteInstance(bp1);
160   return 0 ;
161 }
162