BlinkenArea - GitList
Repositories
Blog
Wiki
Blinker
Code
Commits
Branches
Tags
Search
Tree:
d47b86a
Branches
Tags
master
Blinker
src
noarch
Stream.cpp
implemented stream printer (for debug purposes)
Stefan Schuermans
commited
d47b86a
at 2011-10-23 19:20:38
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_pFrame); else recv->setNoFrame(); } /** * @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) { // 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_pFrame); } /// set current frame to none void Stream::setNoFrame() { // 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(); } } // namespace Blinker