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,);
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*,);
74 /* Définition de ecp_fin */
75 extern "C" CalciumTypes::InfoType
76 ecp_fin_ (void * component, int code) {
78 Superv_Component_i * _component = static_cast<Superv_Component_i *>(component);
80 bool provideLastGivenValue = false;
81 if (code == CalciumTypes::CP_CONT ) provideLastGivenValue = true;
84 CalciumInterface::ecp_fin( *_component,
85 provideLastGivenValue);
86 } catch ( const CalciumException & ex) { //tester l'arrêt par exception
87 DEBTRACE( ex.what() );
90 return CalciumTypes::CPOK;
93 extern "C" CalciumTypes::InfoType
94 ecp_cd_ (void * component, char * instanceName) {
95 Superv_Component_i * _component = static_cast<Superv_Component_i *>(component);
97 CalciumInterface::ecp_cd( *_component,name);
98 strcpy(instanceName,name.c_str());
99 return CalciumTypes::CPOK;
102 // Interface for cleaning
103 extern "C" CalciumTypes::InfoType
104 ecp_fini_ (void * component, char* nomvar, int i)
106 Superv_Component_i * _component = static_cast<Superv_Component_i *>(component);
109 CalciumInterface::ecp_fini( *_component,nomvar,i);
111 catch ( const CalciumException & ex)
113 DEBTRACE( ex.what() );
116 return CalciumTypes::CPOK;
120 extern "C" CalciumTypes::InfoType
121 ecp_fint_ (void * component, char* nomvar, float t)
123 Superv_Component_i * _component = static_cast<Superv_Component_i *>(component);
126 CalciumInterface::ecp_fint( *_component,nomvar,t);
128 catch ( const CalciumException & ex)
130 DEBTRACE( ex.what() );
133 return CalciumTypes::CPOK;
136 extern "C" CalciumTypes::InfoType
137 ecp_effi_ (void * component, char* nomvar, int i)
139 Superv_Component_i * _component = static_cast<Superv_Component_i *>(component);
142 CalciumInterface::ecp_effi( *_component,nomvar,i);
144 catch ( const CalciumException & ex)
146 DEBTRACE( ex.what() );
149 return CalciumTypes::CPOK;
153 extern "C" CalciumTypes::InfoType
154 ecp_efft_ (void * component, char* nomvar, float t)
156 Superv_Component_i * _component = static_cast<Superv_Component_i *>(component);
159 CalciumInterface::ecp_efft( *_component,nomvar,t);
161 catch ( const CalciumException & ex)
163 DEBTRACE( ex.what() );
166 return CalciumTypes::CPOK;
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 ) {
177 // Superv_Component_i * _component = static_cast<Superv_Component_i *>(component);
181 // size_t _bufferLength=bufferLength;
182 // CalciumTypes::DependencyType dependencyType=
183 // static_cast<CalciumTypes::DependencyType>(dependencyType);
185 // // - GERER POINTEUR NULL : NOTHING TODO
186 // // - VERIFIER LA TAILLE DES CHAINES RETOURNEES (ELLES DEVRAIENT ETRES CORRECTES SI L'ECRITURE EST BIEN CODEE.)
188 // DEBTRACE( "-------- CalciumInterface(lecture Inter Part) MARK 1 ------------------" )
190 // CalciumInterface::ecp_lecture< char*, char* >( *_component,
194 // _bufferLength, _nRead, *data);
195 // } catch ( const CalciumException & ex) {
196 // DEBTRACE( ex.what() );
197 // return ex.getInfo();
202 // if (dependencyType == CalciumTypes::CP_SEQUENTIEL )
205 // DEBTRACE( "-------- CalciumInterface(lecture Inter Part), Data Ptr :" << *data ) ;
207 // return CalciumTypes::CPOK;
211 // extern "C" void ecp_lecture_str_free (char** data) {
212 // CalciumInterface::ecp_free< char*, char* >(data);
216 // extern "C" CalciumTypes::InfoType ecp_ecriture_str (void * component, int dependencyType,
218 // const char * const nomvar, size_t bufferLength,
219 // char ** data, int strsize ) {
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*/
224 // size_t _bufferLength=bufferLength;
226 // // - VERIFIER LA TAILLE DES CHAINES RETOURNEES (ELLES DEVRAIENT ETRES CORRECTES SI L'ECRITURE EST BIEN CODEE.)
228 // DEBTRACE( "-------- CalciumInterface(ecriture Inter Part) MARK 1 ------------------" )
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();
239 // DEBTRACE( "-------- CalciumInterface(ecriture Inter Part), Valeur de data :" << data )
240 // return CalciumTypes::CPOK;