1 // Copyright (C) 2007-2024 CEA, EDF, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : CalciumGenericProvidesPort.hxx
24 // Author : Eric Fayolle (EDF)
28 #ifndef _CALCIUM_GENERIC_PROVIDES_PORT_HXX_
29 #define _CALCIUM_GENERIC_PROVIDES_PORT_HXX_
31 #include <omnithread.h>
33 #include "PortProperties_i.hxx"
35 #include "calcium_provides_port.hxx"
37 #include "GenericProvidesPort.hxx"
38 #include "CalciumCouplingPolicy.hxx"
40 #include "CorbaTypes2CalciumTypes.hxx"
41 #include "CalciumTypes2CorbaTypes.hxx"
43 #include "DSC_Exception.hxx"
47 // Cette macro CPP remplace une déclaration : template <typename CorbaInterface, typename CorbaDataManipulator >
48 // mais permet surtout de générer différentes classes (dont le nom est spécifié par specificPortName )
50 // Variante: Creer un trait qui à partir de CorbaInterface déduit CorbaDataManipulator
51 // et simplifier la classe
53 // L'utilisation conjointe du paramètre ... et de __VA_ARGS__ au lieu d'un 'CorbaDataManipulator' permet
54 // d'invoquer la macro avec un troisième token contenant une virgule
55 // (qui est considéré comme un séparateur d'argument par le PP )
57 #define CALCIUM_GENERIC_PROVIDES_PORT_HXX(specificPortName,CorbaInterface,...) \
58 class specificPortName : public virtual CorbaInterface , \
59 public virtual POA_Ports::PortProperties, \
60 public GenericProvidesPort< __VA_ARGS__ , CalciumCouplingPolicy, calcium_provides_port > { \
62 omni_mutex _disconnect_mutex; \
63 int _mustnotdisconnect; \
65 typedef __VA_ARGS__ DataManipulator; \
66 typedef DataManipulator::Type CorbaDataType; \
67 typedef GenericPort< DataManipulator , \
68 CalciumCouplingPolicy > Port; \
69 specificPortName () : _mustnotdisconnect(0) {}; \
71 virtual ~ specificPortName (); \
73 inline void disconnect(bool provideLastGivenValue) { \
74 _disconnect_mutex.lock(); \
75 if(_mustnotdisconnect > 1) \
77 _mustnotdisconnect--; \
79 else if(_mustnotdisconnect == 1) \
81 _mustnotdisconnect--; \
82 Port::disconnect(provideLastGivenValue); \
84 _disconnect_mutex.unlock(); \
86 inline void setDependencyType(CalciumTypes::DependencyType dependencyType) { \
87 Port::setDependencyType(dependencyType); \
89 inline CalciumTypes::DependencyType getDependencyType () const { \
90 return Port::getDependencyType(); \
92 inline void setStorageLevel (size_t storageLevel) { \
93 Port::setStorageLevel(storageLevel); \
95 inline size_t getStorageLevel () const { \
96 return Port::getStorageLevel(); \
98 inline void setDateCalSchem (CalciumTypes::DateCalSchem dateCalSchem) { \
99 Port::setDateCalSchem (dateCalSchem); \
101 inline CalciumTypes::DateCalSchem getDateCalSchem () const { \
102 return Port::getDateCalSchem (); \
104 inline void setAlpha(double alpha) { \
105 Port::setAlpha(alpha); \
107 inline double getAlpha() const { \
108 return Port::getAlpha(); \
110 inline void setDeltaT(double deltaT ) { \
111 Port::setDeltaT(deltaT); \
113 inline double getDeltaT() const { \
114 return Port::getDeltaT(); \
116 inline void setInterpolationSchem (CalciumTypes::InterpolationSchem interpolationSchem) { \
117 Port::setInterpolationSchem(interpolationSchem); \
119 inline void setExtrapolationSchem (CalciumTypes::ExtrapolationSchem extrapolationSchem) { \
120 Port::setExtrapolationSchem(extrapolationSchem); \
122 inline CalciumTypes::InterpolationSchem getInterpolationSchem() const { \
123 return Port::getInterpolationSchem(); \
125 inline CalciumTypes::ExtrapolationSchem getExtrapolationSchem() const { \
126 return Port::getExtrapolationSchem(); \
129 inline void put( DataManipulator::CorbaInType data, \
130 CORBA::Double time, CORBA::Long tag) { \
131 Port::put(data, time, tag); \
134 inline Ports::Port_ptr get_port_ref() { \
138 Ports::PortProperties_ptr get_port_properties() { \
139 return POA_Ports::PortProperties::_this(); \
142 virtual void set_property(const char * name, const CORBA::Any& value); \
144 virtual CORBA::Any* get_property(const char* name); \
146 virtual void provides_port_changed(int /*connection_nbr*/, \
147 const Engines::DSC::Message message) { \
148 if ( message == Engines::DSC::AddingConnection) \
150 _disconnect_mutex.lock(); \
151 _mustnotdisconnect++; \
152 _disconnect_mutex.unlock(); \
154 else if ( message == Engines::DSC::RemovingConnection ) \
160 inline void calcium_erase(float t,long i, bool before) \
168 #define CALCIUM_GENERIC_PROVIDES_PORT_CXX(specificPortName) \
170 specificPortName::~specificPortName(void) {} \
172 void specificPortName::set_property(const char * name, const CORBA::Any& value) \
175 const std::string key(name); \
177 CORBA::Double alpha,delta; \
178 Ports::Calcium_Ports::DependencyType dt; \
179 Ports::Calcium_Ports::DateCalSchem dcs; \
180 Ports::Calcium_Ports::InterpolationSchem is; \
181 Ports::Calcium_Ports::ExtrapolationSchem es; \
186 if (key == "StorageLevel" ) \
187 {if ( ( ok=(value >>= sl) ) ) Port::setStorageLevel(sl);} \
188 else if (key == "Alpha" ) \
189 {if ( ( ok=(value >>= alpha) ) ) Port::setAlpha(alpha);} \
190 else if (key == "DeltaT" ) \
191 {if ( ( ok=(value >>= delta) ) ) Port::setDeltaT(delta);} \
192 else if (key == "DependencyType" ) \
193 {if ( ( ok=( value >>= dt) ) ) Port::setDependencyType(dependencyType[dt]);} \
194 else if (key == "DateCalSchem" ) \
195 {if ( ( ok=(value >>= dcs) ) ) \
196 Port::setDateCalSchem(dateCalSchem[dcs]);} \
197 else if (key == "InterpolationSchem") \
198 {if ( ( ok=(value >>= is) ) ) \
199 Port::setInterpolationSchem(interpolationSchem[is]);} \
200 else if (key == "ExtrapolationSchem") \
201 {if ( ( ok=(value >>= es) ) ) \
202 Port::setExtrapolationSchem(extrapolationSchem[es]);} \
204 throw Ports::NotDefined(); \
205 if (!ok) throw Ports::BadType(); \
207 } catch ( const DSC_Exception & ex ) { \
209 std::cerr << ex.what() << std::endl; \
210 throw Ports::BadValue(); \
215 CORBA::Any* specificPortName::get_property(const char* name) \
217 const std::string key(name); \
218 CORBA::Any* value=new CORBA::Any; \
219 if (key == "StorageLevel" ) \
220 { (*value) <<= static_cast<CORBA::Long>(Port::getStorageLevel()); } \
221 else if (key == "Alpha" ) \
222 { *value <<= (CORBA::Double) Port::getAlpha();} \
223 else if (key == "DeltaT" ) \
224 { *value <<= (CORBA::Double) Port::getDeltaT();} \
225 else if (key == "DependencyType" ) \
226 { *value <<= corbaDependencyType[Port::getDependencyType()];} \
227 else if (key == "DateCalSchem" ) \
228 { *value <<= corbaDateCalSchem[Port::getDateCalSchem()];} \
229 else if (key == "InterpolationSchem") \
230 { *value <<= corbaInterpolationSchem[Port::getInterpolationSchem()];} \
231 else if (key == "ExtrapolationSchem") \
232 { *value <<= corbaExtrapolationSchem[Port::getExtrapolationSchem()];} \
235 throw Ports::NotDefined(); \