//
// Created by Ht on 2021/9/26.
//

#ifndef INC_0_LIBDEVCPP_CPAD_MGNODEGROUPSERVICE_H
#define INC_0_LIBDEVCPP_CPAD_MGNODEGROUPSERVICE_H

#include <src/service/MgbusServerService.h>

namespace jedge {

    /**
     *  mgbus mod分组
     */
    class JE_API MgNodeGroup {
            protected:
            QStringList key_lists_;

            public:
            inline QStringList &getKeySets() {
                return key_lists_;
            };
    };

    class JE_API MgNodeGroupService :
            public MgbusServerService {
    protected:
        qlibc::QSharedObjectHolder<MgNode>  group_nodes_;

    public:
        explicit MgNodeGroupService(MgBusServer &opr, const std::string &name, const qlibc::QData& config):
                MgbusServerService(opr, name, config) {}

        ~MgNodeGroupService() override = default;

        void releaseNodes() override;

        inline void iterateNode(const qlibc::QSharedObjectHolder<MgNode>::SharedObjAccessor& accessor);

        std::shared_ptr<MgNode> findNode(const std::string &nodeKey) override;

        void removeNode(const std::string &nodeKey) override;

        bool reIndexNode(const string &nodeKey, const string &newKey) override;

        void addNode(const std::string &nodeKey, MgNodeRef& node) override;


        bool groupCastMgbusMessage(const std::string &dest, qlibc::QData &datamsg);

        bool existsNode(const std::string &nodeKey) override;

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

}
#endif //INC_0_LIBDEVCPP_CPAD_MGNODEGROUPSERVICE_H
