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