spring_ai_rs/ai_interface/callback/
other.rs

1use std::ffi::CString;
2
3use spring_ai_sys::COMMAND_TO_ID_ENGINE;
4
5use crate::ai_interface::{
6    callback::{
7        command::{
8            command_data::{
9                other::{PauseCommandData, SetLastPosMessageCommandData},
10                CommandData, EmptyCommandData,
11            },
12            command_topic::CommandTopic,
13        },
14        engine::handle_command,
15    },
16    AIInterface,
17};
18
19impl AIInterface {
20    pub fn set_last_message_position(&self, position: [f32; 3]) -> Result<(), &'static str> {
21        let mut command_data = SetLastPosMessageCommandData { position };
22
23        handle_command(
24            self.ai_id,
25            COMMAND_TO_ID_ENGINE,
26            -1,
27            CommandTopic::SetLastPOSMessage.into(),
28            &mut command_data.c_data(),
29        )
30    }
31
32    pub fn pause<S>(&self, enable: bool, reason: S) -> Result<(), &'static str>
33    where
34        S: Into<Vec<u8>>,
35    {
36        let mut command_data = PauseCommandData {
37            enable,
38            reason: CString::new(reason).unwrap(),
39        };
40
41        handle_command(
42            self.ai_id,
43            COMMAND_TO_ID_ENGINE,
44            -1,
45            CommandTopic::Pause.into(),
46            &mut command_data.c_data(),
47        )
48    }
49
50    pub fn null(&self) -> Result<(), &'static str> {
51        let mut command_data = EmptyCommandData {};
52
53        handle_command(
54            self.ai_id,
55            COMMAND_TO_ID_ENGINE,
56            -1,
57            CommandTopic::Null.into(),
58            &mut command_data.c_data(),
59        )
60    }
61
62    pub fn unused0(&self) -> Result<(), &'static str> {
63        let mut command_data = EmptyCommandData {};
64
65        handle_command(
66            self.ai_id,
67            COMMAND_TO_ID_ENGINE,
68            -1,
69            CommandTopic::Unused0.into(),
70            &mut command_data.c_data(),
71        )
72    }
73
74    pub fn unused1(&self) -> Result<(), &'static str> {
75        let mut command_data = EmptyCommandData {};
76
77        handle_command(
78            self.ai_id,
79            COMMAND_TO_ID_ENGINE,
80            -1,
81            CommandTopic::Unused1.into(),
82            &mut command_data.c_data(),
83        )
84    }
85}