BlinkenArea - GitList
Repositories
Blog
Wiki
Blinker
Code
Commits
Branches
Tags
Search
Tree:
be034cc
Branches
Tags
master
Blinker
src
noarch
SenderDest_impl.h
sender static destination now own class
Stefan Schuermans
commited
be034cc
at 2011-11-22 22:13:20
SenderDest_impl.h
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 */ #ifndef SENDERDEST_IMPL_H #define SENDERDEST_IMPL_H #include <string> #include "Directory.h" #include "File.h" #include "Module.h" #include "Sender.h" #include "SenderDest.h" #include "SettingFile.h" namespace Blinker { /** * @brief constructor * @param[in] sender owning sender object * @param[in] dirBase base directory * @param[in] pNoFrameData protocol data for "no frame" packet */ template<typename ADDR, typename SOCK> Sender<ADDR, SOCK>::Dest::Dest(Sender &sender, const Directory &dirBase, const std::string *pNoFrameData): m_sender(sender), m_fileAddr(dirBase.getFile("addr")), m_haveAddr(false), m_pNoFrameData(pNoFrameData), m_pData(pNoFrameData) { // set up getAddr(); } /// destructor template<typename ADDR, typename SOCK> Sender<ADDR, SOCK>::Dest::~Dest() { // send "no frame" protocol data to old address send(m_pNoFrameData); } /// check for update of configuration template<typename ADDR, typename SOCK> void Sender<ADDR, SOCK>::Dest::updateConfig() { // address file was modified -> re-get address if (m_fileAddr.checkModified()) getAddr(); } /** * @brief set current protocol data * @param[in] pData protocol data to send to address */ template<typename ADDR, typename SOCK> void Sender<ADDR, SOCK>::Dest::setProtoData(const std::string *pData) { // remember new data m_pData = pData; // send new protocol data to current address send(m_pData); } /// (re-)get address template<typename ADDR, typename SOCK> void Sender<ADDR, SOCK>::Dest::getAddr() { std::string strAddr; // send "no frame" protocol data to old address send(m_pNoFrameData); // parse new address from file m_haveAddr = m_fileAddr.getStr(strAddr) && m_addr.fromStr(strAddr); // send current protocol data to new address send(m_pData); } /** * @brief send protocol data to address * @param[in] pData protocol data to send to address */ template<typename ADDR, typename SOCK> void Sender<ADDR, SOCK>::Dest::send(const std::string *pData) { if (m_sender.m_pSock && m_haveAddr && pData) m_sender.m_pSock->send(*pData, m_addr); } } // namespace Blinker #endif // #ifndef SENDERDEST_IMPL_H