51 lines
1.1 KiB
C++
51 lines
1.1 KiB
C++
#pragma once
|
|
#include <iostream>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <thread>
|
|
#include <grpcpp/grpcpp.h>
|
|
#include "../protobuf/stream.grpc.pb.h"
|
|
#include "RWData.h"
|
|
|
|
using grpc::Channel;
|
|
using grpc::ClientContext;
|
|
using grpc::Status;
|
|
using stream::Stream;
|
|
using stream::RequestInfo;
|
|
using stream::ResponseInfo;
|
|
|
|
|
|
class StreamClient {
|
|
typedef void (*DataCallBack)(void* pthis, const ReadData& msg);
|
|
public:
|
|
StreamClient();
|
|
~StreamClient();
|
|
|
|
void Init();
|
|
void AllStream(); //双向流式
|
|
|
|
void SetCallBackFunc(void* pthis, DataCallBack dataCallBack) {
|
|
m_handlePtr = pthis;
|
|
m_dataCallBack = dataCallBack;
|
|
}
|
|
|
|
void SetPushMsg(const WriteData& msg);
|
|
private:
|
|
bool GetPushMsg(WriteData& msg);
|
|
|
|
private:
|
|
std::unique_ptr<Stream::Stub> m_stubTwo;
|
|
std::string m_localIp;
|
|
int m_port; //服务端口
|
|
DataCallBack m_dataCallBack;
|
|
|
|
bool m_readQuitFlag;
|
|
bool m_writeQuitFlag;
|
|
|
|
std::thread m_connectTd;
|
|
|
|
std::list<WriteData> m_msgList; //信息缓存区
|
|
std::mutex m_msgLock; //信息锁
|
|
|
|
void* m_handlePtr;
|
|
}; |