BlinkenArea - GitList
Repositories
Blog
Wiki
Blinker
Code
Commits
Branches
Tags
Search
Tree:
7dc3e85
Branches
Tags
master
Blinker
src
noarch
Stream.cpp
avoid passing on same frame multiple times in a row
Stefan Schuermans
commited
7dc3e85
at 2011-11-19 22:13:47
Stream.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 <set> #include <BlinkenLib/BlinkenFrame.h> #include "Stream.h" #include "StreamRecv.h" namespace Blinker { /// constructor Stream::Stream(): m_pFrame(NULL) { } /// virtual destructor Stream::~Stream() { // free current frame if (m_pFrame) BlinkenFrameFree(m_pFrame); } /** * @brief attach a stream receiver * @param[in] recv stream receiver to attach */ void Stream::attach(StreamRecv *recv) { m_recvs.insert(recv); // send current frame to receiver if (m_pFrame) recv->setFrame(m_name, m_pFrame); else recv->setNoFrame(m_name); } /** * @brief detach a stream receiver * @param[in] recv stream receiver to detach */ void Stream::detach(StreamRecv *recv) { m_recvs.erase(recv); } /** * @brief set current frame * @param[in] pFrame current frame */ void Stream::setFrame(stBlinkenFrame *pFrame) { // leave if frame is already set to an identical one if (m_pFrame && !BlinkenFrameCompare(pFrame, m_pFrame)) return; // update local copy of current frame if (m_pFrame) BlinkenFrameFree(m_pFrame); m_pFrame = BlinkenFrameClone(pFrame); if (!m_pFrame) return; // out of memory: do not pass NULL pointer to receivers // pass frame to all receivers Recvs::iterator it; for (it = m_recvs.begin(); it != m_recvs.end(); ++it) (*it)->setFrame(m_name, m_pFrame); } /// set current frame to none void Stream::setNoFrame() { // leave if frame is already set to none if (!m_pFrame) return; // set current frame to none if (m_pFrame) { BlinkenFrameFree(m_pFrame); m_pFrame = NULL; } // pass "no frame" to all receivers Recvs::iterator it; for (it = m_recvs.begin(); it != m_recvs.end(); ++it) (*it)->setNoFrame(m_name); } /** * @brief get current frame * @param[out] pFrame current frame * @return if a current frame exists */ bool Stream::getCurFrame(stBlinkenFrame *&pFrame) { pFrame = m_pFrame; return m_pFrame; } } // namespace Blinker