aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2010-07-06 10:36:27 -0500
committerTed Gould <ted@gould.cx>2010-07-06 10:36:27 -0500
commit8a1255676ed6c7091e9c1c2dfda183dacf00ab31 (patch)
tree6c36b7328264ff91cbf37dd9bcd48d598c04887b
parentc77d719ce54cf07cb4769d37a91f2f33a769a369 (diff)
downloadlibayatana-indicator-8a1255676ed6c7091e9c1c2dfda183dacf00ab31.tar.gz
libayatana-indicator-8a1255676ed6c7091e9c1c2dfda183dacf00ab31.tar.bz2
libayatana-indicator-8a1255676ed6c7091e9c1c2dfda183dacf00ab31.zip
Switching the watchers data structure over to a hashtable.
-rw-r--r--libindicator/indicator-service.c30
1 files changed, 13 insertions, 17 deletions
diff --git a/libindicator/indicator-service.c b/libindicator/indicator-service.c
index fc3c7de..74b5a2e 100644
--- a/libindicator/indicator-service.c
+++ b/libindicator/indicator-service.c
@@ -51,7 +51,7 @@ struct _IndicatorServicePrivate {
gchar * name;
DBusGProxy * dbus_proxy;
guint timeout;
- GList * watchers;
+ GHashTable * watchers;
guint this_service_version;
};
@@ -160,6 +160,8 @@ indicator_service_init (IndicatorService *self)
priv->watchers = NULL;
priv->this_service_version = 0;
+ priv->watchers = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_object_unref);
+
/* Start talkin' dbus */
GError * error = NULL;
DBusGConnection * bus = dbus_g_bus_get(DBUS_BUS_STARTER, &error);
@@ -230,8 +232,7 @@ indicator_service_finalize (GObject *object)
}
if (priv->watchers != NULL) {
- g_list_foreach(priv->watchers, (GFunc)g_free, NULL);
- g_list_free(priv->watchers);
+ g_hash_table_destroy(priv->watchers);
priv->watchers = NULL;
}
@@ -382,8 +383,12 @@ _indicator_service_server_watch (IndicatorService * service, DBusGMethodInvocati
g_return_val_if_fail(INDICATOR_IS_SERVICE(service), FALSE);
IndicatorServicePrivate * priv = INDICATOR_SERVICE_GET_PRIVATE(service);
- priv->watchers = g_list_append(priv->watchers,
- g_strdup(dbus_g_method_get_sender(method)));
+ const gchar * sender = dbus_g_method_get_sender(method);
+ if (g_hash_table_lookup(priv->watchers, sender) == NULL) {
+ DBusGProxy * senderproxy = (gpointer)1;
+
+ g_hash_table_insert(priv->watchers, g_strdup(sender), senderproxy);
+ }
if (priv->timeout != 0) {
g_source_remove(priv->timeout);
@@ -394,13 +399,6 @@ _indicator_service_server_watch (IndicatorService * service, DBusGMethodInvocati
return TRUE;
}
-/* Mung g_strcmp0 into GCompareFunc */
-static gint
-find_watcher (gconstpointer a, gconstpointer b)
-{
- return g_strcmp0((const gchar *)a, (const gchar *)b);
-}
-
/* A function connecting into the dbus interface for the
"UnWatch" function. It is also an async function to get
the sender. It then looks the sender up and removes them
@@ -413,19 +411,17 @@ _indicator_service_server_un_watch (IndicatorService * service, DBusGMethodInvoc
IndicatorServicePrivate * priv = INDICATOR_SERVICE_GET_PRIVATE(service);
/* Remove us from the watcher list here */
- GList * watcher_item = g_list_find_custom(priv->watchers, dbus_g_method_get_sender(method), find_watcher);
+ gpointer watcher_item = g_hash_table_lookup(priv->watchers, dbus_g_method_get_sender(method));
if (watcher_item != NULL) {
/* Free the watcher */
- gchar * name = watcher_item->data;
- priv->watchers = g_list_remove(priv->watchers, name);
- g_free(name);
+ g_hash_table_remove(priv->watchers, dbus_g_method_get_sender(method));
} else {
/* Odd that we couldn't find the person, but, eh */
g_warning("Unable to find watcher who is unwatching: %s", dbus_g_method_get_sender(method));
}
/* If we're out of watchers set the timeout for shutdown */
- if (priv->watchers == NULL) {
+ if (g_hash_table_size(priv->watchers) == 0) {
if (priv->timeout != 0) {
/* This should never really happen, but let's ensure that
bad things don't happen if it does. */