00001
00002
00003 #ifndef PROXY_INTERFACE_H_
00004 #define PROXY_INTERFACE_H_
00005
00006 #include <fesa-core/Proxy/ProxyReplyHandler.h>
00007 #include <fesa-core/Exception/FesaException.h>
00008
00009 #include <cmw-rda/DeviceHandle.h>
00010
00011 #include <string>
00012 #include <map>
00013
00014 class rdaRDAService;
00015
00016 namespace fesa
00017 {
00018
00026 class ProxyInterface
00027 {
00028 public:
00029
00033 ProxyInterface();
00034
00038 ~ProxyInterface();
00039
00049
00050
00051
00063
00064
00065
00066
00078 template<typename DataType> void setProperty(const std::string& deviceName,
00079 const std::string& cycleSelector, DataType& property);
00080
00093 template<typename DataType, typename FilterType> void setProperty(const std::string& deviceName,
00094 std::string& cycleSelector, DataType& property, FilterType& filter);
00095
00105
00106
00107
00118 template<typename DataType> void getProperty(const std::string& deviceName,
00119 const std::string& cycleSelector, DataType& property);
00120
00131
00132
00133
00134
00146 template<typename DataType, typename FilterType> void getProperty(const std::string& deviceName,
00147 const std::string& cycleSelector, DataType& property, FilterType& filter);
00148
00156 void subscribe(const std::string& deviceName, const std::string& propertyName);
00157
00166 void subscribe(const std::string& deviceName, const std::string& propertyName,
00167 const std::string& cycleSelector);
00168
00176 void unsubscribe(const std::string& deviceName, const std::string& propertyName);
00177
00186 void unsubscribe(const std::string& deviceName, const std::string& propertyName,
00187 const std::string& cycleSelector);
00188
00198 void waitNotification(std::string& deviceName, std::string& propertyName, std::string& cycleSelectorName,
00199 rdaData& value);
00200
00201 private:
00202
00211 rdaDeviceHandle* getDeviceHandle(const std::string& deviceName);
00212
00216 rdaRDAService* rda_;
00217
00222 std::map<std::string, rdaDeviceHandle*> rdaDeviceHandleCollection_;
00223
00228 std::map<const std::string, rdaRequest*> subscriptionCollection_;
00229
00236 void registerDevice(const std::string& deviceName);
00237
00241 ProxyReplyHandler replyHandler_;
00242
00243 friend class OnSubscriptionEventSource;
00244
00245 };
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280 template<typename DataType> void ProxyInterface::setProperty(const std::string& deviceName,
00281 const std::string& cycleSelector, DataType& property)
00282 {
00283 try
00284 {
00285 rdaDeviceHandle* device = ProxyInterface::getDeviceHandle(deviceName);
00286 device->set(property.getPropertyName().c_str(), cycleSelector.c_str(), *(property.getRdaData()));
00287 }
00288 catch (const rdaException& ex)
00289 {
00290 throw FesaException(__FILE__, __LINE__, FesaErrorSettingRdaData.c_str(), ex.getMessage());
00291 }
00292 }
00293
00294 template<typename DataType, typename FilterType> void ProxyInterface::setProperty(const std::string& deviceName,
00295 std::string& cycleSelector, DataType& property, FilterType& filter)
00296 {
00297 try
00298 {
00299 rdaDeviceHandle* device = ProxyInterface::getDeviceHandle(deviceName);
00300 device->set(property.getPropertyName().c_str(), cycleSelector.c_str(), *(property.getRdaData()),
00301 *(filter.getRdaData()));
00302 }
00303 catch (const rdaException& ex)
00304 {
00305 throw FesaException(__FILE__, __LINE__, FesaErrorSettingRdaData.c_str(), ex.getMessage());
00306 }
00307 }
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342 template<typename DataType> void ProxyInterface::getProperty(const std::string& deviceName,
00343 const std::string& cycleSelector, DataType& property)
00344 {
00345 try
00346 {
00347 rdaDeviceHandle* device = ProxyInterface::getDeviceHandle(deviceName);
00348 property.setData((*device->get(property.getPropertyName().c_str(), cycleSelector.c_str())), false, false,
00349 true);
00350 }
00351 catch (const rdaException& ex)
00352 {
00353 throw FesaException(__FILE__, __LINE__, FesaErrorGettingRdaData.c_str(), ex.getMessage());
00354 }
00355 }
00356
00357 template<typename DataType, typename FilterType> void ProxyInterface::getProperty(const std::string& deviceName,
00358 const std::string& cycleSelector, DataType& property, FilterType& filter)
00359 {
00360 try
00361 {
00362 rdaDeviceHandle* device = ProxyInterface::getDeviceHandle(deviceName);
00363 property.setData((*device->get(property.getPropertyName().c_str(), cycleSelector.c_str(),
00364 filter.getRdaData())), false, false, true);
00365 }
00366 catch (const rdaException& ex)
00367 {
00368 throw FesaException(__FILE__, __LINE__, FesaErrorGettingRdaData.c_str(), ex.getMessage());
00369 }
00370 }
00371
00372 }
00373
00374 #endif // PROXY_INTERFACE_H_