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_semaphore _mustnotdisconnectyet; \
63 typedef __VA_ARGS__ DataManipulator; \
64 typedef DataManipulator::Type CorbaDataType; \
65 typedef GenericPort< DataManipulator , \
66 CalciumCouplingPolicy > Port; \
68 specificPortName () :_mustnotdisconnectyet(0) {}; \
70 virtual ~ specificPortName (); \
72 inline void disconnect(bool provideLastGivenValue) { \
73 if (! _mustnotdisconnectyet.trywait() ) { \
74 Port::disconnect(provideLastGivenValue); \
77 inline void setDependencyType(CalciumTypes::DependencyType dependencyType) { \
78 Port::setDependencyType(dependencyType); \
80 inline CalciumTypes::DependencyType getDependencyType () const { \
81 return Port::getDependencyType(); \
83 inline void setStorageLevel (size_t storageLevel) { \
84 Port::setStorageLevel(storageLevel); \
86 inline size_t getStorageLevel () const { \
87 return Port::getStorageLevel(); \
89 inline void setDateCalSchem (CalciumTypes::DateCalSchem dateCalSchem) { \
90 Port::setDateCalSchem (dateCalSchem); \
92 inline CalciumTypes::DateCalSchem getDateCalSchem () const { \
93 return Port::getDateCalSchem (); \
95 inline void setAlpha(double alpha) { \
96 Port::setAlpha(alpha); \
98 inline double getAlpha() const { \
99 return Port::getAlpha(); \
101 inline void setDeltaT(double deltaT ) { \
102 Port::setDeltaT(deltaT); \
104 inline double getDeltaT() const { \
105 return Port::getDeltaT(); \
107 inline void setInterpolationSchem (CalciumTypes::InterpolationSchem interpolationSchem) { \
108 Port::setInterpolationSchem(interpolationSchem); \
110 inline void setExtrapolationSchem (CalciumTypes::ExtrapolationSchem extrapolationSchem) { \
111 Port::setExtrapolationSchem(extrapolationSchem); \
113 inline CalciumTypes::InterpolationSchem getInterpolationSchem() const { \
114 return Port::getInterpolationSchem(); \
116 inline CalciumTypes::ExtrapolationSchem getExtrapolationSchem() const { \
117 return Port::getExtrapolationSchem(); \
120 inline void put( DataManipulator::CorbaInType data, \
121 CORBA::Double time, CORBA::Long tag) { \
122 Port::put(data, time, tag); \
125 inline Ports::Port_ptr get_port_ref() { \
129 Ports::PortProperties_ptr get_port_properties() { \
130 return POA_Ports::PortProperties::_this(); \
133 virtual void set_property(const char * name, const CORBA::Any& value) \
134 throw (Ports::NotDefined, Ports::BadType, Ports::BadValue); \
136 virtual CORBA::Any* get_property(const char* name) \
137 throw (Ports::NotDefined); \
139 virtual void provides_port_changed(int connection_nbr, \
140 const Engines::DSC::Message message) { \
141 if ( message == Engines::DSC::AddingConnection) \
142 _mustnotdisconnectyet.post(); \
143 else if ( message == Engines::DSC::RemovingConnection ) \
150 #define CALCIUM_GENERIC_PROVIDES_PORT_CXX(specificPortName) \
152 specificPortName::~specificPortName(void) {}; \
154 void specificPortName::set_property(const char * name, const CORBA::Any& value) \
155 throw (Ports::NotDefined, Ports::BadType, Ports::BadValue) { \
157 const std::string key(name); \
159 CORBA::Double alpha,delta; \
160 Ports::Calcium_Ports::DependencyType dt; \
161 Ports::Calcium_Ports::DateCalSchem dcs; \
162 Ports::Calcium_Ports::InterpolationSchem is; \
163 Ports::Calcium_Ports::ExtrapolationSchem es; \
168 if (key == "StorageLevel" ) \
169 {if ( ok=(value >>= sl) ) Port::setStorageLevel(sl);} \
170 else if (key == "Alpha" ) \
171 {if ( ok=(value >>= alpha) ) Port::setAlpha(alpha);} \
172 else if (key == "DeltaT" ) \
173 {if ( ok=(value >>= delta) ) Port::setDeltaT(delta);} \
174 else if (key == "DependencyType" ) \
175 {if ( ok=( value >>= dt) ) Port::setDependencyType(dependencyType[dt]);} \
176 else if (key == "DateCalSchem" ) \
177 {if ( ok=(value >>= dcs) ) \
178 Port::setDateCalSchem(dateCalSchem[dcs]);} \
179 else if (key == "InterpolationSchem") \
180 {if ( ok=(value >>= is) ) \
181 Port::setInterpolationSchem(interpolationSchem[is]);} \
182 else if (key == "ExtrapolationSchem") \
183 {if ( ok=(value >>= es) ) \
184 Port::setExtrapolationSchem(extrapolationSchem[es]);} \
186 throw Ports::NotDefined(); \
187 if (!ok) throw Ports::BadType(); \
189 } catch ( const DSC_Exception & ex ) { \
191 std::cerr << ex.what() << std::endl; \
192 throw Ports::BadValue(); \
197 CORBA::Any* specificPortName::get_property(const char* name) \
198 throw (Ports::NotDefined) { \
199 const std::string key(name); \
200 CORBA::Any* value=new CORBA::Any; \
201 if (key == "StorageLevel" ) \
202 { (*value) <<= static_cast<CORBA::Long>(Port::getStorageLevel()); } \
203 else if (key == "Alpha" ) \
204 { *value <<= (CORBA::Double) Port::getAlpha();} \
205 else if (key == "DeltaT" ) \
206 { *value <<= (CORBA::Double) Port::getDeltaT();} \
207 else if (key == "DependencyType" ) \
208 { *value <<= corbaDependencyType[Port::getDependencyType()];} \
209 else if (key == "DateCalSchem" ) \
210 { *value <<= corbaDateCalSchem[Port::getDateCalSchem()];} \
211 else if (key == "InterpolationSchem") \
212 { *value <<= corbaInterpolationSchem[Port::getInterpolationSchem()];} \
213 else if (key == "ExtrapolationSchem") \
214 { *value <<= corbaExtrapolationSchem[Port::getExtrapolationSchem()];} \
217 throw Ports::NotDefined(); \