Skip to content

Commit

Permalink
Merge pull request #201 from Lyatus/master
Browse files Browse the repository at this point in the history
Rml::UnregisterPlugin and Rml::Debugger::Shutdown
  • Loading branch information
mikke89 authored Jul 1, 2021
2 parents f40ea52 + 71b9284 commit 38d6355
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 0 deletions.
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

0 comments on commit 38d6355

Please sign in to comment.