61 lines
1.5 KiB
C
Raw Normal View History

2024-05-11 17:43:38 +08:00
#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 Stop();
void SetCallBackFunc(void* pthis, DataCallBack dataCallBack) {
m_handlePtr = pthis;
m_dataCallBack = dataCallBack;
}
2024-05-30 11:18:10 +08:00
void PushMsg(const WriteData& msg);
2024-05-15 17:59:04 +08:00
bool GetLayerByIndex(int index, ::stream::ResponseAny* response);
int RegistRequest(const WriteData& writeData, ::stream::ResponseAny* response);
int Request(const WriteData& writeData, ::stream::ResponseAny* response);
2024-05-11 17:43:38 +08:00
private:
bool GetPushMsg(WriteData& msg);
private:
std::unique_ptr<Stream::Stub> m_stubTwo; //双端流使用
std::shared_ptr<grpc::Channel> m_channelTwo;
std::unique_ptr<Stream::Stub> m_stub; //请求 回复使用
std::string m_localIp;
int m_port; //服务端口
DataCallBack m_dataCallBack;
bool m_readQuitFlag;
bool m_writeQuitFlag;
std::thread m_readTd;
std::thread m_writeTd;
std::thread m_connectTd;
std::list<WriteData> m_msgList; //信息缓存区
std::mutex m_msgLock; //信息锁
void* m_handlePtr;
};