Salome HOME
ff840b94856e9d1df9ee364350fe5b7b89ca8c27
[modules/kernel.git] / src / DSC / DSC_User / Datastream / Calcium / CalciumCInterface.cxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "CalciumCInterface.hxx"
21 #include "CalciumCxxInterface.hxx"
22
23 #include <stdio.h>
24
25
26 //#define MYDEBUG
27 #ifdef MYDEBUG
28 #define DEBTRACE(msg) {std::cerr<<std::flush<<__FILE__<<" ["<<__LINE__<<"] : "<<msg<<std::endl<<std::flush;}
29 #else
30 #define DEBTRACE(msg)
31 #endif
32
33
34 /* Définition de l'Interface entre l'API C  et l'API C++
35    L'utilisateur CALCIUM n'a normalement pas a utliser cette interface
36    En C/C++ il utilisera celle définie dans Calcium.c (calcium.h)
37    En C++/CORBA directement celle de CalciumCxxInterface.hxx
38 */
39
40
41 #define STAR *
42
43 /* Définition de ecp_lecture_... , ecp_ecriture_..., ecp_free_... */
44
45 /*  Le premier argument est utilisée :
46     - comme suffixe dans la définition des noms ecp_lecture_ , ecp_ecriture_ et ecp_free_
47     - comme second argument template à l'appel de la méthode C++ correspondante
48         ( le type de port correspondant est alors obtenu par un trait)
49    Le second argument est utilisée :
50    - pour typer le paramètre data de la procédure générée 
51    - pour déduire le type des paramètres t, ti tf via un trait
52    - comme premier paramètre template à l'appel de la méthode C++ correspondante
53          (pour typer les données passées en paramètre )
54    Notons que dans le cas CALCIUM_C2CPP_INTERFACE_(int,int,), le type int n'existe pas
55    en CORBA, le port CALCIUM correspondant utilise une séquence de long. La méthode
56    C++ CALCIUM de lecture repère cette différence de type et charge 
57    le manipulateur de données d'effectuer  une recopie (qui fonctionne si les types sont compatibles). 
58 */
59 // CALCIUM_C2CPP_INTERFACE_CXX_(_name,_porttype,_type,_qual)
60 CALCIUM_C2CPP_INTERFACE_CXX_(intc,int,int,);
61 CALCIUM_C2CPP_INTERFACE_CXX_(long,long,long,);
62
63 CALCIUM_C2CPP_INTERFACE_CXX_(integer,integer,cal_int,);
64 CALCIUM_C2CPP_INTERFACE_CXX_(int2integer ,integer,  int,);
65 CALCIUM_C2CPP_INTERFACE_CXX_(long2integer, integer, long,);
66
67 CALCIUM_C2CPP_INTERFACE_CXX_(float,float,float, );
68 CALCIUM_C2CPP_INTERFACE_CXX_(double,double,double,);
69
70 CALCIUM_C2CPP_INTERFACE_CXX_(float2double,double,float, );
71
72 /*  Fonnctionne mais essai suivant pour simplification de Calcium.c CALCIUM_C2CPP_INTERFACE_(bool,bool,);*/
73 CALCIUM_C2CPP_INTERFACE_CXX_(bool,bool,int,);
74 CALCIUM_C2CPP_INTERFACE_CXX_(cplx,cplx,float,);
75 CALCIUM_C2CPP_INTERFACE_CXX_(str,str,char*,);
76
77 /* Définition de ecp_fin */
78 extern "C" CalciumTypes::InfoType 
79 ecp_fin_ (void * component, int code) {
80
81   Superv_Component_i * _component = static_cast<Superv_Component_i *>(component); 
82
83   bool provideLastGivenValue = false;
84   if (code == CalciumTypes::CP_CONT ) provideLastGivenValue = true;
85
86   try {                                                                 
87     CalciumInterface::ecp_fin( *_component,                             
88                                provideLastGivenValue); 
89   } catch ( const CalciumException & ex) { //tester l'arrêt par exception
90     DEBTRACE( ex.what() );
91     return ex.getInfo();                                                
92   }                                                                     
93   return CalciumTypes::CPOK;
94 };
95
96 extern "C" CalciumTypes::InfoType 
97 ecp_cd_ (void * component, char * instanceName) {
98   Superv_Component_i * _component = static_cast<Superv_Component_i *>(component); 
99   std::string name;
100   CalciumInterface::ecp_cd( *_component,name);
101   strcpy(instanceName,name.c_str());
102   return CalciumTypes::CPOK;
103 }
104
105 // Interface for cleaning
106 extern "C" CalciumTypes::InfoType 
107 ecp_fini_ (void * component, char* nomvar, int i)
108 {
109   Superv_Component_i * _component = static_cast<Superv_Component_i *>(component); 
110   try
111     {
112       CalciumInterface::ecp_fini( *_component,nomvar,i);
113     }
114   catch ( const CalciumException & ex)
115     {
116       DEBTRACE( ex.what() );
117       return ex.getInfo();
118     }
119   return CalciumTypes::CPOK;
120
121 }
122
123 extern "C" CalciumTypes::InfoType 
124 ecp_fint_ (void * component, char* nomvar, float t)
125 {
126   Superv_Component_i * _component = static_cast<Superv_Component_i *>(component); 
127   try
128     {
129       CalciumInterface::ecp_fint( *_component,nomvar,t);
130     }
131   catch ( const CalciumException & ex)
132     {
133       DEBTRACE( ex.what() );
134       return ex.getInfo();
135     }
136   return CalciumTypes::CPOK;
137 }
138
139 extern "C" CalciumTypes::InfoType 
140 ecp_effi_ (void * component, char* nomvar, int i)
141 {
142   Superv_Component_i * _component = static_cast<Superv_Component_i *>(component); 
143   try
144     {
145       CalciumInterface::ecp_effi( *_component,nomvar,i);
146     }
147   catch ( const CalciumException & ex)
148     {
149       DEBTRACE( ex.what() );
150       return ex.getInfo();
151     }
152   return CalciumTypes::CPOK;
153
154 }
155
156 extern "C" CalciumTypes::InfoType 
157 ecp_efft_ (void * component, char* nomvar, float t)
158 {
159   Superv_Component_i * _component = static_cast<Superv_Component_i *>(component); 
160   try
161     {
162       CalciumInterface::ecp_efft( *_component,nomvar,t);
163     }
164   catch ( const CalciumException & ex)
165     {
166       DEBTRACE( ex.what() );
167       return ex.getInfo();
168     }
169   return CalciumTypes::CPOK;
170 }
171
172 // INTERFACE C/CPP pour les chaines de caractères
173 // Le paramètre supplémentaire strsize n'étant pas utilisé
174 // j'utilise la génération par la macro CALCIUM_C2CPP_INTERFACE_(str,char*,);
175 // extern "C" CalciumTypes::InfoType ecp_lecture_str (void * component, int dependencyType, 
176 //                                                 float * ti, float * tf, long * i, 
177 //                                                 const char * const nomvar, size_t bufferLength, 
178 //                                                 size_t * nRead, char ** *data, size_t strsize ) { 
179
180 //   Superv_Component_i * _component = static_cast<Superv_Component_i *>(component); 
181 //   double         _ti=*ti;                                            
182 //   double         _tf=*tf;                                            
183 //   size_t         _nRead=0;                                           
184 //   size_t         _bufferLength=bufferLength;                         
185 //   CalciumTypes::DependencyType dependencyType=                       
186 //     static_cast<CalciumTypes::DependencyType>(dependencyType);       
187   
188 //   // - GERER POINTEUR NULL : NOTHING TODO 
189 //   // - VERIFIER LA TAILLE DES CHAINES RETOURNEES (ELLES DEVRAIENT ETRES CORRECTES SI L'ECRITURE EST BIEN CODEE.)
190
191 //   DEBTRACE( "-------- CalciumInterface(lecture Inter Part) MARK 1 ------------------" ) 
192 //     try {                                                            
193 //       CalciumInterface::ecp_lecture< char*, char* >( *_component,    
194 //                                                   dependencyType, 
195 //                                                   _ti, _tf, *i,      
196 //                                                   nomvar,            
197 //                                                   _bufferLength, _nRead, *data); 
198 //     } catch ( const CalciumException & ex) {                         
199 //       DEBTRACE( ex.what() );
200 //       return ex.getInfo();                                           
201 //     }                                                                        
202     
203 //     *nRead = _nRead;                                         
204     
205 //     if (dependencyType == CalciumTypes::CP_SEQUENTIEL ) 
206 //       *ti=(float)(_ti);                      
207     
208 //     DEBTRACE( "-------- CalciumInterface(lecture Inter Part), Data Ptr :" << *data ) ;
209
210 //     return CalciumTypes::CPOK;
211 //   };                                                                 
212                                                                         
213
214 // extern "C" void ecp_lecture_str_free (char** data) { 
215 //   CalciumInterface::ecp_free< char*, char* >(data);                  
216 // };                                                                   
217                                                                         
218                                                                         
219 // extern "C" CalciumTypes::InfoType ecp_ecriture_str (void * component, int dependencyType, 
220 //                                                  float *t, long  i,  
221 //                                                  const char * const nomvar, size_t bufferLength, 
222 //                                                  char ** data, int strsize ) { 
223
224 //     Superv_Component_i * _component = static_cast<Superv_Component_i *>(component); 
225 //     /* Je ne sais pas pourquoi, je n'arrive pas à passer t par valeur : corruption de la pile*/ 
226 //     double         _t=*t;                                            
227 //     size_t         _bufferLength=bufferLength;                               
228
229 //     // - VERIFIER LA TAILLE DES CHAINES RETOURNEES (ELLES DEVRAIENT ETRES CORRECTES SI L'ECRITURE EST BIEN CODEE.)
230
231 //     DEBTRACE( "-------- CalciumInterface(ecriture Inter Part) MARK 1 ------------------" ) 
232 //     try {                                                            
233 //       std::string essai(nomvar);                                     
234 //       DEBTRACE( "----------->-" << nomvar )          
235 //      CalciumInterface::ecp_ecriture< char*, char* >( *_component,    
236 //                                                      static_cast<CalciumTypes::DependencyType>(dependencyType), 
237 //                                                      _t,i,nomvar,_bufferLength,*data); 
238 //     } catch ( const CalciumException & ex) {                         
239 //       std::cerr << ex.what() << std::endl;                           
240 //       return ex.getInfo();                                           
241 //     }                                                                        
242 //     DEBTRACE( "-------- CalciumInterface(ecriture Inter Part), Valeur de data :" << data ) 
243 //     return CalciumTypes::CPOK;                                               
244 //   };