omni_director/providers/
mod.rs

1//! # Provider System
2//!
3//! Manages external service providers (VirtualBox, AWS, Docker, etc.)
4//! Providers expose features that can be used by the system.
5
6pub mod registry;
7pub mod loader;
8pub mod metadata;
9pub mod context;
10pub mod feature_registry;
11pub mod event_registry;
12
13pub use registry::*;
14pub use loader::*;
15pub use metadata::*;
16pub use context::*;
17pub use feature_registry::*;
18pub use event_registry::*;
19
20use std::collections::HashMap;
21use serde_json::Value;
22use thiserror::Error;
23
24/// Provider system errors
25#[derive(Error, Debug)]
26pub enum ProviderError {
27    #[error("Provider not found: {0}")]
28    NotFound(String),
29    
30    #[error("Provider loading failed: {0}")]
31    LoadingFailed(String),
32    
33    #[error("Provider initialization failed: {0}")]
34    InitializationFailed(String),
35    
36    #[error("Provider execution failed: {0}")]
37    ExecutionFailed(String),
38    
39    #[error("Feature not supported: {feature} in provider {provider}")]
40    FeatureNotSupported { provider: String, feature: String },
41    
42    #[error("Operation not supported: {operation} in {provider}/{feature}")]
43    OperationNotSupported { provider: String, feature: String, operation: String },
44    
45    #[error("Invalid arguments: {0}")]
46    InvalidArguments(String),
47    
48    #[error("Invalid route: {0}")]
49    InvalidRoute(String),
50    
51    #[error("IO error: {0}")]
52    Io(#[from] std::io::Error),
53    
54    #[error("Library loading error: {0}")]
55    LibraryError(#[from] libloading::Error),
56}
57
58/// Result type for provider operations
59pub type ProviderResult<T> = Result<T, ProviderError>;
60
61/// Provider capability trait
62pub trait Provider: Send + Sync {
63    /// Get provider name
64    fn name(&self) -> &str;
65    
66    /// Get provider version
67    fn version(&self) -> &str;
68    
69    /// Get supported features
70    fn features(&self) -> Vec<String>;
71    
72    /// Check if provider supports a feature
73    fn supports_feature(&self, feature: &str) -> bool {
74        self.features().contains(&feature.to_string())
75    }
76    
77    /// Get operations for a feature
78    fn feature_operations(&self, feature: &str) -> ProviderResult<Vec<String>>;
79    
80    /// Execute an operation
81    fn execute_operation(
82        &self,
83        feature: &str,
84        operation: &str,
85        args: HashMap<String, Value>,
86        context: &dyn ProviderContext,
87    ) -> ProviderResult<Value>;
88    
89    /// Initialize provider
90    fn initialize(&mut self, context: &dyn ProviderContext) -> ProviderResult<()>;
91    
92    /// Shutdown provider
93    fn shutdown(&mut self, context: &dyn ProviderContext) -> ProviderResult<()>;
94}