Salome HOME
Updated copyright comment
[samples/component.git] / src / AddComponent / AddComponent_CheckOfUndefined.cxx
1 // Copyright (C) 2007-2024  CEA, EDF, 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 "SALOMETraceCollector.hxx"
42 #include "OpUtil.hxx"
43
44 #ifdef CHECKTIME
45 #include <Utils_Timer.hxx>
46 #endif
47
48 #ifdef HAVE_MPI2
49 #include <mpi.h>
50 #endif
51
52 //CCRT
53 #include <sstream>
54 #include <time.h>
55 #ifndef WIN32
56 #include <sys/time.h>
57 #include <sys/stat.h>
58 #endif
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 #if PY_VERSION_HEX < 0x03050000
68 static wchar_t*
69 Py_DecodeLocale(const char *arg, size_t *size)
70 {
71         return _Py_char2wchar(arg, size);
72 }
73 #endif
74
75 int main(int argc, char* argv[])
76 {
77 #ifdef HAVE_MPI2
78   MPI_Init(&argc,&argv);
79 #endif
80
81   // Initialise the ORB.
82   //SRN: BugID: IPAL9541, it's necessary to set a size of one message to be at least 100Mb
83   //CORBA::ORB_var orb = CORBA::ORB_init( argc , argv ) ;
84   CORBA::ORB_var orb = KERNEL::GetRefToORB();
85           
86   //SALOMETraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
87   INFOS_COMPILATION;
88   BEGIN_OF(argv[0]);
89
90   ASSERT(argc > 1);
91   SCRUTE(argv[1]);
92   bool isSupervContainer = false;
93   if (strcmp(argv[1],"SuperVisionContainer") == 0) isSupervContainer = true;
94
95   if (!isSupervContainer)
96     {
97       //int _argc = 1;
98       //char* _argv[] = {""};
99       KERNEL_PYTHON::init_python(argc,argv);
100     }
101   else
102     {
103       wchar_t **changed_argv = new wchar_t*[argc];
104       for (int i = 0; i < argc; i++) {
105         changed_argv[i] = Py_DecodeLocale(argv[i], NULL);
106       }
107       Py_Initialize() ;
108       PySys_SetArgv( argc , changed_argv ) ;
109     }
110     
111   char *containerName = "";
112   if(argc > 1)
113     {
114       containerName = argv[1] ;
115     }
116
117   try
118     {  
119       CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
120       ASSERT(!CORBA::is_nil(obj));
121       PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
122
123       PortableServer::POAManager_var pman = root_poa->the_POAManager();
124
125       // add new container to the kill list
126 #ifndef WNT
127       ostrstream aCommand ;
128       aCommand << "addToKillList.py " << getpid() << " SALOME_Container" << ends ;
129       system(aCommand.str());
130 #endif
131       
132       /*Engines_Container_i * myContainer 
133         = */new Engines_Container_i(orb, root_poa, containerName , argc , argv );
134       
135       pman->activate();
136       
137 #ifdef CHECKTIME
138       Utils_Timer timer;
139       timer.Start();
140       timer.Stop();
141       MESSAGE("SALOME_Registry_Server.cxx - orb->run()");
142       timer.ShowAbsolute();
143 #endif
144       
145       HandleServerSideSignals(orb);
146       
147     }
148   catch(CORBA::SystemException&)
149     {
150       INFOS("Caught CORBA::SystemException.");
151     }
152   catch(PortableServer::POA::ServantAlreadyActive&)
153     {
154       INFOS("Caught CORBA::ServantAlreadyActiveException");
155     }
156   catch(CORBA::Exception&)
157     {
158       INFOS("Caught CORBA::Exception.");
159     }
160   catch(std::exception& exc)
161     {
162       INFOS("Caught std::exception - "<<exc.what()); 
163     }
164   catch(...)
165     {
166       INFOS("Caught unknown exception.");
167     }
168
169 #ifdef HAVE_MPI2
170   MPI_Finalize();
171 #endif
172
173   END_OF(argv[0]);
174   //  delete myThreadTrace;
175   return 0 ;
176 }
177