BlinkenArea - GitList
Repositories
Blog
Wiki
Blinker
Code
Commits
Branches
Tags
Search
Tree:
773aff3
Branches
Tags
master
Blinker
src
noarch
Stream.cpp
add function to get current frame
Stefan Schuermans
commited
773aff3
at 2011-11-13 20:53:37
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(); } /** * @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