]> SALOME platform Git repositories - modules/kernel.git/blob - src/DSC/DSC_User/Datastream/Calcium/CalciumGenericProvidesPort.hxx
Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/kernel.git] / src / DSC / DSC_User / Datastream / Calcium / CalciumGenericProvidesPort.hxx
1 //  Copyright (C) 2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
3 // 
4 //  This library is free software; you can redistribute it and/or 
5 //  modify it under the terms of the GNU Lesser General Public 
6 //  License as published by the Free Software Foundation; either 
7 //  version 2.1 of the License. 
8 // 
9 //  This library is distributed in the hope that it will be useful, 
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 //  Lesser General Public License for more details. 
13 // 
14 //  You should have received a copy of the GNU Lesser General Public 
15 //  License along with this library; if not, write to the Free Software 
16 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
17 // 
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 //
21 //
22 //  File   : CalciumGenericProvidesPort.hxx
23 //  Author : Eric Fayolle (EDF)
24 //  Module : KERNEL
25 // Id          : $Id$
26
27 #ifndef _CALCIUM_GENERIC_PROVIDES_PORT_HXX_
28 #define _CALCIUM_GENERIC_PROVIDES_PORT_HXX_
29
30 #include "PortProperties_i.hxx"
31
32 #include "calcium_provides_port.hxx"
33
34 #include "GenericProvidesPort.hxx"
35 #include "CalciumCouplingPolicy.hxx"
36
37 #include "CorbaTypes2CalciumTypes.hxx"
38 #include "CalciumTypes2CorbaTypes.hxx"
39
40 #include "DSC_Exception.hxx"
41 #include <iostream>
42
43 //
44 // Cette macro CPP remplace une déclaration : template <typename CorbaInterface, typename CorbaDataManipulator > 
45 // mais permet surtout de générer différentes classes (dont le nom est spécifié par specificPortName ) 
46 //
47 // Variante: Creer un trait qui à partir de CorbaInterface déduit CorbaDataManipulator
48 // et simplifier la classe
49 //
50 // L'utilisation conjointe du paramètre ... et de __VA_ARGS__ au lieu d'un 'CorbaDataManipulator' permet
51 // d'invoquer la macro avec un troisième token contenant une virgule 
52 // (qui est considéré comme un séparateur d'argument par le PP ) 
53
54 #define CALCIUM_GENERIC_PROVIDES_PORT_HXX(specificPortName,CorbaInterface,...) \
55   class specificPortName :   public virtual CorbaInterface ,            \
56                              public virtual POA_Ports::PortProperties,  \
57                              public GenericProvidesPort< __VA_ARGS__ , CalciumCouplingPolicy, calcium_provides_port > { \
58   public :                                                              \
59     typedef  __VA_ARGS__               DataManipulator;                 \
60     typedef  DataManipulator::Type     CorbaDataType;                   \
61     typedef GenericPort< DataManipulator ,                              \
62       CalciumCouplingPolicy >          Port;                            \
63                                                                         \
64     virtual ~ specificPortName ();                                      \
65                                                                         \
66     inline void disconnect(bool provideLastGivenValue) {                \
67       Port::disconnect(provideLastGivenValue);                          \
68     }                                                                   \
69     inline void setDependencyType(CalciumTypes::DependencyType dependencyType) { \
70       Port::setDependencyType(dependencyType);                          \
71     }                                                                   \
72     inline CalciumTypes::DependencyType getDependencyType () const {    \
73       return Port::getDependencyType();                                 \
74     }                                                                   \
75     inline void   setStorageLevel (size_t storageLevel) {               \
76       Port::setStorageLevel(storageLevel);                              \
77     }                                                                   \
78     inline size_t getStorageLevel () const {                            \
79       return Port::getStorageLevel();                                   \
80     }                                                                   \
81     inline void   setDateCalSchem (CalciumTypes::DateCalSchem   dateCalSchem) { \
82       Port::setDateCalSchem (dateCalSchem);                             \
83     }                                                                   \
84     inline CalciumTypes::DateCalSchem getDateCalSchem () const {        \
85       return Port::getDateCalSchem ();                                  \
86     }                                                                   \
87     inline void setAlpha(double alpha) {                                \
88       Port::setAlpha(alpha);                                            \
89     }                                                                   \
90     inline double getAlpha() const  {                                   \
91       return Port::getAlpha();                                          \
92     }                                                                   \
93     inline void   setDeltaT(double deltaT ) {                           \
94       Port::setDeltaT(deltaT);                                          \
95     }                                                                   \
96     inline double getDeltaT() const  {                                  \
97       return Port::getDeltaT();                                         \
98     }                                                                   \
99     inline void setInterpolationSchem (CalciumTypes::InterpolationSchem interpolationSchem) { \
100       Port::setInterpolationSchem(interpolationSchem);                  \
101     }                                                                   \
102     inline void setExtrapolationSchem (CalciumTypes::ExtrapolationSchem extrapolationSchem) { \
103       Port::setExtrapolationSchem(extrapolationSchem);                  \
104     }                                                                   \
105     inline CalciumTypes::InterpolationSchem getInterpolationSchem() const  { \
106       return Port::getInterpolationSchem();                             \
107     }                                                                   \
108     inline CalciumTypes::ExtrapolationSchem getExtrapolationSchem() const  { \
109       return Port::getExtrapolationSchem();                             \
110     }                                                                   \
111                                                                         \
112     inline void put( DataManipulator::CorbaInType data,                 \
113                      CORBA::Double time, CORBA::Long tag) {             \
114       Port::put(data, time, tag);                                       \
115     }                                                                   \
116                                                                         \
117     inline Ports::Port_ptr get_port_ref() {                             \
118       return _this();                                                   \
119     }                                                                   \
120                                                                         \
121     Ports::PortProperties_ptr get_port_properties() {                   \
122       return POA_Ports::PortProperties::_this();                        \
123     }                                                                   \
124                                                                         \
125     virtual void set_property(const char * name, const CORBA::Any& value) \
126       throw (Ports::NotDefined, Ports::BadType, Ports::BadValue);       \
127                                                                         \
128     virtual CORBA::Any* get_property(const char* name)                  \
129       throw (Ports::NotDefined);                                        \
130                                                                         \
131     virtual void provides_port_changed(int connection_nbr, \
132                        const Engines::DSC::Message message) { \
133       if ( !connection_nbr && (message == Engines::DSC::RemovingConnection) ) \
134         { \
135            disconnect(false); \
136         } \
137     } \
138   };    \
139   
140
141
142
143 #define CALCIUM_GENERIC_PROVIDES_PORT_CXX(specificPortName)             \
144                                                                         \
145   specificPortName::~specificPortName(void) {};                         \
146                                                                         \
147   void specificPortName::set_property(const char * name,  const CORBA::Any& value) \
148     throw (Ports::NotDefined, Ports::BadType, Ports::BadValue) {        \
149                                                                         \
150     const std::string key(name);                                        \
151     CORBA::Long sl;                                                     \
152     CORBA::Double alpha,delta;                                          \
153     Ports::Calcium_Ports::DependencyType dt;                            \
154     Ports::Calcium_Ports::DateCalSchem  dcs;                            \
155     Ports::Calcium_Ports::InterpolationSchem is;                        \
156     Ports::Calcium_Ports::ExtrapolationSchem es;                        \
157     bool ok=false;                                                      \
158                                                                         \
159     try {                                                               \
160                                                                         \
161       if (key == "StorageLevel" )                                       \
162         {if ( ok=(value >>= sl)    ) Port::setStorageLevel(sl);}        \
163       else if (key == "Alpha"      )                                    \
164         {if ( ok=(value >>= alpha) ) Port::setAlpha(alpha);}            \
165       else if (key == "DeltaT"     )                                    \
166         {if ( ok=(value >>= delta) ) Port::setDeltaT(delta);}           \
167       else if (key == "DependencyType" )                                \
168         {if ( ok=( value >>= dt)   ) Port::setDependencyType(dependencyType[dt]);} \
169       else if (key == "DateCalSchem" )                                  \
170         {if ( ok=(value >>= dcs) )                                      \
171             Port::setDateCalSchem(dateCalSchem[dcs]);}                  \
172       else if (key == "InterpolationSchem")                             \
173         {if ( ok=(value >>= is) )                                       \
174             Port::setInterpolationSchem(interpolationSchem[is]);}       \
175       else if (key == "ExtrapolationSchem")                             \
176         {if ( ok=(value >>= es) )                                       \
177             Port::setExtrapolationSchem(extrapolationSchem[es]);}       \
178       else                                                              \
179         throw Ports::NotDefined();                                      \
180       if (!ok) throw Ports::BadType();                                  \
181                                                                         \
182     } catch ( const DSC_Exception & ex ) {                              \
183                                                                         \
184       std::cerr << ex.what() << std::endl;                              \
185       throw Ports::BadValue();                                          \
186     }                                                                   \
187   }                                                                     \
188                                                                         \
189                                                                         \
190   CORBA::Any* specificPortName::get_property(const char* name)          \
191     throw (Ports::NotDefined) {                                         \
192     const std::string key(name);                                        \
193     CORBA::Any* value=new CORBA::Any;                                   \
194     if (key == "StorageLevel"    )                                      \
195       { (*value) <<= static_cast<CORBA::Long>(Port::getStorageLevel()); } \
196     else if (key == "Alpha"      )                                      \
197       { *value <<= (CORBA::Double) Port::getAlpha();}                   \
198     else if (key == "DeltaT"     )                                      \
199       { *value <<= (CORBA::Double) Port::getDeltaT();}                  \
200     else if (key == "DependencyType" )                                  \
201       {  *value <<= corbaDependencyType[Port::getDependencyType()];}    \
202     else if (key == "DateCalSchem" )                                    \
203       { *value <<= corbaDateCalSchem[Port::getDateCalSchem()];}         \
204     else if (key == "InterpolationSchem")                               \
205       { *value <<= corbaInterpolationSchem[Port::getInterpolationSchem()];} \
206     else if (key == "ExtrapolationSchem")                               \
207       { *value <<= corbaExtrapolationSchem[Port::getExtrapolationSchem()];} \
208     else {                                                              \
209       delete value;                                                     \
210       throw Ports::NotDefined();                                        \
211     }                                                                   \
212     return value;                                                       \
213   };                                            
214                                                                         
215
216 #endif