Disconnects the server from a client, if it is connected.
(&self)
| 205 | |
| 206 | /// Disconnects the server from a client, if it is connected. |
| 207 | pub fn disconnect(&self) -> BoxFuture<'_, Result<(), message::ErrorV0>> { |
| 208 | debug!("Buttplug Server {} disconnect requested", self.server_name); |
| 209 | let ping_timer = self.ping_timer.clone(); |
| 210 | // As long as StopScanning/StopAllDevices aren't changed across message specs, we can inject |
| 211 | // them using parse_checked_message and bypass version checking. |
| 212 | let stop_scanning_fut = self.parse_checked_message( |
| 213 | ButtplugCheckedClientMessageV4::StopScanning(StopScanningV0::default()), |
| 214 | ); |
| 215 | let stop_fut = |
| 216 | self.parse_checked_message(ButtplugCheckedClientMessageV4::StopCmd(StopCmdV4::default())); |
| 217 | let state = self.state.clone(); |
| 218 | async move { |
| 219 | { |
| 220 | let mut state_guard = state.write().expect("State lock poisoned"); |
| 221 | *state_guard = ConnectionState::Disconnected; |
| 222 | } |
| 223 | ping_timer.stop_ping_timer().await; |
| 224 | // Ignore returns here, we just want to stop. |
| 225 | info!("Server disconnected, stopping device scanning if it was started..."); |
| 226 | let _ = stop_scanning_fut.await; |
| 227 | info!("Server disconnected, stopping all devices..."); |
| 228 | let _ = stop_fut.await; |
| 229 | Ok(()) |
| 230 | } |
| 231 | .boxed() |
| 232 | } |
| 233 | |
| 234 | pub fn shutdown(&self) -> ButtplugServerResultFuture { |
| 235 | let device_manager = self.device_manager.clone(); |
nothing calls this directly
no test coverage detected