1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "CalciumCInterface.hxx"
21 #include "CalciumCxxInterface.hxx"
28 #define DEBTRACE(msg) {std::cerr<<std::flush<<__FILE__<<" ["<<__LINE__<<"] : "<<msg<<std::endl<<std::flush;}
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
43 /* Définition de ecp_lecture_... , ecp_ecriture_..., ecp_free_... */
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).
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,);
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,);
67 CALCIUM_C2CPP_INTERFACE_CXX_(float,float,float, );
68 CALCIUM_C2CPP_INTERFACE_CXX_(double,double,double,);
70 CALCIUM_C2CPP_INTERFACE_CXX_(float2double,double,float, );
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*,);
77 /* Définition de ecp_fin */
78 extern "C" CalciumTypes::InfoType
79 ecp_fin_ (void * component, int code) {
81 Superv_Component_i * _component = static_cast<Superv_Component_i *>(component);
83 bool provideLastGivenValue = false;
84 if (code == CalciumTypes::CP_CONT ) provideLastGivenValue = true;
87 CalciumInterface::ecp_fin( *_component,
88 provideLastGivenValue);
89 } catch ( const CalciumException & ex) { //tester l'arrêt par exception
90 DEBTRACE( ex.what() );
93 return CalciumTypes::CPOK;
96 extern "C" CalciumTypes::InfoType
97 ecp_cd_ (void * component, char * instanceName) {
98 Superv_Component_i * _component = static_cast<Superv_Component_i *>(component);
100 CalciumInterface::ecp_cd( *_component,name);
101 strcpy(instanceName,name.c_str());
102 return CalciumTypes::CPOK;
105 // Interface for cleaning
106 extern "C" CalciumTypes::InfoType
107 ecp_fini_ (void * component, char* nomvar, int i)
109 Superv_Component_i * _component = static_cast<Superv_Component_i *>(component);
112 CalciumInterface::ecp_fini( *_component,nomvar,i);
114 catch ( const CalciumException & ex)
116 DEBTRACE( ex.what() );
119 return CalciumTypes::CPOK;
123 extern "C" CalciumTypes::InfoType
124 ecp_fint_ (void * component, char* nomvar, float t)
126 Superv_Component_i * _component = static_cast<Superv_Component_i *>(component);
129 CalciumInterface::ecp_fint( *_component,nomvar,t);
131 catch ( const CalciumException & ex)
133 DEBTRACE( ex.what() );
136 return CalciumTypes::CPOK;
139 extern "C" CalciumTypes::InfoType
140 ecp_effi_ (void * component, char* nomvar, int i)
142 Superv_Component_i * _component = static_cast<Superv_Component_i *>(component);
145 CalciumInterface::ecp_effi( *_component,nomvar,i);
147 catch ( const CalciumException & ex)
149 DEBTRACE( ex.what() );
152 return CalciumTypes::CPOK;
156 extern "C" CalciumTypes::InfoType
157 ecp_efft_ (void * component, char* nomvar, float t)
159 Superv_Component_i * _component = static_cast<Superv_Component_i *>(component);
162 CalciumInterface::ecp_efft( *_component,nomvar,t);
164 catch ( const CalciumException & ex)
166 DEBTRACE( ex.what() );
169 return CalciumTypes::CPOK;
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 ) {
180 // Superv_Component_i * _component = static_cast<Superv_Component_i *>(component);
184 // size_t _bufferLength=bufferLength;
185 // CalciumTypes::DependencyType dependencyType=
186 // static_cast<CalciumTypes::DependencyType>(dependencyType);
188 // // - GERER POINTEUR NULL : NOTHING TODO
189 // // - VERIFIER LA TAILLE DES CHAINES RETOURNEES (ELLES DEVRAIENT ETRES CORRECTES SI L'ECRITURE EST BIEN CODEE.)
191 // DEBTRACE( "-------- CalciumInterface(lecture Inter Part) MARK 1 ------------------" )
193 // CalciumInterface::ecp_lecture< char*, char* >( *_component,
197 // _bufferLength, _nRead, *data);
198 // } catch ( const CalciumException & ex) {
199 // DEBTRACE( ex.what() );
200 // return ex.getInfo();
205 // if (dependencyType == CalciumTypes::CP_SEQUENTIEL )
208 // DEBTRACE( "-------- CalciumInterface(lecture Inter Part), Data Ptr :" << *data ) ;
210 // return CalciumTypes::CPOK;
214 // extern "C" void ecp_lecture_str_free (char** data) {
215 // CalciumInterface::ecp_free< char*, char* >(data);
219 // extern "C" CalciumTypes::InfoType ecp_ecriture_str (void * component, int dependencyType,
221 // const char * const nomvar, size_t bufferLength,
222 // char ** data, int strsize ) {
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*/
227 // size_t _bufferLength=bufferLength;
229 // // - VERIFIER LA TAILLE DES CHAINES RETOURNEES (ELLES DEVRAIENT ETRES CORRECTES SI L'ECRITURE EST BIEN CODEE.)
231 // DEBTRACE( "-------- CalciumInterface(ecriture Inter Part) MARK 1 ------------------" )
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();
242 // DEBTRACE( "-------- CalciumInterface(ecriture Inter Part), Valeur de data :" << data )
243 // return CalciumTypes::CPOK;