diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2019-06-12 16:29:44 +0000 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2019-06-17 14:42:59 +0000 |
| commit | 10f461fadf08a0eac6794407527a72a3f8576749 (patch) | |
| tree | 92edde675c444f51b5e9bd78ca73a8a6acafdc16 | |
| parent | f67d5763adb5d5ea4caa97737a2c31022b4e7c06 (diff) | |
| download | mullvadvpn-10f461fadf08a0eac6794407527a72a3f8576749.tar.xz mullvadvpn-10f461fadf08a0eac6794407527a72a3f8576749.zip | |
Create `get_method_id` helper method
| -rw-r--r-- | mullvad-jni/src/jni_event_listener.rs | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/mullvad-jni/src/jni_event_listener.rs b/mullvad-jni/src/jni_event_listener.rs index 7beb7ae844..e24d3885c5 100644 --- a/mullvad-jni/src/jni_event_listener.rs +++ b/mullvad-jni/src/jni_event_listener.rs @@ -1,6 +1,6 @@ use crate::{get_class, into_java::IntoJava}; use jni::{ - objects::{JMethodID, JObject, JValue}, + objects::{GlobalRef, JMethodID, JObject, JValue}, signature::{JavaType, Primitive}, AttachGuard, JNIEnv, }; @@ -83,13 +83,12 @@ impl<'env> JniEventHandler<'env> { events: mpsc::Receiver<TunnelStateTransition>, ) -> Result<Self, Error> { let class = get_class("net/mullvad/mullvadvpn/MullvadDaemon"); - let notify_tunnel_event = env - .get_method_id( - &class, - "notifyTunnelStateEvent", - "(Lnet/mullvad/mullvadvpn/model/TunnelStateTransition;)V", - ) - .map_err(|error| Error::FindMethod("notifyTunnelStateEvent", error))?; + let notify_tunnel_event = Self::get_method_id( + &env, + &class, + "notifyTunnelStateEvent", + "(Lnet/mullvad/mullvadvpn/model/TunnelStateTransition;)V", + )?; Ok(JniEventHandler { env, @@ -99,6 +98,16 @@ impl<'env> JniEventHandler<'env> { }) } + fn get_method_id( + env: &AttachGuard<'env>, + class: &GlobalRef, + method: &'static str, + signature: &str, + ) -> Result<JMethodID<'env>, Error> { + env.get_method_id(class, method, signature) + .map_err(|error| Error::FindMethod(method, error)) + } + fn run(&mut self) { while let Ok(event) = self.events.recv() { self.handle_tunnel_event(event); |
