Struct Daemon
struct Daemon<'a> {
hosts: Vec<String>,
username: Option<String>,
port: Option<u16>,
config: &'a DaemonConfig,
clusters: &'a [Cluster],
control_mode_state: ControlModeState,
debug: bool,
}Expand description
The daemon is responsible to launch a client for each host, positioning the client windows, forwarding input records to all clients and handling control mode.
Fields§
§hosts: Vec<String>A list of hostnames to connect to.
username: Option<String>A username to use to connect to all clients.
If it is empty the clients will use the SSH config to find an approriate username.
port: Option<u16>Optional port used for all SSH connections.
config: &'a DaemonConfigThe DaemonConfig that controls how the daemon console window looks like.
clusters: &'a [Cluster]List of available cluster tags
control_mode_state: ControlModeStateThe current control mode state.
debug: boolIf debug mode is enabled on the daemon it will also be enabled on all clients.
Implementations§
§impl<'a> Daemon<'a>
impl<'a> Daemon<'a>
async fn launch<W: WindowsApi + Clone + 'static>(self, windows_api: &W)
async fn launch<W: WindowsApi + Clone + 'static>(self, windows_api: &W)
Launches all client windows and blocks on the main run loop.
Sets up the daemon console by disabling processed input mode and applying the configured colors and dimensions. Once all client windows have successfully started the daemon console window is moved to the foreground and receives focus.
async fn run<W: WindowsApi + Clone + 'static>(
&mut self,
windows_api: &W,
clients: &mut Arc<Mutex<Vec<Client>>>,
workspace_area: &WorkspaceArea,
)
async fn run<W: WindowsApi + Clone + 'static>( &mut self, windows_api: &W, clients: &mut Arc<Mutex<Vec<Client>>>, workspace_area: &WorkspaceArea, )
The main run loop of the daemon subcommand.
Opens a multi-producer, multi-consumer broadcasting channel used to send the read input records in parallel to the name pipe servers the clients are listening on. Spawns a background thread that waits for all clients to terminate and then stops the current process. Spawns a background thread that ensures the z-order of all client windows is in sync with the daemon window. I.e. if the daemon window is focussed, all clients should be moved to the foreground.
The main loop consists of waiting for input records to read from the keyboard, sending them to all clients and handling control mode.
§Arguments
windows_api- The Windows API implementation to useclients- A thread safe mapping from the number a client console window was launched at in relation to the other client windows and the clients console window handle.workspace_area- The available workspace area on the primary monitor minus the space occupied by the daemon console window.
fn launch_named_pipe_servers(
&self,
sender: &Sender<[u8; 13]>,
) -> Vec<JoinHandle<()>>
fn launch_named_pipe_servers( &self, sender: &Sender<[u8; 13]>, ) -> Vec<JoinHandle<()>>
fn launch_named_pipe_server(
&self,
servers: &mut Vec<JoinHandle<()>>,
sender: &Sender<[u8; 13]>,
)
fn launch_named_pipe_server( &self, servers: &mut Vec<JoinHandle<()>>, sender: &Sender<[u8; 13]>, )
Launch a named pipe server in a dedicated thread.
§Arguments
servers- A list of [JoinHandle]s to which the join handle for the new thread will be added.sender- The sender end of the broadcast channel through which the main thread will send the input records that are to be forwarded to the clients.
async fn handle_input_record<W: WindowsApi + Clone + 'static>(
&mut self,
windows_api: &W,
sender: &Sender<[u8; 13]>,
input_record: INPUT_RECORD_0,
clients: &mut Arc<Mutex<Vec<Client>>>,
workspace_area: &WorkspaceArea,
servers: &mut Arc<Mutex<Vec<JoinHandle<()>>>>,
)
async fn handle_input_record<W: WindowsApi + Clone + 'static>( &mut self, windows_api: &W, sender: &Sender<[u8; 13]>, input_record: INPUT_RECORD_0, clients: &mut Arc<Mutex<Vec<Client>>>, workspace_area: &WorkspaceArea, servers: &mut Arc<Mutex<Vec<JoinHandle<()>>>>, )
Handle the given input record.
Input records are being forwarded to all clients. If a sequence of input records matches the control mode key combination, forwarding is temporarily interrupted, until control mode is exited.
§Arguments
sender- The sender end of the broadcast channel through which we will send the input records that are being forwarded to the clients by the named pipe servers (servers).input_record- The [INPUT_RECORD_0].KeyEventread from the console input buffer.clients- A thread safe mapping from the number a client console window was launched at in relation to the other client windows and the clients console window handle. The mapping will be extended if additional clients are being added through control mode[c]reate window(s).workspace_area- The available workspace area on the primary monitor minus the space occupied by the daemon console window.servers- A thread safe list of [JoinHandle]s, one handle for each named pipe server background thread. The list will be extended if additional clients are being added through control mode[c]reate window(s).
fn control_mode_is_active<W: WindowsApi>(
&mut self,
windows_api: &W,
input_record: INPUT_RECORD_0,
) -> bool
fn control_mode_is_active<W: WindowsApi>( &mut self, windows_api: &W, input_record: INPUT_RECORD_0, ) -> bool
Returns whether control mode is active or not given the input_record.
For control mode to be active this function needs to be called
multiple times, as a key press translates to an input record and
the key combination that activates control mode has 2 keys:
Ctrl + A.
The current control mode state is stored in self.control_mode_state.
§Arguments
windows_api- The Windows API implementation to useinput_record- A KeyEvent input record.
§Returns
Whether or not control mode is active.
fn quit_control_mode<W: WindowsApi>(&mut self, windows_api: &W)
fn quit_control_mode<W: WindowsApi>(&mut self, windows_api: &W)
Prints the default daemon instructions to the daemon console and
sets self.control_mode_state to inactive.
fn print_instructions<W: WindowsApi>(&self, windows_api: &W)
fn print_instructions<W: WindowsApi>(&self, windows_api: &W)
Clears the console screen and prints the default daemon instructions.
fn rearrange_client_windows<W: WindowsApi>(
&self,
windows_api: &W,
clients: &[Client],
workspace_area: &WorkspaceArea,
)
fn rearrange_client_windows<W: WindowsApi>( &self, windows_api: &W, clients: &[Client], workspace_area: &WorkspaceArea, )
Iterates over all still open client windows and re-arranges them on the screen based on the aspect ration adjustment daemon configuration.
Client windows will be re-sized and re-positioned.
§Arguments
windows_api- The Windows API implementation to useclients- A thread safe mapping from the number a client console window was launched at in relation to the other client windows and the clients console window handle. The number is relevant to determine the position on the screen the window should be placed at.workspace_area- The available workspace area on the primary monitor minus the space occupied by the daemon console window.
fn arrange_daemon_console<W: WindowsApi>(
&self,
windows_api: &W,
workspace_area: &WorkspaceArea,
)
fn arrange_daemon_console<W: WindowsApi>( &self, windows_api: &W, workspace_area: &WorkspaceArea, )
Re-sizes and re-positions the daemon console window on the screen based on the daemon height configuration.
§Arguments
windows_api- The Windows API implementation to useworkspace_area- The available workspace area on the primary monitor minus the space occupied by the daemon console window.