00001 #ifndef _RDA_SUBSCRIPTION_H_
00002 #define _RDA_SUBSCRIPTION_H_
00003
00004
00005
00006
00007
00008 #include <IceUtil/RecMutex.h>
00009 #include <IceUtil/Monitor.h>
00010 #include <rda/RDAService.h>
00011
00062 using namespace IceUtil;
00063
00064 class rdaSubscription : public rdaReplyHandler
00065 {
00066 friend class SubscriptionThread;
00067
00068 static rdaRDAService* m_rda;
00069 static rdaSet m_subscriptions;
00070 static Monitor<RecMutex> m_monitor;
00071 static SubscriptionThread* m_thread;
00072 static rdaLogger* m_logger;
00073
00074 char* m_device;
00075 char* m_property;
00076 char* m_cycle;
00077 rdaData* m_context;
00078 bool m_onChange;
00079
00080 rdaDeviceHandle* m_handle;
00081 rdaRequest* m_request;
00082 bool m_rejected;
00083
00084 static void init();
00085
00086 void updateState();
00087 void createHandle();
00088 void subscribe();
00089
00090 rdaSubscription(const rdaSubscription&);
00091 void operator=(const rdaSubscription&);
00092
00093 protected:
00094
00095
00110 rdaSubscription(const char* device,
00111 const char* property,
00112 const char* cycle,
00113 const rdaData* context,
00114 bool onChange);
00115
00124
00132 virtual void handleValue(const rdaData& value) = 0;
00140 virtual void handleError(const rdaIOError& err) = 0;
00141
00143
00152
00156 virtual void confirmed() {}
00162 virtual void rejected(const rdaException& why);
00171 virtual void disconnected() {}
00176 virtual void reconnected() {}
00177
00179
00180 public:
00181
00186 virtual ~rdaSubscription();
00195
00199 const char* getDevice() const { return m_device; }
00203 const char* getProperty() const { return m_property; }
00208 const char* getCycle() const { return m_cycle; }
00212 bool isOnChange() const { return m_onChange; }
00217 const rdaData* getContext() const { return m_context; }
00218
00220
00227
00232 bool isConfirmed() const { return m_request != 0; }
00237 bool isRejected() const { return m_rejected; }
00238
00240
00241
00242
00243 virtual void handleReply(const rdaRequest&, const rdaData& value)
00244 {
00245 handleValue(value);
00246 }
00247
00248 virtual void disconnected(const rdaRequest&);
00249
00250 virtual void reconnected(const rdaRequest&)
00251 {
00252 reconnected();
00253 }
00254
00255 virtual void handleException(const rdaRequest&, const rdaIOError& err)
00256 {
00257 handleError(err);
00258 }
00259
00260 };
00261
00273 #endif