From 6e51efbeaceab68fdf66e53c66afe7a94c82d7cd Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 2 Apr 2009 10:49:35 -0500 Subject: Switching around the show_interest and remove_interest functions so that they are now asyncronous. Not that being asynchronous is important but more that now they get the Method Invocation interface that we can use to find out the sender of the message. Changed various APIs as a result of this, and moved the DBus functions to be internal. --- libindicate/indicate-interface.xml | 2 + libindicate/server.c | 94 ++++++++++++++++++++++++++++---------- libindicate/server.h | 17 ++----- 3 files changed, 74 insertions(+), 39 deletions(-) diff --git a/libindicate/indicate-interface.xml b/libindicate/indicate-interface.xml index 9a58f74..900b336 100644 --- a/libindicate/indicate-interface.xml +++ b/libindicate/indicate-interface.xml @@ -67,9 +67,11 @@ License version 3 and version 2.1 along with this program. If not, see + + diff --git a/libindicate/server.c b/libindicate/server.c index bd7c4dd..597bf74 100644 --- a/libindicate/server.c +++ b/libindicate/server.c @@ -29,7 +29,8 @@ License version 3 and version 2.1 along with this program. If not, see #include "server.h" #include "interests-priv.h" -#include "dbus-indicate-server.h" +#include +#include /* Errors */ enum { @@ -45,6 +46,8 @@ enum { INVALID_INDICATOR_ID, NO_SHOW_INTEREST, NO_REMOVE_INTEREST, + SHOW_INTEREST_FAILED, + REMOVE_INTEREST_FAILED, LAST_ERROR }; @@ -106,6 +109,23 @@ static guint get_next_id (IndicateServer * server); static void set_property (GObject * obj, guint id, const GValue * value, GParamSpec * pspec); static void get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec); +/* DBus API */ +gboolean indicate_server_get_indicator_count (IndicateServer * server, guint * count, GError **error); +gboolean indicate_server_get_indicator_count_by_type (IndicateServer * server, gchar * type, guint * count, GError **error); +gboolean indicate_server_get_indicator_list (IndicateServer * server, GArray ** indicators, GError ** error); +gboolean indicate_server_get_indicator_list_by_type (IndicateServer * server, gchar * type, guint ** indicators, GError ** error); +gboolean indicate_server_get_indicator_property (IndicateServer * server, guint id, gchar * property, gchar ** value, GError **error); +gboolean indicate_server_get_indicator_property_group (IndicateServer * server, guint id, GPtrArray * properties, gchar *** value, GError **error); +gboolean indicate_server_get_indicator_properties (IndicateServer * server, guint id, gchar *** properties, GError **error); +gboolean indicate_server_show_indicator_to_user (IndicateServer * server, guint id, GError ** error); +gboolean indicate_server_show_interest (IndicateServer * server, gchar * interest, DBusGMethodInvocation * method); +gboolean indicate_server_remove_interest (IndicateServer * server, gchar * interest, DBusGMethodInvocation * method); + +/* Has to be after the dbus prototypes */ +#include "dbus-indicate-server.h" + + + /* Code */ static void indicate_server_class_init (IndicateServerClass * class) @@ -895,45 +915,69 @@ interest_string_to_enum (gchar * interest_string) } gboolean -indicate_server_show_interest (IndicateServer * server, gchar * interest, GError ** error) +indicate_server_show_interest (IndicateServer * server, gchar * interest, DBusGMethodInvocation * method) { IndicateServerClass * class = INDICATE_SERVER_GET_CLASS(server); if (class != NULL) { - return class->show_interest (server, interest_string_to_enum(interest)); - } - - if (error) { - g_set_error(error, - indicate_server_error_quark(), - NO_SHOW_INTEREST, - "show_interest function doesn't exist for this server class: %s", - G_OBJECT_TYPE_NAME(server)); - return FALSE; + if (class->show_interest (server, dbus_g_method_get_sender(method), interest_string_to_enum(interest))){ + dbus_g_method_return(method); + return TRUE; + } else { + GError * error; + g_set_error(&error, + indicate_server_error_quark(), + SHOW_INTEREST_FAILED, + "Unable to show interest: %s", + interest); + dbus_g_method_return_error(method, error); + g_error_free(error); + return FALSE; + } } - return TRUE; + GError * error; + g_set_error(&error, + indicate_server_error_quark(), + NO_SHOW_INTEREST, + "show_interest function doesn't exist for this server class: %s", + G_OBJECT_TYPE_NAME(server)); + dbus_g_method_return_error(method, error); + g_error_free(error); + return FALSE; } gboolean -indicate_server_remove_interest (IndicateServer * server, gchar * interest, GError ** error) +indicate_server_remove_interest (IndicateServer * server, gchar * interest, DBusGMethodInvocation * method) { IndicateServerClass * class = INDICATE_SERVER_GET_CLASS(server); if (class != NULL) { - return class->remove_interest (server, interest_string_to_enum(interest)); - } - - if (error) { - g_set_error(error, - indicate_server_error_quark(), - NO_REMOVE_INTEREST, - "remove_interest function doesn't exist for this server class: %s", - G_OBJECT_TYPE_NAME(server)); - return FALSE; + if (class->remove_interest (server, dbus_g_method_get_sender(method), interest_string_to_enum(interest))){ + dbus_g_method_return(method); + return TRUE; + } else { + GError * error; + g_set_error(&error, + indicate_server_error_quark(), + REMOVE_INTEREST_FAILED, + "Unable to remove interest: %s", + interest); + dbus_g_method_return_error(method, error); + g_error_free(error); + return FALSE; + } } - return TRUE; + GError * error; + g_set_error(&error, + indicate_server_error_quark(), + NO_REMOVE_INTEREST, + "remove_interest function doesn't exist for this server class: %s", + G_OBJECT_TYPE_NAME(server)); + dbus_g_method_return_error(method, error); + g_error_free(error); + return FALSE; } /* Signal emission functions for sub-classes of the server */ diff --git a/libindicate/server.h b/libindicate/server.h index 4d6bbc5..0db5bef 100644 --- a/libindicate/server.h +++ b/libindicate/server.h @@ -86,8 +86,9 @@ struct _IndicateServerClass { gboolean (*get_indicator_properties) (IndicateServer * server, guint id, gchar *** properties, GError **error); gboolean (*show_indicator_to_user) (IndicateServer * server, guint id, GError ** error); guint (*get_next_id) (IndicateServer * server); - gboolean (*show_interest) (IndicateServer * server, IndicateInterests interest); - gboolean (*remove_interest) (IndicateServer * server, IndicateInterests interest); + gboolean (*show_interest) (IndicateServer * server, gchar * sender, IndicateInterests interest); + gboolean (*remove_interest) (IndicateServer * server, gchar * sender, IndicateInterests interest); + gboolean (*check_interest) (IndicateServer * server, IndicateInterests interest); /* Reserver for future use */ void (*indicate_server_reserved1)(void); @@ -127,18 +128,6 @@ void indicate_server_set_default (IndicateServer * server); gboolean indicate_server_check_interest (IndicateServer * server, IndicateInterests interest); -/* DBus API */ -gboolean indicate_server_get_indicator_count (IndicateServer * server, guint * count, GError **error); -gboolean indicate_server_get_indicator_count_by_type (IndicateServer * server, gchar * type, guint * count, GError **error); -gboolean indicate_server_get_indicator_list (IndicateServer * server, GArray ** indicators, GError ** error); -gboolean indicate_server_get_indicator_list_by_type (IndicateServer * server, gchar * type, guint ** indicators, GError ** error); -gboolean indicate_server_get_indicator_property (IndicateServer * server, guint id, gchar * property, gchar ** value, GError **error); -gboolean indicate_server_get_indicator_property_group (IndicateServer * server, guint id, GPtrArray * properties, gchar *** value, GError **error); -gboolean indicate_server_get_indicator_properties (IndicateServer * server, guint id, gchar *** properties, GError **error); -gboolean indicate_server_show_indicator_to_user (IndicateServer * server, guint id, GError ** error); -gboolean indicate_server_show_interest (IndicateServer * server, gchar * interest, GError ** error); -gboolean indicate_server_remove_interest (IndicateServer * server, gchar * interest, GError ** error); - /* Signal emission functions for sub-classes of the server */ void indicate_server_emit_indicator_added (IndicateServer *server, guint id, const gchar *type); void indicate_server_emit_indicator_removed (IndicateServer *server, guint id, const gchar *type); -- cgit v1.2.3