SubscriptionFilter.h

Go to the documentation of this file.
00001 // Copyright CERN 2012 - Developed in collaboration with GSI
00002 
00003 #ifndef SUBSCRIPTION_FILTER_H_
00004 #define SUBSCRIPTION_FILTER_H_
00005 
00006 #include <fesa-core/Core/FesaDefs.h>
00007 
00008 #include <cmw-rda/Data.h>
00009 
00010 #include <string>
00011 #include <vector>
00012 #include <map>
00013 #include <sstream>
00014 #include <boost/shared_ptr.hpp>
00015 
00016 class rdaValueChangeListener;
00017 
00018 namespace fesa
00019 {
00020 
00021 class AbstractDevice;
00022 class Property;
00023 class MultiplexingContext;
00024 class NotificationThread;
00025 
00029 class AbstractSubscriptionFilter
00030 {
00031   public:
00032     AbstractSubscriptionFilter(AbstractDevice& device, Property& property, const rdaData& newFilter, bool useFastUpdate);
00033 
00034     virtual ~AbstractSubscriptionFilter();
00035 
00036     virtual void addSubscriber(const std::string& cycleSelector, rdaValueChangeListener* subscriber);
00037 
00038     virtual bool removeSubscriber(const std::string& cycleSelector, rdaValueChangeListener* subscriber, bool& isEmpty, bool& toBeDeleted);
00039 
00040     bool matchFilter(const rdaData& filter);
00041 
00042     virtual void notify(MultiplexingContext& muxContext, RequestType& reqType, std::vector<std::string>& validCS)  = 0;
00043 
00052     void cycleFirstUpdate(const std::string& cycleSelector, const rdaData& newFilter, rdaValueChangeListener* l);
00053 
00062     void allCyclesFirstUpdate(const rdaData& newFilter, rdaValueChangeListener* l);
00063 
00064     void reportInternalError(const std::string& category, int32_t errorCode, const std::string& message, bool changed);
00065 
00066     void cancelInternalError(const std::string& message, bool changed);
00067 
00068     void virtual printDebugState(std::stringstream& str);
00069 
00070   protected:
00071 
00072     AbstractDevice& device_;
00073 
00074     Property& property_;
00075 
00076     rdaData filter_;
00077 
00078     bool useFastUpdate_;
00079 
00080     struct FesaListener
00081     {
00082         // Constructor to initialize members
00083         FesaListener(rdaValueChangeListener* l) : subscriber_(l), updateStamp_(0), reportErrorOnce_(false) {};
00084 
00085         ~FesaListener() {};
00086         //the rda listener itself
00087         rdaValueChangeListener* subscriber_;
00088 
00089         //the time of the last update
00090         int64_t updateStamp_;
00091 
00092         //tells if the client never received any error in case we are still
00093         //reporting the same error
00094         bool reportErrorOnce_;
00095     };
00096 
00098     typedef std::vector<boost::shared_ptr<FesaListener> > ListenerVector;
00099     typedef ListenerVector::iterator LstnrItr;
00100 
00101     typedef std::map<std::string, boost::shared_ptr<ListenerVector> > ListenerMap;
00102     typedef ListenerMap::iterator LstnrMapItr;
00103     ListenerMap listeners_;
00104 
00105 };
00106 
00107 
00108 class SubscriptionFilter: public AbstractSubscriptionFilter
00109 {
00110   public:
00111     SubscriptionFilter(AbstractDevice& device, Property& property, const rdaData& newFilter, bool useFastUpdate, NotificationThread* pNotificationThread);
00112 
00113     ~SubscriptionFilter();
00114 
00115     void addSubscriber(const std::string& cycleSelector, rdaValueChangeListener* subscriber);
00116 
00117     bool removeSubscriber(const std::string& cycleSelector, rdaValueChangeListener* subscriber, bool& isEmpty, bool& toBeDeleted);
00118 
00119     void notify(MultiplexingContext& muxContext, RequestType& reqType, std::vector<std::string>& validCS);
00120 
00121     void doUpdate(MultiplexingContext& muxContext, RequestType& reqType, std::vector<std::string>& validCS);
00122 
00123   private:
00124 
00125     NotificationThread* pNotificationThread_;
00126 
00132     bool cancelled_;
00133 
00139     uint32_t pendingNotification_;
00140 };
00141 
00142 } // fesa
00143 
00144 #endif // SUBSCRIPTION_FILTER_H_

Generated on 18 Jan 2013 for Fesa by  doxygen 1.6.1