1 // Copyright (C) 2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : CalciumGenericProvidesPort.hxx
23 // Author : Eric Fayolle (EDF)
27 #ifndef _CALCIUM_GENERIC_PROVIDES_PORT_HXX_
28 #define _CALCIUM_GENERIC_PROVIDES_PORT_HXX_
30 #include <omnithread.h>
32 #include "PortProperties_i.hxx"
34 #include "calcium_provides_port.hxx"
36 #include "GenericProvidesPort.hxx"
37 #include "CalciumCouplingPolicy.hxx"
39 #include "CorbaTypes2CalciumTypes.hxx"
40 #include "CalciumTypes2CorbaTypes.hxx"
42 #include "DSC_Exception.hxx"
46 // Cette macro CPP remplace une déclaration : template <typename CorbaInterface, typename CorbaDataManipulator >
47 // mais permet surtout de générer différentes classes (dont le nom est spécifié par specificPortName )
49 // Variante: Creer un trait qui à partir de CorbaInterface déduit CorbaDataManipulator
50 // et simplifier la classe
52 // L'utilisation conjointe du paramètre ... et de __VA_ARGS__ au lieu d'un 'CorbaDataManipulator' permet
53 // d'invoquer la macro avec un troisième token contenant une virgule
54 // (qui est considéré comme un séparateur d'argument par le PP )
56 #define CALCIUM_GENERIC_PROVIDES_PORT_HXX(specificPortName,CorbaInterface,...) \
57 class specificPortName : public virtual CorbaInterface , \
58 public virtual POA_Ports::PortProperties, \
59 public GenericProvidesPort< __VA_ARGS__ , CalciumCouplingPolicy, calcium_provides_port > { \
61 omni_mutex _disconnect_mutex; \
62 int _mustnotdisconnect; \
64 typedef __VA_ARGS__ DataManipulator; \
65 typedef DataManipulator::Type CorbaDataType; \
66 typedef GenericPort< DataManipulator , \
67 CalciumCouplingPolicy > Port; \
68 specificPortName () : _mustnotdisconnect(0) {}; \
70 virtual ~ specificPortName (); \
72 inline void disconnect(bool provideLastGivenValue) { \
73 _disconnect_mutex.lock(); \
74 if(_mustnotdisconnect > 1) \
76 _mustnotdisconnect--; \
78 else if(_mustnotdisconnect == 1) \
80 _mustnotdisconnect--; \
81 Port::disconnect(provideLastGivenValue); \
83 _disconnect_mutex.unlock(); \
85 inline void setDependencyType(CalciumTypes::DependencyType dependencyType) { \
86 Port::setDependencyType(dependencyType); \
88 inline CalciumTypes::DependencyType getDependencyType () const { \
89 return Port::getDependencyType(); \
91 inline void setStorageLevel (size_t storageLevel) { \
92 Port::setStorageLevel(storageLevel); \
94 inline size_t getStorageLevel () const { \
95 return Port::getStorageLevel(); \
97 inline void setDateCalSchem (CalciumTypes::DateCalSchem dateCalSchem) { \
98 Port::setDateCalSchem (dateCalSchem); \
100 inline CalciumTypes::DateCalSchem getDateCalSchem () const { \
101 return Port::getDateCalSchem (); \
103 inline void setAlpha(double alpha) { \
104 Port::setAlpha(alpha); \
106 inline double getAlpha() const { \
107 return Port::getAlpha(); \
109 inline void setDeltaT(double deltaT ) { \
110 Port::setDeltaT(deltaT); \
112 inline double getDeltaT() const { \
113 return Port::getDeltaT(); \
115 inline void setInterpolationSchem (CalciumTypes::InterpolationSchem interpolationSchem) { \
116 Port::setInterpolationSchem(interpolationSchem); \
118 inline void setExtrapolationSchem (CalciumTypes::ExtrapolationSchem extrapolationSchem) { \
119 Port::setExtrapolationSchem(extrapolationSchem); \
121 inline CalciumTypes::InterpolationSchem getInterpolationSchem() const { \
122 return Port::getInterpolationSchem(); \
124 inline CalciumTypes::ExtrapolationSchem getExtrapolationSchem() const { \
125 return Port::getExtrapolationSchem(); \
128 inline void put( DataManipulator::CorbaInType data, \
129 CORBA::Double time, CORBA::Long tag) { \
130 Port::put(data, time, tag); \
133 inline Ports::Port_ptr get_port_ref() { \
137 Ports::PortProperties_ptr get_port_properties() { \
138 return POA_Ports::PortProperties::_this(); \
141 virtual void set_property(const char * name, const CORBA::Any& value) \
142 throw (Ports::NotDefined, Ports::BadType, Ports::BadValue); \
144 virtual CORBA::Any* get_property(const char* name) \
145 throw (Ports::NotDefined); \
147 virtual void provides_port_changed(int connection_nbr, \
148 const Engines::DSC::Message message) { \
149 if ( message == Engines::DSC::AddingConnection) \
151 _disconnect_mutex.lock(); \
152 _mustnotdisconnect++; \
153 _disconnect_mutex.unlock(); \
155 else if ( message == Engines::DSC::RemovingConnection ) \
164 #define CALCIUM_GENERIC_PROVIDES_PORT_CXX(specificPortName) \
166 specificPortName::~specificPortName(void) {}; \
168 void specificPortName::set_property(const char * name, const CORBA::Any& value) \
169 throw (Ports::NotDefined, Ports::BadType, Ports::BadValue) { \
171 const std::string key(name); \
173 CORBA::Double alpha,delta; \
174 Ports::Calcium_Ports::DependencyType dt; \
175 Ports::Calcium_Ports::DateCalSchem dcs; \
176 Ports::Calcium_Ports::InterpolationSchem is; \
177 Ports::Calcium_Ports::ExtrapolationSchem es; \
182 if (key == "StorageLevel" ) \
183 {if ( ok=(value >>= sl) ) Port::setStorageLevel(sl);} \
184 else if (key == "Alpha" ) \
185 {if ( ok=(value >>= alpha) ) Port::setAlpha(alpha);} \
186 else if (key == "DeltaT" ) \
187 {if ( ok=(value >>= delta) ) Port::setDeltaT(delta);} \
188 else if (key == "DependencyType" ) \
189 {if ( ok=( value >>= dt) ) Port::setDependencyType(dependencyType[dt]);} \
190 else if (key == "DateCalSchem" ) \
191 {if ( ok=(value >>= dcs) ) \
192 Port::setDateCalSchem(dateCalSchem[dcs]);} \
193 else if (key == "InterpolationSchem") \
194 {if ( ok=(value >>= is) ) \
195 Port::setInterpolationSchem(interpolationSchem[is]);} \
196 else if (key == "ExtrapolationSchem") \
197 {if ( ok=(value >>= es) ) \
198 Port::setExtrapolationSchem(extrapolationSchem[es]);} \
200 throw Ports::NotDefined(); \
201 if (!ok) throw Ports::BadType(); \
203 } catch ( const DSC_Exception & ex ) { \
205 std::cerr << ex.what() << std::endl; \
206 throw Ports::BadValue(); \
211 CORBA::Any* specificPortName::get_property(const char* name) \
212 throw (Ports::NotDefined) { \
213 const std::string key(name); \
214 CORBA::Any* value=new CORBA::Any; \
215 if (key == "StorageLevel" ) \
216 { (*value) <<= static_cast<CORBA::Long>(Port::getStorageLevel()); } \
217 else if (key == "Alpha" ) \
218 { *value <<= (CORBA::Double) Port::getAlpha();} \
219 else if (key == "DeltaT" ) \
220 { *value <<= (CORBA::Double) Port::getDeltaT();} \
221 else if (key == "DependencyType" ) \
222 { *value <<= corbaDependencyType[Port::getDependencyType()];} \
223 else if (key == "DateCalSchem" ) \
224 { *value <<= corbaDateCalSchem[Port::getDateCalSchem()];} \
225 else if (key == "InterpolationSchem") \
226 { *value <<= corbaInterpolationSchem[Port::getInterpolationSchem()];} \
227 else if (key == "ExtrapolationSchem") \
228 { *value <<= corbaExtrapolationSchem[Port::getExtrapolationSchem()];} \
231 throw Ports::NotDefined(); \