lichao
2021-04-06 bb9a7e348892eb5c4fccb063380aa6fcd9612b71
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
 * =====================================================================================
 *
 *       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