]> SALOME platform Git repositories - modules/kernel.git/blob - src/DSC/DSC_User/Datastream/Calcium/CalciumCInterface.cxx
Salome HOME
bos #42937: [CEA 41954] Integration of UB24.04 patches
[modules/kernel.git] / src / DSC / DSC_User / Datastream / Calcium / CalciumCInterface.cxx
1 // Copyright (C) 2007-2024  CEA, EDF, 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 DEBTRACE(msg) \
27   if (SALOME::VerbosityActivated()) \
28   { std::cerr << std::flush << __FILE__ << " [" << __LINE__ << "] : " << msg << std::endl << std::flush; } \
29   else (void)0
30
31 /* Définition de l'Interface entre l'API C  et l'API C++
32    L'utilisateur CALCIUM n'a normalement pas a utliser cette interface
33    En C/C++ il utilisera celle définie dans Calcium.c (calcium.h)
34    En C++/CORBA directement celle de CalciumCxxInterface.hxx
35 */
36
37
38 #define STAR *
39
40 /* Définition de ecp_lecture_... , ecp_ecriture_..., ecp_free_... */
41
42 /*  Le premier argument est utilisée :
43     - comme suffixe dans la définition des noms ecp_lecture_ , ecp_ecriture_ et ecp_free_
44     - comme second argument template à l'appel de la méthode C++ correspondante
45         ( le type de port correspondant est alors obtenu par un trait)
46    Le second argument est utilisée :
47    - pour typer le paramètre data de la procédure générée 
48    - pour déduire le type des paramètres t, ti tf via un trait
49    - comme premier paramètre template à l'appel de la méthode C++ correspondante
50          (pour typer les données passées en paramètre )
51    Notons que dans le cas CALCIUM_C2CPP_INTERFACE_(int,int,), le type int n'existe pas
52    en CORBA, le port CALCIUM correspondant utilise une séquence de long. La méthode
53    C++ CALCIUM de lecture repère cette différence de type et charge 
54    le manipulateur de données d'effectuer  une recopie (qui fonctionne si les types sont compatibles). 
55 */
56 // CALCIUM_C2CPP_INTERFACE_CXX_(_name,_porttype,_type,_qual)
57 CALCIUM_C2CPP_INTERFACE_CXX_(intc,int,int,)
58 CALCIUM_C2CPP_INTERFACE_CXX_(long,long,long,)
59
60 CALCIUM_C2CPP_INTERFACE_CXX_(integer,integer,cal_int,)
61 CALCIUM_C2CPP_INTERFACE_CXX_(int2integer ,integer,  int,)
62 CALCIUM_C2CPP_INTERFACE_CXX_(long2integer, integer, long,)
63
64 CALCIUM_C2CPP_INTERFACE_CXX_(float,float,float, )
65 CALCIUM_C2CPP_INTERFACE_CXX_(double,double,double,)
66
67 CALCIUM_C2CPP_INTERFACE_CXX_(float2double,double,float, )
68
69 /*  Fonnctionne mais essai suivant pour simplification de Calcium.c CALCIUM_C2CPP_INTERFACE_(bool,bool,);*/
70 CALCIUM_C2CPP_INTERFACE_CXX_(bool,bool,int,)
71 CALCIUM_C2CPP_INTERFACE_CXX_(cplx,cplx,float,)
72 CALCIUM_C2CPP_INTERFACE_CXX_(str,str,char*,)
73
74 /* Définition de ecp_fin */
75 extern "C" CalciumTypes::InfoType 
76 ecp_fin_ (void * component, int code) {
77
78   Superv_Component_i * _component = static_cast<Superv_Component_i *>(component); 
79
80   bool provideLastGivenValue = false;
81   if (code == CalciumTypes::CP_CONT ) provideLastGivenValue = true;
82
83   try {                                                                 
84     CalciumInterface::ecp_fin( *_component,                             
85                                provideLastGivenValue); 
86   } catch ( const CalciumException & ex) { //tester l'arrêt par exception
87     DEBTRACE( ex.what() );
88     return ex.getInfo();                                                
89   }                                                                     
90   return CalciumTypes::CPOK;
91 }
92
93 extern "C" CalciumTypes::InfoType 
94 ecp_cd_ (void * component, char * instanceName) {
95   Superv_Component_i * _component = static_cast<Superv_Component_i *>(component); 
96   std::string name;
97   CalciumInterface::ecp_cd( *_component,name);
98   strcpy(instanceName,name.c_str());
99   return CalciumTypes::CPOK;
100 }
101
102 // Interface for cleaning
103 extern "C" CalciumTypes::InfoType 
104 ecp_fini_ (void * component, char* nomvar, int i)
105 {
106   Superv_Component_i * _component = static_cast<Superv_Component_i *>(component); 
107   try
108     {
109       CalciumInterface::ecp_fini( *_component,nomvar,i);
110     }
111   catch ( const CalciumException & ex)
112     {
113       DEBTRACE( ex.what() );
114       return ex.getInfo();
115     }
116   return CalciumTypes::CPOK;
117
118 }
119
120 extern "C" CalciumTypes::InfoType 
121 ecp_fint_ (void * component, char* nomvar, float t)
122 {
123   Superv_Component_i * _component = static_cast<Superv_Component_i *>(component); 
124   try
125     {
126       CalciumInterface::ecp_fint( *_component,nomvar,t);
127     }
128   catch ( const CalciumException & ex)
129     {
130       DEBTRACE( ex.what() );
131       return ex.getInfo();
132     }
133   return CalciumTypes::CPOK;
134 }
135
136 extern "C" CalciumTypes::InfoType 
137 ecp_effi_ (void * component, char* nomvar, int i)
138 {
139   Superv_Component_i * _component = static_cast<Superv_Component_i *>(component); 
140   try
141     {
142       CalciumInterface::ecp_effi( *_component,nomvar,i);
143     }
144   catch ( const CalciumException & ex)
145     {
146       DEBTRACE( ex.what() );
147       return ex.getInfo();
148     }
149   return CalciumTypes::CPOK;
150
151 }
152
153 extern "C" CalciumTypes::InfoType 
154 ecp_efft_ (void * component, char* nomvar, float t)
155 {
156   Superv_Component_i * _component = static_cast<Superv_Component_i *>(component); 
157   try
158     {
159       CalciumInterface::ecp_efft( *_component,nomvar,t);
160     }
161   catch ( const CalciumException & ex)
162     {
163       DEBTRACE( ex.what() );
164       return ex.getInfo();
165     }
166   return CalciumTypes::CPOK;
167 }
168
169 // INTERFACE C/CPP pour les chaines de caractères
170 // Le paramètre supplémentaire strsize n'étant pas utilisé
171 // j'utilise la génération par la macro CALCIUM_C2CPP_INTERFACE_(str,char*,);
172 // extern "C" CalciumTypes::InfoType ecp_lecture_str (void * component, int dependencyType, 
173 //                                                 float * ti, float * tf, long * i, 
174 //                                                 const char * const nomvar, size_t bufferLength, 
175 //                                                 size_t * nRead, char ** *data, size_t strsize ) { 
176
177 //   Superv_Component_i * _component = static_cast<Superv_Component_i *>(component); 
178 //   double         _ti=*ti;                                            
179 //   double         _tf=*tf;                                            
180 //   size_t         _nRead=0;                                           
181 //   size_t         _bufferLength=bufferLength;                         
182 //   CalciumTypes::DependencyType dependencyType=                       
183 //     static_cast<CalciumTypes::DependencyType>(dependencyType);       
184   
185 //   // - GERER POINTEUR NULL : NOTHING TODO 
186 //   // - VERIFIER LA TAILLE DES CHAINES RETOURNEES (ELLES DEVRAIENT ETRES CORRECTES SI L'ECRITURE EST BIEN CODEE.)
187
188 //   DEBTRACE( "-------- CalciumInterface(lecture Inter Part) MARK 1 ------------------" ) 
189 //     try {                                                            
190 //       CalciumInterface::ecp_lecture< char*, char* >( *_component,    
191 //                                                   dependencyType, 
192 //                                                   _ti, _tf, *i,      
193 //                                                   nomvar,            
194 //                                                   _bufferLength, _nRead, *data); 
195 //     } catch ( const CalciumException & ex) {                         
196 //       DEBTRACE( ex.what() );
197 //       return ex.getInfo();                                           
198 //     }                                                                        
199     
200 //     *nRead = _nRead;                                         
201     
202 //     if (dependencyType == CalciumTypes::CP_SEQUENTIEL ) 
203 //       *ti=(float)(_ti);                      
204     
205 //     DEBTRACE( "-------- CalciumInterface(lecture Inter Part), Data Ptr :" << *data ) ;
206
207 //     return CalciumTypes::CPOK;
208 //   };                                                                 
209                                                                         
210
211 // extern "C" void ecp_lecture_str_free (char** data) { 
212 //   CalciumInterface::ecp_free< char*, char* >(data);                  
213 // };                                                                   
214                                                                         
215                                                                         
216 // extern "C" CalciumTypes::InfoType ecp_ecriture_str (void * component, int dependencyType, 
217 //                                                  float *t, long  i,  
218 //                                                  const char * const nomvar, size_t bufferLength, 
219 //                                                  char ** data, int strsize ) { 
220
221 //     Superv_Component_i * _component = static_cast<Superv_Component_i *>(component); 
222 //     /* Je ne sais pas pourquoi, je n'arrive pas à passer t par valeur : corruption de la pile*/ 
223 //     double         _t=*t;                                            
224 //     size_t         _bufferLength=bufferLength;                               
225
226 //     // - VERIFIER LA TAILLE DES CHAINES RETOURNEES (ELLES DEVRAIENT ETRES CORRECTES SI L'ECRITURE EST BIEN CODEE.)
227
228 //     DEBTRACE( "-------- CalciumInterface(ecriture Inter Part) MARK 1 ------------------" ) 
229 //     try {                                                            
230 //       std::string essai(nomvar);                                     
231 //       DEBTRACE( "----------->-" << nomvar )          
232 //      CalciumInterface::ecp_ecriture< char*, char* >( *_component,    
233 //                                                      static_cast<CalciumTypes::DependencyType>(dependencyType), 
234 //                                                      _t,i,nomvar,_bufferLength,*data); 
235 //     } catch ( const CalciumException & ex) {                         
236 //       std::cerr << ex.what() << std::endl;                           
237 //       return ex.getInfo();                                           
238 //     }                                                                        
239 //     DEBTRACE( "-------- CalciumInterface(ecriture Inter Part), Valeur de data :" << data ) 
240 //     return CalciumTypes::CPOK;                                               
241 //   };