/*
 * @Author: your name
 * @Date: 2022-01-27 10:27:26
 * @LastEditors: your name
 * @LastEditTime: 2022-02-17 10:40:16
 * @Description: file content
 * @FilePath: \lirs\code\GrpcEngine\GrpcEngine.h
 * 
 * Copyright © 2022 <Shandong Matrix Software Engineering Co., Ltd>
 */
/**
 * grpc微服务接口
 * */

#ifndef GRPC_ENGINE_H
#define GRPC_ENGINE_H

#include <grpcpp/ext/proto_server_reflection_plugin.h>
#include <grpcpp/grpcpp.h>
#include <grpcpp/health_check_service_interface.h>

#include "grpcservice.grpc.pb.h"

#include "AppCommon.h"

using grpc::Server;
using grpc::ServerBuilder;
using grpc::ServerContext;
using grpc::Status;
using grpc::StatusCode;

using MatrixAi::Train;
using MatrixAi::Request;
using MatrixAi::Reply;
using MatrixAi::QueryWorkstationRequest;
using MatrixAi::QueryWorkstationReply;
using MatrixAi::UpdateWorkstationRequest;
using MatrixAi::UpdateWorkstationReply;
using MatrixAi::QueryCameraRequest;
using MatrixAi::QueryCameraReply;
using MatrixAi::UpdateCameraRequest;
using MatrixAi::UpdateCameraReply;
using MatrixAi::QueryFTPRequest;
using MatrixAi::QueryFTPReply;
using MatrixAi::UpdateFTPRequest;
using MatrixAi::UpdateFTPReply;

#include "EngineBase.h"
#include "EngineFactory.h"
#include "MyYaml.h"

class GrpcEngine : public ai_matrix::EngineBase, public Train::Service
{
public:
    GrpcEngine();
    ~GrpcEngine();

    APP_ERROR Init() override;
    APP_ERROR DeInit() override;
    APP_ERROR Process() override;

    //识别状态控制-来车
    Status Come(ServerContext *context, const Request *request,Reply *reply);

    //识别状态控制-车走
    Status Leave(ServerContext *context, const Request *request, Reply *reply);

    //识别状态控制-停车
    Status TemporaryStop(ServerContext *context, const Request *request,Reply *reply);

    //识别状态控制-倒车
    Status Reversing(ServerContext *context, const Request *request, Reply *reply);

    //查看“工作站设置”
    Status QueryWorkstation(ServerContext *context, const QueryWorkstationRequest *request, QueryWorkstationReply *reply);

    //修改“工作站设置”
    Status UpdateWorkstation(ServerContext *context, const UpdateWorkstationRequest *request, UpdateWorkstationReply *reply);

    //查询摄像头配置
    Status QueryCamera(ServerContext *context, const QueryCameraRequest *request, QueryCameraReply *reply);

    //修改摄像头配置
    Status UpdateCamera(ServerContext *context, const UpdateCameraRequest *request, UpdateCameraReply *reply);

    //查询FTP的配置
    Status QueryFTP(ServerContext *context, const QueryFTPRequest *request, QueryFTPReply *reply);

    //修改FTP的配置
    Status UpdateFTP(ServerContext *context, const UpdateFTPRequest *request, UpdateFTPReply *reply);

    //重启识别程序
    Status RebootAI(ServerContext *context, const Request *request, Reply *reply);
private:
    std::string strPort0_;

    //接口调用必须的命令标志
	const int HEAD = 0x7d;
    
    // 线程的运行函数
	static void* system_restart(void* args);
};

ENGINE_REGIST(GrpcEngine)

#endif