//
// Created by Ht on 2020/7/26.
//

#ifndef LIBDEVCPP_USERSTATUSSERVICE_H
#define LIBDEVCPP_USERSTATUSSERVICE_H

#include <mgbus/MgBusService.h>

namespace jedge {


    class DeviceStatusService :
            public MgBusService {

    protected:

    public:
        explicit DeviceStatusService(MgBusHolder& opr, const std::string& name, const qlibc::QData& config = qlibc::QData()) : MgBusService(opr, name, config){}

        ~DeviceStatusService() override = default;

        void preparePattern() override;

        bool queryStatus(qlibc::QData &message, qlibc::QData *response);

        void onServiceStart(const qlibc::QData &config) override;

        void onServiceStop() override;

        bool bNeedSave = false;

        qlibc::QRTimer mTimer = nullptr;

        std::recursive_mutex  mm;


        void doSaveWork();

        void cacheSaveData(const std::string& key, qlibc::QData& dataToSave);
    };
}

#endif //LIBDEVCPP_USERSTATUSSERVICE_H
