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

Manages plugin dependency relationships and validates for safe initialization. More...

#include <PluginDependencyGraph.hpp>

Collaboration diagram for plugin::PluginDependencyGraph:
Collaboration graph

Classes

struct  DependencyNode
 Represents a plugin node in the dependency graph. More...
 

Public Member Functions

void AddNode (const std::string &id, const std::vector< std::string > &dependencies)
 Adds a node to the dependency graph.
 
util::Result< bool, error::Error > ValidateNoCycles () const
 Validates that no circular dependencies exist.
 
util::Result< std::vector< std::string >, error::Error > GetInitializationOrder () const
 Gets plugins in valid initialization order.
 
util::Result< std::vector< std::string >, error::Error > GetShutdownOrder () const
 Gets plugins in valid shutdown order.
 
util::Result< std::vector< std::string >, error::Error > ValidateDependenciesAvailable (const std::set< std::string > &availablePlugins) const
 Validates all dependencies are available.
 
std::vector< std::string > GetDependencies (const std::string &id) const
 Gets dependencies for a specific plugin.
 
size_t GetNodeCount () const
 Gets number of nodes in graph.
 

Private Member Functions

bool HasCycle (const std::string &id, std::set< std::string > &visited, std::set< std::string > &recursionStack) const
 Checks for cycle using depth-first search.
 
void TopologicalSort (const std::string &id, std::set< std::string > &visited, std::vector< std::string > &order) const
 Topological sort using DFS.
 

Static Private Member Functions

static std::string FormatList (const std::vector< std::string > &items)
 Formats vector of strings for logging.
 

Private Attributes

std::map< std::string, DependencyNode > m_nodes
 

Detailed Description

Manages plugin dependency relationships and validates for safe initialization.

Detects circular dependencies and provides topological sorting for safe initialization and shutdown ordering.

Features
  • Cycle detection using DFS-based algorithm
  • Topological sort for initialization order
  • Reverse topological sort for shutdown order
  • Missing dependency detection
Usage Example
graph.AddNode("plugin-a", {});
graph.AddNode("plugin-b", {"plugin-a"});
graph.AddNode("plugin-c", {"plugin-b", "plugin-a"});
// Validate
if (auto result = graph.ValidateNoCycles(); result.isErr()) {
Logger::Error("Circular dependency: {}", result.error().Message());
return;
}
// Get safe initialization order
auto order = graph.GetInitializationOrder();
for (const auto& id : order.unwrap()) {
PluginManager::EnablePlugin(id); // Guaranteed deps are loaded
}
Manages plugin dependency relationships and validates for safe initialization.
Definition PluginDependencyGraph.hpp:55
util::Result< bool, error::Error > ValidateNoCycles() const
Validates that no circular dependencies exist.
Definition PluginDependencyGraph.hpp:85
void AddNode(const std::string &id, const std::vector< std::string > &dependencies)
Adds a node to the dependency graph.
Definition PluginDependencyGraph.hpp:71
util::Result< std::vector< std::string >, error::Error > GetInitializationOrder() const
Gets plugins in valid initialization order.
Definition PluginDependencyGraph.hpp:117
util::Result< bool, error::Error > EnablePlugin(const std::string &pluginId)
Enables a plugin (loads and initializes it)
Definition PluginManager.cpp:1347
std::string result
Definition OllamaClient.cpp:144

Member Function Documentation

◆ AddNode()

void plugin::PluginDependencyGraph::AddNode ( const std::string &  id,
const std::vector< std::string > &  dependencies 
)
inline

Adds a node to the dependency graph.

Parameters
idPlugin identifier
dependenciesList of dependency plugin IDs
Here is the call graph for this function:

◆ FormatList()

static std::string plugin::PluginDependencyGraph::FormatList ( const std::vector< std::string > &  items)
inlinestaticprivate

Formats vector of strings for logging.

Here is the caller graph for this function:

◆ GetDependencies()

std::vector< std::string > plugin::PluginDependencyGraph::GetDependencies ( const std::string &  id) const
inline

Gets dependencies for a specific plugin.

Parameters
idPlugin identifier
Returns
List of dependency IDs, or empty vector if not found

◆ GetInitializationOrder()

util::Result< std::vector< std::string >, error::Error > plugin::PluginDependencyGraph::GetInitializationOrder ( ) const
inline

Gets plugins in valid initialization order.

Plugins are ordered such that all dependencies appear before the dependent plugin.

Returns
Order for initialization, or error if cycles exist
Example Result
If C depends on B, B depends on A: Returns: [A, B, C]
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetNodeCount()

size_t plugin::PluginDependencyGraph::GetNodeCount ( ) const
inline

Gets number of nodes in graph.

Returns
Node count

◆ GetShutdownOrder()

util::Result< std::vector< std::string >, error::Error > plugin::PluginDependencyGraph::GetShutdownOrder ( ) const
inline

Gets plugins in valid shutdown order.

Reverse of initialization order - shutdown dependents before dependencies.

Returns
Order for shutdown, or error if cycles exist
Here is the call graph for this function:

◆ HasCycle()

bool plugin::PluginDependencyGraph::HasCycle ( const std::string &  id,
std::set< std::string > &  visited,
std::set< std::string > &  recursionStack 
) const
inlineprivate

Checks for cycle using depth-first search.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TopologicalSort()

void plugin::PluginDependencyGraph::TopologicalSort ( const std::string &  id,
std::set< std::string > &  visited,
std::vector< std::string > &  order 
) const
inlineprivate

Topological sort using DFS.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ValidateDependenciesAvailable()

util::Result< std::vector< std::string >, error::Error > plugin::PluginDependencyGraph::ValidateDependenciesAvailable ( const std::set< std::string > &  availablePlugins) const
inline

Validates all dependencies are available.

Parameters
availablePluginsSet of available plugin IDs
Returns
Missing dependency IDs, or empty if all satisfied
Here is the call graph for this function:

◆ ValidateNoCycles()

util::Result< bool, error::Error > plugin::PluginDependencyGraph::ValidateNoCycles ( ) const
inline

Validates that no circular dependencies exist.

Returns
Success with true, or Error with description
Complexity
O(V + E) where V is nodes, E is edges
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_nodes

std::map<std::string, DependencyNode> plugin::PluginDependencyGraph::m_nodes
private

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