//
// Created by Ht on 2022/1/7.
//

#ifndef INC_1_LIBDEVCPP_QPLUGINENTRY_H
#define INC_1_LIBDEVCPP_QPLUGINENTRY_H

#include <jebase/config.h>
#include <string>
#include <cross/DllUtil.h>

namespace qlibc {

#ifndef PLUGIN
#define PLUGIN ".none"
#endif

    /**
     *  Entry对象：
     *      由插件创建，并提供一个插件函数表
     *
     */
    class QPluginManager;

    class JE_API QPluginEntry {
    protected:
        void* dllHandler = nullptr;
        std::string nameKey_;
        std::string typeKey_;
        std::string filePath_;
        int         ver_;

        auto getHandle() -> void *;

        friend class QPluginManager;

    public:

        explicit QPluginEntry(std::string name, std::string type = "", int ver = 0);

        virtual ~QPluginEntry() = default;

        virtual bool initEntry() { return true;};   //打开Entry后对之进行基本的调用函数接口的初始化

        virtual void beforeCloseEntry() {};         //关闭Entry的接口表

        virtual void onEntryLoaded() {}

        virtual void onEntryReleased() {}

        const std::string &getPluginName();

        const std::string &getPluginType();

        const std::string &getPluginFilePath();

        int getPluginVer() const;

        void* getFunctionEntry(const std::string& funcName);

        void setPluginPath(const std::string &pluginPath);

        void setHandle(void *dh);
    };

}
#endif //INC_1_LIBDEVCPP_QPLUGINENTRY_H
