action_core/client_server/
server.rs1use std::collections::VecDeque;
2use std::marker::PhantomData;
3
4use core_types::ActionGoalId;
5
6use crate::message::ActionSchema;
7
8use super::ActionChannel;
9
10mod trait_impl;
11
12pub struct BasicActionServer<G, F, R> {
13 action_name: String,
14 schema: ActionSchema,
15 closed: bool,
16 channel: Option<std::sync::Arc<ActionChannel<G, F, R>>>,
17 injected: VecDeque<(ActionGoalId, G)>,
19 _marker: PhantomData<(G, F, R)>,
20}
21
22impl<G, F, R> BasicActionServer<G, F, R> {
23 pub fn new(action_name: impl Into<String>, schema: ActionSchema) -> Self {
24 Self {
25 action_name: action_name.into(),
26 schema,
27 closed: false,
28 channel: None,
29 injected: VecDeque::new(),
30 _marker: PhantomData,
31 }
32 }
33
34 pub fn with_channel(
35 action_name: impl Into<String>,
36 schema: ActionSchema,
37 channel: std::sync::Arc<ActionChannel<G, F, R>>,
38 ) -> Self {
39 Self {
40 action_name: action_name.into(),
41 schema,
42 closed: false,
43 channel: Some(channel),
44 injected: VecDeque::new(),
45 _marker: PhantomData,
46 }
47 }
48
49 pub fn inject_goal(&mut self, goal_id: ActionGoalId, goal: G) {
51 self.injected.push_back((goal_id, goal));
52 }
53}