Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SALOME_Container.cxx
25 //  Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
26 //  Module : SALOME
27 //  $Header$
28
29 using namespace std;
30 using namespace std;
31 #include <stdio.h>
32
33 # include "Utils_ORB_INIT.hxx"
34 # include "Utils_SINGLETON.hxx"
35
36 #include "SALOME_Container_i.hxx"
37 #include <iostream>
38 #include <string>
39 #include "utilities.h"
40
41 //#define CHECKTIME
42 #ifdef CHECKTIME
43 #include <Utils_Timer.hxx>
44 #endif
45
46 #include <Python.h>
47
48 static PyMethodDef MethodPyVoidMethod[] = {
49   { NULL,        NULL }
50 };
51
52 int main(int argc, char* argv[])
53 {
54   INFOS_COMPILATION;
55   BEGIN_OF(argv[0])
56
57   Py_Initialize() ;
58   PySys_SetArgv( argc , argv ) ;
59   Py_InitModule( "InitPyRunMethod" , MethodPyVoidMethod ) ;
60
61   try {
62     
63     // Initialise the ORB.
64 //     CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
65     ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
66     ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
67     CORBA::ORB_var &orb = init( argc , argv ) ;
68  
69     // Obtain a reference to the root POA.
70     CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
71     PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
72
73     // obtain the root poa manager
74     PortableServer::POAManager_var pman = root_poa->the_POAManager();
75
76     // define policy objects     
77     PortableServer::ImplicitActivationPolicy_var implicitActivation =
78       root_poa->create_implicit_activation_policy(PortableServer::NO_IMPLICIT_ACTIVATION) ;
79
80       // default = NO_IMPLICIT_ACTIVATION
81     PortableServer::ThreadPolicy_var threadPolicy =
82       root_poa->create_thread_policy(PortableServer::ORB_CTRL_MODEL) ;
83       // default = ORB_CTRL_MODEL, other choice SINGLE_THREAD_MODEL
84
85     // create policy list
86     CORBA::PolicyList policyList;
87     policyList.length(2);
88     policyList[0] = PortableServer::ImplicitActivationPolicy::_duplicate(implicitActivation) ;
89     policyList[1] = PortableServer::ThreadPolicy::_duplicate(threadPolicy) ;
90
91     // create the child POA
92     PortableServer::POAManager_var nil_mgr = PortableServer::POAManager::_nil() ;
93     PortableServer::POA_var factory_poa =
94       root_poa->create_POA("factory_poa", pman, policyList) ;
95       //with nil_mgr instead of pman, a new POA manager is created with the new POA
96     
97     // destroy policy objects
98     implicitActivation->destroy() ;
99     threadPolicy->destroy() ;
100
101     char *containerName = "";
102     if (argc >1) 
103     {
104         containerName = argv[1] ;
105     }
106     
107     Engines_Container_i * myContainer 
108      = new Engines_Container_i(orb, factory_poa, containerName , argc , argv );
109
110 //     Engines_Container_i * myContainer 
111 //      = new Engines_Container_i(string(argv[1]),string(argv[2]), orb, factory_poa);
112
113     // use naming service
114 //     myContainer->_NS.init_orb(orb);
115 //     Engines::Container_ptr pCont = Engines::Container::_narrow(myContainer->_this());
116 //     myContainer->_NS.Register(pCont, argv[2]); 
117     
118     pman->activate();
119
120 #ifdef CHECKTIME
121     Utils_Timer timer;
122     timer.Start();
123     timer.Stop();
124     MESSAGE("SALOME_Registry_Server.cxx - orb->run()");
125     timer.ShowAbsolute();
126 #endif
127     orb->run();
128
129     orb->destroy();
130   }
131   catch(CORBA::SystemException&)
132   {
133     INFOS("Caught CORBA::SystemException.")
134   }
135   catch(PortableServer::POA::WrongPolicy&)
136   {
137     INFOS("Caught CORBA::WrongPolicyException.")
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(...)
148   {
149     INFOS("Caught unknown exception.")
150   }
151   END_OF(argv[0]);
152 }
153