@@ -6,7 +6,7 @@ use std::{
6
6
vec:: Vec ,
7
7
} ;
8
8
9
- use crate :: { rcl_bindings:: * , RclrsError , ToResult } ;
9
+ use crate :: { rcl_bindings:: * , LoggingLifecycle , RclrsError , ToResult } ;
10
10
11
11
/// This is locked whenever initializing or dropping any middleware entity
12
12
/// because we have found issues in RCL and some RMW implementations that
@@ -56,6 +56,10 @@ unsafe impl Send for rcl_context_t {}
56
56
/// - middleware-specific data, e.g. the domain participant in DDS
57
57
/// - the allocator used (left as the default by `rclrs`)
58
58
///
59
+ /// The context also configures the rcl_logging_* layer to allow publication to /rosout
60
+ /// (as well as the terminal). TODO: This behaviour should be configurable using an
61
+ /// "auto logging initialise" flag as per rclcpp and rclpy.
62
+ ///
59
63
pub struct Context {
60
64
pub ( crate ) handle : Arc < ContextHandle > ,
61
65
}
@@ -68,6 +72,10 @@ pub struct Context {
68
72
/// bindings in this library.
69
73
pub ( crate ) struct ContextHandle {
70
74
pub ( crate ) rcl_context : Mutex < rcl_context_t > ,
75
+ /// This ensures that logging does not get cleaned up until after this ContextHandle
76
+ /// has dropped.
77
+ #[ allow( unused) ]
78
+ logging : Arc < LoggingLifecycle > ,
71
79
}
72
80
73
81
impl Context {
@@ -143,9 +151,16 @@ impl Context {
143
151
// Move the check after the last fini()
144
152
ret?;
145
153
}
154
+
155
+ // TODO: "Auto set-up logging" is forced but should be configurable as per rclcpp and rclpy
156
+ // SAFETY: We created this context a moment ago and verified that it is valid.
157
+ // No other conditions are needed.
158
+ let logging = unsafe { LoggingLifecycle :: configure ( & rcl_context) ? } ;
159
+
146
160
Ok ( Self {
147
161
handle : Arc :: new ( ContextHandle {
148
162
rcl_context : Mutex :: new ( rcl_context) ,
163
+ logging,
149
164
} ) ,
150
165
} )
151
166
}
0 commit comments