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