add backend for history

This commit is contained in:
2024-12-30 20:13:03 -05:00
parent c7ca250b66
commit aa1763cbe7
11 changed files with 319 additions and 28 deletions

View File

@@ -1,19 +1,23 @@
use crate::core::{TelemetryDefinitionRequest, Uuid};
use crate::telemetry::data::TelemetryData;
use crate::telemetry::data::{TelemetryData, TelemetryDataHistory};
use crate::telemetry::definition::TelemetryDefinition;
use papaya::HashMap;
use papaya::{HashMap, HashMapRef, LocalGuard};
use std::error::Error;
use std::hash::RandomState;
use crate::telemetry::history::{TelemetryHistory, TelemetryHistoryService};
pub struct TelemetryManagementService {
uuid_index: HashMap<String, String>,
tlm_data: HashMap<String, TelemetryData>,
tlm_data: HashMap<String, TelemetryDataHistory>,
telemetry_history_service: TelemetryHistoryService
}
impl TelemetryManagementService {
pub fn new() -> Self {
pub fn new(telemetry_history_service: TelemetryHistoryService) -> Self {
Self {
uuid_index: HashMap::new(),
tlm_data: HashMap::new(),
telemetry_history_service
}
}
@@ -32,13 +36,16 @@ impl TelemetryManagementService {
let _ = tlm_data.try_insert(
uuid.clone(),
TelemetryData {
definition: TelemetryDefinition {
uuid: uuid.clone(),
name: telemetry_definition_request.name.clone(),
data_type: telemetry_definition_request.data_type(),
TelemetryDataHistory {
data: TelemetryData {
definition: TelemetryDefinition {
uuid: uuid.clone(),
name: telemetry_definition_request.name.clone(),
data_type: telemetry_definition_request.data_type(),
},
data: tokio::sync::watch::channel(None).0,
},
data: tokio::sync::watch::channel(None).0,
history: TelemetryHistory::new(),
},
);
@@ -53,6 +60,27 @@ impl TelemetryManagementService {
pub fn get_by_uuid(&self, uuid: &String) -> Option<TelemetryData> {
let tlm_data = self.tlm_data.pin();
tlm_data.get(uuid).cloned()
tlm_data.get(uuid).map(|data_history| &data_history.data).cloned()
}
pub fn pin(&self) -> TelemetryManagementServicePin {
TelemetryManagementServicePin {
tlm_data: self.tlm_data.pin()
}
}
pub fn history_service(&self) -> &TelemetryHistoryService {
&self.telemetry_history_service
}
}
pub struct TelemetryManagementServicePin<'a> {
tlm_data: HashMapRef<'a, String, TelemetryDataHistory, RandomState, LocalGuard<'a>>
}
impl<'a> TelemetryManagementServicePin<'a> {
pub fn get_by_uuid(&'a self, uuid: &String) -> Option<&'a TelemetryDataHistory> {
self.tlm_data.get(uuid)
}
}