rhythmbox r6028 - in trunk: . plugins/daap



Author: jmatthew
Date: Sun Nov  9 08:39:04 2008
New Revision: 6028
URL: http://svn.gnome.org/viewvc/rhythmbox?rev=6028&view=rev

Log:
2008-11-09  Jonathan Matthew  <jonathan d14n org>

	* plugins/daap/Makefile.am:
	* plugins/daap/rb-daap-mdns-avahi.c: (client_cb),
	(rb_daap_mdns_avahi_get_client),
	(rb_daap_mdns_avahi_set_entry_group):
	* plugins/daap/rb-daap-mdns-avahi.h:
	Add some machinery to create a single avahi client to use for both
	browsing and publishing.

	* plugins/daap/rb-daap-mdns-browser-avahi.c: (browse_cb),
	(rb_daap_mdns_browser_init), (rb_daap_mdns_browser_finalize):
	* plugins/daap/rb-daap-mdns-publisher-avahi.c: (create_service),
	(rb_daap_mdns_publisher_withdraw), (rb_daap_mdns_publisher_init),
	(rb_daap_mdns_publisher_finalize):
	Use the shared avahi client.  Since we publish and browse using the
	same client, we can use the AVAHI_LOOKUP_RESULT_OUR_OWN flag (rather
	than AVAHI_LOOKUP_RESULT_LOCAL) to ignore just our own share.
	Previously, we ignored all shares on the same machine.  Fixes #342655.


Added:
   trunk/plugins/daap/rb-daap-mdns-avahi.c
   trunk/plugins/daap/rb-daap-mdns-avahi.h
Modified:
   trunk/ChangeLog
   trunk/plugins/daap/Makefile.am
   trunk/plugins/daap/rb-daap-mdns-browser-avahi.c
   trunk/plugins/daap/rb-daap-mdns-publisher-avahi.c

Modified: trunk/plugins/daap/Makefile.am
==============================================================================
--- trunk/plugins/daap/Makefile.am	(original)
+++ trunk/plugins/daap/Makefile.am	Sun Nov  9 08:39:04 2008
@@ -24,6 +24,7 @@
 	rb-daap-src.h				\
 	rb-daap-dialog.c			\
 	rb-daap-dialog.h			\
+	rb-daap-mdns-avahi.c			\
 	rb-daap-mdns-publisher-avahi.c		\
 	rb-daap-mdns-browser-avahi.c		\
 	$(NULL)

Added: trunk/plugins/daap/rb-daap-mdns-avahi.c
==============================================================================
--- (empty file)
+++ trunk/plugins/daap/rb-daap-mdns-avahi.c	Sun Nov  9 08:39:04 2008
@@ -0,0 +1,120 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ *  Copyright (C) 2006 William Jon McCann <mccann jhu edu>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * The Rhythmbox authors hereby grant permission for non-GPL compatible
+ * GStreamer plugins to be used and distributed together with GStreamer
+ * and Rhythmbox. This permission is above and beyond the permissions granted
+ * by the GPL license by which Rhythmbox is covered. If you modify this code
+ * you may extend this exception to your version of the code, but you are not
+ * obligated to do so. If you do not wish to do so, delete this exception
+ * statement from your version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
+ *
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <avahi-glib/glib-malloc.h>
+#include <avahi-glib/glib-watch.h>
+#include <avahi-common/error.h>
+
+#include "rb-daap-mdns-avahi.h"
+
+static AvahiClient *client = NULL;
+static AvahiEntryGroup *entry_group = NULL;
+static gsize client_init = 0;
+
+static void
+client_cb (AvahiClient         *client,
+	   AvahiClientState     state,
+	   gpointer             data)
+{
+	/* FIXME
+	 * check to make sure we're in the _RUNNING state before we publish
+	 * check for COLLISION state and remove published information
+	 */
+
+	/* Called whenever the client or server state changes */
+
+	switch (state) {
+	case AVAHI_CLIENT_S_RUNNING:
+		/* The server has startup successfully and registered its host
+		 * name on the network, so it's time to create our services
+		 */
+
+		break;
+
+	case AVAHI_CLIENT_S_COLLISION:
+
+		 /* Let's drop our registered services. When the server is back
+		  * in AVAHI_SERVER_RUNNING state we will register them
+		  * again with the new host name.
+		  */
+		 if (entry_group) {
+			 avahi_entry_group_reset (entry_group);
+		 }
+		 break;
+
+	case AVAHI_CLIENT_FAILURE:
+		 g_warning ("Client failure: %s\n", avahi_strerror (avahi_client_errno (client)));
+		 break;
+
+	case AVAHI_CLIENT_CONNECTING:
+	case AVAHI_CLIENT_S_REGISTERING:
+	default:
+		break;
+	}
+}
+
+AvahiClient *
+rb_daap_mdns_avahi_get_client (void)
+{
+	if (g_once_init_enter (&client_init)) {
+		AvahiClientFlags flags = 0;
+		AvahiGLibPoll *apoll;
+		int error = 0;
+
+		avahi_set_allocator (avahi_glib_allocator ());
+
+		apoll = avahi_glib_poll_new (NULL, G_PRIORITY_DEFAULT);
+		if (apoll == NULL) {
+			g_warning ("Unable to create AvahiGlibPoll object for mDNS");
+		}
+
+		client = avahi_client_new (avahi_glib_poll_get (apoll),
+					   flags,
+					   (AvahiClientCallback) client_cb,
+					   NULL,
+					   &error);
+		if (error != 0) {
+			g_warning ("Unable to initialize mDNS: %s", avahi_strerror (error));
+		}
+
+		g_once_init_leave (&client_init, 1);
+	}
+
+	return client;
+}
+
+void
+rb_daap_mdns_avahi_set_entry_group (AvahiEntryGroup *eg)
+{
+	g_assert (eg == NULL || entry_group == NULL);
+	g_assert (avahi_entry_group_get_client (eg) == client);
+	entry_group = eg;
+}

Added: trunk/plugins/daap/rb-daap-mdns-avahi.h
==============================================================================
--- (empty file)
+++ trunk/plugins/daap/rb-daap-mdns-avahi.h	Sun Nov  9 08:39:04 2008
@@ -0,0 +1,40 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ *  Copyright (C) 2008 Jonathan Matthew  <jonathan d14n org>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The Rhythmbox authors hereby grant permission for non-GPL compatible
+ *  GStreamer plugins to be used and distributed together with GStreamer
+ *  and Rhythmbox. This permission is above and beyond the permissions granted
+ *  by the GPL license by which Rhythmbox is covered. If you modify this code
+ *  you may extend this exception to your version of the code, but you are not
+ *  obligated to do so. If you do not wish to do so, delete this exception
+ *  statement from your version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
+ *
+ */
+
+#ifndef __RB_DAAP_MDNS_AVAHI_H
+#define __RB_DAAP_MDNS_AVAHI_H
+
+#include <avahi-client/client.h>
+#include <avahi-client/publish.h>
+
+AvahiClient *	rb_daap_mdns_avahi_get_client (void);
+
+void		rb_daap_mdns_avahi_set_entry_group (AvahiEntryGroup *group);
+
+#endif
+

Modified: trunk/plugins/daap/rb-daap-mdns-browser-avahi.c
==============================================================================
--- trunk/plugins/daap/rb-daap-mdns-browser-avahi.c	(original)
+++ trunk/plugins/daap/rb-daap-mdns-browser-avahi.c	Sun Nov  9 08:39:04 2008
@@ -44,6 +44,7 @@
 #include <avahi-glib/glib-malloc.h>
 #include <avahi-glib/glib-watch.h>
 
+#include "rb-daap-mdns-avahi.h"
 #include "rb-daap-mdns-browser.h"
 #include "rb-marshal.h"
 #include "rb-debug.h"
@@ -57,7 +58,6 @@
 struct RBDaapMdnsBrowserPrivate
 {
 	AvahiClient         *client;
-	AvahiGLibPoll       *poll;
 	AvahiServiceBrowser *service_browser;
 
 	GSList              *resolvers;
@@ -91,46 +91,6 @@
 }
 
 static void
-client_cb (AvahiClient         *client,
-	   AvahiClientState     state,
-	   RBDaapMdnsBrowser   *browser)
-{
-	/* Called whenever the client or server state changes */
-
-	switch (state) {
-	case AVAHI_CLIENT_FAILURE:
-
-		 g_warning ("Client failure: %s\n", avahi_strerror (avahi_client_errno (client)));
-		 break;
-	default:
-		break;
-	}
-}
-
-static void
-avahi_client_init (RBDaapMdnsBrowser *browser)
-{
-	int error = 0;
-	AvahiClientFlags flags;
-
-	avahi_set_allocator (avahi_glib_allocator ());
-
-	browser->priv->poll = avahi_glib_poll_new (NULL, G_PRIORITY_DEFAULT);
-
-	if (! browser->priv->poll) {
-		rb_debug ("Unable to create AvahiGlibPoll object for mDNS");
-	}
-
-	flags = 0;
-
-	browser->priv->client = avahi_client_new (avahi_glib_poll_get (browser->priv->poll),
-						  flags,
-						  (AvahiClientCallback)client_cb,
-						  browser,
-						  &error);
-}
-
-static void
 resolve_cb (AvahiServiceResolver  *service_resolver,
 	    AvahiIfIndex           interface,
 	    AvahiProtocol          protocol,
@@ -252,7 +212,7 @@
 {
 	gboolean local;
 
-	local = ((flags & AVAHI_LOOKUP_RESULT_LOCAL) != 0);
+	local = ((flags & AVAHI_LOOKUP_RESULT_OUR_OWN) != 0);
 	if (local) {
 		rb_debug ("Ignoring local service %s", name);
 		return;
@@ -401,7 +361,7 @@
 {
 	browser->priv = RB_DAAP_MDNS_BROWSER_GET_PRIVATE (browser);
 
-	avahi_client_init (browser);
+	browser->priv->client = rb_daap_mdns_avahi_get_client ();
 }
 
 static void
@@ -427,14 +387,6 @@
 		avahi_service_browser_free (browser->priv->service_browser);
 	}
 
-	if (browser->priv->client) {
-		avahi_client_free (browser->priv->client);
-	}
-
-	if (browser->priv->poll) {
-		avahi_glib_poll_free (browser->priv->poll);
-	}
-
 	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 

Modified: trunk/plugins/daap/rb-daap-mdns-publisher-avahi.c
==============================================================================
--- trunk/plugins/daap/rb-daap-mdns-publisher-avahi.c	(original)
+++ trunk/plugins/daap/rb-daap-mdns-publisher-avahi.c	Sun Nov  9 08:39:04 2008
@@ -43,6 +43,7 @@
 #include <avahi-glib/glib-malloc.h>
 #include <avahi-glib/glib-watch.h>
 
+#include "rb-daap-mdns-avahi.h"
 #include "rb-daap-mdns-publisher.h"
 #include "rb-debug.h"
 
@@ -55,7 +56,6 @@
 struct RBDaapMdnsPublisherPrivate
 {
 	AvahiClient     *client;
-	AvahiGLibPoll   *poll;
 	AvahiEntryGroup *entry_group;
 
 	char            *name;
@@ -90,70 +90,6 @@
 }
 
 static void
-client_cb (AvahiClient         *client,
-	   AvahiClientState     state,
-	   RBDaapMdnsPublisher *publisher)
-{
-	/* FIXME
-	 * check to make sure we're in the _RUNNING state before we publish
-	 * check for COLLISION state and remove published information
-	 */
-
-	/* Called whenever the client or server state changes */
-
-	switch (state) {
-	case AVAHI_CLIENT_S_RUNNING:
-
-		/* The server has startup successfully and registered its host
-		 * name on the network, so it's time to create our services */
-
-		break;
-
-	case AVAHI_CLIENT_S_COLLISION:
-
-		 /* Let's drop our registered services. When the server is back
-		  * in AVAHI_SERVER_RUNNING state we will register them
-		  * again with the new host name. */
-		 if (publisher->priv->entry_group) {
-			 avahi_entry_group_reset (publisher->priv->entry_group);
-		 }
-		 break;
-
-	case AVAHI_CLIENT_FAILURE:
-
-		 g_warning ("Client failure: %s\n", avahi_strerror (avahi_client_errno (client)));
-		 break;
-	case AVAHI_CLIENT_CONNECTING:
-	case AVAHI_CLIENT_S_REGISTERING:
-	default:
-		break;
-	}
-}
-
-static void
-avahi_client_init (RBDaapMdnsPublisher *publisher)
-{
-	gint error = 0;
-	AvahiClientFlags flags;
-
-	avahi_set_allocator (avahi_glib_allocator ());
-
-	publisher->priv->poll = avahi_glib_poll_new (NULL, G_PRIORITY_DEFAULT);
-
-	if (! publisher->priv->poll) {
-		rb_debug ("Unable to create AvahiGlibPoll object for mDNS");
-	}
-
-	flags = 0;
-
-	publisher->priv->client = avahi_client_new (avahi_glib_poll_get (publisher->priv->poll),
-						    flags,
-						    (AvahiClientCallback)client_cb,
-						    publisher,
-						    &error);
-}
-
-static void
 entry_group_cb (AvahiEntryGroup     *group,
 		AvahiEntryGroupState state,
 		RBDaapMdnsPublisher *publisher)
@@ -180,6 +116,7 @@
 		publisher->priv->entry_group = avahi_entry_group_new (publisher->priv->client,
 								      (AvahiEntryGroupCallback)entry_group_cb,
 								      publisher);
+		rb_daap_mdns_avahi_set_entry_group (publisher->priv->entry_group);
 	} else {
 		avahi_entry_group_reset (publisher->priv->entry_group);
 	}
@@ -377,6 +314,7 @@
 	avahi_entry_group_reset (publisher->priv->entry_group);
 	avahi_entry_group_free (publisher->priv->entry_group);
 	publisher->priv->entry_group = NULL;
+	rb_daap_mdns_avahi_set_entry_group (NULL);
 
 	return TRUE;
 }
@@ -445,7 +383,7 @@
 {
 	publisher->priv = RB_DAAP_MDNS_PUBLISHER_GET_PRIVATE (publisher);
 
-	avahi_client_init (publisher);
+	publisher->priv->client = rb_daap_mdns_avahi_get_client ();
 }
 
 static void
@@ -462,14 +400,7 @@
 
 	if (publisher->priv->entry_group) {
 		avahi_entry_group_free (publisher->priv->entry_group);
-	}
-
-	if (publisher->priv->client) {
-		avahi_client_free (publisher->priv->client);
-	}
-
-	if (publisher->priv->poll) {
-		avahi_glib_poll_free (publisher->priv->poll);
+		rb_daap_mdns_avahi_set_entry_group (NULL);
 	}
 
 	g_free (publisher->priv->name);



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