BlinkenArea - GitList
Repositories
Blog
Wiki
Blinker
Code
Commits
Branches
Tags
Search
Tree:
3032550
Branches
Tags
master
Blinker
src
noarch
CallMgr.cpp
first version, plays videos to stdout
Stefan Schuermans
commited
3032550
at 2011-10-23 11:37:40
CallMgr.cpp
Blame
History
Raw
/* Blinker Copyright 2011 Stefan Schuermans <stefan@blinkenarea.org> Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html a blinkenarea.org project */ #include <map> #include <set> #include "CallMgr.h" #include "Time.h" #include "TimeCallee.h" namespace Blinker { /// constructor CallMgr::CallMgr() { } /// destructor CallMgr::~CallMgr() { } /** * @brief cancel callback at certain time * @param[in] callee whom not to call */ void CallMgr::cancelTimeCall(TimeCallee *callee) { // find time a call is registered at TimeCalleeMap::iterator itCallee; itCallee = m_timeCallees.find(callee); if (itCallee == m_timeCallees.end()) return; // no call registered const Time &time = itCallee->second; // remove registered call m_times[time].erase(callee); m_timeCallees.erase(itCallee); } /** * @brief request callback at certain time * @param[in] callee whom to call * @param[in] time when to call * * this cancels a previous time call request from callee */ void CallMgr::requestTimeCall(TimeCallee *callee, const Time &time) { // cancel previous call cancelTimeCall(callee); // register call at new time m_times[time].insert(callee); m_timeCallees[callee] = time; } /// run call manager void CallMgr::run() { while (!m_times.empty()) { // wait until next time is reached m_times.begin()->first.sleepUntil(); // get callees and remove entry from time map TimeCallees timeCallees = m_times.begin()->second; m_times.erase(m_times.begin()); // call callees TimeCallees::const_iterator itTC; for (itTC = timeCallees.begin(); itTC != timeCallees.end(); ++itTC) { m_timeCallees.erase(*itTC); // first remove request from callee map (*itTC)->timeCall(); // then call callee } } // while m_times } } // namespace Blinker