pub struct Request { /* private fields */ }Expand description
Represents a request client that manages socket-based connections and interacts with the server.
§Thread Safety
Request is Send but not Sync. This means you can move a Request
to another thread, but you cannot share it between threads by reference.
The Req/Rep protocol requires strict send→receive ordering, which cannot
be guaranteed with concurrent callers.
Each thread that needs concurrent server access should create its own
Request instance, or protect shared access with a Mutex<Request>.
Implementations§
Source§impl Request
impl Request
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new Request instance.
No socket is opened until connect() is called.
Sourcepub fn connect(
&mut self,
url: &str,
connection_options: ConnectionOptions,
) -> Result<()>
pub fn connect( &mut self, url: &str, connection_options: ConnectionOptions, ) -> Result<()>
Establishes a connection to a specified server URL using the given configuration options.
Opens a REQ socket and connects to the server.
§Arguments:
url- The server’s address (e.g., “wss://127.0.0.1:5568”).connection_options- The connection settings, including TLS certificate and timeouts.
§Errors:
Returns MotorcortexError::Connection if the socket cannot be opened or the connection fails.
Sourcepub fn disconnect(&mut self) -> Result<()>
pub fn disconnect(&mut self) -> Result<()>
Disconnects the current connection and frees the associated resources.
§Errors:
Returns MotorcortexError::Connection if the disconnection fails.
Sourcepub fn login(&self, username: String, password: String) -> Result<StatusCode>
pub fn login(&self, username: String, password: String) -> Result<StatusCode>
Sends a login message to the server with the specified username and password.
§Arguments:
username- The username to authenticate with.password- The password for authentication.
§Returns:
Ok(StatusCode)- The status code representing the login response.
§Errors:
Returns MotorcortexError::Encode, MotorcortexError::Io, or MotorcortexError::Decode.
Sourcepub fn logout(&self) -> Result<StatusCode>
pub fn logout(&self) -> Result<StatusCode>
Sourcepub fn request_parameter_tree(&mut self) -> Result<StatusCode>
pub fn request_parameter_tree(&mut self) -> Result<StatusCode>
Sourcepub fn set_parameter<V>(&self, path: &str, value: V) -> Result<StatusCode>
pub fn set_parameter<V>(&self, path: &str, value: V) -> Result<StatusCode>
Updates a specific parameter on the server with the provided value.
§Arguments:
path- The hierarchical path to the parameter being updated.value- The new value for the parameter. Must implementSetParameterValue.
§Returns:
Ok(StatusCode)- The status code after setting the parameter.
§Errors:
Returns MotorcortexError::ParameterNotFound if the path doesn’t exist in the tree.
Returns MotorcortexError::Encode, MotorcortexError::Io, or MotorcortexError::Decode
for communication failures.
Sourcepub fn set_parameters<T>(
&self,
paths: Vec<&str>,
values: T,
) -> Result<StatusCode>where
T: SetParameterTuple,
pub fn set_parameters<T>(
&self,
paths: Vec<&str>,
values: T,
) -> Result<StatusCode>where
T: SetParameterTuple,
Sourcepub fn get_parameter<V>(&self, path: &str) -> Result<V>where
V: GetParameterValue + Default,
pub fn get_parameter<V>(&self, path: &str) -> Result<V>where
V: GetParameterValue + Default,
Retrieves the value of a parameter from the server for the given path.
§Arguments:
path- The hierarchical path of the parameter to retrieve.
§Type Parameters:
V- The expected value type. The server value is automatically converted.
§Errors:
Returns MotorcortexError::ParameterNotFound if the path doesn’t exist in the tree.
Returns MotorcortexError::Encode, MotorcortexError::Io, or MotorcortexError::Decode
for communication failures.
Sourcepub fn get_parameters<T>(&self, paths: Vec<&str>) -> Result<T>where
T: GetParameterTuple,
pub fn get_parameters<T>(&self, paths: Vec<&str>) -> Result<T>where
T: GetParameterTuple,
Sourcepub fn get_parameter_tree(&self) -> Result<(StatusCode, ParameterTree)>
pub fn get_parameter_tree(&self) -> Result<(StatusCode, ParameterTree)>
Sourcepub fn get_parameter_tree_hash(&self) -> Result<u32>
pub fn get_parameter_tree_hash(&self) -> Result<u32>
Retrieves the hash of the server’s parameter tree for change detection.
Sourcepub fn create_group<I>(
&self,
parameters: I,
group_name: &str,
frequency_divider: u32,
) -> Result<GroupStatusMsg>where
I: Parameters,
pub fn create_group<I>(
&self,
parameters: I,
group_name: &str,
frequency_divider: u32,
) -> Result<GroupStatusMsg>where
I: Parameters,
Creates a subscription group on the server.
§Arguments:
parameters- The parameter paths to include in the group.group_name- An alias for the group.frequency_divider- Update rate divider relative to the server’s base frequency.
Sourcepub fn remove_group(&self, group_name: &str) -> Result<StatusCode>
pub fn remove_group(&self, group_name: &str) -> Result<StatusCode>
Removes a subscription group from the server.
§Arguments:
group_name- The alias of the group to remove.