diff --git a/Jupiter/Plugin.cpp b/Jupiter/Plugin.cpp index 3afe8af..747bb3e 100644 --- a/Jupiter/Plugin.cpp +++ b/Jupiter/Plugin.cpp @@ -31,7 +31,6 @@ Jupiter::ArrayList _plugins; Jupiter::ArrayList *Jupiter::plugins = &_plugins; struct dlib; Jupiter::ArrayList _libList; -Jupiter::ArrayList *libList = &_libList; Jupiter::Plugin::~Plugin() { @@ -113,7 +112,7 @@ Jupiter::Plugin *Jupiter::loadPluginFile(const char *file) dPlug->plugin = func(); if (dPlug->plugin == nullptr) goto fail; - libList->add(dPlug); + _libList.add(dPlug); _plugins.add(dPlug->plugin); return dPlug->plugin; @@ -129,7 +128,7 @@ bool Jupiter::freePlugin(size_t index) { // Do not free() the plugin; plugin gets free'd by FreeLibrary(). _plugins.remove(index); - dlib *dPlug = libList->remove(index); + dlib *dPlug = _libList.remove(index); typedef void (*func_type)(void); #if defined _WIN32 @@ -178,6 +177,27 @@ Jupiter::Plugin *Jupiter::getPlugin(const Jupiter::ReadableString &pluginName) // Event Placeholders +int Jupiter::Plugin::think() +{ + return 0; +} + +int Jupiter::Plugin::OnRehash() +{ + return 0; +} + +bool Jupiter::Plugin::OnBadRehash(bool removed) +{ + Jupiter::Plugin::_shouldRemove = removed; + return false; +} + +bool Jupiter::Plugin::shouldRemove() +{ + return Jupiter::Plugin::_shouldRemove; +} + void Jupiter::Plugin::OnConnect(Jupiter::IRC::Client *) { return; @@ -193,11 +213,6 @@ void Jupiter::Plugin::OnReconnectAttempt(Jupiter::IRC::Client *, bool) return; } -int Jupiter::Plugin::OnRehash() -{ - return 0; -} - void Jupiter::Plugin::OnRaw(Jupiter::IRC::Client *, const Jupiter::ReadableString &) { return; @@ -276,9 +291,4 @@ void Jupiter::Plugin::OnMode(Jupiter::IRC::Client *, const Jupiter::ReadableStri void Jupiter::Plugin::OnThink(Jupiter::IRC::Client *) { return; -} - -int Jupiter::Plugin::think() -{ - return 0; } \ No newline at end of file diff --git a/Jupiter/Plugin.h b/Jupiter/Plugin.h index 475cf8f..b4e3083 100644 --- a/Jupiter/Plugin.h +++ b/Jupiter/Plugin.h @@ -38,7 +38,43 @@ namespace Jupiter */ class JUPITER_API Plugin : public Jupiter::Thinker, public Jupiter::Rehashable { - public: + public: // Jupiter::Thinker + /** + * @brief Makes the Plugin "think". This does nothing, unless overloaded. + * This method should return an error other than 0 if you want the plugin to be released. + * + * @return 0 when no error occurs, an error otherwise. + */ + virtual int think() override; + + public: // Jupiter::Rehashable + /** + * @brief This is called when rehash() is called. + * @see Jupiter::Rehashable::OnRehash(). + * + * @return 0 if no error occurs, a postive integer if an error occurs, or a negative integer if an error occurs and the object should be deleted. + */ + virtual int OnRehash() override; + + /** + * @brief This is called when OnRehash() returns an error during rehash(). + * @see Jupiter::Rehashable::OnRehash(). + * Note: If you override this, be sure to call Jupiter::Plugin::OnBadRehash(removed) before returning. + * + * @param removed True if the object was removed from the rehash list, false otherwise. + * @return True if the object should be deleted, false otherwise. + */ + virtual bool OnBadRehash(bool removed) override; + + public: // Jupiter::Plugin + /** + * @brief Checks if this plugin should be unloaded. + * This returns "true" after a call to OnBadRehash(). + * + * @returns True if this plugin should be unloaded, false otherwise. + */ + bool shouldRemove(); + /** * @brief This is called when a connection has been successfully established. * The current implementation calls this after the MOTD. @@ -59,14 +95,6 @@ namespace Jupiter */ virtual void OnReconnectAttempt(Jupiter::IRC::Client *server, bool successConnect); - /** - * @brief This is called when rehash() is called. - * @see Jupiter::Rehashable::OnRehash(). - * - * @return 0 if no error occurs, a postive integer if an error occurs, or a negative integer if an error occurs and the object should be deleted. - */ - virtual int OnRehash(); - /** * @brief This is called after a message has been normally processed. * This always happens last. All other hooks will be called before this. @@ -204,14 +232,6 @@ namespace Jupiter */ virtual void OnThink(Jupiter::IRC::Client *server); - /** - * @brief Makes the Plugin "think". This does nothing, unless overloaded. - * This method should return an error other than 0 if you want the plugin to be released. - * - * @return 0 when no error occurs, an error otherwise. - */ - virtual int think(); - /** * @brief Returns the name of the plugin. * @@ -223,6 +243,9 @@ namespace Jupiter * @brief Destructor for Plugin class. */ virtual ~Plugin(); + + protected: + bool _shouldRemove = false; }; /** Plugin management functions */ diff --git a/Release/Jupiter.lib b/Release/Jupiter.lib index 7b72af9..71cc322 100644 Binary files a/Release/Jupiter.lib and b/Release/Jupiter.lib differ