celp_sdk/broker/
interface.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use std::result::Result;

use crate::protobuf::system_event::Severity;

/// Message returned by an object implementing the Subscribe trait
pub struct Message {
    pub data: Vec<u8>,
    pub topic: String,
}

/// Publish trait: defines the publish behaviour for an object implementing it. It provides short hands for
/// publishing protobuf messages and system events
pub trait Publish {
    type Error;

    fn publish<M: prost::Message>(&mut self, topic: &str, message: &M) -> Result<(), Self::Error>;
    fn publish_with_cache<M: prost::Message>(
        &mut self,
        topic: &str,
        message: &M,
    ) -> Result<(), Self::Error>;

    fn publish_event<E: prost::Message + prost::Name>(
        &mut self,
        event_details: &E,
        severity: Severity,
    ) -> Result<(), Self::Error>;

    fn publish_raw(&mut self, topic: &str, data: &[u8]) -> Result<(), Self::Error>;
}

/// Publish trait: defines the subscribe behaviour for an object implementing it. It provides short hands for
/// subscribing to system events
pub trait Subscribe {
    type Error;

    fn subscribe(&mut self, topic: &str) -> Result<Option<Message>, Self::Error>;
    fn subscribe_pattern(&mut self, pattern: &str) -> Result<(), Self::Error>;
    fn subscribe_event<E: prost::Message + prost::Name>(
        &mut self,
    ) -> Result<Option<Message>, Self::Error>;

    fn unsubscribe(&mut self, topic: &str) -> Result<(), Self::Error>;
    fn unsubscribe_pattern(&mut self, pattern: &str) -> Result<(), Self::Error>;
    fn unsubscribe_event<E: prost::Message + prost::Name>(&mut self) -> Result<(), Self::Error>;

    fn get_message(&mut self) -> Result<Message, Self::Error>;
}