Module node

Module node 

Source
Expand description

Central instance that owns all service entities and can handle incoming event in an event loop The Node is the central entry point of iceoryx2. It is the owner of all communication entities and provides additional memory to them to perform reference counting amongst other things.

It allows also the system to monitor the state of processes and cleanup stale resources of dead processes.

§Create a Node

use iceoryx2::prelude::*;

let node = NodeBuilder::new()
                .name(&"my_little_node".try_into()?)
                .create::<ipc::Service>()?;

println!("created node {:?}", node);

§List all existing Nodes

use iceoryx2::prelude::*;

Node::<ipc::Service>::list(Config::global_config(), |node_state| {
    println!("found node {:?}", node_state);
    CallbackProgression::Continue
});

§Cleanup stale resources of all dead Nodes

use iceoryx2::prelude::*;

Node::<ipc::Service>::list(Config::global_config(), |node_state| {
    if let NodeState::<ipc::Service>::Dead(view) = node_state {
        println!("cleanup resources of dead node {:?}", view);
        if let Err(e) = view.remove_stale_resources() {
            println!("failed to cleanup resources due to {:?}", e);
        }
    }
    CallbackProgression::Continue
})?;

§Simple Event Loop

use core::time::Duration;
use iceoryx2::prelude::*;

const CYCLE_TIME: Duration = Duration::from_secs(1);
let node = NodeBuilder::new()
                .name(&"my_little_node".try_into()?)
                .create::<ipc::Service>()?;

while node.wait(CYCLE_TIME).is_ok() {
    // your algorithm in here
}

§Simple Event Loop With Disabled Signal Handling

This example demonstrates how the Node can be used when system signals are being handled elsewhere. The builder parameter NodeBuilder::signal_handling_mode() can be used to disable signal handling in all Node calls like Node::wait().

use core::time::Duration;
use iceoryx2::prelude::*;

const CYCLE_TIME: Duration = Duration::from_secs(1);
let node = NodeBuilder::new()
                .name(&"my_little_node".try_into()?)
                // disable signal handling
                .signal_handling_mode(SignalHandlingMode::Disabled)
                .create::<ipc::Service>()?;

while node.wait(CYCLE_TIME).is_ok() {
    // your algorithm in here
}

§Advanced Event Loop

use core::time::Duration;
use iceoryx2::node::NodeWaitFailure;
use iceoryx2::prelude::*;

const CYCLE_TIME: Duration = Duration::from_secs(1);
let node = NodeBuilder::new()
                .name(&"my_little_node".try_into()?)
                .create::<ipc::Service>()?;

loop {
    match node.wait(CYCLE_TIME) {
        Ok(()) => {
            println!("entered next cycle");
        }
        Err(NodeWaitFailure::TerminationRequest) => {
            println!("User pressed CTRL+c, terminating");
            break;
        }
        Err(NodeWaitFailure::Interrupt) => {
            println!("Someone send an interrupt signal ...");
        }
    }
}

Modules§

node_name
The name for a node.

Structs§

AliveNodeView
All the informations of a Node that is alive.
CleanupState
Returned by Node::cleanup_dead_nodes(). Contains the cleanup report of the call and contains the number of dead nodes that were successfully cleaned up and how many could not be cleaned up. This does not have to be an error, for instance when the current process does not have the permission to access the corresponding resources.
DeadNodeView
All the informations and management operations belonging to a dead Node.
Node
The Node is the entry point to the whole iceoryx2 infrastructure and owns all entities.
NodeBuilder
Creates a Node.
NodeDetails
Optional detailed informations that a Node can have. They can only be obtained when the process has sufficient access permissions.
NodeId
The system-wide unique id of a Node

Enums§

NodeCleanupFailure
Failures of DeadNodeView::remove_stale_resources() that occur when the stale resources of a dead Node are removed.
NodeCreationFailure
The failures that can occur when a Node is created with the NodeBuilder.
NodeListFailure
The failures that can occur when a list of NodeStates is created with Node::list().
NodeState
The current state of the Node. If the Node is dead all of its resources can be removed with DeadNodeView::remove_stale_resources().
NodeWaitFailure
The failures that can occur when a list of NodeStates is created with Node::list().

Traits§

NodeView
Contains all available details of a Node.