2019-11-02 00:31:59 +08:00
|
|
|
#pragma once
|
2023-01-01 06:19:29 +08:00
|
|
|
|
2019-11-02 00:31:59 +08:00
|
|
|
#include <cstddef>
|
2020-05-22 04:57:25 +08:00
|
|
|
#include <map>
|
2019-11-02 00:31:59 +08:00
|
|
|
#include <string>
|
2020-05-22 04:57:25 +08:00
|
|
|
#include <vector>
|
2023-01-01 08:33:09 +08:00
|
|
|
#include <utility>
|
2022-11-22 08:10:55 +08:00
|
|
|
#include <time.h>
|
|
|
|
|
2023-01-01 06:19:29 +08:00
|
|
|
|
2019-11-02 00:31:59 +08:00
|
|
|
|
2020-09-14 04:38:23 +08:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#define CLOCK_BOOTTIME CLOCK_MONOTONIC
|
|
|
|
#endif
|
|
|
|
|
2019-12-05 06:05:20 +08:00
|
|
|
#define MSG_MULTIPLE_PUBLISHERS 100
|
|
|
|
|
2021-01-08 21:54:41 +08:00
|
|
|
bool messaging_use_zmq();
|
|
|
|
|
2019-11-02 00:31:59 +08:00
|
|
|
class Context {
|
|
|
|
public:
|
|
|
|
virtual void * getRawContext() = 0;
|
|
|
|
static Context * create();
|
2023-01-01 06:19:29 +08:00
|
|
|
virtual ~Context(){}
|
2019-11-02 00:31:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class Message {
|
|
|
|
public:
|
|
|
|
virtual void init(size_t size) = 0;
|
|
|
|
virtual void init(char * data, size_t size) = 0;
|
|
|
|
virtual void close() = 0;
|
|
|
|
virtual size_t getSize() = 0;
|
|
|
|
virtual char * getData() = 0;
|
2023-08-25 02:31:53 +08:00
|
|
|
virtual ~Message(){}
|
2019-11-02 00:31:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class SubSocket {
|
|
|
|
public:
|
2021-01-08 21:54:41 +08:00
|
|
|
virtual int connect(Context *context, std::string endpoint, std::string address, bool conflate=false, bool check_endpoint=true) = 0;
|
2019-11-02 00:31:59 +08:00
|
|
|
virtual void setTimeout(int timeout) = 0;
|
|
|
|
virtual Message *receive(bool non_blocking=false) = 0;
|
|
|
|
virtual void * getRawSocket() = 0;
|
|
|
|
static SubSocket * create();
|
2021-01-08 21:54:41 +08:00
|
|
|
static SubSocket * create(Context * context, std::string endpoint, std::string address="127.0.0.1", bool conflate=false, bool check_endpoint=true);
|
2023-08-25 02:31:53 +08:00
|
|
|
virtual ~SubSocket(){}
|
2019-11-02 00:31:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class PubSocket {
|
|
|
|
public:
|
2021-01-08 21:54:41 +08:00
|
|
|
virtual int connect(Context *context, std::string endpoint, bool check_endpoint=true) = 0;
|
2019-11-02 00:31:59 +08:00
|
|
|
virtual int sendMessage(Message *message) = 0;
|
|
|
|
virtual int send(char *data, size_t size) = 0;
|
2021-04-19 23:28:06 +08:00
|
|
|
virtual bool all_readers_updated() = 0;
|
2019-11-02 00:31:59 +08:00
|
|
|
static PubSocket * create();
|
2021-01-08 21:54:41 +08:00
|
|
|
static PubSocket * create(Context * context, std::string endpoint, bool check_endpoint=true);
|
|
|
|
static PubSocket * create(Context * context, std::string endpoint, int port, bool check_endpoint=true);
|
2023-08-25 02:31:53 +08:00
|
|
|
virtual ~PubSocket(){}
|
2019-11-02 00:31:59 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class Poller {
|
|
|
|
public:
|
|
|
|
virtual void registerSocket(SubSocket *socket) = 0;
|
|
|
|
virtual std::vector<SubSocket*> poll(int timeout) = 0;
|
|
|
|
static Poller * create();
|
|
|
|
static Poller * create(std::vector<SubSocket*> sockets);
|
2023-08-25 02:31:53 +08:00
|
|
|
virtual ~Poller(){}
|
2024-06-07 04:58:15 +08:00
|
|
|
};
|