[libdmapsharing] Implement fine-grained service withdrawl Signed-off-by: W. Michael Petullo <mike flyn org>



commit 78322364687a74d1eeba25791c5151a96053fd01
Author: W. Michael Petullo <mike flyn org>
Date:   Thu Sep 9 17:55:58 2010 -0500

    Implement fine-grained service withdrawl
    Signed-off-by: W. Michael Petullo <mike flyn org>

 TODO                                       |    2 +
 libdmapsharing/dmap-mdns-publisher-avahi.c |   63 +++++++++++++++++++---------
 libdmapsharing/dmap-mdns-publisher.h       |    3 +-
 libdmapsharing/dmap-share.c                |    2 +-
 4 files changed, 48 insertions(+), 22 deletions(-)
---
diff --git a/TODO b/TODO
index 30a9013..baa5318 100644
--- a/TODO
+++ b/TODO
@@ -1,3 +1,5 @@
+Fix DNSSD on Mac OS X
+
 Complete DACP code and push Rhythmbox patch
 
 Reduce the memory usage while building response to media list query.
diff --git a/libdmapsharing/dmap-mdns-publisher-avahi.c b/libdmapsharing/dmap-mdns-publisher-avahi.c
index 6ebca53..a7a3487 100644
--- a/libdmapsharing/dmap-mdns-publisher-avahi.c
+++ b/libdmapsharing/dmap-mdns-publisher-avahi.c
@@ -217,20 +217,30 @@ refresh_services (DmapMdnsPublisher *publisher,
 	return create_services (publisher, error);
 }
 
+static struct DmapMdnsPublisherService *
+find_service_by_port (GSList *list, guint port)
+{
+	GSList *ptr;
+
+	for (ptr = list; ptr; ptr = g_slist_next (ptr)) {
+		if (port == ((struct DmapMdnsPublisherService *) ptr->data)->port)
+			break;
+	}
+
+	return ptr ? ptr->data : NULL;
+}
+
 gboolean
 dmap_mdns_publisher_rename_at_port (DmapMdnsPublisher *publisher,
 				    guint	       port,
 				    const char        *name,
 				    GError           **error)
 {
-	GSList *ptr;
+	struct DmapMdnsPublisherService *ptr;
 
         g_return_val_if_fail (publisher != NULL, FALSE);
 
-	for (ptr = publisher->priv->service; ptr; ptr = g_slist_next (ptr)) {
-		if (port == ((struct DmapMdnsPublisherService *) ptr->data)->port)
-			break;
-	}
+	ptr = find_service_by_port (publisher->priv->service, port);
 
 	if (ptr == NULL) {
                 g_set_error (error,
@@ -241,8 +251,8 @@ dmap_mdns_publisher_rename_at_port (DmapMdnsPublisher *publisher,
 		return FALSE;
 	}
 
-	g_free (((struct DmapMdnsPublisherService *) ptr->data)->name);
-	((struct DmapMdnsPublisherService *) ptr->data)->name = g_strdup (name);
+	g_free (ptr->name);
+	ptr->name = g_strdup (name);
 
 	if (publisher->priv->entry_group) {
 		refresh_services (publisher, error);
@@ -285,10 +295,21 @@ dmap_mdns_publisher_publish (DmapMdnsPublisher *publisher,
 	return create_services (publisher, error);
 }
 
+static void
+free_service (struct DmapMdnsPublisherService *service, gpointer user_data)
+{
+	g_free (service->name);
+	g_free (service->type_of_service);
+	g_strfreev (service->txt_records);
+}
+
 gboolean
 dmap_mdns_publisher_withdraw (DmapMdnsPublisher *publisher,
-				 GError             **error)
+			      guint port,
+			      GError             **error)
 {
+	struct DmapMdnsPublisherService *ptr;
+
 	if (publisher->priv->client == NULL) {
                 g_set_error (error,
 			     DMAP_MDNS_PUBLISHER_ERROR,
@@ -298,7 +319,8 @@ dmap_mdns_publisher_withdraw (DmapMdnsPublisher *publisher,
 		return FALSE;
 	}
 
-	if (publisher->priv->entry_group == NULL) {
+	if (publisher->priv->entry_group == NULL
+	    || ! (ptr = find_service_by_port (publisher->priv->service, port))) {
                 g_set_error (error,
 			     DMAP_MDNS_PUBLISHER_ERROR,
 			     DMAP_MDNS_PUBLISHER_ERROR_FAILED,
@@ -307,9 +329,18 @@ dmap_mdns_publisher_withdraw (DmapMdnsPublisher *publisher,
 		return FALSE;
 	}
 
-	avahi_entry_group_reset (publisher->priv->entry_group);
-	avahi_entry_group_free (publisher->priv->entry_group);
-	publisher->priv->entry_group = NULL;
+	free_service (ptr, NULL);
+	publisher->priv->service = g_slist_remove (publisher->priv->service, ptr);
+
+	if (publisher->priv->service == NULL) {
+		avahi_entry_group_reset (publisher->priv->entry_group);
+		avahi_entry_group_free (publisher->priv->entry_group);
+		publisher->priv->entry_group = NULL;
+	} else {
+		create_services (publisher, error);
+		if (error != NULL)
+			return FALSE;
+	}
 
 	return TRUE;
 }
@@ -403,14 +434,6 @@ dmap_mdns_publisher_init (DmapMdnsPublisher *publisher)
 }
 
 static void
-free_service (struct DmapMdnsPublisherService *service, gpointer user_data)
-{
-	g_free (service->name);
-	g_free (service->type_of_service);
-	g_strfreev (service->txt_records);
-}
-
-static void
 dmap_mdns_publisher_finalize (GObject *object)
 {
 	DmapMdnsPublisher *publisher;
diff --git a/libdmapsharing/dmap-mdns-publisher.h b/libdmapsharing/dmap-mdns-publisher.h
index 25c3bb1..32fce17 100644
--- a/libdmapsharing/dmap-mdns-publisher.h
+++ b/libdmapsharing/dmap-mdns-publisher.h
@@ -82,7 +82,8 @@ gboolean             dmap_mdns_publisher_rename_at_port         (DmapMdnsPublish
 								    const char          *name,
 								    GError             **error);
 gboolean             dmap_mdns_publisher_withdraw               (DmapMdnsPublisher *publisher,
-								    GError             **error);
+								 guint port,
+								 GError             **error);
 
 G_END_DECLS
 
diff --git a/libdmapsharing/dmap-share.c b/libdmapsharing/dmap-share.c
index db0da5b..392e1e3 100644
--- a/libdmapsharing/dmap-share.c
+++ b/libdmapsharing/dmap-share.c
@@ -359,7 +359,7 @@ _dmap_share_publish_stop (DMAPShare *share)
 		gboolean res;
 		GError  *error;
 		error = NULL;
-		res = dmap_mdns_publisher_withdraw (share->priv->publisher, &error);
+		res = dmap_mdns_publisher_withdraw (share->priv->publisher, share->priv->port, &error);
 		if (error != NULL) {
 			g_warning ("Unable to withdraw music sharing service: %s", error->message);
 			g_error_free (error);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]