robotrt-middleware-core 0.1.0-beta.1

RobotRT modular robotics runtime and middleware components.
Documentation
use std::time::Duration;

use transport_core::Endpoint;

use crate::config::MiddlewareRuntimeConfig;
use crate::discovery::{
    DiscoveryEndpoint, DiscoveryEntry, DiscoveryPruneReport, DiscoverySnapshot,
};
use crate::qos::QosProfile;

use super::MiddlewareStack;

impl MiddlewareStack {
    pub fn apply_runtime_config(&mut self, config: MiddlewareRuntimeConfig) {
        self.route_rules = config.route_rules;
        self.namespace_isolation = config.namespace_isolation;
        for item in config.topic_qos_overrides {
            self.qos.set_topic_qos(item.topic, item.profile);
        }
    }

    pub fn register_topic(&mut self, topic: impl Into<String>) {
        self.discovery.register_topic(topic);
    }

    pub fn register_topic_with_ttl(&mut self, topic: impl Into<String>, ttl: Duration) {
        self.discovery.register_topic_with_ttl(topic, ttl);
    }

    pub fn set_topic_qos(&mut self, topic: impl Into<String>, profile: QosProfile) {
        self.qos.set_topic_qos(topic, profile);
    }

    pub fn set_topic_qos_if_absent(&mut self, topic: impl Into<String>, profile: QosProfile) {
        self.qos.set_topic_qos_if_absent(topic, profile);
    }

    pub fn topic_qos(&self, topic: &str) -> Option<QosProfile> {
        self.qos.topic_qos(topic)
    }

    pub fn register_service(&mut self, service: impl Into<String>) {
        self.discovery.register_service(service);
    }

    pub fn register_service_with_ttl(&mut self, service: impl Into<String>, ttl: Duration) {
        self.discovery.register_service_with_ttl(service, ttl);
    }

    pub fn register_mission(&mut self, mission: impl Into<String>) {
        self.discovery.register_mission(mission);
    }

    pub fn register_mission_with_ttl(&mut self, mission: impl Into<String>, ttl: Duration) {
        self.discovery.register_mission_with_ttl(mission, ttl);
    }

    pub fn register_endpoint(&mut self, name: impl Into<String>, endpoint: Endpoint) {
        self.discovery.register_endpoint(name, endpoint);
    }

    pub fn register_endpoint_with_ttl(
        &mut self,
        name: impl Into<String>,
        endpoint: Endpoint,
        ttl: Duration,
    ) {
        self.discovery
            .register_endpoint_with_ttl(name, endpoint, ttl);
    }

    pub fn find_endpoint(&self, name: &str) -> Option<DiscoveryEndpoint> {
        self.discovery.find_endpoint(name)
    }

    pub fn renew_topic_lease(&mut self, topic: &str, ttl: Duration) -> bool {
        self.discovery.renew_topic_lease(topic, ttl)
    }

    pub fn renew_service_lease(&mut self, service: &str, ttl: Duration) -> bool {
        self.discovery.renew_service_lease(service, ttl)
    }

    pub fn renew_mission_lease(&mut self, mission: &str, ttl: Duration) -> bool {
        self.discovery.renew_mission_lease(mission, ttl)
    }

    pub fn renew_endpoint_lease(&mut self, endpoint: &str, ttl: Duration) -> bool {
        self.discovery.renew_endpoint_lease(endpoint, ttl)
    }

    pub fn set_topic_health(&mut self, topic: &str, healthy: bool) -> bool {
        self.discovery.set_topic_health(topic, healthy)
    }

    pub fn set_service_health(&mut self, service: &str, healthy: bool) -> bool {
        self.discovery.set_service_health(service, healthy)
    }

    pub fn set_mission_health(&mut self, mission: &str, healthy: bool) -> bool {
        self.discovery.set_mission_health(mission, healthy)
    }

    pub fn set_endpoint_health(&mut self, endpoint: &str, healthy: bool) -> bool {
        self.discovery.set_endpoint_health(endpoint, healthy)
    }

    pub fn prune_discovery_inactive(&mut self) -> DiscoveryPruneReport {
        self.discovery.prune_inactive()
    }

    pub fn snapshot(&self) -> DiscoverySnapshot {
        self.discovery.snapshot()
    }

    pub fn topic_entries(&self) -> Vec<DiscoveryEntry> {
        self.discovery.topic_entries()
    }

    pub fn service_entries(&self) -> Vec<DiscoveryEntry> {
        self.discovery.service_entries()
    }

    pub fn mission_entries(&self) -> Vec<DiscoveryEntry> {
        self.discovery.mission_entries()
    }
}