Salome HOME
Merge from V6_main (patch ubuntu)
[samples/dsccode.git] / src / DSCCODCENG / DSCCODCENG.cxx
1 using namespace std;
2 #include "DSCCODCENG.hxx"
3 #include <string>
4 #include <unistd.h>
5 #include "CalciumInterface.hxx"
6 #include <calcium.h>
7
8 //! Constructor for component "DSCCODC" instance
9 /*!
10  *  
11  */
12 DSCCODC_i::DSCCODC_i(CORBA::ORB_ptr orb, 
13                      PortableServer::POA_ptr poa, 
14                      PortableServer::ObjectId * contId, 
15                      const char *instanceName, 
16                      const char *interfaceName) 
17           : Superv_Component_i(orb, poa, contId, instanceName, interfaceName)
18 {
19   cerr << "create component" << endl;
20   _thisObj = this ;
21   _id = _poa->activate_object(_thisObj);
22 }
23
24 //! Destructor for component "DSCCODC" instance
25 DSCCODC_i::~DSCCODC_i()
26 {
27 }
28
29 //! Register datastream ports for a component service given its name
30 /*!
31  *  \param service_name : service name
32  *  \return true if port registering succeeded, false if not
33  */
34 CORBA::Boolean
35 DSCCODC_i::init_service(const char * service_name) {
36   CORBA::Boolean rtn = false;
37   string s_name(service_name);
38   if (s_name == "prun") 
39     {
40       try
41         {
42           std::cerr << "DSCCODC: prun: "  << std::endl;
43
44           //initialization CALCIUM ports
45           calcium_integer_port_provides * p1;
46           /* ETP_EN  T       IN      ENTIER */
47           p1 = add_port<calcium_integer_port_provides>("CALCIUM_integer","provides","ETP_EN");
48           p1->setDependencyType(CalciumTypes::TIME_DEPENDENCY);
49           /* STP_EN  T       OUT     ENTIER */
50           add_port<calcium_integer_port_uses>("CALCIUM_integer","uses","STP_EN");
51           //end of initialization CALCIUM ports
52         }
53       catch(const PortAlreadyDefined& ex)
54         {
55           std::cerr << "DSCCODC: " << ex.what() << std::endl;
56           //Ports already created : we use them
57         }
58       catch ( ... ) 
59         {
60           std::cerr << "DSCCODC: unknown exception" << std::endl;
61         }
62
63       rtn = true;
64     }
65   if (s_name == "trun") 
66     {
67       try
68         {
69           std::cerr << "DSCCODC: trun: "  << std::endl;
70           calcium_real_port_provides * p1;
71           /* ETP_RE  T       IN      REEL   */
72           p1 = add_port<calcium_real_port_provides>("CALCIUM_real","provides","ETP_RE");
73           p1->setDependencyType(CalciumTypes::TIME_DEPENDENCY);
74           /* STP_RE  T       OUT     REEL   */
75           add_port<calcium_real_port_uses>("CALCIUM_real","uses","STP_RE");
76         }
77       catch(const PortAlreadyDefined& ex)
78         {
79           std::cerr << "DSCCODC: " << ex.what() << std::endl;
80           //Ports already created : we use them
81         }
82       catch ( ... ) 
83         {
84           std::cerr << "DSCCODC: unknown exception" << std::endl;
85         }
86       rtn = true;
87     }
88   return rtn;
89 }
90
91 void DSCCODC_i::prun(CORBA::Long niter)
92 {
93   cerr << "DSCCODC_i::prun" << endl;
94   Superv_Component_i * component = dynamic_cast<Superv_Component_i*>(this);
95   std::cerr << "Valeur de component : " << component << std::endl;
96   std::cerr << "Valeur de this : " << this << std::endl;
97   char       nom_instance[INSTANCE_LEN];
98   int   SDATA_EN [3]; // buffer
99   int   EDATA_EN [3]; // buffer
100
101   int info = cp_cd(component,nom_instance);
102
103   float ti_re = 0.0; // step time
104   int  i = 0; // not used
105   SDATA_EN[0] = 3;
106   SDATA_EN[1] = 1;
107   SDATA_EN[2] = 2;
108   info = cp_een(component,CP_TEMPS,ti_re,i,(char *)"STP_EN",2,SDATA_EN);
109
110   float tf_re = 1.0; // step start time
111   int max=3; // max size expected
112   int n; // real size received
113
114   info = cp_len(component,CP_TEMPS,&ti_re,&tf_re,&i,(char *)"ETP_EN",max,&n,EDATA_EN);
115
116   for (int i = 0; i < n; ++i)
117     cerr << "seqLongData[" << i << "] = " << EDATA_EN[i] << endl;
118
119   cerr << "end of DSCCODC_i::prun" << endl;
120 }
121
122 void DSCCODC_i::trun(CORBA::Long niter)
123 {
124   cerr << "DSCCODC_i::trun" << endl;
125   Superv_Component_i * component = dynamic_cast<Superv_Component_i*>(this);
126   char       nom_instance[INSTANCE_LEN];
127   int info = cp_cd(component,nom_instance);
128
129   float     SDATA_RE [3], EDATA_RE [3];
130   SDATA_RE[0] = 3.;
131   SDATA_RE[1] = 1.;
132   SDATA_RE[2] = 2.;
133
134   float ti_re = 0.0; // time
135   int  i = 0; // not used
136
137   info = cp_ere(component,CP_TEMPS,ti_re,i,(char *)"STP_RE",2,SDATA_RE);
138   cerr << "apres cp_ere: " << info << endl;
139
140   int max=3; // max size expected
141   int n=2; // real size received
142   float tf_re = 1.0; // time
143   info = cp_lre(component,CP_TEMPS,&ti_re,&tf_re,&i,(char *)"ETP_RE",max,&n,EDATA_RE);
144
145   for (int i = 0; i < n; ++i)
146     cerr << "seqRealData[" << i << "] = " << EDATA_RE[i] << endl;
147   cerr << "end of DSCCODC_i::trun" << endl;
148 }
149
150 extern "C"
151 {
152   PortableServer::ObjectId * DSCCODCEngine_factory( CORBA::ORB_ptr orb, 
153                                                     PortableServer::POA_ptr poa, 
154                                                     PortableServer::ObjectId * contId,
155                                                     const char *instanceName, 
156                                                     const char *interfaceName)
157   {
158     MESSAGE("PortableServer::ObjectId * DSCCODCEngine_factory()");
159     DSCCODC_i * myEngine = new DSCCODC_i(orb, poa, contId, instanceName, interfaceName);
160     return myEngine->getId() ;
161   }
162 }