diff options
author | Mathias Hasselmann <hasselmm@src.gnome.org> | 2007-11-24 14:24:04 +0000 |
---|---|---|
committer | Mathias Hasselmann <hasselmm@src.gnome.org> | 2007-11-24 14:24:04 +0000 |
commit | 57c1ad5c4308cb2f23b6832d1f0f490a5e2a4d73 (patch) | |
tree | 882fa6d7758f3c3deebbcdf4b6fa38e2fa86f10d | |
parent | 0dc0c36381289aaa5cfa5f7374d8c313a710cd33 (diff) | |
download | totem-57c1ad5c4308cb2f23b6832d1f0f490a5e2a4d73.tar.gz |
Add service monitor for finding other Totem instances.
* src/plugins/publish/totem-publish.c: Add service monitor.
svn path=/branches/LIBEPC/; revision=4897
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | src/plugins/publish/totem-publish.c | 72 |
2 files changed, 64 insertions, 14 deletions
@@ -1,5 +1,11 @@ 2007-11-24 Mathias Hasselmann <mathias@openismus.com> + Add service monitor for finding other Totem instances. + + * src/plugins/publish/totem-publish.c: Add service monitor. + +2007-11-24 Mathias Hasselmann <mathias@openismus.com> + Resync with libepc trunk. * src/plugins/publish/totem-publish.c: Adopt to new memory management. diff --git a/src/plugins/publish/totem-publish.c b/src/plugins/publish/totem-publish.c index 76ce330db..075777396 100644 --- a/src/plugins/publish/totem-publish.c +++ b/src/plugins/publish/totem-publish.c @@ -34,6 +34,7 @@ #include <glib/gi18n-lib.h> #include <libepc/publisher.h> +#include <libepc/service-monitor.h> #include "totem-plugin.h" #include "totem-interface.h" @@ -53,17 +54,19 @@ typedef struct { - TotemPlugin parent; - - TotemObject *totem; - GtkWidget *dialog; - - EpcPublisher *publisher; - - guint name_id; - guint protocol_id; - guint item_added_id; - guint item_removed_id; + TotemPlugin parent; + + TotemObject *totem; + EpcPublisher *publisher; + EpcServiceMonitor *monitor; + GtkWidget *dialog; + + guint name_id; + guint protocol_id; + guint item_added_id; + guint item_removed_id; + guint service_found_id; + guint service_removed_id; } TotemPublishPlugin; typedef struct @@ -252,6 +255,28 @@ totem_publish_plugin_item_removed_cb (TotemPlaylist *playlist, g_free (key); } +static void +totem_publish_plugin_service_found_cb (EpcServiceMonitor *monitor, + const gchar *type, + const gchar *name, + const gchar *host, + guint port, + gpointer data) +{ + TotemPublishPlugin *self G_GNUC_UNUSED = TOTEM_PUBLISH_PLUGIN (data); + g_print ("+ %s (%s, %s:%d)\n", name, type, host, port); +} + +static void +totem_publish_plugin_service_removed_cb (EpcServiceMonitor *monitor, + const gchar *type, + const gchar *name, + gpointer data) +{ + TotemPublishPlugin *self G_GNUC_UNUSED = TOTEM_PUBLISH_PLUGIN (data); + g_print ("- %s (%s)\n", name, type); +} + static gboolean totem_publish_plugin_activate (TotemPlugin *plugin, TotemObject *totem, @@ -289,7 +314,14 @@ totem_publish_plugin_activate (TotemPlugin *plugin, if (protocol_name) protocol = epc_protocol_from_name (protocol_name, EPC_PROTOCOL_HTTPS); - self->publisher = epc_publisher_new (service_name, NULL, NULL); + self->monitor = epc_service_monitor_new ("totem", NULL, EPC_PROTOCOL_UNKNOWN); + + self->service_found_id = g_signal_connect (self->monitor, "service-found", + G_CALLBACK (totem_publish_plugin_service_found_cb), self); + self->service_removed_id = g_signal_connect (self->monitor, "service-removed", + G_CALLBACK (totem_publish_plugin_service_removed_cb), self); + + self->publisher = epc_publisher_new (service_name, "totem", NULL); epc_publisher_set_protocol (self->publisher, protocol); g_free (protocol_name); @@ -316,21 +348,33 @@ totem_publish_plugin_deactivate (TotemPlugin *plugin, { TotemPublishPlugin *self = TOTEM_PUBLISH_PLUGIN (plugin); + if (self->monitor) { + g_object_unref (self->monitor); + self->monitor = NULL; + } + if (self->publisher) { epc_publisher_quit (self->publisher); - self->publisher = (g_object_unref (self->publisher), NULL); + g_object_unref (self->publisher); + self->publisher = NULL; } if (self->totem) { + gconf_client_notify_remove (self->totem->gc, self->name_id); gconf_client_notify_remove (self->totem->gc, self->protocol_id); gconf_client_remove_dir (self->totem->gc, TOTEM_PUBLISH_CONFIG_ROOT, NULL); - self->totem = (g_object_unref (self->totem), NULL); + g_object_unref (self->totem); + self->totem = NULL; } if (self->item_added_id) self->item_added_id = (g_source_remove (self->item_added_id), 0); if (self->item_removed_id) self->item_removed_id = (g_source_remove (self->item_removed_id), 0); + if (self->service_found_id) + self->service_found_id = (g_source_remove (self->service_found_id), 0); + if (self->service_removed_id) + self->service_removed_id = (g_source_remove (self->service_removed_id), 0); } void |