use std::marker::PhantomData;
use rustdds::*;
use serde::{Deserialize, Serialize};
pub use action_msgs::{CancelGoalRequest, CancelGoalResponse, GoalId, GoalInfo, GoalStatusEnum};
#[allow(unused_imports)]
use log::{debug, error, info, warn};
use crate::{action_msgs, builtin_interfaces, message::Message};
mod client;
#[doc(inline)]
pub use client::ActionClient;
mod server;
#[doc(inline)]
pub use server::{
AcceptedGoalHandle, ActionServer, AsyncActionServer, CancelHandle, ExecutingGoalHandle,
GoalEndStatus, GoalError, NewGoalHandle,
};
pub trait ActionTypes {
type GoalType: Message + Clone; type ResultType: Message + Clone; type FeedbackType: Message;
fn goal_type_name(&self) -> &str;
fn result_type_name(&self) -> &str;
fn feedback_type_name(&self) -> &str;
}
pub struct Action<G, R, F> {
g: PhantomData<G>,
r: PhantomData<R>,
f: PhantomData<F>,
goal_typename: String,
result_typename: String,
feedback_typename: String,
}
impl<G, R, F> Action<G, R, F>
where
G: Message + Clone,
R: Message + Clone,
F: Message,
{
pub fn new(goal_typename: String, result_typename: String, feedback_typename: String) -> Self {
Self {
goal_typename,
result_typename,
feedback_typename,
g: PhantomData,
r: PhantomData,
f: PhantomData,
}
}
}
impl<G, R, F> ActionTypes for Action<G, R, F>
where
G: Message + Clone,
R: Message + Clone,
F: Message,
{
type GoalType = G;
type ResultType = R;
type FeedbackType = F;
fn goal_type_name(&self) -> &str {
&self.goal_typename
}
fn result_type_name(&self) -> &str {
&self.result_typename
}
fn feedback_type_name(&self) -> &str {
&self.feedback_typename
}
}
pub struct ActionClientQosPolicies {
pub goal_service: QosPolicies,
pub result_service: QosPolicies,
pub cancel_service: QosPolicies,
pub feedback_subscription: QosPolicies,
pub status_subscription: QosPolicies,
}
pub struct ActionServerQosPolicies {
pub goal_service: QosPolicies,
pub result_service: QosPolicies,
pub cancel_service: QosPolicies,
pub feedback_publisher: QosPolicies,
pub status_publisher: QosPolicies,
}
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct SendGoalRequest<G> {
pub goal_id: GoalId,
pub goal: G,
}
impl<G: Message> Message for SendGoalRequest<G> {}
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct SendGoalResponse {
pub accepted: bool,
pub stamp: builtin_interfaces::Time,
}
impl Message for SendGoalResponse {}
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct GetResultRequest {
pub goal_id: GoalId,
}
impl Message for GetResultRequest {}
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct GetResultResponse<R> {
pub status: GoalStatusEnum, pub result: R,
}
impl<R: Message> Message for GetResultResponse<R> {}
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct FeedbackMessage<F> {
pub goal_id: GoalId,
pub feedback: F,
}
impl<F: Message> Message for FeedbackMessage<F> {}