]> SALOME platform Git repositories - samples/dsccode.git/blob - src/FLUIDE/FLUIDE.cxx
Salome HOME
initial import into CVS
[samples/dsccode.git] / src / FLUIDE / FLUIDE.cxx
1 #include "FLUIDE.hxx"
2 #include <string>
3 #include <unistd.h>
4
5 #include <Calcium.hxx>
6 #include <calcium.h>
7
8 using namespace std;
9
10 extern "C" void transit_(void *compo,double *dt);
11 extern "C" void perma_(void *compo);
12
13 //! Constructor for component "FLUIDE" instance
14 /*!
15  *  
16  */
17 FLUIDE_i::FLUIDE_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 "FLUIDE" instance
30 FLUIDE_i::~FLUIDE_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 FLUIDE_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 << "FLUIDE: prun: "  << std::endl;
48           //initialization CALCIUM ports IN
49           create_calcium_port(this,"tpi","CALCIUM_real","IN","I");
50           create_calcium_port(this,"iconv","CALCIUM_integer","IN","I");
51           //initialization CALCIUM ports OUT
52           create_calcium_port(this,"tfi","CALCIUM_real","OUT","I");
53         }
54       catch(const PortAlreadyDefined& ex)
55         {
56           std::cerr << "FLUIDE: " << ex.what() << std::endl;
57           //Ports already created : we use them
58         }
59       catch ( ... ) 
60         {
61           std::cerr << "FLUIDE: unknown exception" << std::endl;
62         }
63
64       rtn = true;
65     }
66   if (s_name == "trun") 
67     {
68       try
69         {
70           std::cerr << "FLUIDE: trun: "  << std::endl;
71           //initialization CALCIUM ports IN
72           create_calcium_port(this,"tparoi","CALCIUM_real","IN","T");
73           create_calcium_port(this,"rparoi","CALCIUM_real","IN","T");
74           //initialization CALCIUM ports OUT
75           create_calcium_port(this,"tfluide","CALCIUM_real","OUT","T");
76           create_calcium_port(this,"rfluide","CALCIUM_real","OUT","T");
77         }
78       catch(const PortAlreadyDefined& ex)
79         {
80           std::cerr << "FLUIDE: " << ex.what() << std::endl;
81           //Ports already created : we use them
82         }
83       catch ( ... ) 
84         {
85           std::cerr << "FLUIDE: unknown exception" << std::endl;
86         }
87       rtn = true;
88     }
89   return rtn;
90 }
91
92 void FLUIDE_i::prun()
93 {
94   std::cerr << "FLUIDE_i::prun" << std::endl;
95   Superv_Component_i * component = dynamic_cast<Superv_Component_i*>(this);
96   char       nom_instance[INSTANCE_LEN];
97   int info = cp_cd(component,nom_instance);
98   try
99     {
100       perma_(&component);
101       //to do or not to do ???
102       cp_fin(component,CP_ARRET);
103     }
104   catch ( const CalciumException & ex)
105     {
106       std::cerr << ex.what() << std::endl;
107       cp_fin(component,CP_ARRET);
108     }
109   catch (...)
110     {
111       std::cerr << "unexpected exception" << std::endl;
112       cp_fin(component,CP_ARRET);
113     }
114   std::cerr << "end of FLUIDE_i::prun" << std::endl;
115 }
116
117 void FLUIDE_i::trun(CORBA::Double dt)
118 {
119   std::cerr << "FLUIDE_i::trun" << std::endl;
120   Superv_Component_i * component = dynamic_cast<Superv_Component_i*>(this);
121   char       nom_instance[INSTANCE_LEN];
122   int info = cp_cd(component,nom_instance);
123   try
124     {
125       transit_(&component,&dt);
126       //to do or not to do ???
127       cp_fin(component,CP_ARRET);
128     }
129   catch ( const CalciumException & ex)
130     {
131       std::cerr << ex.what() << std::endl;
132       cp_fin(component,CP_ARRET);
133     }
134   catch (...)
135     {
136       std::cerr << "unexpected exception" << std::endl;
137       cp_fin(component,CP_ARRET);
138     }
139   std::cerr << "end of FLUIDE_i::trun" << std::endl;
140 }
141
142 extern "C"
143 {
144   PortableServer::ObjectId * FLUIDEEngine_factory( CORBA::ORB_ptr orb, 
145                                                     PortableServer::POA_ptr poa, 
146                                                     PortableServer::ObjectId * contId,
147                                                     const char *instanceName, 
148                                                     const char *interfaceName)
149   {
150     MESSAGE("PortableServer::ObjectId * FLUIDEEngine_factory()");
151     FLUIDE_i * myEngine = new FLUIDE_i(orb, poa, contId, instanceName, interfaceName);
152     return myEngine->getId() ;
153   }
154 }