Salome HOME
Initialisation de la base KERNEL avec la version operationnelle de KERNEL_SRC issue...
[modules/kernel.git] / src / Container / SALOME_Container.cxx
1 using namespace std;
2 //=============================================================================
3 // File      : SALOME_Container.cxx
4 // Created   : jeu jui 12 08:04:40 CEST 2001
5 // Author    : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
6 // Project   : SALOME
7 // Copyright : EDF 2001 - CEA 2001
8 // $Header$
9 //=============================================================================
10 using namespace std;
11 #include <stdio.h>
12
13 # include "Utils_ORB_INIT.hxx"
14 # include "Utils_SINGLETON.hxx"
15
16 #include "SALOME_Container_i.hxx"
17 #include <iostream>
18 #include <string>
19 #include "utilities.h"
20
21 #include <Python.h>
22
23 static PyMethodDef MethodPyVoidMethod[] = {
24   { NULL,        NULL }
25 };
26
27 int main(int argc, char* argv[])
28 {
29   INFOS_COMPILATION;
30   BEGIN_OF(argv[0])
31
32   Py_Initialize() ;
33   PySys_SetArgv( argc , argv ) ;
34   Py_InitModule( "InitPyRunMethod" , MethodPyVoidMethod ) ;
35
36   try {
37     
38     // Initialise the ORB.
39 //     CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
40     ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
41     ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
42     CORBA::ORB_var &orb = init( argc , argv ) ;
43  
44     // Obtain a reference to the root POA.
45     CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
46     PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
47
48     // obtain the root poa manager
49     PortableServer::POAManager_var pman = root_poa->the_POAManager();
50
51     // define policy objects     
52     PortableServer::ImplicitActivationPolicy_var implicitActivation =
53       root_poa->create_implicit_activation_policy(PortableServer::NO_IMPLICIT_ACTIVATION) ;
54
55       // default = NO_IMPLICIT_ACTIVATION
56     PortableServer::ThreadPolicy_var threadPolicy =
57       root_poa->create_thread_policy(PortableServer::ORB_CTRL_MODEL) ;
58       // default = ORB_CTRL_MODEL, other choice SINGLE_THREAD_MODEL
59
60     // create policy list
61     CORBA::PolicyList policyList;
62     policyList.length(2);
63     policyList[0] = PortableServer::ImplicitActivationPolicy::_duplicate(implicitActivation) ;
64     policyList[1] = PortableServer::ThreadPolicy::_duplicate(threadPolicy) ;
65
66     // create the child POA
67     PortableServer::POAManager_var nil_mgr = PortableServer::POAManager::_nil() ;
68     PortableServer::POA_var factory_poa =
69       root_poa->create_POA("factory_poa", pman, policyList) ;
70       //with nil_mgr instead of pman, a new POA manager is created with the new POA
71     
72     // destroy policy objects
73     implicitActivation->destroy() ;
74     threadPolicy->destroy() ;
75
76     char *containerName = "";
77     if (argc >1) 
78     {
79         containerName = argv[1] ;
80     }
81     
82     Engines_Container_i * myContainer 
83      = new Engines_Container_i(orb, factory_poa, containerName , argc , argv );
84
85 //     Engines_Container_i * myContainer 
86 //      = new Engines_Container_i(string(argv[1]),string(argv[2]), orb, factory_poa);
87
88     // use naming service
89 //     myContainer->_NS.init_orb(orb);
90 //     Engines::Container_ptr pCont = Engines::Container::_narrow(myContainer->_this());
91 //     myContainer->_NS.Register(pCont, argv[2]); 
92     
93     pman->activate();
94
95     orb->run();
96
97     orb->destroy();
98   }
99   catch(CORBA::SystemException&)
100   {
101     INFOS("Caught CORBA::SystemException.")
102   }
103   catch(PortableServer::POA::WrongPolicy&)
104   {
105     INFOS("Caught CORBA::WrongPolicyException.")
106   }
107   catch(PortableServer::POA::ServantAlreadyActive&)
108   {
109     INFOS("Caught CORBA::ServantAlreadyActiveException")
110   }
111   catch(CORBA::Exception&)
112   {
113     INFOS("Caught CORBA::Exception.")
114   }
115   catch(...)
116   {
117     INFOS("Caught unknown exception.")
118   }
119   END_OF(argv[0]);
120 }
121