Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rml::UnregisterPlugin and Rml::Debugger::Shutdown #201

Merged
merged 2 commits into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Include/RmlUi/Core/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ RMLUICORE_API bool LoadFontFace(const byte* data, int data_size, const String& f
/// Registers a generic RmlUi plugin.
RMLUICORE_API void RegisterPlugin(Plugin* plugin);

/// Unregisters a generic RmlUi plugin.
RMLUICORE_API void UnregisterPlugin(Plugin* plugin);

/// Registers a new event type. If the type already exists, it will replace custom event types, but not internal types.
/// @param[in] type The new event type.
/// @param[in] interruptible Whether the event can be interrupted during dispatch.
Expand Down
4 changes: 4 additions & 0 deletions Include/RmlUi/Debugger/Debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ namespace Debugger {
/// @return True if the debugger was successfully initialised
RMLUIDEBUGGER_API bool Initialise(Context* context);

/// Shuts down the debugger.
/// @return True if the debugger was successfully shut down
RMLUIDEBUGGER_API bool Shutdown();

/// Sets the context to be debugged.
/// @param[in] context The context to be debugged.
/// @return True if the debugger is initialised and the context was switched, false otherwise.
Expand Down
9 changes: 9 additions & 0 deletions Source/Core/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,15 @@ void RegisterPlugin(Plugin* plugin)
PluginRegistry::RegisterPlugin(plugin);
}

// Unregisters a generic rmlui plugin
void UnregisterPlugin(Plugin* plugin)
{
PluginRegistry::UnregisterPlugin(plugin);

if(initialised)
plugin->OnShutdown();
}

EventId RegisterEventType(const String& type, bool interruptible, bool bubbles, DefaultActionPhase default_action_phase)
{
return EventSpecificationInterface::InsertOrReplaceCustom(type, interruptible, bubbles, default_action_phase);
Expand Down
13 changes: 13 additions & 0 deletions Source/Core/PluginRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include "PluginRegistry.h"
#include "../../Include/RmlUi/Core/Plugin.h"
#include <algorithm>

namespace Rml {

Expand All @@ -52,6 +53,18 @@ void PluginRegistry::RegisterPlugin(Plugin* plugin)
element_plugins.push_back(plugin);
}

void PluginRegistry::UnregisterPlugin(Plugin* plugin)
{
int event_classes = plugin->GetEventClasses();

if(event_classes & Plugin::EVT_BASIC)
basic_plugins.erase(std::remove(basic_plugins.begin(), basic_plugins.end(), plugin), basic_plugins.end());
if(event_classes & Plugin::EVT_DOCUMENT)
document_plugins.erase(std::remove(document_plugins.begin(), document_plugins.end(), plugin), document_plugins.end());
if(event_classes & Plugin::EVT_ELEMENT)
element_plugins.erase(std::remove(element_plugins.begin(), element_plugins.end(), plugin), element_plugins.end());
}

// Calls OnInitialise() on all plugins.
void PluginRegistry::NotifyInitialise()
{
Expand Down
1 change: 1 addition & 0 deletions Source/Core/PluginRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class PluginRegistry
{
public:
static void RegisterPlugin(Plugin* plugin);
static void UnregisterPlugin(Plugin* plugin);

/// Calls OnInitialise() on all plugins.
static void NotifyInitialise();
Expand Down
14 changes: 14 additions & 0 deletions Source/Debugger/Debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ bool Initialise(Context* context)
return true;
}

// Shuts down the debugger.
bool Shutdown()
{
DebuggerPlugin* plugin = DebuggerPlugin::GetInstance();
if(plugin == nullptr) {
Log::Message(Log::LT_WARNING, "Unable to shutdown debugger plugin, it was not initialised!");
return false;
}

UnregisterPlugin(plugin);

return true;
}

// Sets the context to be debugged.
bool SetContext(Context* context)
{
Expand Down