Struct safe_drive::context::Context

source ·
pub struct Context { /* private fields */ }
Expand description

Context of ROS2.

Implementations§

Create a new context.

Example
use safe_drive::context::Context;

// Create a context.
let ctx = Context::new().unwrap();

Create a new node of ROS2.

Example
use safe_drive::context::Context;

// Create a context.
let ctx = Context::new().unwrap();

// Create a node.
let node = ctx
    .create_node("context_rs", None, Default::default())
    .unwrap();
Errors
  • RCLError::AlreadyInit if the node has already be initialized, or
  • RCLError::NotInit if the given context is invalid, or
  • RCLError::InvalidArgument if any arguments are invalid, or
  • RCLError::BadAlloc if allocating memory failed, or
  • RCLError::NodeInvalidName if the name is invalid, or
  • RCLError::NodeInvalidNamespace if the namespace_ is invalid, or
  • RCLError::Error if an unspecified error occurs.

Create a new selector. The selector is used to wait event and invoke callback for single threaded execution.

Example
use safe_drive::context::Context;

// Create a context.
let ctx = Context::new().unwrap();

// Create a selector.
let selector = ctx.create_selector().unwrap();
Errors
  • RCLError::AlreadyInit if the wait set is not zero initialized, or
  • RCLError::NotInit if the given context is invalid, or
  • RCLError::InvalidArgument if any arguments are invalid, or
  • RCLError::BadAlloc if allocating memory failed, or
  • RCLError::WaitSetInvalid if the wait set is not destroyed properly, or
  • RCLError::Error if an unspecified error occurs.
Examples found in repository?
src/parameter.rs (line 838)
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
fn param_server(
    node: Arc<Node>,
    params: Arc<RwLock<Parameters>>,
    cond_halt: GuardCondition,
    cond_callback: GuardCondition,
) -> Result<(), DynError> {
    if let Ok(mut selector) = node.context.create_selector() {
        add_srv_list(&node, &mut selector, params.clone())?;
        add_srv_set(
            &node,
            &mut selector,
            params.clone(),
            "set_parameters",
            cond_callback.clone(),
        )?;
        add_srv_set(
            &node,
            &mut selector,
            params.clone(),
            "set_parameters_atomically",
            cond_callback,
        )?;
        add_srv_get(&node, &mut selector, params.clone())?;
        add_srv_get_types(&node, &mut selector, params.clone())?;
        add_srv_describe(&node, &mut selector, params)?;

        let is_halt = Rc::new(Cell::new(false));
        let is_halt_cloned = is_halt.clone();

        selector.add_guard_condition(
            &cond_halt,
            Some(Box::new(move || {
                is_halt_cloned.set(true);
                CallbackResult::Remove
            })),
            false,
        );

        while !is_halt.get() {
            selector.wait()?;
        }
    } else {
        let logger = Logger::new("safe_drive");
        pr_error_in!(logger, "failed to start a parameter server");
    }

    Ok(())
}

Trait Implementations§

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.