netxserver/server/
controller.rs

1use crate::async_token::NetxToken;
2use crate::result::RetResult;
3use anyhow::Result;
4use data_rw::DataOwnedReader;
5use std::sync::Arc;
6
7/// Trait representing a controller that can handle calls.
8pub trait IController: Send + Sync {
9    /// Handles a call with the given parameters.
10    ///
11    /// # Parameters
12    /// - `tt`: A `u8` representing the type.
13    /// - `cmd_tag`: An `i32` representing the command tag.
14    /// - `dr`: A `DataOwnedReader` instance.
15    ///
16    /// # Returns
17    /// A future that resolves to a `Result` containing a `RetResult`.
18    fn call(
19        &self,
20        tt: u8,
21        cmd_tag: i32,
22        dr: DataOwnedReader,
23    ) -> impl std::future::Future<Output = Result<RetResult>> + Send;
24}
25
26/// Trait for creating controllers.
27pub trait ICreateController {
28    type Controller: IController;
29
30    /// Creates a new controller.
31    ///
32    /// # Parameters
33    /// - `token`: A `NetxToken` for the controller.
34    ///
35    /// # Returns
36    /// A `Result` containing an `Arc` to the created controller.
37    fn create_controller(
38        &self,
39        token: NetxToken<Self::Controller>,
40    ) -> Result<Arc<Self::Controller>>;
41}