2024-03-15 12:31:34 +08:00
|
|
|
|
#pragma once
|
|
|
|
|
#include <thread>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <grpcpp/grpcpp.h>
|
|
|
|
|
#include <grpc/support/log.h>
|
|
|
|
|
#include "../protobuf/stream.grpc.pb.h"
|
2024-03-19 17:45:12 +08:00
|
|
|
|
#include "ClientInfo.h"
|
2024-03-22 11:28:06 +08:00
|
|
|
|
#include "../Machine/Machine.h"
|
2024-03-15 12:31:34 +08:00
|
|
|
|
|
|
|
|
|
using grpc::Server;
|
|
|
|
|
using grpc::ServerBuilder;
|
|
|
|
|
using grpc::ServerContext;
|
|
|
|
|
using grpc::Status;
|
|
|
|
|
using stream::Stream;
|
|
|
|
|
using stream::RequestInfo;
|
|
|
|
|
using stream::ResponseInfo;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class StreamServer final : public Stream::Service {
|
|
|
|
|
typedef void (*DataCallBack)(void* pthis,const ReadData& msg);
|
2024-04-23 13:41:16 +08:00
|
|
|
|
typedef void (*LayerDataCallBack)(void* pthis, const ReadData& msg, ::stream::LayerData** response);
|
2024-03-22 11:28:06 +08:00
|
|
|
|
|
|
|
|
|
|
2024-03-15 12:31:34 +08:00
|
|
|
|
public:
|
2024-03-22 11:28:06 +08:00
|
|
|
|
StreamServer(Machine* pConfig);
|
2024-03-15 12:31:34 +08:00
|
|
|
|
~StreamServer();
|
|
|
|
|
|
2024-03-22 11:28:06 +08:00
|
|
|
|
void Init();
|
2024-03-15 12:31:34 +08:00
|
|
|
|
void Run();
|
2024-03-22 11:28:06 +08:00
|
|
|
|
void Stop();
|
2024-03-15 12:31:34 +08:00
|
|
|
|
|
2024-04-23 13:41:16 +08:00
|
|
|
|
void SetCallBackFunc(void* pdata,DataCallBack dataCallBack, LayerDataCallBack layerCB) {
|
2024-03-15 12:31:34 +08:00
|
|
|
|
m_dataCallBack = dataCallBack;
|
|
|
|
|
m_handlePtr = pdata;
|
2024-04-23 13:41:16 +08:00
|
|
|
|
m_layerDataCallBack = layerCB;
|
2024-03-15 12:31:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Status AllStream(ServerContext* context, grpc::ServerReaderWriter<ResponseInfo, RequestInfo>* stream) override;
|
2024-04-23 13:41:16 +08:00
|
|
|
|
::grpc::Status Simple(::grpc::ServerContext* context, const ::stream::RequestInfo* request, ::stream::LayerData* response);
|
2024-03-15 12:31:34 +08:00
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
std::thread m_checkCloseTd; //检测客户端关闭线程
|
|
|
|
|
bool m_checkQuitFlag;
|
|
|
|
|
DataCallBack m_dataCallBack;
|
2024-04-23 13:41:16 +08:00
|
|
|
|
LayerDataCallBack m_layerDataCallBack;
|
2024-03-15 12:31:34 +08:00
|
|
|
|
|
|
|
|
|
int m_port; //监听端口
|
|
|
|
|
void* m_handlePtr;
|
2024-03-19 17:45:12 +08:00
|
|
|
|
|
2024-03-22 11:28:06 +08:00
|
|
|
|
Machine* m_machine;
|
|
|
|
|
|
|
|
|
|
std::thread m_listenTd;
|
|
|
|
|
std::unique_ptr<Server> m_server;
|
|
|
|
|
|
2024-03-15 12:31:34 +08:00
|
|
|
|
};
|