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