Skip to main content

over_there/core/msg/content/reply/
mod.rs

1mod batch;
2mod capabilities;
3mod custom;
4mod forward;
5mod generic_error;
6mod internal_debug;
7mod io;
8mod sequence;
9mod version;
10
11pub use batch::*;
12pub use capabilities::*;
13pub use custom::*;
14pub use forward::*;
15pub use generic_error::*;
16pub use internal_debug::*;
17pub use io::*;
18pub use sequence::*;
19pub use version::*;
20
21use schemars::JsonSchema;
22use serde::{Deserialize, Serialize};
23
24// NOTE: Cannot adjacently tag as JsonSchema does not support it and
25//       it leads to deserialization errors with enum variants without
26//       any real arguments (empty struct doesn't fix)
27#[derive(JsonSchema, Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
28// #[serde(tag = "type")]
29#[serde(tag = "type", content = "payload")]
30pub enum Reply {
31    /// Used when we want to NOT send a reply at all
32    #[serde(skip)]
33    Ignore,
34
35    // ------------------------------------------------------------------------
36    // Heartbeats are used to ensure remote instances are alive
37    #[serde(rename = "heartbeat_reply")]
38    #[allow(dead_code)]
39    Heartbeat,
40
41    // ------------------------------------------------------------------------
42    // Version information to ensure that we don't have
43    // conflicting functionality
44    #[serde(rename = "version_reply")]
45    Version(VersionArgs),
46
47    // ------------------------------------------------------------------------
48    // Capability information to convey what is available remotely, which
49    // can differ based on enabled features at compile time
50    #[serde(rename = "capabilities_reply")]
51    Capabilities(CapabilitiesArgs),
52
53    // ------------------------------------------------------------------------
54    // Dir-based operations such as creating and listing entries
55    /// This will be returned upon creating a directory
56    #[serde(rename = "create_dir_reply")]
57    DirCreated(DirCreatedArgs),
58
59    /// This will be returned upon renaming a directory
60    #[serde(rename = "rename_dir_reply")]
61    DirRenamed(DirRenamedArgs),
62
63    /// This will be returned upon removing a directory
64    #[serde(rename = "remove_dir_reply")]
65    DirRemoved(DirRemovedArgs),
66
67    /// This will be returned upon collecting the list of files and directories
68    /// at the provided path
69    #[serde(rename = "list_dir_contents_reply")]
70    DirContentsList(DirContentsListArgs),
71
72    // ------------------------------------------------------------------------
73    // File-based operations such as reading and writing
74    /// This will be returned upon a file being opened or refreshed
75    #[serde(rename = "open_file_reply")]
76    FileOpened(FileOpenedArgs),
77
78    /// This will be returned upon a file being closed
79    #[serde(rename = "close_file_reply")]
80    FileClosed(FileClosedArgs),
81
82    /// This will be returned upon renaming a file
83    #[serde(rename = "rename_unopened_file_reply")]
84    UnopenedFileRenamed(UnopenedFileRenamedArgs),
85
86    /// This will be returned upon renaming an open file
87    #[serde(rename = "rename_file_reply")]
88    FileRenamed(FileRenamedArgs),
89
90    /// This will be returned upon removing a file
91    #[serde(rename = "remove_unopened_file_reply")]
92    UnopenedFileRemoved(UnopenedFileRemovedArgs),
93
94    /// This will be returned upon removing an open file
95    #[serde(rename = "remove_file_reply")]
96    FileRemoved(FileRemovedArgs),
97
98    /// This will be returned upon reading a file's contents
99    #[serde(rename = "read_file_reply")]
100    FileContents(FileContentsArgs),
101
102    /// This will be returned upon writing a file's contents
103    /// Contains the updated signature for the file
104    #[serde(rename = "write_file_reply")]
105    FileWritten(FileWrittenArgs),
106
107    // ------------------------------------------------------------------------
108    // Program execution operations such as running and streaming
109    /// This will be returned upon starting a process on the server, indicating
110    /// success and providing an id for sending stdin and receiving stdout/stderr
111    #[serde(rename = "exec_proc_reply")]
112    ProcStarted(ProcStartedArgs),
113
114    /// This will be returned upon successfully writing to stdin
115    #[serde(rename = "write_proc_stdin_reply")]
116    ProcStdinWritten(ProcStdinWrittenArgs),
117
118    /// This will be returned upon receiving stdout from a remote process on
119    /// the server, if enabled when first executing
120    #[serde(rename = "read_proc_stdout_reply")]
121    ProcStdoutContents(ProcStdoutContentsArgs),
122
123    /// This will be returned upon receiving stderr from a remote process on
124    /// the server, if enabled when first executing
125    #[serde(rename = "read_proc_stderr_reply")]
126    ProcStderrContents(ProcStderrContentsArgs),
127
128    /// This will be returned upon attempting to kill a process
129    #[serde(rename = "kill_proc_reply")]
130    ProcKilled(ProcKilledArgs),
131
132    /// This will be returned reporting the status of the process, indicating
133    /// if still running or if has completed (and the exit code)
134    #[serde(rename = "read_proc_status_reply")]
135    ProcStatus(ProcStatusArgs),
136
137    // ------------------------------------------------------------------------
138    // Miscellaneous, adhoc messages
139    /// This will be returned upon encountering an error during evaluation
140    #[serde(rename = "error_reply")]
141    Error(ReplyError),
142
143    /// This will be returned upon successfully evaluating a sequence of operations
144    #[serde(rename = "sequence_reply")]
145    Sequence(SequenceArgs),
146
147    /// This will be returned upon successfully evaluating a batch of operations in parallel
148    #[serde(rename = "batch_reply")]
149    Batch(BatchArgs),
150
151    /// This will be sent to either the client or server and the msg will be
152    /// passed along to the associated address (if possible)
153    #[serde(rename = "forward_reply")]
154    Forward(ForwardArgs),
155
156    /// This will be sent in either direction to provide a custom content
157    /// that would be evaluated through user-implemented handlers
158    #[serde(rename = "custom_reply")]
159    Custom(CustomArgs),
160
161    /// For debugging purposes when needing to query the state of client/server
162    #[serde(rename = "internal_debug_reply")]
163    InternalDebug(InternalDebugArgs),
164}
165
166impl crate::core::SchemaInfo for Reply {}
167
168impl From<std::io::Error> for Reply {
169    fn from(x: std::io::Error) -> Self {
170        Self::Error(ReplyError::from(x))
171    }
172}
173
174impl From<Box<dyn std::error::Error>> for Reply {
175    fn from(x: Box<dyn std::error::Error>) -> Self {
176        Self::Error(ReplyError::from(x))
177    }
178}
179
180#[derive(JsonSchema, Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
181#[serde(tag = "type")]
182pub enum ReplyError {
183    #[serde(rename = "generic_error")]
184    Generic(GenericErrorArgs),
185
186    #[serde(rename = "io_error")]
187    Io(IoErrorArgs),
188
189    #[serde(rename = "file_sig_changed_error")]
190    FileSigChanged(FileSigChangedArgs),
191}
192
193impl crate::core::SchemaInfo for ReplyError {}
194
195impl ToString for ReplyError {
196    fn to_string(&self) -> String {
197        match self {
198            Self::Generic(args) => args.to_string(),
199            Self::Io(args) => args.to_string(),
200            Self::FileSigChanged(args) => args.to_string(),
201        }
202    }
203}
204
205impl From<String> for ReplyError {
206    fn from(text: String) -> Self {
207        Self::Generic(GenericErrorArgs::from(text))
208    }
209}
210
211impl From<&str> for ReplyError {
212    fn from(text: &str) -> Self {
213        Self::from(String::from(text))
214    }
215}
216
217impl From<Box<dyn std::error::Error>> for ReplyError {
218    fn from(x: Box<dyn std::error::Error>) -> Self {
219        Self::Generic(GenericErrorArgs::from(x))
220    }
221}
222
223impl From<std::io::Error> for ReplyError {
224    fn from(x: std::io::Error) -> Self {
225        Self::Io(IoErrorArgs::from(x))
226    }
227}