BlinkenArea - GitList
Repositories
Blog
Wiki
Blinker
Code
Commits
Branches
Tags
Search
Tree:
7eaa394
Branches
Tags
master
Blinker
src
noarch
Sender.h
simplified sender module a lot, support only one protocol per instance
Stefan Schuermans
commited
7eaa394
at 2011-12-04 14:49:17
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 "Protocol.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 (NULL for none) */ virtual void setFrame(const std::string &stream, stBlinkenFrame *pFrame); /// 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: /// (re-)read protocol void readProto(); /// 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 */ void updateDestsLight(); /** * @brief full update of static destinations, * i.e. scan files in playlist directory */ void updateDestsFull(); /// 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 */ void sendDests(const std::string *pData); /** * @brief send protocol data to address * @param[in] data protcol data of frame (empty if unknown) * @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 (NULL for none) * @param[out] data protcol data */ void frame2data(stBlinkenFrame *pFrame, std::string &data) const; /// receive data from socket void receiveFromSock(); protected: SettingFile m_fileInStream; ///< input stream name file SettingFile m_fileBind; ///< bind address file SettingFile m_fileProtocol; ///< protocol file Directory m_dirDests; ///< static destinations directory std::string m_nameInStream; ///< name of input stream Stream *m_pInStream; ///< input stream SOCK *m_pSock; ///< socket to use for sending streams Protocol m_protocol; ///< protocol bool m_haveProtocol; ///< if protocol is known DestList m_destList; ///< static destinations DynDests m_dynDests; ///< dynamic destinations std::string m_noFrameData; ///< "no frame" protocol data (empty if unknown) std::string m_data; ///< current protocol data (empty if unknown) }; // class Sender } // namespace Blinker #endif // #ifndef SENDER_H