Skip to main content

EventSubscription

Struct EventSubscription 

Source
pub struct EventSubscription { /* private fields */ }

Implementations§

Source§

impl EventSubscription

Source

pub fn next(&self, timeout_ms: u64) -> Result<PollResult, NodeError>

Examples found in repository?
examples/std_managed_node.rs (line 33)
9fn main() {
10    let node = EmbeddedNode::new();
11    let subscription = node.subscribe_events().expect("subscribe");
12
13    let config = NodeConfig {
14        runtime: RuntimeConfig {
15            store_identity: [0x11; 32],
16            lxmf_address: [0x22; 16],
17            node_mode: NodeTransportMode::BleOnly,
18            announce_interval_ms: 1_000,
19            max_outbound_queue: 8,
20            max_events: 16,
21            capture_defaults: Default::default(),
22        },
23        backend: NodeBackendConfig::Ble(BleNodeBackendConfig::default()),
24    };
25
26    node.start(config).expect("start");
27    node.set_link_state(LinkState::Up).expect("link up");
28    node.send([0x42; 16], b"hello from managed std", SendOptions).expect("send");
29
30    thread::sleep(Duration::from_millis(75));
31
32    loop {
33        match subscription.next(0).expect("poll") {
34            PollResult::Event(event) => {
35                if let NodeEventKind::PacketSent { sequence, .. } = event.kind {
36                    println!("packet sent with sequence {sequence}");
37                    break;
38                }
39            }
40            PollResult::Timeout => break,
41            other => println!("poll result: {other:?}"),
42        }
43    }
44
45    node.stop().expect("stop");
46}
More examples
Hide additional examples
examples/tcp_receive_once.rs (line 41)
14fn main() {
15    let Some(port) = env::args().nth(1).and_then(|value| value.parse::<u16>().ok()) else {
16        eprintln!("usage: cargo run -p rns-embedded-runtime --example tcp_receive_once -- <port>");
17        process::exit(2);
18    };
19
20    println!("LISTENING port={port} destination={}", encode_hex(&SERVER_LXMF_ADDRESS));
21
22    let node = EmbeddedNode::new();
23    let subscription = node.subscribe_events().expect("subscribe");
24    node.start(NodeConfig {
25        runtime: RuntimeConfig {
26            store_identity: SERVER_STORE_IDENTITY,
27            lxmf_address: SERVER_LXMF_ADDRESS,
28            node_mode: NodeTransportMode::TcpServer,
29            announce_interval_ms: 1_000,
30            max_outbound_queue: 8,
31            max_events: 32,
32            capture_defaults: Default::default(),
33        },
34        backend: NodeBackendConfig::TcpServer(TcpServerConfig { listen_port: port }),
35    })
36    .expect("start tcp server");
37    node.set_network_provisioned(true).expect("set network provisioned");
38
39    let deadline = Instant::now() + Duration::from_secs(10);
40    loop {
41        match subscription.next(500).expect("poll") {
42            PollResult::Event(event) => match event.kind {
43                NodeEventKind::Extension {
44                    extension_id: NODE_EXTENSION_ID_RECEIVED_SUMMARY,
45                    value0,
46                    value1,
47                } => {
48                    println!("RECEIVED sequence={value0} bytes={value1}");
49                    break;
50                }
51                NodeEventKind::Error { error, .. } => {
52                    eprintln!("ERROR {error:?}");
53                    process::exit(1);
54                }
55                _ => {}
56            },
57            PollResult::NodeRestarted { .. } | PollResult::NodeStopped => continue,
58            PollResult::Timeout if Instant::now() < deadline => continue,
59            PollResult::Timeout => {
60                eprintln!("timeout waiting for inbound message");
61                process::exit(1);
62            }
63            other => {
64                eprintln!("unexpected poll result: {other:?}");
65            }
66        }
67    }
68
69    node.stop().expect("stop");
70}
Source

pub fn close(&self) -> Result<(), NodeError>

Trait Implementations§

Source§

impl Clone for EventSubscription

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.