use super::{CancellingGoal, ExecutingGoal, FeedbackPublisher, LiveActionServerGoal};
use rosidl_runtime_rs::Action;
use std::{future::Future, sync::Arc};
pub struct AcceptedGoal<A: Action> {
live: Arc<LiveActionServerGoal<A>>,
}
impl<A: Action> AcceptedGoal<A> {
#[must_use]
pub fn goal(&self) -> &Arc<A::Goal> {
self.live.goal()
}
#[must_use]
pub fn execute(self) -> ExecutingGoal<A> {
ExecutingGoal::new(self.live)
}
pub async fn until_cancel_requested<F: Future + Unpin>(&self, f: F) -> Result<F::Output, F> {
self.live.cancellation().until_cancel_requested(f).await
}
pub async fn unless_cancel_requested<F: Future>(&self, f: F) -> Result<F::Output, ()> {
self.live.cancellation().unless_cancel_requested(f).await
}
#[must_use]
pub fn begin_cancelling(self) -> CancellingGoal<A> {
CancellingGoal::new(self.live)
}
pub fn reject_cancellation(&self) {
self.live.reject_cancellation();
}
#[must_use]
pub fn begin(self) -> BeginAcceptedGoal<A> {
if self.live.cancel_requested() {
BeginAcceptedGoal::Cancel(self.begin_cancelling())
} else {
BeginAcceptedGoal::Execute(self.execute())
}
}
pub fn publish_feedback(&self, feedback: A::Feedback) {
self.live.publish_feedback(feedback);
}
pub fn feedback_publisher(&self) -> FeedbackPublisher<A> {
FeedbackPublisher::new(Arc::clone(&self.live))
}
pub(super) fn new(live: Arc<LiveActionServerGoal<A>>) -> Self {
Self { live }
}
}
pub enum BeginAcceptedGoal<A: Action> {
Execute(ExecutingGoal<A>),
Cancel(CancellingGoal<A>),
}