Notification.cpp

Go to the documentation of this file.
00001 // Copyright CERN 2012 - Developed in collaboration with GSI
00002 
00003 #include <fesa-core/RDADeviceServer/Notification.h>
00004 
00005 #include <fesa-core/RDADeviceServer/SubscriptionParameter.h>
00006 #include <fesa-core/Core/NotificationID.h>
00007 
00008 
00009 namespace fesa
00010 {
00011 
00012 Notification::Notification(NotificationID& id) :
00013     id_(id)
00014 {
00015 }
00016 
00017 void Notification::addSubscriber(boost::shared_ptr<SubscriptionParameter> sp)
00018 {
00019     // Insert the subscriptionParameter if it's not already registered
00020     SubscriptionItr itr = subscriptions_.find(sp->getName());
00021     if(itr == subscriptions_.end())
00022     {
00023         subscriptions_[sp->getName()] = sp;
00024     }
00025 }
00026 
00027 void Notification::addCycle(const std::string& cycleSelector)
00028 {
00029     // Update the subscriptionCycle list with the new cycleSelector
00030     subscriptionCycle_.addCycle(cycleSelector);
00031 }
00032 
00033 void Notification::removeSubscriber(boost::shared_ptr<SubscriptionParameter> sp, const std::string& cycleSelector, bool toBeDeleted)
00034 {
00035     // Remove the subscriptionParameter
00036     SubscriptionItr itr = subscriptions_.find(sp->getName());
00037     if(itr != subscriptions_.end())
00038     {
00039         if (toBeDeleted)
00040             subscriptions_.erase(itr);
00041         // remove the newCycleSelector from subscriptionCycle
00042         subscriptionCycle_.removeCycle(cycleSelector);
00043     }
00044 }
00045 
00046 void Notification::notify(MultiplexingContext& muxContext, RequestType& reqType)
00047 {
00048     // Check if any cycleSelector is matching the current context
00049     std::vector<std::string> validCS;
00050     // fill the validCS by calling matchContext
00051     subscriptionCycle_.matchContext(muxContext, validCS);
00052 
00053     if (validCS.size() != 0) // At least one registered cycleSelector is matching the current context
00054     {
00055         SubscriptionItr itr = subscriptions_.begin();
00056         SubscriptionItr itrEnd = subscriptions_.end();
00057         for(; itr != itrEnd; ++itr)
00058         {
00059             (*itr).second->notify(muxContext, reqType, validCS);
00060         }
00061     }
00062 }
00063 
00064 bool Notification::contains(const std::string& deviceName, const std::string &propName)
00065 {
00066     return id_.contains(propName, deviceName);
00067 }
00068 
00069 void Notification::printDebugState(std::stringstream& str)
00070 {
00071     str << "\t\tNotificationID: " << id_.getIDKey() << "\n";
00072 
00073     str << "\t\t\tSubscribers:\n";
00074     SubscriptionItr itr = subscriptions_.begin();
00075     SubscriptionItr itrEnd = subscriptions_.end();
00076     for(; itr != itrEnd; ++itr)
00077     {
00078         str << "\t\t\t\t" << (*itr).second->getName() << "\n";
00079     }
00080 
00081     str << "\t\t\tsubscriptionCycle:\n";
00082     subscriptionCycle_.printDebugState(str,4);
00083 }
00084 
00085 
00086 } // fesa

Generated on 18 Jan 2013 for Fesa by  doxygen 1.6.1