fsipc 0.12.0

fsipc, zbus Proxy for the modio-logger DBus interface
Documentation
// Author: D.S. Ljungmark <spider@skuggor.se>, Modio AB
// SPDX-License-Identifier: MIT
//! # `DBus` interface proxies for: `se.modio.logger`, `se.modio.logger.Logger1`, `se.modio.logger.fsipc`
//!
//! This code was generated by `zbus-xmlgen` `3.0.0` from `DBus` introspection data.
//! Source: `Interface '/se/modio/logger' from service 'se.modio.logger' on session bus`.
//!
//! You may prefer to adapt it, instead of using it verbatim.
//!
//! More information can be found in the
//! [Writing a client proxy](https://dbus.pages.freedesktop.org/zbus/client.html)
//! section of the zbus documentation.
//!
//! This `DBus` object implements
//! [standard `DBus` interfaces](https://dbus.freedesktop.org/doc/dbus-specification.html),
//! (`org.freedesktop.DBus.*`) for which the following zbus proxies can be used:
//!
//! * [`zbus::fdo::PropertiesProxy`]
//! * [`zbus::fdo::PeerProxy`]
//! * [`zbus::fdo::IntrospectableProxy`]
//!
//! …consequently `zbus-xmlgen` did not generate code for the above interfaces.

use serde::Deserialize;
use serde::Serialize;
use std::collections::HashMap;
use zbus::proxy;
use zbus::zvariant::{DeserializeDict, SerializeDict, Type, Value};

pub type ValueMap = HashMap<u32, String>;

#[derive(Debug, PartialEq, Eq, Type, Serialize, Deserialize)]
pub enum SensorMode {
    ReadOnly,
    ReadWrite,
    WriteOnly,
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Type, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum DataType {
    F64,
    String,
    Bool,
    U64,
}

// This type should match the one here:
// https://gitlab.com/ModioAB/modio-logger/-/blob/main/modio-logger/src/types.rs
#[derive(Debug, PartialEq, Eq, DeserializeDict, SerializeDict, Type)]
#[zvariant(signature = "dict")]
pub struct Metadata {
    pub n: String,
    pub u: Option<String>,
    pub name: Option<String>,
    pub description: Option<String>,
    pub value_map: Option<ValueMap>,
    pub mode: Option<SensorMode>,
    pub value_type: Option<DataType>,
}

#[proxy(
    interface = "se.modio.logger.Logger1",
    default_service = "se.modio.logger",
    default_path = "/se/modio/logger"
)]
pub trait Logger1 {
    /// GetMetadata method
    fn get_metadata(&self, key: &str) -> zbus::Result<Metadata>;

    /// SetMetadataDescription method
    fn set_metadata_description(&self, key: &str, description: &str) -> zbus::Result<()>;

    /// SetMetadataMode method
    fn set_metadata_mode(&self, key: &str, mode: SensorMode) -> zbus::Result<()>;

    /// SetMetadataName method
    fn set_metadata_name(&self, key: &str, name: &str) -> zbus::Result<()>;

    /// SetMetadataUnit method
    fn set_metadata_unit(&self, key: &str, unit: &str) -> zbus::Result<()>;

    /// SetMetadataValueMap method
    fn set_metadata_value_map(&self, key: &str, value_map: ValueMap) -> zbus::Result<()>;

    /// SetMetadataValueType method
    fn set_metadata_value_type(&self, key: &str, value_type: DataType) -> zbus::Result<()>;

    /// MetadataUpdated signal
    #[zbus(signal)]
    fn metadata_updated(&self, key: &str) -> zbus::Result<()>;

    /// StoreBatch method,  store a batch of key:value for Anachronistic Measures
    async fn store_batch(&self, batch: HashMap<String, Value<'_>>) -> zbus::Result<()>;

    /// Store method,  store a single key:value of an Anachronistic Measure
    /// ( Wraps store_batch internally, only use for ease of porting)
    async fn store(&self, key: String, value: Value<'_>) -> zbus::Result<()>;

    fn store_ts(&self, batch: Vec<(String, Value<'_>, f64)>) -> zbus::Result<()>;

    fn store_rows(&self, rows: Vec<(f64, Vec<Value<'_>>)>) -> zbus::Result<()>;

    /// Signal sent when values are stored.
    /// Contents is a vector of (key, value, timestamp)
    #[zbus(signal)]
    async fn store_signal(&self, batch: Vec<(String, Value<'_>, i64)>) -> zbus::Result<()>;
}