use serde::{Deserialize, Serialize};
use crate::error::BrokerError;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CapabilityRequest {
pub capability_group: String,
pub operation: BrokerOperation,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum BrokerOperation {
TopicSubscribe { topic: String },
TopicPublish { topic: String, data: Vec<u8> },
ServiceCall { service: String, request: Vec<u8> },
ParamGet { name: String },
ParamSet { name: String, value: Vec<u8> },
RosList,
LogSourceList,
LogStream { source: String, pattern: String },
FsRead { path: String },
FsWrite { path: String, data: Vec<u8> },
FsList { path: String },
FsStat { path: String },
SystemInfo,
ProcessList,
NetworkState,
ArtifactPublish {
data: Vec<u8>,
filename: Option<String>,
content_type: Option<String>,
},
ArtifactExists { cid: String },
ProcessSpawn {
command: String,
args: Vec<String>,
cwd: Option<String>,
env: Vec<(String, String)>,
timeout_secs: u64,
},
NetPing { host: String, count: u32 },
NetDnsLookup {
hostname: String,
record_type: String,
},
NetPortCheck {
host: String,
port: u16,
timeout_secs: u64,
},
NetTraceroute { host: String, max_hops: u32 },
MetricEmit {
name: String,
value: f64,
unit: Option<String>,
tags: Vec<(String, String)>,
},
MetricEmitBatch { metrics: Vec<MetricPoint> },
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MetricPoint {
pub name: String,
pub value: f64,
pub unit: Option<String>,
pub tags: Vec<(String, String)>,
pub timestamp_ms: u64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CapabilityResponse {
pub success: bool,
pub data: Vec<u8>,
pub error: Option<String>,
pub bytes_in: u64,
pub bytes_out: u64,
}
#[async_trait::async_trait]
pub trait CapabilityBroker: Send + Sync {
async fn handle_request(
&self,
req: CapabilityRequest,
) -> Result<CapabilityResponse, BrokerError>;
fn capability_group(&self) -> &str;
}