Plugin types
The plugin system supports two main plugin types:- InfoProvider: Provides structured information (weather, media, Docker stats, etc.)
- OutputFormat: Adds new output formats (JSON, YAML, Markdown, etc.)
PluginManager class
ThePluginManager is a singleton that manages plugin discovery, loading, and lifecycle.
getInstance
Returns the singleton instance of the plugin manager.Reference to the singleton PluginManager instance
initialize
Initializes the plugin manager and optionally auto-loads plugins.Plugin configuration containing:
enabled: Whether the plugin system is enabled (default: true)autoLoad: Vector of plugin names to automatically load
Returns success or an error if initialization fails
- Adds default search paths for plugins
- Scans for available plugins in search paths
- Auto-loads plugins specified in config
- Sets the initialized state
- Windows:
%LOCALAPPDATA%\draconis++\plugins,%APPDATA%\draconis++\plugins,%USERPROFILE%\.config\draconis++\plugins,./plugins - Unix-like:
/usr/local/lib/draconis++/plugins,/usr/lib/draconis++/plugins,~/.local/lib/draconis++/plugins,./plugins
shutdown
Shuts down the plugin manager and unloads all plugins.- Calls shutdown on all loaded plugins
- Unloads all plugin libraries
- Clears all plugin state
isInitialized
Checks if the plugin manager has been initialized.Returns true if initialized, false otherwise
Plugin discovery and loading
addSearchPath
Adds a directory to the plugin search paths.Directory path to search for plugins
getSearchPaths
Returns all configured plugin search paths.Vector of filesystem paths being searched for plugins
loadPlugin
Loads a plugin by name.Name of the plugin to load (without file extension)
Cache manager for plugin data persistence
Returns success or an error if loading fails
- Searches for the plugin library in search paths
- Loads the dynamic library
- Retrieves plugin factory functions
- Creates the plugin instance
- Initializes the plugin with context and cache
- Adds the plugin to appropriate type caches
- Plugin not found in any search path
- Plugin already loaded
- Dynamic library loading fails
- Plugin initialization fails
- Missing required plugin exports
unloadPlugin
Unloads a plugin by name.Name of the plugin to unload
Returns success or an error if unloading fails
- Calls shutdown on the plugin
- Removes from type-specific caches
- Destroys the plugin instance
- Unloads the dynamic library
- Plugin not found
- Plugin not currently loaded
Plugin access
getPlugin
Retrieves a plugin by name.Name of the plugin to retrieve
Returns a pointer to the plugin if loaded, None otherwise
getInfoProviderPlugins
Returns all loaded info provider plugins.Vector of pointers to all loaded info provider plugins
getOutputFormatPlugins
Returns all loaded output format plugins.Vector of pointers to all loaded output format plugins
getInfoProviderByName
Retrieves an info provider plugin by its provider ID.Provider ID to search for (e.g., “weather”, “media”)
Returns a pointer to the provider if found, None otherwise
Plugin metadata
listLoadedPlugins
Returns metadata for all loaded plugins.Vector of metadata for all loaded plugins, each containing:
name: Plugin nameversion: Plugin versionauthor: Plugin authordescription: Plugin descriptiontype: Plugin type (InfoProvider or OutputFormat)dependencies: Plugin dependencies structure
listDiscoveredPlugins
Returns names of all discovered plugin files.Vector of plugin names found in search paths (not necessarily loaded)
isPluginLoaded
Checks if a plugin is currently loaded.Name of the plugin to check
Returns true if the plugin is loaded, false otherwise
Plugin context
GetPluginContext
Returns the default plugin context with standard paths.Returns a PluginContext struct containing:
configDir: Plugin configuration directorycacheDir: Plugin cache directorydataDir: Plugin data directory
- Windows:
%LOCALAPPDATA%\draconis++\plugins\{config,cache,data} - Unix-like:
~/.config/draconis++/plugins,~/.cache/draconis++/plugins,~/.local/share/draconis++/plugins
Plugin interfaces
IPlugin
Base interface for all plugins.IInfoProviderPlugin
Interface for plugins that provide structured information.getProviderId(): Returns unique identifier (e.g., “weather”, “media”)collectData(): Refreshes data from the providertoJson(): Serializes data to JSON for--jsonoutputgetFields(): Returns key-value pairs for compact format templatesgetDisplayValue(): Returns formatted string for UI displaygetDisplayIcon(): Returns Nerd Font icon for UIgetDisplayLabel(): Returns label for UI displaygetLastError(): Returns last error from data collectionisEnabled(): Returns whether the provider is enabled in config
IOutputFormatPlugin
Interface for plugins that provide output formatting.formatOutput(): Formats data using the specified format variantgetFormatNames(): Returns all format names this plugin supportsgetFileExtension(): Returns file extension for a format
Plugin cache
ThePluginCache class provides efficient BEVE-based caching for plugin data.
Creating a plugin
Use theDRAC_PLUGIN macro to export your plugin:
Performance characteristics
- Lazy loading: Plugins are loaded only when first accessed
- Lock-free reads: Plugin access is thread-safe without mutexes after initialization
- Cache-friendly: Uses contiguous memory and sorted vectors for fast iteration
- Zero-cost abstractions: When
DRAC_ENABLE_PLUGINSis disabled, the plugin system compiles to no-ops - Efficient caching: BEVE binary format for minimal serialization overhead
Platform support
Dynamic library extensions:- Windows:
.dll - macOS:
.dylib - Linux/Unix:
.so
CreatePlugin(): Factory function returningIPlugin*DestroyPlugin(IPlugin*): Cleanup functionSetPluginLogLevel(LogLevel*): Log level synchronization