#include"module_mgr.h"


#include"module_web.h"
#include"module_call_help.h"
#include"module_call.h"
#include"module_over_speed_vehicle.h"
#include"module_other_alarm.h"
#include"module_attendance_vehicle.h"
#include"module_motionless_persion.h"
#include"module_geofault.h"
#include"log.h"
#include"common_tool.h"

/**
 * @brief 注册web回调函数，读配置文件，启动向web发送线程
 */
void module_mgr::init(config_file& config, std::map<std::string, YA::MSG_HANDLE_FUNC_TYPE>& MsgFuncList)
{
    module_web::instance()->init(config, MsgFuncList);
    module_call::instance()->init(config);

    module_motionless_persion::instance()->init(config);
    module_geofault::instance()->init(config);
}

/**
     * @brief 启动线程start：向web发送事件
     */
void module_mgr::start()
{
    module_geofault::instance()->init_geofault_from_db();
    module_over_speed_vehicle::instance()->init_vehicle_category_from_db();
    module_attendance_vehicle::instance()->init_attendance_area_from_db();

    module_web::instance()->start();
    module_call::instance()->start();
    module_motionless_persion::instance()->start();
}

/**
     * @brief 结束线程stop
     */
void module_mgr::stop()
{
    module_web::instance()->stop();
    module_call::instance()->stop();
    module_motionless_persion::instance()->stop();
}

void module_mgr::do_status(STATUS_CARD st, uint32_t card_id, int32_t type)
{
    auto card_ptr=card_list::instance()->get(tool_other::type_id_to_u64(type, card_id));
    if(!card_ptr)
    {
        log_error("卡不存在card_id=%d", card_id);
        return;
    }

    if(STATUS_HELP == st)
    {
        module_call_help::instance()->rev_from_card_help(card_ptr);
    }
    if(STATUS_CALL == st)
    {
        module_call::instance()->rev_from_card_resp(card_ptr);
    }
    if(STATUS_POWER_LOWER_SERIOUS == st)
    {
        module_other_alarm::power_lower_serious(card_ptr);
    }
    if(STATUS_POWER_NOMARL == st)
    {
        module_other_alarm::power_nomarl(card_ptr);
    }
}


