mirror of
https://github.com/feschber/lan-mouse.git
synced 2026-03-23 05:00:52 +03:00
cleanup capture task (#177)
* cleanup capture task
* rename {Capture,Emulation}Event to %Request
This commit is contained in:
committed by
GitHub
parent
266ad28c6b
commit
fe06ca1fae
@@ -1,5 +1,5 @@
|
||||
use capture_task::CaptureEvent;
|
||||
use emulation_task::EmulationEvent;
|
||||
use capture_task::CaptureRequest;
|
||||
use emulation_task::EmulationRequest;
|
||||
use log;
|
||||
use std::{
|
||||
cell::{Cell, RefCell},
|
||||
@@ -253,7 +253,7 @@ impl Server {
|
||||
self.notifies.capture.notify_waiters()
|
||||
}
|
||||
|
||||
async fn capture_notified(&self) {
|
||||
async fn capture_enabled(&self) {
|
||||
self.notifies.capture.notified().await
|
||||
}
|
||||
|
||||
@@ -306,8 +306,8 @@ impl Server {
|
||||
|
||||
async fn handle_request(
|
||||
&self,
|
||||
capture: &Sender<CaptureEvent>,
|
||||
emulate: &Sender<EmulationEvent>,
|
||||
capture: &Sender<CaptureRequest>,
|
||||
emulate: &Sender<EmulationRequest>,
|
||||
event: FrontendRequest,
|
||||
) -> bool {
|
||||
log::debug!("frontend: {event:?}");
|
||||
@@ -372,8 +372,8 @@ impl Server {
|
||||
|
||||
async fn deactivate_client(
|
||||
&self,
|
||||
capture: &Sender<CaptureEvent>,
|
||||
emulate: &Sender<EmulationEvent>,
|
||||
capture: &Sender<CaptureRequest>,
|
||||
emulate: &Sender<EmulationRequest>,
|
||||
handle: ClientHandle,
|
||||
) {
|
||||
log::debug!("deactivating client {handle}");
|
||||
@@ -382,15 +382,15 @@ impl Server {
|
||||
None => return,
|
||||
};
|
||||
|
||||
let _ = capture.send(CaptureEvent::Destroy(handle)).await;
|
||||
let _ = emulate.send(EmulationEvent::Destroy(handle)).await;
|
||||
let _ = capture.send(CaptureRequest::Destroy(handle)).await;
|
||||
let _ = emulate.send(EmulationRequest::Destroy(handle)).await;
|
||||
log::debug!("deactivating client {handle} done");
|
||||
}
|
||||
|
||||
async fn activate_client(
|
||||
&self,
|
||||
capture: &Sender<CaptureEvent>,
|
||||
emulate: &Sender<EmulationEvent>,
|
||||
capture: &Sender<CaptureRequest>,
|
||||
emulate: &Sender<EmulationRequest>,
|
||||
handle: ClientHandle,
|
||||
) {
|
||||
log::debug!("activating client");
|
||||
@@ -415,15 +415,17 @@ impl Server {
|
||||
};
|
||||
|
||||
/* notify emulation, capture and frontends */
|
||||
let _ = capture.send(CaptureEvent::Create(handle, pos.into())).await;
|
||||
let _ = emulate.send(EmulationEvent::Create(handle)).await;
|
||||
let _ = capture
|
||||
.send(CaptureRequest::Create(handle, pos.into()))
|
||||
.await;
|
||||
let _ = emulate.send(EmulationRequest::Create(handle)).await;
|
||||
log::debug!("activating client {handle} done");
|
||||
}
|
||||
|
||||
async fn remove_client(
|
||||
&self,
|
||||
capture: &Sender<CaptureEvent>,
|
||||
emulate: &Sender<EmulationEvent>,
|
||||
capture: &Sender<CaptureRequest>,
|
||||
emulate: &Sender<EmulationRequest>,
|
||||
handle: ClientHandle,
|
||||
) {
|
||||
let Some(active) = self
|
||||
@@ -436,8 +438,8 @@ impl Server {
|
||||
};
|
||||
|
||||
if active {
|
||||
let _ = capture.send(CaptureEvent::Destroy(handle)).await;
|
||||
let _ = emulate.send(EmulationEvent::Destroy(handle)).await;
|
||||
let _ = capture.send(CaptureRequest::Destroy(handle)).await;
|
||||
let _ = emulate.send(EmulationRequest::Destroy(handle)).await;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -502,8 +504,8 @@ impl Server {
|
||||
async fn update_pos(
|
||||
&self,
|
||||
handle: ClientHandle,
|
||||
capture: &Sender<CaptureEvent>,
|
||||
emulate: &Sender<EmulationEvent>,
|
||||
capture: &Sender<CaptureRequest>,
|
||||
emulate: &Sender<EmulationRequest>,
|
||||
pos: Position,
|
||||
) {
|
||||
let (changed, active) = {
|
||||
@@ -520,11 +522,13 @@ impl Server {
|
||||
// update state in event input emulator & input capture
|
||||
if changed {
|
||||
if active {
|
||||
let _ = capture.send(CaptureEvent::Destroy(handle)).await;
|
||||
let _ = emulate.send(EmulationEvent::Destroy(handle)).await;
|
||||
let _ = capture.send(CaptureRequest::Destroy(handle)).await;
|
||||
let _ = emulate.send(EmulationRequest::Destroy(handle)).await;
|
||||
}
|
||||
let _ = capture.send(CaptureEvent::Create(handle, pos.into())).await;
|
||||
let _ = emulate.send(EmulationEvent::Create(handle)).await;
|
||||
let _ = capture
|
||||
.send(CaptureRequest::Create(handle, pos.into()))
|
||||
.await;
|
||||
let _ = emulate.send(EmulationRequest::Create(handle)).await;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -563,6 +567,27 @@ impl Server {
|
||||
.get_mut(handle)
|
||||
.and_then(|(c, _)| c.hostname.clone())
|
||||
}
|
||||
|
||||
fn get_state(&self) -> State {
|
||||
self.state.get()
|
||||
}
|
||||
|
||||
fn set_state(&self, state: State) {
|
||||
log::debug!("state => {state:?}");
|
||||
self.state.replace(state);
|
||||
}
|
||||
|
||||
fn set_active(&self, handle: Option<u64>) {
|
||||
log::debug!("active client => {handle:?}");
|
||||
self.active_client.replace(handle);
|
||||
}
|
||||
|
||||
fn active_addr(&self, handle: u64) -> Option<SocketAddr> {
|
||||
self.client_manager
|
||||
.borrow()
|
||||
.get(handle)
|
||||
.and_then(|(_, s)| s.active_addr)
|
||||
}
|
||||
}
|
||||
|
||||
async fn listen_frontend(
|
||||
|
||||
Reference in New Issue
Block a user