/*
 * engine管理类
 */

#ifndef INC_ENGINE_MANAGER_H
#define INC_ENGINE_MANAGER_H

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

namespace ai_matrix
{
    //引擎描述
    struct EngineDesc
    {
        std::string engine_name;  //引擎名称
        int engine_id; //引擎id
    };

    struct EngineConnectDesc
    {
        std::string engine_send_name;   //发送引擎名称
        int engine_send_id;     //发送引擎id
        int engine_send_port;       //发送引擎端口
        std::string engine_recv_name;   //接收引擎名称
        int engine_recv_id;     //接收引擎id
        int engine_recv_port;   //接收引擎端口
    };

    class EngineManager
    {
    public:
        EngineManager();
        ~EngineManager();

        //初始化
        APP_ERROR Init();
        //去初始化
        APP_ERROR DeInit(void);

        //使用yaml文件注册engine实例及连接
        APP_ERROR load_yaml_config(std::string path);

        //初始化engine
        APP_ERROR InitEngineInstance(std::shared_ptr<EngineBase> engineInstance, std::string engineName, int engineId);

        //运行所有engine
        APP_ERROR RunAllEngine();

        //停止所有engine
        APP_ERROR StopAllEngine();

        //得到某个engine的指针
        EngineBase *get_engine(std::string engineName);

    private:
        int32_t deviceId_ = 0;

        //engine名和实例map
        std::map<std::string, std::shared_ptr<EngineBase>> engine_map_ = {};

        //初始化的设备id
        std::set<int> init_deviceIds_ = {};

        //engine使用deviceid
        std::map<std::string, int> mapUseDevice_ = {};

        //初始化设备id
        bool InitDeviceIds();
    };
}

#endif
