BlinkenArea - GitList
Repositories
Blog
Wiki
Blinker
Code
Commits
Branches
Tags
Search
Tree:
05eaa37
Branches
Tags
master
Blinker
src
noarch
Priority.cpp
minor typos in comment
Stefan Schuermans
commited
05eaa37
at 2011-11-22 22:10:35
Priority.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 <list> #include <string> #include <BlinkenLib/BlinkenFrame.h> #include "CallMgr.h" #include "Directory.h" #include "File.h" #include "Module.h" #include "Priority.h" #include "PriorityInput.h" #include "SettingFile.h" #include "StreamMgr.h" #include "StreamRecv.h" namespace Blinker { /** * @brief constructor * @param[in] callMgr callback manager * @param[in] streamMgr stream manager * @param[in] dirBase base directory */ Priority::Priority(CallMgr &callMgr, StreamMgr &streamMgr, const Directory &dirBase): Module(callMgr, streamMgr, dirBase), m_dirInputs(dirBase.getSubdir("inputs")), m_fileOutStream(dirBase.getFile("outstream")), m_itCurIn(m_inList.rend()), m_pOutStream(NULL) { // set up updateInListFull(); getOutStream(); } /// virtual destructor Priority::~Priority() { // clean up releaseOutStream(); while (!m_inList.empty()) { delete m_inList.back().m_pInput; m_inList.pop_back(); } } /// check for update of configuration void Priority::updateConfig() { // input list update (directory modified -> full, otherwise -> light) if (m_dirInputs.checkModified()) updateInListFull(); else updateInListLight(); // output stream name file was modified -> re-get output stream if (m_fileOutStream.checkModified()) { releaseOutStream(); getOutStream(); } } /// light update of input list, i.e. check all entries in current input list void Priority::updateInListLight() { // walk through all inputs in input list and check for modification InList::iterator itIn; for (itIn = m_inList.begin(); itIn != m_inList.end(); ++itIn) itIn->m_pInput->updateConfig(); } /// full update of input list, i.e. scan subdirs in input list directory void Priority::updateInListFull() { // get list of subdirs in input directory typedef std::list<std::string> Subdirlist; Subdirlist curSubdirs; m_dirInputs.getEntries(Directory::TypeSubdir, curSubdirs); // walk through current input list and subdir list simultaneously Subdirlist::const_iterator itSubdir = curSubdirs.begin(); InList::iterator itIn = m_inList.begin(); while (itSubdir != curSubdirs.end() || itIn != m_inList.end()) { // new input inserted if (itIn == m_inList.end() || (itSubdir != curSubdirs.end() && *itSubdir < itIn->m_name)) { // create input object InEntry inEntry(*itSubdir); inEntry.m_pInput = new Input(*this, *itSubdir, m_dirInputs.getSubdir(*itSubdir)); if (inEntry.m_pInput) // insert input list entry m_inList.insert(itIn, inEntry); // advance to next subdir ++itSubdir; } // input removed else if (itSubdir == curSubdirs.end() || *itSubdir > itIn->m_name) { // remove input delete itIn->m_pInput; itIn = m_inList.erase(itIn); // do not advance to next subdir } // input stayed in input list else { // check for update itIn->m_pInput->updateConfig(); // advance to next file and next entry ++itSubdir; ++itIn; } } // while itSubdir itIn } /// get output stream void Priority::getOutStream() { // get name of output stream m_fileOutStream.getStr(m_nameOutStream); // get output stream m_pOutStream = &m_streamMgr.refStream(m_nameOutStream); // send current frame to stream curFrame(); } /// release output stream void Priority::releaseOutStream() { // send no frame information if (m_pOutStream) m_pOutStream->setNoFrame(); // unreference output stream m_pOutStream = NULL; m_streamMgr.unrefStream(m_nameOutStream); } /** * @brief select specific input (called by inputs) * @param[in] input input to select */ void Priority::select(const Input *pInput) { // search inputs for passed input m_itCurIn = m_inList.rbegin(); while (m_itCurIn != m_inList.rend() && m_itCurIn->m_pInput != pInput) ++m_itCurIn; // send current frame curFrame(); } /// select lower priority input (called by inputs) void Priority::selectLower() { stBlinkenFrame *pFrame; // search inputs with lower priority until a frame is found while (m_itCurIn != m_inList.rend()) { // check for frame if (m_itCurIn->m_pInput->getCurFrame(pFrame)) { // frame found -> keep this input as current, send frame frame(pFrame); return; } // try next input ++m_itCurIn; } // no input has got a frame -> send no frame noFrame(); } /// send current frame to output stream void Priority::curFrame() { stBlinkenFrame *pFrame; // current input available and frame it it available -> send frame if (m_itCurIn != m_inList.rend() && m_itCurIn->m_pInput->getCurFrame(pFrame)) frame(pFrame); // no frame available -> send this information else noFrame(); } /** * @brief set current frame (also called by inputs) * @param[in] pFrame new frame to use */ void Priority::frame(stBlinkenFrame *pFrame) { if (m_pOutStream) m_pOutStream->setFrame(pFrame); } /// set current frame to "no frame" void Priority::noFrame() { if (m_pOutStream) m_pOutStream->setNoFrame(); } /* ##################### # Priority::InEntry # ##################### */ /// constructor Priority::InEntry::InEntry(const std::string &name): m_name(name), m_pInput(NULL) { } } // namespace Blinker