00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef _CALCIUM_GENERIC_PROVIDES_PORT_HXX_
00029 #define _CALCIUM_GENERIC_PROVIDES_PORT_HXX_
00030
00031 #include <omnithread.h>
00032
00033 #include "PortProperties_i.hxx"
00034
00035 #include "calcium_provides_port.hxx"
00036
00037 #include "GenericProvidesPort.hxx"
00038 #include "CalciumCouplingPolicy.hxx"
00039
00040 #include "CorbaTypes2CalciumTypes.hxx"
00041 #include "CalciumTypes2CorbaTypes.hxx"
00042
00043 #include "DSC_Exception.hxx"
00044 #include <iostream>
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 #define CALCIUM_GENERIC_PROVIDES_PORT_HXX(specificPortName,CorbaInterface,...) \
00058 class specificPortName : public virtual CorbaInterface , \
00059 public virtual POA_Ports::PortProperties, \
00060 public GenericProvidesPort< __VA_ARGS__ , CalciumCouplingPolicy, calcium_provides_port > { \
00061 private : \
00062 omni_mutex _disconnect_mutex; \
00063 int _mustnotdisconnect; \
00064 public : \
00065 typedef __VA_ARGS__ DataManipulator; \
00066 typedef DataManipulator::Type CorbaDataType; \
00067 typedef GenericPort< DataManipulator , \
00068 CalciumCouplingPolicy > Port; \
00069 specificPortName () : _mustnotdisconnect(0) {}; \
00070 \
00071 virtual ~ specificPortName (); \
00072 \
00073 inline void disconnect(bool provideLastGivenValue) { \
00074 _disconnect_mutex.lock(); \
00075 if(_mustnotdisconnect > 1) \
00076 { \
00077 _mustnotdisconnect--; \
00078 } \
00079 else if(_mustnotdisconnect == 1) \
00080 { \
00081 _mustnotdisconnect--; \
00082 Port::disconnect(provideLastGivenValue); \
00083 } \
00084 _disconnect_mutex.unlock(); \
00085 } \
00086 inline void setDependencyType(CalciumTypes::DependencyType dependencyType) { \
00087 Port::setDependencyType(dependencyType); \
00088 } \
00089 inline CalciumTypes::DependencyType getDependencyType () const { \
00090 return Port::getDependencyType(); \
00091 } \
00092 inline void setStorageLevel (size_t storageLevel) { \
00093 Port::setStorageLevel(storageLevel); \
00094 } \
00095 inline size_t getStorageLevel () const { \
00096 return Port::getStorageLevel(); \
00097 } \
00098 inline void setDateCalSchem (CalciumTypes::DateCalSchem dateCalSchem) { \
00099 Port::setDateCalSchem (dateCalSchem); \
00100 } \
00101 inline CalciumTypes::DateCalSchem getDateCalSchem () const { \
00102 return Port::getDateCalSchem (); \
00103 } \
00104 inline void setAlpha(double alpha) { \
00105 Port::setAlpha(alpha); \
00106 } \
00107 inline double getAlpha() const { \
00108 return Port::getAlpha(); \
00109 } \
00110 inline void setDeltaT(double deltaT ) { \
00111 Port::setDeltaT(deltaT); \
00112 } \
00113 inline double getDeltaT() const { \
00114 return Port::getDeltaT(); \
00115 } \
00116 inline void setInterpolationSchem (CalciumTypes::InterpolationSchem interpolationSchem) { \
00117 Port::setInterpolationSchem(interpolationSchem); \
00118 } \
00119 inline void setExtrapolationSchem (CalciumTypes::ExtrapolationSchem extrapolationSchem) { \
00120 Port::setExtrapolationSchem(extrapolationSchem); \
00121 } \
00122 inline CalciumTypes::InterpolationSchem getInterpolationSchem() const { \
00123 return Port::getInterpolationSchem(); \
00124 } \
00125 inline CalciumTypes::ExtrapolationSchem getExtrapolationSchem() const { \
00126 return Port::getExtrapolationSchem(); \
00127 } \
00128 \
00129 inline void put( DataManipulator::CorbaInType data, \
00130 CORBA::Double time, CORBA::Long tag) { \
00131 Port::put(data, time, tag); \
00132 } \
00133 \
00134 inline Ports::Port_ptr get_port_ref() { \
00135 return _this(); \
00136 } \
00137 \
00138 Ports::PortProperties_ptr get_port_properties() { \
00139 return POA_Ports::PortProperties::_this(); \
00140 } \
00141 \
00142 virtual void set_property(const char * name, const CORBA::Any& value) \
00143 throw (Ports::NotDefined, Ports::BadType, Ports::BadValue); \
00144 \
00145 virtual CORBA::Any* get_property(const char* name) \
00146 throw (Ports::NotDefined); \
00147 \
00148 virtual void provides_port_changed(int connection_nbr, \
00149 const Engines::DSC::Message message) { \
00150 if ( message == Engines::DSC::AddingConnection) \
00151 { \
00152 _disconnect_mutex.lock(); \
00153 _mustnotdisconnect++; \
00154 _disconnect_mutex.unlock(); \
00155 } \
00156 else if ( message == Engines::DSC::RemovingConnection ) \
00157 { \
00158 disconnect(false); \
00159 } \
00160 } \
00161 \
00162 inline void calcium_erase(float t,long i, bool before) \
00163 { \
00164 erase(t,i,before); \
00165 } \
00166 }; \
00167
00168
00169
00170 #define CALCIUM_GENERIC_PROVIDES_PORT_CXX(specificPortName) \
00171 \
00172 specificPortName::~specificPortName(void) {}; \
00173 \
00174 void specificPortName::set_property(const char * name, const CORBA::Any& value) \
00175 throw (Ports::NotDefined, Ports::BadType, Ports::BadValue) { \
00176 \
00177 const std::string key(name); \
00178 CORBA::Long sl; \
00179 CORBA::Double alpha,delta; \
00180 Ports::Calcium_Ports::DependencyType dt; \
00181 Ports::Calcium_Ports::DateCalSchem dcs; \
00182 Ports::Calcium_Ports::InterpolationSchem is; \
00183 Ports::Calcium_Ports::ExtrapolationSchem es; \
00184 bool ok=false; \
00185 \
00186 try { \
00187 \
00188 if (key == "StorageLevel" ) \
00189 {if ( ( ok=(value >>= sl) ) ) Port::setStorageLevel(sl);} \
00190 else if (key == "Alpha" ) \
00191 {if ( ( ok=(value >>= alpha) ) ) Port::setAlpha(alpha);} \
00192 else if (key == "DeltaT" ) \
00193 {if ( ( ok=(value >>= delta) ) ) Port::setDeltaT(delta);} \
00194 else if (key == "DependencyType" ) \
00195 {if ( ( ok=( value >>= dt) ) ) Port::setDependencyType(dependencyType[dt]);} \
00196 else if (key == "DateCalSchem" ) \
00197 {if ( ( ok=(value >>= dcs) ) ) \
00198 Port::setDateCalSchem(dateCalSchem[dcs]);} \
00199 else if (key == "InterpolationSchem") \
00200 {if ( ( ok=(value >>= is) ) ) \
00201 Port::setInterpolationSchem(interpolationSchem[is]);} \
00202 else if (key == "ExtrapolationSchem") \
00203 {if ( ( ok=(value >>= es) ) ) \
00204 Port::setExtrapolationSchem(extrapolationSchem[es]);} \
00205 else \
00206 throw Ports::NotDefined(); \
00207 if (!ok) throw Ports::BadType(); \
00208 \
00209 } catch ( const DSC_Exception & ex ) { \
00210 \
00211 std::cerr << ex.what() << std::endl; \
00212 throw Ports::BadValue(); \
00213 } \
00214 } \
00215 \
00216 \
00217 CORBA::Any* specificPortName::get_property(const char* name) \
00218 throw (Ports::NotDefined) { \
00219 const std::string key(name); \
00220 CORBA::Any* value=new CORBA::Any; \
00221 if (key == "StorageLevel" ) \
00222 { (*value) <<= static_cast<CORBA::Long>(Port::getStorageLevel()); } \
00223 else if (key == "Alpha" ) \
00224 { *value <<= (CORBA::Double) Port::getAlpha();} \
00225 else if (key == "DeltaT" ) \
00226 { *value <<= (CORBA::Double) Port::getDeltaT();} \
00227 else if (key == "DependencyType" ) \
00228 { *value <<= corbaDependencyType[Port::getDependencyType()];} \
00229 else if (key == "DateCalSchem" ) \
00230 { *value <<= corbaDateCalSchem[Port::getDateCalSchem()];} \
00231 else if (key == "InterpolationSchem") \
00232 { *value <<= corbaInterpolationSchem[Port::getInterpolationSchem()];} \
00233 else if (key == "ExtrapolationSchem") \
00234 { *value <<= corbaExtrapolationSchem[Port::getExtrapolationSchem()];} \
00235 else { \
00236 delete value; \
00237 throw Ports::NotDefined(); \
00238 } \
00239 return value; \
00240 };
00241
00242
00243 #endif