diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2017-07-17 11:29:43 +0200 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2017-07-17 11:29:43 +0200 |
| commit | 90588bced678c1ecbf7db0190c7c039d79e94d3e (patch) | |
| tree | 5a5209baefc0b10ba528f254e7ce2456c23f6ac9 /talpid-openvpn-plugin/src/processing.rs | |
| parent | 6a4202fc8c55752f0fef86c04b628a3f9ada5279 (diff) | |
| parent | f07f1a0262c908ff83490850b67a167f963efc2d (diff) | |
| download | mullvadvpn-90588bced678c1ecbf7db0190c7c039d79e94d3e.tar.xz mullvadvpn-90588bced678c1ecbf7db0190c7c039d79e94d3e.zip | |
Merge branch 'rename-crates'
Diffstat (limited to 'talpid-openvpn-plugin/src/processing.rs')
| -rw-r--r-- | talpid-openvpn-plugin/src/processing.rs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/talpid-openvpn-plugin/src/processing.rs b/talpid-openvpn-plugin/src/processing.rs new file mode 100644 index 0000000000..e33097c633 --- /dev/null +++ b/talpid-openvpn-plugin/src/processing.rs @@ -0,0 +1,43 @@ +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)) + .map(|_: Option<()>| ()) + .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"); + } +} |
