56 lines
1.1 KiB
C
56 lines
1.1 KiB
C
|
|
#pragma once
|
||
|
|
#include <iostream>
|
||
|
|
#include <atomic>
|
||
|
|
#include <thread>
|
||
|
|
#include <mutex>
|
||
|
|
#include <condition_variable>
|
||
|
|
#include <vector>
|
||
|
|
#include <functional>
|
||
|
|
#include <chrono>
|
||
|
|
#include <string>
|
||
|
|
#include <memory>
|
||
|
|
#include "zmq.hpp"
|
||
|
|
#include "IVrZeroMQServer.h"
|
||
|
|
|
||
|
|
#ifdef _DEBUG
|
||
|
|
#pragma comment(lib, "libzmq-v142-mt-gd-4_3_5.lib")
|
||
|
|
#else
|
||
|
|
#pragma comment(lib, "libzmq-v142-mt-4_3_5.lib")
|
||
|
|
#endif // _DEBUG
|
||
|
|
|
||
|
|
#define MAX_BUF_LEN 2048
|
||
|
|
#define MONITOR_CHECK_TIMEOUT_MS 100
|
||
|
|
#define MONITOR_SLEEP_MS 10
|
||
|
|
#define POLL_TIMEOUT_MS 100
|
||
|
|
|
||
|
|
class CVrZeroMQTask
|
||
|
|
{
|
||
|
|
public:
|
||
|
|
CVrZeroMQTask();
|
||
|
|
virtual ~CVrZeroMQTask();
|
||
|
|
|
||
|
|
/// 创建服务
|
||
|
|
int Init(zmq::context_t* pContext, FunMQEvent funMQEvent, FunServerRecvAndAck funRecvAck);
|
||
|
|
|
||
|
|
/// 销毁服务
|
||
|
|
int UnInit();
|
||
|
|
|
||
|
|
private:
|
||
|
|
// Internal methods
|
||
|
|
void _WorkTask(zmq::context_t *context);
|
||
|
|
|
||
|
|
// ZeroMQ components
|
||
|
|
zmq::context_t* m_pContext;
|
||
|
|
zmq::socket_t* m_pSocket;
|
||
|
|
|
||
|
|
// Thread control
|
||
|
|
std::atomic<bool> m_bRecv;
|
||
|
|
std::atomic<bool> m_bRecvWorking;
|
||
|
|
|
||
|
|
std::thread m_recvThread;
|
||
|
|
|
||
|
|
// Callback functions
|
||
|
|
FunMQEvent m_funMQEvent;
|
||
|
|
FunServerRecvAndAck m_funRecvAck;
|
||
|
|
|
||
|
|
};
|