Class PluginBase

Synopsis

#include <lib/inc/drogon/plugins/Plugin.h>

class PluginBase : public virtual DrObjectBase, public trantor::NonCopyable

Description

The abstract base class for plugins.

Mentioned in

Inheritance

Ancestors: NonCopyable, DrObjectBase

Decsendents: Plugin

Methods

PluginBase
~PluginBase
initAndStartThis method must be called by drogon to initialize and start the plugin
initializeThis method must be called by drogon.
shutdownThis method must be called by drogon to shutdown the plugin

Source

Lines 35-99 in lib/inc/drogon/plugins/Plugin.h.

class PluginBase : public virtual DrObjectBase, public trantor::NonCopyable
{
  public:
    /// This method must be called by drogon.
    void initialize()
    {
        if (status_ == PluginStatus::None)
        {
            status_ = PluginStatus::Initializing;
            for (auto dependency : dependencies_)
            {
                dependency->initialize();
            }
            initAndStart(config_);
            status_ = PluginStatus::Initialized;
            if (initializedCallback_)
                initializedCallback_(this);
        }
        else if (status_ == PluginStatus::Initialized)
        {
            // Do nothing;
        }
        else
        {
            LOG_FATAL << "There are a circular dependency within plugins.";
            abort();
        }
    }

    /// This method must be called by drogon to initialize and start the plugin.
    /// It must be implemented by the user.
    virtual void initAndStart(const Json::Value &config) = 0;

    /// This method must be called by drogon to shutdown the plugin.
    /// It must be implemented by the user.
    virtual void shutdown() = 0;

    virtual ~PluginBase()
    {
    }

  protected:
    PluginBase()
    {
    }

  private:
    PluginStatus status_{PluginStatus::None};
    friend class PluginsManager;
    void setConfig(const Json::Value &config)
    {
        config_ = config;
    }
    void addDependency(PluginBase *dp)
    {
        dependencies_.push_back(dp);
    }
    void setInitializedCallback(const std::function<void(PluginBase *)> &cb)
    {
        initializedCallback_ = cb;
    }
    Json::Value config_;
    std::vector<PluginBase *> dependencies_;
    std::function<void(PluginBase *)> initializedCallback_;
};





Add Discussion as Guest

Log in to DocsForge