BlinkenArea - GitList
Repositories
Blog
Wiki
Blinker
Code
Commits
Branches
Tags
Search
Tree:
0fee1b0
Branches
Tags
master
Blinker
src
noarch
Priority.cpp
implemented specialized setting files for different data types, simplified input/output stream handling in modules
Stefan Schuermans
commited
0fee1b0
at 2011-12-04 20:46:14
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 "OutStreamFile.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"), streamMgr), m_itCurIn(m_inList.rend()) { // set up updateInListFull(); } /// virtual destructor Priority::~Priority() { // clean up 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()) m_fileOutStream.update(); } /// 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 } /** * @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 ((pFrame = m_itCurIn->m_pInput->getCurFrame())) { // frame found -> keep this input as current, send frame m_fileOutStream.setFrame(pFrame); return; } // try next input ++m_itCurIn; } // no input has got a frame -> send no frame m_fileOutStream.setFrame(NULL); } /// 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() && (pFrame = m_itCurIn->m_pInput->getCurFrame())) m_fileOutStream.setFrame(pFrame); // no frame available -> send this information else m_fileOutStream.setFrame(NULL); } /* ##################### # Priority::InEntry # ##################### */ /// constructor Priority::InEntry::InEntry(const std::string &name): m_name(name), m_pInput(NULL) { } } // namespace Blinker