/* * ===================================================================================== * * Filename: failed_msg.h * * Description: * * Version: 1.0 * Created: 2021年04月12日 11时21分30秒 * Revision: none * Compiler: gcc * * Author: Li Chao (), lichao@aiotlink.com * Organization: * * ===================================================================================== */ #ifndef FAILED_MSG_9YOI86AS #define FAILED_MSG_9YOI86AS #include "msg.h" #include "socket.h" #include "timed_queue.h" #include //TODO change storage to map>>, to avoid retry failed remotes messages. class FailedMsgQ { typedef std::function Func; typedef TimedQueue TimedFuncQ; public: typedef bhome_msg::MsgI Msg; void Push(const std::string &remote, Msg const &msg, TimedFuncQ::TimePoint const &exr) { queue_.Push(PrepareSender(remote, msg), exr); } void Push(const std::string &remote, Msg const &msg, TimedFuncQ::Duration const &exr) { queue_.Push(PrepareSender(remote, msg), exr); } void TrySend(ShmSocket &socket) { queue_.CheckAll([&](Func &f) { return f(&socket); }); } private: Func PrepareSender(const std::string &remote, Msg const &msg); TimedFuncQ queue_; }; #endif // end of include guard: FAILED_MSG_9YOI86AS