]> SALOME platform Git repositories - samples/dsccode.git/blob - src/INTERPI/INTERPI.cxx
Salome HOME
Merge branch 'V9_13_BR'
[samples/dsccode.git] / src / INTERPI / INTERPI.cxx
1 using namespace std;
2 #include "INTERPI.hxx"
3 #include <string>
4 #include <unistd.h>
5
6 #include <Calcium.hxx>
7 #include <CalciumInterface.hxx>
8 #include <calcium.h>
9
10 extern "C" void transit_(void *compo);
11 extern "C" void perma_(void *compo);
12
13 //! Constructor for component "INTERPI" instance
14 /*!
15  *  
16  */
17 INTERPI_i::INTERPI_i(CORBA::ORB_ptr orb, 
18                      PortableServer::POA_ptr poa, 
19                      PortableServer::ObjectId * contId, 
20                      const char *instanceName, 
21                      const char *interfaceName) 
22           : Superv_Component_i(orb, poa, contId, instanceName, interfaceName)
23 {
24   cerr << "create component" << endl;
25   _thisObj = this ;
26   _id = _poa->activate_object(_thisObj);
27 }
28
29 //! Destructor for component "INTERPI" instance
30 INTERPI_i::~INTERPI_i()
31 {
32 }
33
34 //! Register datastream ports for a component service given its name
35 /*!
36  *  \param service_name : service name
37  *  \return true if port registering succeeded, false if not
38  */
39 CORBA::Boolean
40 INTERPI_i::init_service(const char * service_name) {
41   CORBA::Boolean rtn = false;
42   string s_name(service_name);
43   if (s_name == "prun") 
44     {
45       try
46         {
47           std::cerr << "INTERPI: prun: "  << std::endl;
48           //initialization CALCIUM ports IN
49           calcium_real_port_provides * p1;
50           p1 = add_port<calcium_real_port_provides>("CALCIUM_real","provides","tparoi");
51           p1->setDependencyType(CalciumTypes::ITERATION_DEPENDENCY);
52           //initialization CALCIUM ports OUT
53           add_port<calcium_real_port_uses>("CALCIUM_real","uses","tpar");
54         }
55       catch(const PortAlreadyDefined& ex)
56         {
57           std::cerr << "INTERPI: " << ex.what() << std::endl;
58           //Ports already created : we use them
59         }
60       catch ( ... ) 
61         {
62           std::cerr << "INTERPI: unknown exception" << std::endl;
63         }
64
65       rtn = true;
66     }
67   if (s_name == "trun") 
68     {
69       try
70         {
71           std::cerr << "INTERPI: trun: "  << std::endl;
72           //initialization CALCIUM ports IN
73           calcium_real_port_provides * p1;
74           p1 = add_port<calcium_real_port_provides>("CALCIUM_real","provides","tparoit");
75           p1->setDependencyType(CalciumTypes::TIME_DEPENDENCY);
76           //initialization CALCIUM ports OUT
77           add_port<calcium_real_port_uses>("CALCIUM_real","uses","tpart");
78         }
79       catch(const PortAlreadyDefined& ex)
80         {
81           std::cerr << "INTERPI: " << ex.what() << std::endl;
82           //Ports already created : we use them
83         }
84       catch ( ... ) 
85         {
86           std::cerr << "INTERPI: unknown exception" << std::endl;
87         }
88       rtn = true;
89     }
90   return rtn;
91 }
92
93 void INTERPI_i::prun()
94 {
95   std::cerr << "INTERPI_i::prun" << std::endl;
96   beginService("INTERPI_i::prun");
97   Superv_Component_i * component = dynamic_cast<Superv_Component_i*>(this);
98   char       nom_instance[INSTANCE_LEN];
99   int info = cp_cd(component,nom_instance);
100   try
101     {
102       perma_(&component);
103       //to do or not to do ???
104       cp_fin(component,CP_ARRET);
105     }
106   catch ( const CalciumException & ex)
107     {
108       std::cerr << ex.what() << std::endl;
109       cp_fin(component,CP_ARRET);
110     }
111   catch (...)
112     {
113       std::cerr << "unexpected exception" << std::endl;
114       cp_fin(component,CP_ARRET);
115     }
116   endService("INTERPI_i::prun");
117   std::cerr << "end of INTERPI_i::prun" << std::endl;
118 }
119
120 void INTERPI_i::trun()
121 {
122   std::cerr << "INTERPI_i::trun" << std::endl;
123   beginService("INTERPI_i::trun");
124   Superv_Component_i * component = dynamic_cast<Superv_Component_i*>(this);
125   char       nom_instance[INSTANCE_LEN];
126   int info = cp_cd(component,nom_instance);
127   try
128     {
129       transit_(&component);
130       //to do or not to do ???
131       cp_fin(component,CP_ARRET);
132     }
133   catch ( const CalciumException & ex)
134     {
135       std::cerr << ex.what() << std::endl;
136       cp_fin(component,CP_ARRET);
137     }
138   catch (...)
139     {
140       std::cerr << "unexpected exception" << std::endl;
141       cp_fin(component,CP_ARRET);
142     }
143   endService("INTERPI_i::trun");
144   std::cerr << "end of INTERPI_i::trun" << std::endl;
145 }
146
147 extern "C"
148 {
149   PortableServer::ObjectId * INTERPIEngine_factory( CORBA::ORB_ptr orb, 
150                                                     PortableServer::POA_ptr poa, 
151                                                     PortableServer::ObjectId * contId,
152                                                     const char *instanceName, 
153                                                     const char *interfaceName)
154   {
155     std::cerr << "INTERPIEngine_factory" << std::endl;
156     INTERPI_i * myEngine = new INTERPI_i(orb, poa, contId, instanceName, interfaceName);
157     return myEngine->getId() ;
158   }
159
160   PortableServer::ObjectId * INTERPJEngine_factory( CORBA::ORB_ptr orb, 
161                                                     PortableServer::POA_ptr poa, 
162                                                     PortableServer::ObjectId * contId,
163                                                     const char *instanceName, 
164                                                     const char *interfaceName)
165   {
166     std::cerr << "INTERPJEngine_factory" << std::endl;
167     INTERPI_i * myEngine = new INTERPI_i(orb, poa, contId, instanceName, interfaceName);
168     return myEngine->getId() ;
169   }
170   PortableServer::ObjectId * INTERPKEngine_factory( CORBA::ORB_ptr orb, 
171                                                     PortableServer::POA_ptr poa, 
172                                                     PortableServer::ObjectId * contId,
173                                                     const char *instanceName, 
174                                                     const char *interfaceName)
175   {
176     std::cerr << "INTERPKEngine_factory" << std::endl;
177     INTERPI_i * myEngine = new INTERPI_i(orb, poa, contId, instanceName, interfaceName);
178     return myEngine->getId() ;
179   }
180 }