summaryrefslogtreecommitdiffhomepage
path: root/talpid_openvpn_plugin/src/processing.rs
blob: dd6967135e20e37fdce005d1f7da152c336ed738 (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
use openvpn_ffi;

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> {
        debug!("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_ffi::OpenVpnPluginEvent,
                         env: openvpn_ffi::OpenVpnEnv)
                         -> Result<()> {
        trace!("Processing \"{:?}\" event", event);
        self.ipc_client
            .call("openvpn_event", &(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");
    }
}