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