/*
|
* =====================================================================================
|
*
|
* Filename: topic_reply.h
|
*
|
* Description:
|
*
|
* Version: 1.0
|
* Created: 2021年04月06日 14时41分12秒
|
* Revision: none
|
* Compiler: gcc
|
*
|
* Author: Li Chao (),
|
* Organization:
|
*
|
* =====================================================================================
|
*/
|
#ifndef TOPIC_REPLY_3RVYPPWI
|
#define TOPIC_REPLY_3RVYPPWI
|
|
#include "bh_util.h"
|
#include "defs.h"
|
#include "msg.h"
|
#include "socket.h"
|
#include <deque>
|
#include <functional>
|
|
using bhome::msg::ProcInfo;
|
|
class SocketReply : private ShmSocket
|
{
|
typedef ShmSocket Socket;
|
|
public:
|
SocketReply(Socket::Shm &shm) :
|
Socket(shm, 64) {}
|
SocketReply() :
|
SocketReply(BHomeShm()) {}
|
~SocketReply() { Stop(); }
|
|
typedef std::function<bool(const std::string &topic, const std::string &data, std::string &reply)> OnRequest;
|
bool StartWorker(const OnRequest &rcb, int nworker = 2);
|
bool Stop() { return Socket::Stop(); }
|
bool RecvRequest(void *&src_info, std::string &topic, std::string &data, const int timeout_ms);
|
bool SendReply(void *src_info, const std::string &data, const int timeout_ms);
|
bool Register(const ProcInfo &proc_info, const std::vector<std::string> &topics, const int timeout_ms);
|
bool Heartbeat(const ProcInfo &proc_info, const int timeout_ms);
|
|
private:
|
};
|
|
#endif // end of include guard: TOPIC_REPLY_3RVYPPWI
|