#pragma once

/*
	PluginFramework
	by John Ryland
	Copyright (c) 2023
*/

////////////////////////////////////////////////////////////////////////////////////
//	Plugin

#include "Library.h"
#include <string>

#ifdef _WIN32
#define PLUGIN_EXPORT   extern "C" __declspec(dllexport)
#else
#define PLUGIN_EXPORT   extern "C"
#endif

#define PLUGIN_REGISTER_FUNCTION        RegisterPlugin
#define PLUGIN_DEREGISTER_FUNCTION      DeregisterPlugin
#define STRINGIZE2(x)                   #x
#define STRINGIZE(x)                    STRINGIZE2(x)

namespace PluginFramework {

class PluginManager;

class Plugin
{
public:
    Plugin(std::string pluginName, const char* libraryFileName);
    Plugin(Plugin&& other);
    ~Plugin();

    bool Loaded() const;
    bool Registered() const;

    std::string Name() const;
    std::string FileName() const;

    void Register(PluginManager& pluginManager);

    void HotEject();

private:
    void Load();
    void Deregister();

    std::string    mName;
    PluginManager* mManager;
    LibraryPtr     mLibrary;
    void*          mRegisterFuncPtr;
};

} // PluginFramework namespace
