@@ -3,10 +3,11 @@ use crate::{
33 error:: { RclReturnCode , ToResult } ,
44 rcl_bindings:: * ,
55 wait:: WaitableNumEntities ,
6- Clock , DropGuard , Node , NodeHandle , RclrsError , ENTITY_LIFECYCLE_MUTEX ,
6+ Clock , DropGuard , Node , NodeHandle , QoSProfile , RclrsError , ENTITY_LIFECYCLE_MUTEX ,
77} ;
88use rosidl_runtime_rs:: { Action , ActionImpl , Message , Service } ;
99use std:: {
10+ borrow:: Borrow ,
1011 collections:: HashMap ,
1112 ffi:: CString ,
1213 sync:: { atomic:: AtomicBool , Arc , Mutex , MutexGuard } ,
@@ -120,23 +121,25 @@ where
120121 T : rosidl_runtime_rs:: Action + rosidl_runtime_rs:: ActionImpl ,
121122{
122123 /// Creates a new action server.
123- pub ( crate ) fn new (
124+ pub ( crate ) fn new < ' a > (
124125 node : & Node ,
125- topic : & str ,
126+ options : impl Into < ActionServerOptions < ' a > > ,
126127 goal_callback : impl Fn ( GoalUuid , T :: Goal ) -> GoalResponse + ' static + Send + Sync ,
127128 cancel_callback : impl Fn ( Arc < ServerGoalHandle < T > > ) -> CancelResponse + ' static + Send + Sync ,
128129 accepted_callback : impl Fn ( Arc < ServerGoalHandle < T > > ) + ' static + Send + Sync ,
129130 ) -> Result < Self , RclrsError >
130131 where
131132 T : rosidl_runtime_rs:: Action + rosidl_runtime_rs:: ActionImpl ,
132133 {
134+ let options = options. into ( ) ;
133135 // SAFETY: Getting a zero-initialized value is always safe.
134136 let mut rcl_action_server = unsafe { rcl_action_get_zero_initialized_server ( ) } ;
135137 let type_support = T :: get_type_support ( ) as * const rosidl_action_type_support_t ;
136- let topic_c_string = CString :: new ( topic) . map_err ( |err| RclrsError :: StringContainsNul {
137- err,
138- s : topic. into ( ) ,
139- } ) ?;
138+ let action_name_c_string =
139+ CString :: new ( options. action_name ) . map_err ( |err| RclrsError :: StringContainsNul {
140+ err,
141+ s : options. action_name . into ( ) ,
142+ } ) ?;
140143
141144 // SAFETY: No preconditions for this function.
142145 let action_server_options = unsafe { rcl_action_server_get_default_options ( ) } ;
@@ -151,7 +154,7 @@ where
151154 // SAFETY:
152155 // * The rcl_action_server is zero-initialized as mandated by this function.
153156 // * The rcl_node is kept alive by the NodeHandle because it is a dependency of the action server.
154- // * The topic name and the options are copied by this function, so they can be dropped
157+ // * The action name and the options are copied by this function, so they can be dropped
155158 // afterwards.
156159 // * The entity lifecycle mutex is locked to protect against the risk of global
157160 // variables in the rmw implementation being unsafely modified during initialization.
@@ -161,7 +164,7 @@ where
161164 & mut * rcl_node,
162165 & mut * rcl_clock,
163166 type_support,
164- topic_c_string . as_ptr ( ) ,
167+ action_name_c_string . as_ptr ( ) ,
165168 & action_server_options,
166169 )
167170 . ok ( ) ?;
@@ -736,3 +739,45 @@ where
736739 }
737740 }
738741}
742+
743+ /// `ActionServerOptions` are used by [`Node::create_action_server`][1] to initialize an
744+ /// [`ActionServer`].
745+ ///
746+ /// [1]: crate::Node::create_action_server
747+ #[ derive( Debug , Clone ) ]
748+ #[ non_exhaustive]
749+ pub struct ActionServerOptions < ' a > {
750+ /// The name of the action implemented by this server
751+ pub action_name : & ' a str ,
752+ /// The quality of service profile for the goal service
753+ pub goal_service_qos : QoSProfile ,
754+ /// The quality of service profile for the result service
755+ pub result_service_qos : QoSProfile ,
756+ /// The quality of service profile for the cancel service
757+ pub cancel_service_qos : QoSProfile ,
758+ /// The quality of service profile for the feedback topic
759+ pub feedback_topic_qos : QoSProfile ,
760+ /// The quality of service profile for the status topic
761+ pub status_topic_qos : QoSProfile ,
762+ // TODO(nwn): result_timeout
763+ }
764+
765+ impl < ' a > ActionServerOptions < ' a > {
766+ /// Initialize a new [`ActionServerOptions`] with default settings.
767+ pub fn new ( action_name : & ' a str ) -> Self {
768+ Self {
769+ action_name,
770+ goal_service_qos : QoSProfile :: services_default ( ) ,
771+ result_service_qos : QoSProfile :: services_default ( ) ,
772+ cancel_service_qos : QoSProfile :: services_default ( ) ,
773+ feedback_topic_qos : QoSProfile :: topics_default ( ) ,
774+ status_topic_qos : QoSProfile :: action_status_default ( ) ,
775+ }
776+ }
777+ }
778+
779+ impl < ' a , T : Borrow < str > + ?Sized + ' a > From < & ' a T > for ActionServerOptions < ' a > {
780+ fn from ( value : & ' a T ) -> Self {
781+ Self :: new ( value. borrow ( ) )
782+ }
783+ }
0 commit comments