rmux_client/commands/
server.rs1use std::path::Path;
2
3use rmux_proto::{
4 KillServerRequest, LockClientRequest, LockServerRequest, LockSessionRequest, Request, Response,
5 ServerAccessRequest, SessionName,
6};
7
8use crate::{
9 auto_start::{ensure_server_running_with_config, AutoStartConfig, AutoStartError},
10 connection::{connect, Connection},
11 ClientError,
12};
13
14impl Connection {
15 pub fn start_server(
17 socket_path: &Path,
18 no_start_server: bool,
19 config: AutoStartConfig,
20 ) -> Result<Self, StartServerError> {
21 if no_start_server {
22 return connect(socket_path).map_err(StartServerError::Client);
23 }
24
25 ensure_server_running_with_config(socket_path, config).map_err(StartServerError::AutoStart)
26 }
27
28 pub fn kill_server(&mut self) -> Result<Response, ClientError> {
30 self.roundtrip(&Request::KillServer(KillServerRequest))
31 }
32
33 pub fn lock_server(&mut self) -> Result<Response, ClientError> {
35 self.roundtrip(&Request::LockServer(LockServerRequest))
36 }
37
38 pub fn lock_session(&mut self, target: SessionName) -> Result<Response, ClientError> {
40 self.roundtrip(&Request::LockSession(LockSessionRequest { target }))
41 }
42
43 pub fn lock_client(&mut self, target_client: String) -> Result<Response, ClientError> {
45 self.roundtrip(&Request::LockClient(LockClientRequest { target_client }))
46 }
47
48 pub fn server_access(&mut self, request: ServerAccessRequest) -> Result<Response, ClientError> {
50 self.roundtrip(&Request::ServerAccess(request))
51 }
52}
53
54#[derive(Debug)]
56pub enum StartServerError {
57 Client(ClientError),
59 AutoStart(AutoStartError),
61}