Manages plugin dependency relationships and validates for safe initialization.
More...
#include <PluginDependencyGraph.hpp>
|
| 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 std::string | FormatList (const std::vector< std::string > &items) |
| | Formats vector of strings for logging.
|
| |
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-b", {
"plugin-a"});
graph.
AddNode(
"plugin-c", {
"plugin-b",
"plugin-a"});
Logger::Error(
"Circular dependency: {}",
result.error().Message());
return;
}
for (const auto& id : order.unwrap()) {
}
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
◆ AddNode()
| void plugin::PluginDependencyGraph::AddNode |
( |
const std::string & |
id, |
|
|
const std::vector< std::string > & |
dependencies |
|
) |
| |
|
inline |
Adds a node to the dependency graph.
- Parameters
-
| id | Plugin identifier |
| dependencies | List of dependency plugin IDs |
◆ FormatList()
| static std::string plugin::PluginDependencyGraph::FormatList |
( |
const std::vector< std::string > & |
items | ) |
|
|
inlinestaticprivate |
Formats vector of strings for logging.
◆ GetDependencies()
| std::vector< std::string > plugin::PluginDependencyGraph::GetDependencies |
( |
const std::string & |
id | ) |
const |
|
inline |
Gets dependencies for a specific plugin.
- Parameters
-
- 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]
◆ GetNodeCount()
| size_t plugin::PluginDependencyGraph::GetNodeCount |
( |
| ) |
const |
|
inline |
Gets number of nodes in graph.
- Returns
- Node count
◆ GetShutdownOrder()
Gets plugins in valid shutdown order.
Reverse of initialization order - shutdown dependents before dependencies.
- Returns
- Order for shutdown, or error if cycles exist
◆ 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.
◆ 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.
◆ 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
-
| availablePlugins | Set of available plugin IDs |
- Returns
- Missing dependency IDs, or empty if all satisfied
◆ ValidateNoCycles()
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
◆ m_nodes
| std::map<std::string, DependencyNode> plugin::PluginDependencyGraph::m_nodes |
|
private |
The documentation for this class was generated from the following file: