BlinkenArea - GitList
Repositories
Blog
Wiki
Blinker
Code
Commits
Branches
Tags
Search
Tree:
3534d9a
Branches
Tags
master
Blinker
src
noarch
PriorityInput.cpp
simplified interface of getCurFrame mehtods
Stefan Schuermans
commited
3534d9a
at 2011-12-04 14:57:24
PriorityInput.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 <string> #include <BlinkenLib/BlinkenFrame.h> #include "Directory.h" #include "File.h" #include "Priority.h" #include "PriorityInput.h" #include "SettingFile.h" #include "StreamMgr.h" #include "StreamRecv.h" namespace Blinker { /** * @brief constructor * @param[in] priority owning priority based selector * @param[in] name name of input (i.e. priority) * @param[in] dirBase base directory */ Priority::Input::Input(Priority &priority, const std::string &name, const Directory &dirBase): m_priority(priority), m_name(name), m_fileInStream(dirBase.getFile("instream")), m_pInStream(NULL), m_pFrame(NULL) { // attach to input stream getInStream(); } /// virtual destructor Priority::Input::~Input() { // detach from input stream and release it releaseInStream(); } /// check for update of configuration void Priority::Input::updateConfig() { // input stream name file was modified -> re-get input stream if (m_fileInStream.checkModified()) { releaseInStream(); getInStream(); } } /** * @brief set current frame * @param[in] stream stream name * @param[in] pFrame current frame (NULL for none) */ void Priority::Input::setFrame(const std::string &stream, stBlinkenFrame *pFrame) { frame(pFrame); (void)stream; // unused } /** * @brief get current frame * @return current frame (NULL if none) */ stBlinkenFrame * Priority::Input::getCurFrame() { return m_pFrame; } /// get input stream and attach to it void Priority::Input::getInStream() { // get input stream m_fileInStream.getStr(m_nameInStream); m_pInStream = &m_priority.m_streamMgr.refStream(m_nameInStream); // attach to input stream if (m_pInStream) m_pInStream->attach(this); // processing of frame will happen automatically when stream sets frame } /// detach from input stream and release it void Priority::Input::releaseInStream() { // set current frame to none frame(NULL); // detach from input stream if (m_pInStream) m_pInStream->detach(this); // unreference stream m_pInStream = NULL; m_priority.m_streamMgr.unrefStream(m_nameInStream); } /** * @brief set current frame * @param[in] pFrame current frame (NULL for none) */ void Priority::Input::frame(stBlinkenFrame *pFrame) { // save new frame m_pFrame = pFrame; // there is a frame now if (pFrame) { // if we are current input if (m_priority.m_itCurIn != m_priority.m_inList.rend() && m_priority.m_itCurIn->m_pInput == this) // pass on frame m_priority.frame(pFrame); // we have a higher priority than current input if (m_priority.m_itCurIn == m_priority.m_inList.rend() || m_priority.m_itCurIn->m_name < m_name) // tell priority based selector to select us as input m_priority.select(this); } // there is no frame else { // if we are current input if (m_priority.m_itCurIn != m_priority.m_inList.rend() && m_priority.m_itCurIn->m_pInput == this) // tell priority based selector to select lower priority input m_priority.selectLower(); } } } // namespace Blinker