Salome HOME
Integrate missing files
[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.salome-platform.org/ or email : webmaster.salome@opencascade.com
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 #ifndef WNT
39 # include <sys/time.h>
40 # include <dlfcn.h>
41 #endif
42
43
44 #ifndef WNT
45 #include <unistd.h>
46 #else
47 #include <process.h>
48 #endif
49 #include "SALOME_Container_i.hxx"
50 #include "utilities.h"
51 #include "Utils_ORB_INIT.hxx"
52 #include "Utils_SINGLETON.hxx"
53 #include "OpUtil.hxx"
54
55 #ifdef CHECKTIME
56 #include <Utils_Timer.hxx>
57 #endif
58
59 #include "Container_init_python.hxx"
60
61 using namespace std;
62
63 extern "C" void HandleServerSideSignals(CORBA::ORB_ptr theORB);
64
65 int main(int argc, char* argv[])
66 {
67 #ifdef HAVE_MPI2
68   MPI_Init(&argc,&argv);
69 #endif
70
71   // Initialise the ORB.
72   //SRN: BugID: IPAL9541, it's necessary to set a size of one message to be at least 100Mb
73   //CORBA::ORB_var orb = CORBA::ORB_init( argc , argv ) ;
74   ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
75   ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
76   CORBA::ORB_ptr orb = init(argc , argv ) ;
77           
78   //  LocalTraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
79   INFOS_COMPILATION;
80   BEGIN_OF(argv[0]);
81
82   ASSERT(argc > 1);
83   SCRUTE(argv[1]);
84   bool isSupervContainer = false;
85   if (strcmp(argv[1],"SuperVisionContainer") == 0) isSupervContainer = true;
86
87   if (!isSupervContainer)
88     {
89       int _argc = 1;
90       char* _argv[] = {""};
91       KERNEL_PYTHON::init_python(argc,argv);
92     }
93   else
94     {
95       Py_Initialize() ;
96       PySys_SetArgv( argc , argv ) ;
97     }
98     
99   char *containerName = "";
100   if(argc > 1)
101     {
102       containerName = argv[1] ;
103     }
104
105   try
106     {  
107       CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
108       ASSERT(!CORBA::is_nil(obj));
109       PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
110
111       PortableServer::POAManager_var pman = root_poa->the_POAManager();
112
113       // add new container to the kill list
114 #ifndef WNT
115       ostrstream aCommand ;
116       aCommand << "addToKillList.py " << getpid() << " SALOME_Container" << ends ;
117       system(aCommand.str());
118 #endif
119       
120       Engines_Container_i * myContainer 
121         = new Engines_Container_i(orb, root_poa, containerName , argc , argv );
122       
123       pman->activate();
124       
125 #ifdef CHECKTIME
126       Utils_Timer timer;
127       timer.Start();
128       timer.Stop();
129       timer.ShowAbsolute();
130 #endif
131
132       HandleServerSideSignals(orb);
133       
134     }
135   catch(CORBA::SystemException&)
136     {
137       INFOS("Caught CORBA::SystemException.");
138     }
139   catch(PortableServer::POA::ServantAlreadyActive&)
140     {
141       INFOS("Caught CORBA::ServantAlreadyActiveException");
142     }
143   catch(CORBA::Exception&)
144     {
145       INFOS("Caught CORBA::Exception.");
146     }
147   catch(std::exception& exc)
148     {
149       INFOS("Caught std::exception - "<<exc.what()); 
150     }
151   catch(...)
152     {
153       INFOS("Caught unknown exception.");
154     }
155
156 #ifdef HAVE_MPI2
157   MPI_Finalize();
158 #endif
159
160   //END_OF(argv[0]);
161   //LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
162   //bp1->deleteInstance(bp1);
163   return 0 ;
164 }
165