/*
 * @Author: error: git config user.name && git config user.email & please set dead value or install git
 * @Date: 2022-07-10 17:23:57
 * @LastEditors: error: git config user.name && git config user.email & please set dead value or install git
 * @LastEditTime: 2022-07-10 17:35:56
 * @FilePath: /gsd/plugins/gsd_MonitorPlugin.h
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
/**
 *
 *  gsd_MonitorPlugin.h
 *
 */

#pragma once

#include <drogon/plugins/Plugin.h>
#include "config.hpp"
#include "dataTypeList.h"
#include "monitor.h"
#include "gsd_TcpPlugin.h"

namespace gsd
{

class MonitorPlugin : public drogon::Plugin<MonitorPlugin>
{
  public:
    MonitorPlugin() {}
    /// This method must be called by drogon to initialize and start the plugin.
    /// It must be implemented by the user.
    virtual void initAndStart(const Json::Value &config) override;

    /// This method must be called by drogon to shutdown the plugin.
    /// It must be implemented by the user.
    virtual void shutdown() override;

    /**
     * @description: 初始化
     * @return {*}
     */    
    int8_t Init();

    /**
     * @description: 启动任务
     * @return {*}
     */    
    void StartTask();

    /**
     * @description: 处理数据的进程
     * @return {*}
     */    
    void MonitorProThrd();

    /**
     * @description: 消费数据
     * @param {Ptr&} result
     * @return {*}
     */    
    bool ConsumeData(FrameInferData::Ptr& result);

    /**
    * @description: 保存视频记录
    * @param {HistoryVideo&} historyVideo
    * @return {*}
    */
    bool SaveVideoRecord(HistoryVideo& historyVideo);

    /**
    * @description: 发送请求
    * @param {CNStreamInferData Ptr} data
    * @return {*}
    */
    bool sendRequest(CNStreamInferData::Ptr data);

  private:
    std::shared_ptr<Monitor> monitor = nullptr;
    std::shared_ptr<ThreadPool> pool = nullptr;

    bool stop_ = false;
};
}
