LogViewer
A modern log viewer with AI-assisted analysis (Qt 6)
Loading...
Searching...
No Matches
plugin::PluginManager Class Reference

Manages plugin lifecycle and registration. More...

#include <PluginManager.hpp>

Collaboration diagram for plugin::PluginManager:
Collaboration graph

Classes

struct  PluginConfigCache
 

Public Member Functions

 PluginManager (const PluginManager &)=delete
 
PluginManager & operator= (const PluginManager &)=delete
 
void SetPluginsDirectory (const std::filesystem::path &directory)
 Sets the plugins directory.
 
std::filesystem::path GetPluginsDirectory () const
 Gets the plugins directory.
 
std::vector< std::filesystem::path > DiscoverPlugins ()
 Discovers plugins in the plugins directory.
 
util::Result< std::string, error::Error > LoadPlugin (const std::filesystem::path &pluginPath)
 Loads a plugin from file.
 
util::Result< bool, error::Error > UnloadPlugin (const std::string &pluginId)
 Unloads a plugin and removes it from GetLoadedPlugins()
 
util::Result< std::string, error::Error > RegisterPlugin (const std::filesystem::path &sourcePath)
 Registers a plugin file (copies to user plugins directory)
 
util::Result< bool, error::Error > UnregisterPlugin (const std::string &pluginId)
 Unregisters a plugin (removes from user plugins directory)
 
IPlugin * GetPlugin (const std::string &pluginId)
 Gets a plugin by ID.
 
const std::map< std::string, PluginLoadInfo > & GetLoadedPlugins () const
 Gets all loaded plugins.
 
std::vector< std::string > GetPluginsByType (PluginType type) const
 Gets plugins by type.
 
util::Result< bool, error::Error > EnablePlugin (const std::string &pluginId)
 Enables a plugin (loads and initializes it)
 
util::Result< bool, error::Error > DisablePlugin (const std::string &pluginId)
 Disables a plugin (unloads it but keeps file registered)
 
void SetPluginAutoLoad (const std::string &pluginId, bool autoLoad)
 Sets plugin auto-load preference.
 
void RegisterObserver (IPluginObserver *observer)
 Registers an observer for plugin lifecycle events.
 
void UnregisterObserver (IPluginObserver *observer)
 Unregisters an observer.
 
util::Result< bool, error::Error > LoadConfiguration ()
 Loads plugin configuration.
 
util::Result< bool, error::Error > SaveConfiguration ()
 Saves plugin configuration.
 
util::Result< bool, error::Error > ValidateDependencies () const
 Validates all plugin dependencies.
 
std::filesystem::path GetPluginConfigDirectory (const std::string &pluginId) const
 Gets the configuration directory path for a specific plugin.
 
std::filesystem::path GetPluginConfigPath (const std::string &pluginId) const
 Gets the configuration file path for a specific plugin.
 
void SetEventsContainerOpaque (void *handle)
 
void SetEventsCallbacks (EventsContainer_GetSize_Fn sizeFn, EventsContainer_GetEventJson_Fn getEventFn)
 
void SetHostUiCallbacks (void *hostOpaque, const PluginHostUiCallbacks &callbacks)
 

Static Public Member Functions

static PluginManager & GetInstance ()
 Gets singleton instance.
 

Private Member Functions

 PluginManager ()=default
 
 ~PluginManager ()
 
util::Result< std::unique_ptr< IPlugin >, error::Error > LoadPluginLibrary (const std::filesystem::path &path, const std::string &expectedApiVersion, void **outLibraryHandle, void **outPluginOpaqueHandle)
 Loads plugin from dynamic library.
 
void UnloadLibrary (void *handle)
 Unloads dynamic library.
 
void NotifyObservers (PluginEvent event, const std::string &pluginId, IPlugin *plugin)
 Notifies all observers of a plugin event.
 

Private Attributes

std::filesystem::path m_pluginsDirectory
 
std::map< std::string, PluginLoadInfo > m_plugins
 
std::map< std::string, std::filesystem::path > m_registeredPlugins
 
std::filesystem::path m_configPath
 
std::vector< IPluginObserver * > m_observers
 
void * m_eventsContainerOpaque = nullptr
 
EventsContainer_GetSize_Fn m_eventsGetSizeFn = nullptr
 
EventsContainer_GetEventJson_Fn m_eventsGetEventJsonFn = nullptr
 
void * m_hostUiOpaque = nullptr
 
PluginHostUiCallbacks m_hostUiCallbacks {0u, nullptr}
 
std::map< std::string, PluginConfigCache > m_configCache
 
std::vector< void * > m_dependencyHandles
 

Detailed Description

Manages plugin lifecycle and registration.

The PluginManager handles:

  • Plugin discovery and loading
  • Plugin registration and unregistration
  • Plugin configuration persistence
  • License validation
  • Dependency resolution

Constructor & Destructor Documentation

◆ PluginManager() [1/2]

plugin::PluginManager::PluginManager ( const PluginManager &  )
delete

◆ PluginManager() [2/2]

plugin::PluginManager::PluginManager ( )
privatedefault

◆ ~PluginManager()

plugin::PluginManager::~PluginManager ( )
private
Here is the call graph for this function:

Member Function Documentation

◆ DisablePlugin()

util::Result< bool, error::Error > plugin::PluginManager::DisablePlugin ( const std::string &  pluginId)

Disables a plugin (unloads it but keeps file registered)

Parameters
pluginIdPlugin identifier
Returns
Result with success or error
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DiscoverPlugins()

std::vector< std::filesystem::path > plugin::PluginManager::DiscoverPlugins ( )

Discovers plugins in the plugins directory.

Returns
List of discovered plugin paths
Here is the call graph for this function:

◆ EnablePlugin()

util::Result< bool, error::Error > plugin::PluginManager::EnablePlugin ( const std::string &  pluginId)

Enables a plugin (loads and initializes it)

Parameters
pluginIdPlugin identifier
Returns
Result with success or error
Here is the call graph for this function:

◆ GetInstance()

PluginManager & plugin::PluginManager::GetInstance ( )
static

Gets singleton instance.

Returns
PluginManager reference
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetLoadedPlugins()

const std::map< std::string, PluginLoadInfo > & plugin::PluginManager::GetLoadedPlugins ( ) const

Gets all loaded plugins.

Returns
Map of plugin ID to plugin info

◆ GetPlugin()

IPlugin * plugin::PluginManager::GetPlugin ( const std::string &  pluginId)

Gets a plugin by ID.

Parameters
pluginIdPlugin identifier
Returns
Pointer to plugin or nullptr
Here is the caller graph for this function:

◆ GetPluginConfigDirectory()

std::filesystem::path plugin::PluginManager::GetPluginConfigDirectory ( const std::string &  pluginId) const

Gets the configuration directory path for a specific plugin.

Parameters
pluginIdPlugin identifier
Returns
Path to plugin's config directory (e.g., ~/Library/Application Support/LogViewer/plugins/<plugin_id>/)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetPluginConfigPath()

std::filesystem::path plugin::PluginManager::GetPluginConfigPath ( const std::string &  pluginId) const

Gets the configuration file path for a specific plugin.

Parameters
pluginIdPlugin identifier
Returns
Path to plugin's config file (e.g., ~/Library/Application Support/LogViewer/plugins/<plugin_id>/config.json)
Here is the call graph for this function:

◆ GetPluginsByType()

std::vector< std::string > plugin::PluginManager::GetPluginsByType ( PluginType  type) const

Gets plugins by type.

Parameters
typePlugin type filter
Returns
Vector of plugin IDs matching type

◆ GetPluginsDirectory()

std::filesystem::path plugin::PluginManager::GetPluginsDirectory ( ) const

Gets the plugins directory.

Returns
Path to plugins directory

◆ LoadConfiguration()

util::Result< bool, error::Error > plugin::PluginManager::LoadConfiguration ( )

Loads plugin configuration.

Returns
Result with success or error
Here is the call graph for this function:

◆ LoadPlugin()

util::Result< std::string, error::Error > plugin::PluginManager::LoadPlugin ( const std::filesystem::path &  pluginPath)

Loads a plugin from file.

Parameters
pluginPathPath to plugin library
Returns
Result with plugin ID or error
Here is the call graph for this function:
Here is the caller graph for this function:

◆ LoadPluginLibrary()

util::Result< std::unique_ptr< IPlugin >, error::Error > plugin::PluginManager::LoadPluginLibrary ( const std::filesystem::path &  path,
const std::string &  expectedApiVersion,
void **  outLibraryHandle,
void **  outPluginOpaqueHandle 
)
private

Loads plugin from dynamic library.

Parameters
pathPlugin library path
Returns
Result with plugin instance or error
Here is the call graph for this function:
Here is the caller graph for this function:

◆ NotifyObservers()

void plugin::PluginManager::NotifyObservers ( PluginEvent  event,
const std::string &  pluginId,
IPlugin *  plugin 
)
private

Notifies all observers of a plugin event.

Parameters
eventType of event
pluginIdID of the plugin
pluginPointer to plugin instance (nullptr for unload/unregister)
Here is the caller graph for this function:

◆ operator=()

PluginManager & plugin::PluginManager::operator= ( const PluginManager &  )
delete

◆ RegisterObserver()

void plugin::PluginManager::RegisterObserver ( IPluginObserver *  observer)

Registers an observer for plugin lifecycle events.

Parameters
observerObserver to register
Here is the call graph for this function:
Here is the caller graph for this function:

◆ RegisterPlugin()

util::Result< std::string, error::Error > plugin::PluginManager::RegisterPlugin ( const std::filesystem::path &  sourcePath)

Registers a plugin file (copies to user plugins directory)

Fails if a plugin with the same id is loaded (unload it first to update). If the id was registered from another folder of the user plugins directory, that superseded folder is deleted once the new copy loads.

Parameters
sourcePathPath to plugin file to register
Returns
Result with plugin ID or error
Here is the call graph for this function:

◆ SaveConfiguration()

util::Result< bool, error::Error > plugin::PluginManager::SaveConfiguration ( )

Saves plugin configuration.

Returns
Result with success or error
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetEventsCallbacks()

void plugin::PluginManager::SetEventsCallbacks ( EventsContainer_GetSize_Fn  sizeFn,
EventsContainer_GetEventJson_Fn  getEventFn 
)
inline
Here is the caller graph for this function:

◆ SetEventsContainerOpaque()

void plugin::PluginManager::SetEventsContainerOpaque ( void *  handle)
inline
Here is the caller graph for this function:

◆ SetHostUiCallbacks()

void plugin::PluginManager::SetHostUiCallbacks ( void *  hostOpaque,
const PluginHostUiCallbacks &  callbacks 
)
inline
Here is the caller graph for this function:

◆ SetPluginAutoLoad()

void plugin::PluginManager::SetPluginAutoLoad ( const std::string &  pluginId,
bool  autoLoad 
)

Sets plugin auto-load preference.

Parameters
pluginIdPlugin identifier
autoLoadAuto-load on startup
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetPluginsDirectory()

void plugin::PluginManager::SetPluginsDirectory ( const std::filesystem::path &  directory)

Sets the plugins directory.

Parameters
directoryPath to plugins directory
Here is the call graph for this function:

◆ UnloadLibrary()

void plugin::PluginManager::UnloadLibrary ( void *  handle)
private

Unloads dynamic library.

Parameters
handleLibrary handle
Here is the call graph for this function:
Here is the caller graph for this function:

◆ UnloadPlugin()

util::Result< bool, error::Error > plugin::PluginManager::UnloadPlugin ( const std::string &  pluginId)

Unloads a plugin and removes it from GetLoadedPlugins()

It stays registered, so EnablePlugin() or LoadPlugin() can load it again.

Parameters
pluginIdPlugin identifier
Returns
Result with success or error
Here is the call graph for this function:
Here is the caller graph for this function:

◆ UnregisterObserver()

void plugin::PluginManager::UnregisterObserver ( IPluginObserver *  observer)

Unregisters an observer.

Parameters
observerObserver to unregister
Here is the call graph for this function:

◆ UnregisterPlugin()

util::Result< bool, error::Error > plugin::PluginManager::UnregisterPlugin ( const std::string &  pluginId)

Unregisters a plugin (removes from user plugins directory)

Parameters
pluginIdPlugin identifier
Returns
Result with success or error
Here is the call graph for this function:

◆ ValidateDependencies()

util::Result< bool, error::Error > plugin::PluginManager::ValidateDependencies ( ) const

Validates all plugin dependencies.

Returns
Result with missing dependencies or success
Here is the call graph for this function:

Member Data Documentation

◆ m_configCache

std::map<std::string, PluginConfigCache> plugin::PluginManager::m_configCache
private

◆ m_configPath

std::filesystem::path plugin::PluginManager::m_configPath
private

◆ m_dependencyHandles

std::vector<void*> plugin::PluginManager::m_dependencyHandles
private

◆ m_eventsContainerOpaque

void* plugin::PluginManager::m_eventsContainerOpaque = nullptr
private

◆ m_eventsGetEventJsonFn

EventsContainer_GetEventJson_Fn plugin::PluginManager::m_eventsGetEventJsonFn = nullptr
private

◆ m_eventsGetSizeFn

EventsContainer_GetSize_Fn plugin::PluginManager::m_eventsGetSizeFn = nullptr
private

◆ m_hostUiCallbacks

PluginHostUiCallbacks plugin::PluginManager::m_hostUiCallbacks {0u, nullptr}
private

◆ m_hostUiOpaque

void* plugin::PluginManager::m_hostUiOpaque = nullptr
private

◆ m_observers

std::vector<IPluginObserver*> plugin::PluginManager::m_observers
private

◆ m_plugins

std::map<std::string, PluginLoadInfo> plugin::PluginManager::m_plugins
private

◆ m_pluginsDirectory

std::filesystem::path plugin::PluginManager::m_pluginsDirectory
private

◆ m_registeredPlugins

std::map<std::string, std::filesystem::path> plugin::PluginManager::m_registeredPlugins
private

The documentation for this class was generated from the following files: