ThreadController

Trait ThreadController 

Source
pub trait ThreadController {
Show 19 methods // Required methods fn discover_usb_devices(&mut self) -> Result<Vec<u32>>; fn discover_network_devices( &mut self, timeout_ms: u32, ) -> Result<Vec<NetworkDeviceSummary>>; fn start_usb_device_thread(&mut self, device_index: u32) -> Result<u32>; fn start_network_device_thread( &mut self, device_summary: NetworkDeviceSummary, ) -> Result<u32>; fn start_device_thread_by_serial( &mut self, serial_number: u32, check_network: bool, timeout_ms: u32, ) -> Result<u32>; fn send_command(&self, thread_id: u32, command: DeviceCommand) -> Result<()>; fn get_status(&self, thread_id: u32) -> Result<ThreadStatus>; fn get_state(&self, thread_id: u32) -> Result<DeviceState>; fn get_shared_state(&self, thread_id: u32) -> Result<Arc<SharedDeviceState>>; fn create_observer(&self, thread_id: u32) -> Result<StateObserver>; fn stop_all(&mut self) -> Result<()>; fn set_thread_log_level( &mut self, thread_id: u32, level: LevelFilter, ) -> Result<()>; fn set_global_log_level(&mut self, level: LevelFilter) -> Result<()>; fn start_model_monitoring( &mut self, thread_id: u32, model_dir: Option<PathBuf>, ) -> Result<()>; fn stop_model_monitoring(&mut self, thread_id: u32) -> Result<()>; fn update_device_model( &self, thread_id: u32, model: DeviceModel, ) -> Result<()>; fn list_active_threads(&self) -> Result<Vec<u32>>; fn stop_thread(&mut self, thread_id: u32) -> Result<()>; // Provided method fn is_thread_running(&self, thread_id: u32) -> Result<bool> { ... }
}
Expand description

Thread controller for managing device threads.

The thread controller is responsible for:

  • Discovering devices
  • Starting and stopping device threads
  • Sending commands to device threads
  • Retrieving device state
  • Creating state observers
  • Performing device operations

Required Methods§

Source

fn discover_usb_devices(&mut self) -> Result<Vec<u32>>

Discover USB devices connected to the system.

§Returns

A vector of device indices that can be used to connect to the devices.

§Errors

Returns an error if the device enumeration fails.

Source

fn discover_network_devices( &mut self, timeout_ms: u32, ) -> Result<Vec<NetworkDeviceSummary>>

Discover network devices on the local network.

§Parameters
  • timeout_ms - The timeout in milliseconds for the discovery process.
§Returns

A vector of network device summaries that can be used to connect to the devices.

§Errors

Returns an error if the device enumeration fails.

Source

fn start_usb_device_thread(&mut self, device_index: u32) -> Result<u32>

Start a thread for a USB device.

§Parameters
  • device_index - The index of the USB device to connect to.
§Returns

The thread ID of the newly created thread.

§Errors

Returns an error if the thread creation fails or if the device connection fails.

Source

fn start_network_device_thread( &mut self, device_summary: NetworkDeviceSummary, ) -> Result<u32>

Start a thread for a network device.

§Parameters
  • device_summary - The network device summary to connect to.
§Returns

The thread ID of the newly created thread.

§Errors

Returns an error if the thread creation fails or if the device connection fails.

Source

fn start_device_thread_by_serial( &mut self, serial_number: u32, check_network: bool, timeout_ms: u32, ) -> Result<u32>

Start a thread for a device with a specific serial number.

§Parameters
  • serial_number - The serial number of the device to connect to.
  • check_network - Whether to check for network devices.
  • timeout_ms - The timeout in milliseconds for network device discovery.
§Returns

The thread ID of the newly created thread.

§Errors

Returns an error if the thread creation fails or if the device connection fails.

Source

fn send_command(&self, thread_id: u32, command: DeviceCommand) -> Result<()>

Send a command to a device thread.

§Parameters
  • thread_id - The ID of the thread to send the command to.
  • command - The command to send.
§Errors

Returns an error if the thread is not found or if the command send fails.

Source

fn get_status(&self, thread_id: u32) -> Result<ThreadStatus>

Get the status of a device thread.

§Parameters
  • thread_id - The ID of the thread to get the status of.
§Returns

The status of the thread.

§Errors

Returns an error if the thread is not found.

Source

fn get_state(&self, thread_id: u32) -> Result<DeviceState>

Get the state of a device thread.

§Parameters
  • thread_id - The ID of the thread to get the state of.
§Returns

The state of the device.

§Errors

Returns an error if the thread is not found.

Source

fn get_shared_state(&self, thread_id: u32) -> Result<Arc<SharedDeviceState>>

Get the shared state of a device thread.

§Parameters
  • thread_id - The ID of the thread to get the shared state of.
§Returns

The shared state of the device.

§Errors

Returns an error if the thread is not found.

Source

fn create_observer(&self, thread_id: u32) -> Result<StateObserver>

Create a state observer for a device thread.

§Parameters
  • thread_id - The ID of the thread to create an observer for.
§Returns

A state observer for the thread.

§Errors

Returns an error if the thread is not found.

Source

fn stop_all(&mut self) -> Result<()>

Stop all device threads.

§Errors

Returns an error if any thread fails to stop.

Source

fn set_thread_log_level( &mut self, thread_id: u32, level: LevelFilter, ) -> Result<()>

Set the log level for a specific thread.

§Parameters
  • thread_id - The ID of the thread to set the log level for.
  • level - The log level to set.
§Errors

Returns an error if the thread is not found or if the log level set fails.

Source

fn set_global_log_level(&mut self, level: LevelFilter) -> Result<()>

Set the log level for all threads and the controller.

§Parameters
  • level - The log level to set.
§Errors

Returns an error if any thread fails to set the log level.

Source

fn start_model_monitoring( &mut self, thread_id: u32, model_dir: Option<PathBuf>, ) -> Result<()>

Start model monitoring for a device thread.

This method starts monitoring the device model file for changes and updates the device model when changes are detected.

§Parameters
  • thread_id - The ID of the thread to monitor.
  • model_dir - Optional custom directory for model files.
§Errors

Returns an error if the thread is not found or if monitoring fails to start.

Source

fn stop_model_monitoring(&mut self, thread_id: u32) -> Result<()>

Stop model monitoring for a device thread.

§Parameters
  • thread_id - The ID of the thread to stop monitoring.
§Errors

Returns an error if the thread is not found or if monitoring fails to stop.

Source

fn update_device_model(&self, thread_id: u32, model: DeviceModel) -> Result<()>

Update the device model for a thread.

§Parameters
  • thread_id - The ID of the thread to update.
  • model - The new device model.
§Errors

Returns an error if the thread is not found or if the model update fails.

Source

fn list_active_threads(&self) -> Result<Vec<u32>>

Get a list of all active thread IDs.

§Returns

A vector of thread IDs that are currently active.

Source

fn stop_thread(&mut self, thread_id: u32) -> Result<()>

Stop a specific thread.

§Parameters
  • thread_id - The ID of the thread to stop.
§Errors

Returns an error if the thread is not found or fails to stop.

Provided Methods§

Source

fn is_thread_running(&self, thread_id: u32) -> Result<bool>

Check if a thread is currently running.

§Parameters
  • thread_id - The ID of the thread to check.
§Returns

True if the thread is running, false otherwise.

§Errors

Returns an error if the thread is not found.

Implementors§