]> SALOME platform Git repositories - samples/dsccode.git/blob - src/SOLIDE/SOLIDE.cxx
Salome HOME
initial import into CVS
[samples/dsccode.git] / src / SOLIDE / SOLIDE.cxx
1 using namespace std;
2 #include "SOLIDE.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 "SOLIDE" instance
13 /*!
14  *  
15  */
16 SOLIDE_i::SOLIDE_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 "SOLIDE" instance
29 SOLIDE_i::~SOLIDE_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 SOLIDE_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 << "SOLIDE: 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","puissi");
50           p1->setDependencyType(CalciumTypes::ITERATION_DEPENDENCY);
51           p1 = add_port<calcium_real_port_provides>("CALCIUM_real","provides","tfi");
52           p1->setDependencyType(CalciumTypes::ITERATION_DEPENDENCY);
53           //initialization CALCIUM ports OUT
54           add_port<calcium_real_port_uses>("CALCIUM_real","uses","tempi");
55           add_port<calcium_real_port_uses>("CALCIUM_real","uses","tpi");
56           add_port<calcium_integer_port_uses>("CALCIUM_integer","uses","iconv");
57         }
58       catch(const PortAlreadyDefined& ex)
59         {
60           std::cerr << "SOLIDE: " << ex.what() << std::endl;
61           //Ports already created : we use them
62         }
63       catch ( ... ) 
64         {
65           std::cerr << "SOLIDE: unknown exception" << std::endl;
66         }
67
68       rtn = true;
69     }
70   if (s_name == "trun") 
71     {
72       try
73         {
74           std::cerr << "SOLIDE: trun: "  << std::endl;
75           //initialization CALCIUM ports IN
76           calcium_real_port_provides * p1;
77           p1 = add_port<calcium_real_port_provides>("CALCIUM_real","provides","rext");
78           p1->setDependencyType(CalciumTypes::TIME_DEPENDENCY);
79           p1 = add_port<calcium_real_port_provides>("CALCIUM_real","provides","puissa");
80           p1->setDependencyType(CalciumTypes::TIME_DEPENDENCY);
81           p1 = add_port<calcium_real_port_provides>("CALCIUM_real","provides","text");
82           p1->setDependencyType(CalciumTypes::TIME_DEPENDENCY);
83           //initialization CALCIUM ports OUT
84           add_port<calcium_real_port_uses>("CALCIUM_real","uses","tparoi");
85           add_port<calcium_real_port_uses>("CALCIUM_real","uses","rparoi");
86           add_port<calcium_real_port_uses>("CALCIUM_real","uses","temperature");
87         }
88       catch(const PortAlreadyDefined& ex)
89         {
90           std::cerr << "SOLIDE: " << ex.what() << std::endl;
91           //Ports already created : we use them
92         }
93       catch ( ... ) 
94         {
95           std::cerr << "SOLIDE: unknown exception" << std::endl;
96         }
97       rtn = true;
98     }
99   return rtn;
100 }
101
102 void SOLIDE_i::prun()
103 {
104   std::cerr << "SOLIDE_i::prun" << std::endl;
105   Superv_Component_i * component = dynamic_cast<Superv_Component_i*>(this);
106   char       nom_instance[INSTANCE_LEN];
107   int info = cp_cd(component,nom_instance);
108   try
109     {
110       perma_(&component);
111       //to do or not to do ???
112       cp_fin(component,CP_ARRET);
113     }
114   catch ( const CalciumException & ex)
115     {
116       std::cerr << ex.what() << std::endl;
117       cp_fin(component,CP_ARRET);
118     }
119   catch (...)
120     {
121       std::cerr << "unexpected exception" << std::endl;
122       cp_fin(component,CP_ARRET);
123     }
124   std::cerr << "end of SOLIDE_i::prun" << std::endl;
125 }
126
127 void SOLIDE_i::trun(CORBA::Double dt)
128 {
129   std::cerr << "SOLIDE_i::trun" << std::endl;
130   Superv_Component_i * component = dynamic_cast<Superv_Component_i*>(this);
131   char       nom_instance[INSTANCE_LEN];
132   int info = cp_cd(component,nom_instance);
133   try
134     {
135       transit_(&component,&dt);
136       //to do or not to do ???
137       cp_fin(component,CP_ARRET);
138     }
139   catch ( const CalciumException & ex)
140     {
141       std::cerr << ex.what() << std::endl;
142       cp_fin(component,CP_ARRET);
143     }
144   catch (...)
145     {
146       std::cerr << "unexpected exception" << std::endl;
147       cp_fin(component,CP_ARRET);
148     }
149   std::cerr << "end of SOLIDE_i::trun" << std::endl;
150 }
151
152 extern "C"
153 {
154   PortableServer::ObjectId * SOLIDEEngine_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 * SOLIDEEngine_factory()");
161     SOLIDE_i * myEngine = new SOLIDE_i(orb, poa, contId, instanceName, interfaceName);
162     return myEngine->getId() ;
163   }
164 }