Salome HOME
updated copyright message
[modules/kernel.git] / src / DSC / DSC_User / Datastream / Calcium / CalciumMacroCInterface.hxx
1 // Copyright (C) 2007-2023  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 /*  
21 File   : CalciumInterface.hxx
22 Author : Eric Fayolle (EDF)
23 Module : KERNEL
24 Modified by : $LastChangedBy$
25 Date        : $LastChangedDate: 2007-03-01 13:27:58 +0100 (jeu, 01 mar 2007) $
26 Id          : $Id$
27 */
28
29 #ifndef _CALCIUM_MACRO_C_INTERFACE_H_
30 #define _CALCIUM_MACRO_C_INTERFACE_H_
31
32
33
34 /****** CALCIUM_C2CPP_INTERFACE_HXX_ :                                  ******/
35 /****** Declarations: ecp_lecture_... , ecp_ecriture_..., ecp_free_... ******/
36
37 #define CALCIUM_C2CPP_INTERFACE_HXX_(_name,_porttype,_type,_qual)                                                 \
38   extern "C" CalciumTypes::InfoType ecp_lecture_##_name (void * component, int dependencyType,                    \
39                                                          CalTimeType< _type _qual >::TimeType * ti,               \
40                                                          CalTimeType< _type _qual >::TimeType * tf, long * i,     \
41                                                          const char * const nomvar, size_t bufferLength,          \
42                                                          size_t * nRead, _type _qual ** data );                   \
43                                                                                                                   \
44                                                                                                                   \
45   extern "C" void ecp_lecture_##_name##_free ( _type _qual * data);                                               \
46                                                                                                                   \
47                                                                                                                   \
48   extern "C" CalciumTypes::InfoType ecp_ecriture_##_name (void * component, int dependencyType,                   \
49                                                           CalTimeType< _type _qual >::TimeType *t,                \
50                                                           long  i,                                                \
51                                                           const char * const nomvar, size_t bufferLength,         \
52                                                           _type _qual * data );                                   \
53   
54
55
56
57                                                                         
58 /****** CALCIUM_C2CPP_INTERFACE_CXX_ :                                ******/                                                                        
59 /******Definitions: ecp_lecture_... , ecp_ecriture_..., ecp_free_... ******/
60 #define CALCIUM_C2CPP_INTERFACE_CXX_(_name,_porttype,_type,_qual)                                                \
61   extern "C" CalciumTypes::InfoType ecp_lecture_##_name (void * component, int dependencyType,                   \
62                                                          CalTimeType< _type _qual >::TimeType * ti,              \
63                                                          CalTimeType< _type _qual >::TimeType * tf, long * i,    \
64                                                          const char * const nomvar, size_t bufferLength,         \
65                                                          size_t * nRead, _type _qual ** data )                   \
66   {                                                                                                              \
67     Superv_Component_i * _component = static_cast<Superv_Component_i *>(component);                              \
68     double         _ti=0.;                                                                                       \
69     double         _tf=0.;                                                                                       \
70     if(dependencyType == CalciumTypes::CP_TEMPS)                                                                               \
71       {                                                                                                          \
72         _ti=*ti;                                                                                                 \
73         _tf=*tf;                                                                                                 \
74       }                                                                                                          \
75     size_t         _nRead=0;                                                                                     \
76     size_t         _bufferLength=bufferLength;                                                                   \
77                                                                                                                  \
78     if ( IsSameType< _porttype , cplx >::value ) _bufferLength*=2;                                               \
79     DEBTRACE( "-------- CalciumInterface(lecture Inter Part) MARK 1 ------------------" );                       \
80     try                                                                                                          \
81       {                                                                                                          \
82         CalciumInterface::ecp_lecture< _type,_porttype >( *_component, dependencyType, _ti, _tf, *i, nomvar,     \
83                                                           _bufferLength, _nRead, *data);                         \
84       }                                                                                                          \
85     catch ( const CalciumException & ex)                                                                         \
86       {                                                                                                          \
87         DEBTRACE( ex.what() );                                                                                   \
88         return ex.getInfo();                                                                                     \
89       }                                                                                                          \
90     catch ( ... )                                                                                                \
91       {                                                                                                          \
92         DEBTRACE( "Unexpected exception ");                                                                      \
93         return CalciumTypes::CPATAL;                                                                             \
94       }                                                                                                          \
95     if ( IsSameType< _porttype , cplx >::value )                                                                 \
96       {                                                                                                          \
97         *nRead=_nRead/2;                                                                                         \
98         DEBTRACE( "-------- CalciumInterface(lecture Inter Part) IsSameType cplx -------------" );               \
99         DEBTRACE( "-------- CalciumInterface(lecture Inter Part) _nRead  : " << _nRead );                        \
100         DEBTRACE( "-------- CalciumInterface(lecture Inter Part) *nRead  : " << *nRead );                        \
101       }                                                                                                          \
102     else                                                                                                         \
103       *nRead = _nRead;                                                                                           \
104     if (dependencyType == CalciumTypes::CP_SEQUENTIEL )                                                          \
105       *ti=(CalTimeType< _type _qual >::TimeType)(_ti);                                                           \
106     DEBTRACE( "-------- CalciumInterface(lecture Inter Part), Data Ptr :" << *data );                            \
107     return CalciumTypes::CPOK;                                                                                   \
108   }                                                                                                              \
109                                                                                                                  \
110                                                                                                                  \
111   extern "C" void ecp_lecture_##_name##_free ( _type _qual * data)                                               \
112   {                                                                                                              \
113     CalciumInterface::ecp_free< _type, _porttype >(data);                                                        \
114   }                                                                                                             \
115                                                                                                                  \
116                                                                                                                  \
117   extern "C" CalciumTypes::InfoType ecp_ecriture_##_name (void * component, int dependencyType,           \
118                                                           CalTimeType< _type _qual >::TimeType *t,        \
119                                                           long  i,                                        \
120                                                           const char * const nomvar, size_t bufferLength, \
121                                                           _type _qual * data )                            \
122   {                                                                                                       \
123     DEBTRACE( "-------- CalciumInterface(ecriture Inter Part) MARK 0 ------------------" );               \
124     Superv_Component_i * _component = static_cast<Superv_Component_i *>(component);                       \
125     /* Je ne sais pas pourquoi, je n'arrive pas à passer t par valeur : corruption de la pile*/           \
126     double         _t=0.;                                                                                 \
127     if(dependencyType == CalciumTypes::CP_TEMPS)                                                                        \
128       _t=*t;                                                                                              \
129     size_t         _bufferLength=bufferLength;                                                            \
130     if ( IsSameType< _porttype , cplx >::value ) _bufferLength=_bufferLength*2;                           \
131     DEBTRACE( "-------- CalciumInterface(ecriture Inter Part) MARK 1 ------------------" );               \
132     try                                                                                                   \
133       {                                                                                                   \
134         /*printf("-------- CalciumInterface(ecriture Inter Part), cp_name : Nom de la var. de type %s : %s\n",#_type,nomvar);*/ \
135         DEBTRACE( "----------->-" << nomvar );                                                            \
136         CalciumInterface::ecp_ecriture< _type, _porttype >( *_component, dependencyType,                  \
137                                                             _t,i,nomvar,_bufferLength,*data);             \
138       }                                                                                                   \
139     catch ( const CalciumException & ex)                                                                  \
140       {                                                                                                   \
141         DEBTRACE( ex.what() );                                                                            \
142         return ex.getInfo();                                                                              \
143       }                                                                                                   \
144     catch ( ... )                                                                                         \
145       {                                                                                                   \
146         DEBTRACE("Unexpected exception " );                                                               \
147         return CalciumTypes::CPATAL;                                                                      \
148       }                                                                                                   \
149     DEBTRACE( "-------- CalciumInterface(ecriture Inter Part), Valeur de data :" << data );               \
150     return CalciumTypes::CPOK;                                                                            \
151   }                                                                                                      \
152
153
154 #endif