blob: b76e92e409306f48db906e38bca8fd3315bb1cd1 (
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
|
use openvpn_plugin;
use std::collections::HashMap;
use talpid_ipc::{IpcServerId, WsIpcClient};
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: WsIpcClient,
}
impl EventProcessor {
pub fn new(server_id: IpcServerId) -> Result<EventProcessor> {
trace!("Creating EventProcessor");
let ipc_client = WsIpcClient::new(server_id).chain_err(|| "Unable to create IPC client")?;
Ok(EventProcessor { ipc_client })
}
pub fn process_event(
&mut self,
event: openvpn_plugin::types::OpenVpnPluginEvent,
env: HashMap<String, String>,
) -> Result<()> {
trace!("Processing \"{:?}\" event", event);
self.ipc_client
.call("openvpn_event", &(event, env))
.map(|_: Option<()>| ())
.chain_err(|| ErrorKind::IpcSendingError)
}
}
|