/*
|
* =====================================================================================
|
*
|
* 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 <string>
|
|
//TODO change storage to map<Remote,list<TimedData<Msg>>>, to avoid retry failed remotes messages.
|
class FailedMsgQ
|
{
|
typedef std::function<bool(void *)> Func;
|
typedef TimedQueue<Func> 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 msg);
|
|
TimedFuncQ queue_;
|
};
|
|
#endif // end of include guard: FAILED_MSG_9YOI86AS
|