Skip to content

Add rosout logging to rclrs #422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rclrs/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ fn main() {
}
};

println!("cargo:rustc-check-cfg=cfg(ros_distro, values(\"humble\", \"iron\", \"jazzy\", \"rolling\"))");
println!("cargo:rustc-cfg=ros_distro=\"{ros_distro}\"");

let mut builder = bindgen::Builder::default()
Expand Down
17 changes: 16 additions & 1 deletion rclrs/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
vec::Vec,
};

use crate::{rcl_bindings::*, RclrsError, ToResult};
use crate::{rcl_bindings::*, LoggingLifecycle, RclrsError, ToResult};

/// This is locked whenever initializing or dropping any middleware entity
/// because we have found issues in RCL and some RMW implementations that
Expand Down Expand Up @@ -56,6 +56,10 @@ unsafe impl Send for rcl_context_t {}
/// - middleware-specific data, e.g. the domain participant in DDS
/// - the allocator used (left as the default by `rclrs`)
///
/// The context also configures the rcl_logging_* layer to allow publication to /rosout
/// (as well as the terminal). TODO: This behaviour should be configurable using an
/// "auto logging initialise" flag as per rclcpp and rclpy.
///
pub struct Context {
pub(crate) handle: Arc<ContextHandle>,
}
Expand All @@ -68,6 +72,10 @@ pub struct Context {
/// bindings in this library.
pub(crate) struct ContextHandle {
pub(crate) rcl_context: Mutex<rcl_context_t>,
/// This ensures that logging does not get cleaned up until after this ContextHandle
/// has dropped.
#[allow(unused)]
logging: Arc<LoggingLifecycle>,
}

impl Context {
Expand Down Expand Up @@ -143,9 +151,16 @@ impl Context {
// Move the check after the last fini()
ret?;
}

// TODO: "Auto set-up logging" is forced but should be configurable as per rclcpp and rclpy
// SAFETY: We created this context a moment ago and verified that it is valid.
// No other conditions are needed.
let logging = unsafe { LoggingLifecycle::configure(&rcl_context)? };

Ok(Self {
handle: Arc::new(ContextHandle {
rcl_context: Mutex::new(rcl_context),
logging,
}),
})
}
Expand Down
2 changes: 2 additions & 0 deletions rclrs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mod clock;
mod context;
mod error;
mod executor;
mod logging;
mod node;
mod parameter;
mod publisher;
Expand Down Expand Up @@ -38,6 +39,7 @@ pub use clock::*;
pub use context::*;
pub use error::*;
pub use executor::*;
pub use logging::*;
pub use node::*;
pub use parameter::*;
pub use publisher::*;
Expand Down
Loading
Loading