blob: b1f1b97abc685b5508753e030a22466642a1b76f (
plain)
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
|
use openvpn_ffi;
use std::collections::HashMap;
use talpid_ipc::{IpcClient, IpcServerId};
error_chain! {
errors {
IpcSendingError {
description("Failed while sending an event over the IPC channel")
}
}
}
/// Struct processing OpenVPN events and notifies listeners over IPC
pub struct EventProcessor {
ipc_client: IpcClient<(openvpn_ffi::OpenVpnPluginEvent, HashMap<String, String>)>,
}
impl EventProcessor {
pub fn new(server_id: IpcServerId) -> Result<EventProcessor> {
debug!("Creating EventProcessor");
let ipc_client = IpcClient::new(server_id);
Ok(EventProcessor { ipc_client: ipc_client })
}
pub fn process_event(&mut self,
event: openvpn_ffi::OpenVpnPluginEvent,
env: HashMap<String, String>)
-> Result<()> {
trace!("Processing \"{:?}\" event", event);
self.ipc_client.send(&(event, env)).chain_err(|| ErrorKind::IpcSendingError)
}
}
impl Drop for EventProcessor {
fn drop(&mut self) {
// TODO(linus): If we need, this is where we send some shutdown event or similar to core.
debug!("Dropping EventProcessor");
}
}
|