BlinkenArea - GitList
Repositories
Blog
Wiki
Blinker
Code
Commits
Branches
Tags
Search
Tree:
73f8b37
Branches
Tags
master
Blinker
src
noarch
Sender.h
simplified implementation of sender module
Stefan Schuermans
commited
73f8b37
at 2011-11-22 22:43:29
Sender.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 SENDER_H #define SENDER_H #include <list> #include <map> #include <string> #include <BlinkenLib/BlinkenProto.h> #include <BlinkenLib/BlinkenFrame.h> #include "CallMgr.h" #include "Directory.h" #include "File.h" #include "IoCallee.h" #include "Module.h" #include "SettingFile.h" #include "StreamMgr.h" #include "StreamRecv.h" #include "Time.h" #include "TimeCallee.h" namespace Blinker { /// stream sender template<typename ADDR, typename SOCK> class Sender: public IoCallee, public Module, public StreamRecv, public TimeCallee { protected: /// static destination class Dest; /// static destination list entry struct DestEntry { std::string m_name; ///< name of static destination Dest *m_pDest; ///< static destination object DestEntry(const std::string &name); ///< constructor }; /// static destinations typedef std::list<DestEntry> DestList; /// dynamic destinations: address -> time of last request typedef std::map<ADDR, Time> DynDests; public: /** * @brief constructor * @param[in] callMgr callback manager * @param[in] streamMgr stream manager * @param[in] dirBase base directory */ Sender(CallMgr &callMgr, StreamMgr &streamMgr, const Directory &dirBase); /// virtual destructor virtual ~Sender(); private: /// copy constructor disabled Sender(const Sender &that); /// assignment operator disabled const Sender & operator=(const Sender &that); public: /// check for update of configuration virtual void updateConfig(); /** * @brief set current frame * @param[in] stream stream name * @param[in] pFrame current frame */ virtual void setFrame(const std::string &stream, stBlinkenFrame *pFrame); /** * @brief set current frame to none * @param[in] stream stream name */ virtual void setNoFrame(const std::string &stream); /// callback when requsted time reached virtual void timeCall(); /** * @brief callback when I/O object is readable * @param[in] io I/O object that is readable */ virtual void ioReadCall(Io *io); /** * @brief callback when I/O object is writable * @param[in] io I/O object that is writable */ virtual void ioWriteCall(Io *io); protected: /** * @brief free static destiation list * @param[in] destList static destination list to free */ void freeDestList(DestList &destList); /// get input stream and attach to it void getInStream(); /// detach from input stream and release it void releaseInStream(); /// create socket and bind it void createSock(); /// destroy socket void destroySock(); /** * @brief light update of static destinations, * i.e. stat all files in current static destination directory * @param[in] destList static destinations for protocol */ void updateDestsLight(DestList &destList); /** * @brief full update of static destinations, * i.e. scan files in playlist directory * @param[in] dirDests static destinations directory for protocol * @param[in] destList static destinations for protocol * @param[in] pNoFrameData "no frame" protocaol data */ void updateDestsFull(Directory &dirDests, DestList &destList, const std::string *pNoFrameData); /// remove timed-out dynamic destinations void removeTimedOutDynDests(); /// send current protocol data to all destinations void sendAllProto(); /// send "no frame" to all destinations void sendAllNoFrame(); /** * @brief send data to static/dynamic destinations * @param[in] data *pData protocol data to send * @param[in] destList static destinations * @param[in] dynDests dynamic destinations */ void sendDests(const std::string *pData, const DestList destList, const DynDests dynDests); /** * @brief send protocol data to address * @param[in] data protcol data of frame * @param[in] addr address to send to */ void sendProto(const std::string &data, const ADDR &addr) const; /** * @brief convert frame to protocol data * @param[in] pFrame frame * @param[in] proto Blinken protocol identifier * @param[out] data protcol data */ static void frame2data(stBlinkenFrame *pFrame, etBlinkenProto proto, std::string &data); /** * @brief get "no frame" protocol data * @param[in] proto Blinken protocol identifier * @param[out] data protcol data */ static void noFrame2data(etBlinkenProto proto, std::string &data); /// receive data from socket void receiveFromSock(); protected: SettingFile m_fileInStream; ///< input stream name file SettingFile m_fileBind; ///< bind address file Directory m_dirDestsBlp; ///< static BLP destinations directory Directory m_dirDestsEblp; ///< static EBLP destinations directory Directory m_dirDestsMcuf; ///< static MCUF destinations directory std::string m_nameInStream; ///< name of input stream Stream *m_pInStream; ///< input stream SOCK *m_pSock; ///< socket to use for sending streams DestList m_destListBlp; ///< static BLP destinations DestList m_destListEblp; ///< static EBLP destinations DestList m_destListMcuf; ///< static MCUF destinations DynDests m_dynDestsBlp; ///< dynamic BLP destinations DynDests m_dynDestsEblp; ///< dynamic EBLP destinations DynDests m_dynDestsMcuf; ///< dynamic MCUF destinations std::string m_noFrameDataBlp; ///< "no frame" BLP protocol data std::string m_noFrameDataEblp; ///< "no frame" EBLP protocol data std::string m_noFrameDataMcuf; ///< "no frame" MCUF protocol data std::string m_dataBlp; ///< current BLP protocol data std::string m_dataEblp; ///< current BLP protocol data std::string m_dataMcuf; ///< current BLP protocol data }; // class Sender } // namespace Blinker #endif // #ifndef SENDER_H