From 555b1f5aa8b35b6cb12be2d318d286899992d808 Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Wed, 15 Jun 2011 16:37:34 +0100 Subject: [PATCH] Neaten IdentityRequest callback code With Vala 0.10.4 a few compiler warnings about mismatched function pointer types are generated. This is due to Vala's code generation and cannot be avoided, the warnings are harmless. --- src/moonshot-dbus-server.vala | 2 +- src/moonshot-identity-request.vala | 29 +++++++---------------------- src/moonshot-msrpc-server.vala | 2 +- 3 files changed, 9 insertions(+), 24 deletions(-) diff --git a/src/moonshot-dbus-server.vala b/src/moonshot-dbus-server.vala index 82e9568..3bf447c 100644 --- a/src/moonshot-dbus-server.vala +++ b/src/moonshot-dbus-server.vala @@ -37,7 +37,7 @@ public class MoonshotServer : Object { nai, password, service); - request.set_source_func_callback (get_identity.callback); + request.set_callback ((IdentityRequest) => get_identity.callback()); request.execute (); yield; diff --git a/src/moonshot-identity-request.vala b/src/moonshot-identity-request.vala index 82c5e9e..9568f4c 100644 --- a/src/moonshot-identity-request.vala +++ b/src/moonshot-identity-request.vala @@ -9,10 +9,7 @@ class IdentityRequest : Object { private string password; private string certificate; - // Only one of these is used, we must support two types for - // the DBus and MSRPC servers. - ReturnIdentityCallback return_identity_cb = null; - SourceFunc source_func_cb = null; + ReturnIdentityCallback callback = null; public IdentityRequest (MainWindow main_window, string nai, @@ -25,21 +22,12 @@ class IdentityRequest : Object { this.certificate = certificate; } - public void set_return_identity_callback (owned ReturnIdentityCallback cb) + public void set_callback (owned ReturnIdentityCallback cb) { #if VALA_0_12 - this.return_identity_cb = ((owned) cb); + this.callback = ((owned) cb); #else - this.return_identity_cb = ((IdCard) => cb (IdCard)); -#endif - } - - public void set_source_func_callback (owned SourceFunc cb) - { -#if VALA_0_12 - this.source_func_cb = ((owned) cb); -#else - this.source_func_cb = (() => cb ()); + this.callback = ((IdCard) => cb (IdCard)); #endif } @@ -53,15 +41,12 @@ class IdentityRequest : Object { } public void return_identity (IdCard? id_card) { + return_if_fail (callback != null); + this.id_card = id_card; this.complete = true; - if (return_identity_cb != null) - return_identity_cb (this); - else if (source_func_cb != null) - source_func_cb (); - else - warn_if_reached (); + callback (this); } #if OS_WIN32 diff --git a/src/moonshot-msrpc-server.vala b/src/moonshot-msrpc-server.vala index 91f7348..35f3207 100644 --- a/src/moonshot-msrpc-server.vala +++ b/src/moonshot-msrpc-server.vala @@ -46,7 +46,7 @@ public class MoonshotServer : Object { // Pass execution to the main loop and block the RPC thread request.mutex = new Mutex (); request.cond = new Cond (); - request.set_return_identity_callback (return_identity_cb); + request.set_callback (return_identity_cb); request.mutex.lock (); Idle.add (request.execute); -- 2.1.4