use parking_lot::Mutex;
use crate::contracts::RegisterGrpcServiceFn;
#[derive(Default)]
pub struct ModuleInstallers {
pub module_name: String,
pub installers: Vec<RegisterGrpcServiceFn>,
}
#[derive(Default)]
pub struct GrpcInstallerData {
pub modules: Vec<ModuleInstallers>,
}
pub struct GrpcInstallerStore {
inner: Mutex<Option<GrpcInstallerData>>,
}
impl GrpcInstallerStore {
#[must_use]
pub fn new() -> Self {
Self {
inner: Mutex::new(None),
}
}
pub fn set(&self, data: GrpcInstallerData) -> anyhow::Result<()> {
let mut guard = self.inner.lock();
if guard.is_some() {
anyhow::bail!("gRPC installers already initialized");
}
*guard = Some(data);
Ok(())
}
pub fn take(&self) -> Option<GrpcInstallerData> {
let mut guard = self.inner.lock();
guard.take()
}
#[allow(dead_code)]
pub fn is_empty(&self) -> bool {
self.inner.lock().is_none()
}
}
impl Default for GrpcInstallerStore {
fn default() -> Self {
Self::new()
}
}