pub struct EventSubscription { /* private fields */ }Implementations§
Source§impl EventSubscription
impl EventSubscription
Sourcepub fn next(&self, timeout_ms: u64) -> Result<PollResult, NodeError>
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
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}pub fn close(&self) -> Result<(), NodeError>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for EventSubscription
impl RefUnwindSafe for EventSubscription
impl Send for EventSubscription
impl Sync for EventSubscription
impl Unpin for EventSubscription
impl UnsafeUnpin for EventSubscription
impl UnwindSafe for EventSubscription
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more