SubscriptionCycle.cpp

Go to the documentation of this file.
00001 // Copyright CERN 2012 - Developed in collaboration with GSI
00002 
00003 #include <fesa-core/RDADeviceServer/SubscriptionCycle.h>
00004 
00005 #include <fesa-core/Synchronization/MultiplexingContext.h>
00006 
00007 
00008 namespace fesa
00009 {
00010 
00011 SubscriptionCycle::SubscriptionCycle()
00012 {
00013 }
00014 
00015 SubscriptionCycle::~SubscriptionCycle()
00016 {
00017 }
00018 
00019 void SubscriptionCycle::addCycle(const std::string& cycle)
00020 {
00021     CyclesItr itr = cycles_.find(cycle);
00022     if(itr != cycles_.end())
00023     {
00024         //increment the refCounter for this cycle
00025         uint32_t refCount = (*itr).second +1;
00026         (*itr).second = refCount;
00027     }
00028     else
00029     {
00030         cycles_[cycle] = 1;
00031     }
00032 }
00033 
00034 void SubscriptionCycle::removeCycle(const std::string& cycle)
00035 {
00036     CyclesItr itr = cycles_.find(cycle);
00037     if ((*itr).second == 1)
00038         cycles_.erase(itr);
00039     else
00040     {
00041         //decrement the refCounter for this cycle
00042         uint32_t refCount = (*itr).second -1;
00043         (*itr).second = refCount;
00044     }
00045 }
00046 
00047 void SubscriptionCycle::matchContext(MultiplexingContext& ctxt, std::vector<std::string>& validCycles)
00048 {
00049     CyclesItr itr = cycles_.begin();
00050     CyclesItr itrEnd = cycles_.end();
00051     // just in case...
00052     validCycles.clear();
00053 
00054     for(; itr != itrEnd; ++itr)
00055     {
00056         const std::string& cs = (*itr).first;
00057         if (ctxt.match(cs))
00058         {
00059             validCycles.push_back(cs);
00060         }
00061     }
00062 }
00063 
00064 void SubscriptionCycle::printDebugState(std::stringstream& str, int32_t tabNb)
00065 {
00066     std::string tabs;
00067     for (int32_t i=0; i<tabNb;++i)
00068         tabs.append("\t");
00069     CyclesItr itr = cycles_.begin();
00070     CyclesItr itrEnd = cycles_.end();
00071     for(; itr != itrEnd; ++itr)
00072     {
00073         str << tabs << " cycle: " << (*itr).first << " . refcount: " << (*itr).second << "\n";
00074     }
00075 }
00076 
00077 } // fesa

Generated on 18 Jan 2013 for Fesa by  doxygen 1.6.1