-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathr2_event.rs
51 lines (46 loc) · 1.66 KB
/
r2_event.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright (c) 2023 Unfolded Circle ApS, Markus Zehnder <markus.z@unfoldedcircle.com>
// SPDX-License-Identifier: MPL-2.0
//! Actix message handler for [R2EventMsg].
use crate::controller::handler::{AbortDriverSetup, ConnectMsg, DisconnectMsg};
use crate::controller::{Controller, R2EventMsg};
use actix::{AsyncContext, Handler};
use log::error;
use uc_api::intg::ws::R2Event;
use uc_api::intg::DeviceState;
impl Handler<R2EventMsg> for Controller {
type Result = ();
fn handle(&mut self, msg: R2EventMsg, ctx: &mut Self::Context) -> Self::Result {
let session = match self.sessions.get_mut(&msg.ws_id) {
None => {
error!("Session not found: {}", msg.ws_id);
return;
}
Some(s) => s,
};
match msg.event {
R2Event::Connect => {
if self.device_state != DeviceState::Connected {
ctx.notify(ConnectMsg::default());
}
// make sure client has the correct state, it might be out of sync, or not calling get_device_state
self.send_device_state(&msg.ws_id);
}
R2Event::Disconnect => {
ctx.notify(DisconnectMsg {});
}
R2Event::EnterStandby => {
session.standby = true;
}
R2Event::ExitStandby => {
session.standby = false;
// TODO send updates #5
}
R2Event::AbortDriverSetup => {
ctx.notify(AbortDriverSetup {
ws_id: msg.ws_id,
timeout: false,
});
}
}
}
}