]> SALOME platform Git repositories - samples/dsccode.git/blob - src/NEUTRO/NEUTRO.cxx
Salome HOME
Merge branch 'V9_13_BR'
[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 <CalciumInterface.hxx>
8 #include <calcium.h>
9
10 extern "C" void transit_(void *compo,double *dt);
11 extern "C" void perma_(void *compo);
12
13 //! Constructor for component "NEUTRO" instance
14 /*!
15  *  
16  */
17 NEUTRO_i::NEUTRO_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 "NEUTRO" instance
30 NEUTRO_i::~NEUTRO_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 NEUTRO_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 << "NEUTRO: 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","tempi");
51           p1->setDependencyType(CalciumTypes::ITERATION_DEPENDENCY);
52           calcium_integer_port_provides * p2;
53           p2 = add_port<calcium_integer_port_provides>("CALCIUM_integer","provides","iconv");
54           p2->setDependencyType(CalciumTypes::ITERATION_DEPENDENCY);
55
56           //initialization CALCIUM ports OUT
57           add_port<calcium_real_port_uses>("CALCIUM_real","uses","puissi");
58         }
59       catch(const PortAlreadyDefined& ex)
60         {
61           std::cerr << "NEUTRO: " << ex.what() << std::endl;
62           //Ports already created : we use them
63         }
64       catch ( ... ) 
65         {
66           std::cerr << "NEUTRO: unknown exception" << std::endl;
67         }
68
69       rtn = true;
70     }
71   if (s_name == "trun") 
72     {
73       try
74         {
75           std::cerr << "NEUTRO: trun: "  << std::endl;
76           //initialization CALCIUM ports IN
77           calcium_real_port_provides * p1;
78           p1 = add_port<calcium_real_port_provides>("CALCIUM_real","provides","temperature");
79           p1->setDependencyType(CalciumTypes::TIME_DEPENDENCY);
80           //initialization CALCIUM ports OUT
81           add_port<calcium_real_port_uses>("CALCIUM_real","uses","puissance");
82           add_port<calcium_integer_port_uses>("CALCIUM_integer","uses","topo");
83         }
84       catch(const PortAlreadyDefined& ex)
85         {
86           std::cerr << "NEUTRO: " << ex.what() << std::endl;
87           //Ports already created : we use them
88         }
89       catch ( ... ) 
90         {
91           std::cerr << "NEUTRO: unknown exception" << std::endl;
92         }
93       rtn = true;
94     }
95   return rtn;
96 }
97
98 void NEUTRO_i::prun()
99 {
100   std::cerr << "NEUTRO_i::prun" << std::endl;
101   beginService("NEUTRO_i::prun");
102   Superv_Component_i * component = dynamic_cast<Superv_Component_i*>(this);
103   char       nom_instance[INSTANCE_LEN];
104   int info = cp_cd(component,nom_instance);
105   try
106     {
107       perma_(&component);
108       //to do or not to do ???
109       cp_fin(component,CP_ARRET);
110     }
111   catch ( const CalciumException & ex)
112     {
113       std::cerr << ex.what() << std::endl;
114       cp_fin(component,CP_ARRET);
115     }
116   catch (...)
117     {
118       std::cerr << "unexpected exception" << std::endl;
119       cp_fin(component,CP_ARRET);
120     }
121   endService("NEUTRO_i::prun");
122   std::cerr << "end of NEUTRO_i::prun" << std::endl;
123 }
124
125 void NEUTRO_i::trun(CORBA::Double dt)
126 {
127   std::cerr << "NEUTRO_i::trun" << std::endl;
128   beginService("NEUTRO_i::trun");
129   Superv_Component_i * component = dynamic_cast<Superv_Component_i*>(this);
130   char       nom_instance[INSTANCE_LEN];
131   int info = cp_cd(component,nom_instance);
132   try
133     {
134       transit_(&component,&dt);
135       //to do or not to do ???
136       cp_fin(component,CP_ARRET);
137     }
138   catch ( const CalciumException & ex)
139     {
140       std::cerr << ex.what() << std::endl;
141       cp_fin(component,CP_ARRET);
142     }
143   catch (...)
144     {
145       std::cerr << "unexpected exception" << std::endl;
146       cp_fin(component,CP_ARRET);
147     }
148   endService("NEUTRO_i::trun");
149   std::cerr << "end of NEUTRO_i::trun" << std::endl;
150 }
151
152 extern "C"
153 {
154   PortableServer::ObjectId * NEUTROEngine_factory( CORBA::ORB_ptr orb, 
155                                                     PortableServer::POA_ptr poa, 
156                                                     PortableServer::ObjectId * contId,
157                                                     const char *instanceName, 
158                                                     const char *interfaceName)
159   {
160     MESSAGE("PortableServer::ObjectId * NEUTROEngine_factory()");
161     NEUTRO_i * myEngine = new NEUTRO_i(orb, poa, contId, instanceName, interfaceName);
162     return myEngine->getId() ;
163   }
164 }