2022-08-07 19:42:22 +02:00
|
|
|
mod data;
|
2022-10-05 15:33:57 +02:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
2022-08-07 19:42:22 +02:00
|
|
|
pub use data::Data;
|
|
|
|
|
2022-09-07 13:25:51 +02:00
|
|
|
use crate::Result;
|
2022-08-07 19:42:22 +02:00
|
|
|
|
2022-10-05 12:45:54 +02:00
|
|
|
pub struct Service {
|
2022-10-08 13:02:52 +02:00
|
|
|
pub db: &'static dyn Data,
|
2022-08-07 19:42:22 +02:00
|
|
|
}
|
|
|
|
|
2022-10-05 12:45:54 +02:00
|
|
|
impl Service {
|
2022-08-07 19:42:22 +02:00
|
|
|
/// Registers an appservice and returns the ID to the caller
|
|
|
|
pub fn register_appservice(&self, yaml: serde_yaml::Value) -> Result<String> {
|
|
|
|
self.db.register_appservice(yaml)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Remove an appservice registration
|
|
|
|
///
|
|
|
|
/// # Arguments
|
|
|
|
///
|
|
|
|
/// * `service_name` - the name you send to register the service previously
|
|
|
|
pub fn unregister_appservice(&self, service_name: &str) -> Result<()> {
|
|
|
|
self.db.unregister_appservice(service_name)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_registration(&self, id: &str) -> Result<Option<serde_yaml::Value>> {
|
|
|
|
self.db.get_registration(id)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn iter_ids(&self) -> Result<impl Iterator<Item = Result<String>> + '_> {
|
|
|
|
self.db.iter_ids()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn all(&self) -> Result<Vec<(String, serde_yaml::Value)>> {
|
|
|
|
self.db.all()
|
|
|
|
}
|
|
|
|
}
|