robotrt-action-core 0.1.0-beta.1

RobotRT modular robotics runtime and middleware components.
Documentation
use std::collections::VecDeque;
use std::marker::PhantomData;

use core_types::ActionGoalId;

use crate::message::ActionSchema;

use super::ActionChannel;

mod trait_impl;

pub struct BasicActionServer<G, F, R> {
    action_name: String,
    schema: ActionSchema,
    closed: bool,
    channel: Option<std::sync::Arc<ActionChannel<G, F, R>>>,
    /// Goal injection queue for standalone mode (test helper).
    injected: VecDeque<(ActionGoalId, G)>,
    _marker: PhantomData<(G, F, R)>,
}

impl<G, F, R> BasicActionServer<G, F, R> {
    pub fn new(action_name: impl Into<String>, schema: ActionSchema) -> Self {
        Self {
            action_name: action_name.into(),
            schema,
            closed: false,
            channel: None,
            injected: VecDeque::new(),
            _marker: PhantomData,
        }
    }

    pub fn with_channel(
        action_name: impl Into<String>,
        schema: ActionSchema,
        channel: std::sync::Arc<ActionChannel<G, F, R>>,
    ) -> Self {
        Self {
            action_name: action_name.into(),
            schema,
            closed: false,
            channel: Some(channel),
            injected: VecDeque::new(),
            _marker: PhantomData,
        }
    }

    /// Test helper: inject a goal directly without going through the channel (standalone mode).
    pub fn inject_goal(&mut self, goal_id: ActionGoalId, goal: G) {
        self.injected.push_back((goal_id, goal));
    }
}