summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorW. Michael Petullo <mike@flyn.org>2015-09-05 08:26:09 -0400
committerJuan A. Suarez Romero <jasuarez@igalia.com>2015-09-06 16:13:54 +0200
commit29c43ffe2f387061dfa22a5d9af9610d4c247450 (patch)
tree41125021e0c08f37f1cfcc82396bf5cc7c870af8
parentcf67ef3de46c0f6769f48619957a42f4c066cd6e (diff)
downloadgrilo-plugins-29c43ffe2f387061dfa22a5d9af9610d4c247450.tar.gz
dmap: Move some code to grl-common.{c,h} to prepare for DPAP plugin
https://bugzilla.gnome.org/show_bug.cgi?id=746722
-rw-r--r--src/dmap/Makefile.am2
-rw-r--r--src/dmap/grl-common.c45
-rw-r--r--src/dmap/grl-common.h49
-rw-r--r--src/dmap/grl-daap-db.c30
-rw-r--r--src/dmap/grl-daap.c117
5 files changed, 157 insertions, 86 deletions
diff --git a/src/dmap/Makefile.am b/src/dmap/Makefile.am
index 6a00155..c89bb0f 100644
--- a/src/dmap/Makefile.am
+++ b/src/dmap/Makefile.am
@@ -23,6 +23,8 @@ libgrldaap_la_LDFLAGS = \
-avoid-version
libgrldaap_la_SOURCES = \
+ grl-common.c \
+ grl-common.h \
grl-daap.c \
grl-daap.h \
grl-daap-record.c \
diff --git a/src/dmap/grl-common.c b/src/dmap/grl-common.c
new file mode 100644
index 0000000..fa92df9
--- /dev/null
+++ b/src/dmap/grl-common.c
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2011 W. Michael Petullo.
+ * Copyright (C) 2012 Igalia S.L.
+ *
+ * Contact: W. Michael Petullo <mike@flyn.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <errno.h>
+#include <grilo.h>
+#include <glib/gi18n-lib.h>
+#include <gio/gio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <libdmapsharing/dmap.h>
+
+#include "grl-common.h"
+
+gchar *
+grl_dmap_build_url (DMAPMdnsBrowserService *service)
+{
+ return g_strdup_printf ("%s://%s:%u",
+ service->service_name,
+ service->host,
+ service->port);
+}
diff --git a/src/dmap/grl-common.h b/src/dmap/grl-common.h
new file mode 100644
index 0000000..e9c8327
--- /dev/null
+++ b/src/dmap/grl-common.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2011 W. Michael Petullo
+ * Copyright (C) 2012 Igalia S.L.
+ *
+ * Contact: W. Michael Petullo <mike@flyn.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef _GRL_COMMON_H_
+#define _GRL_COMMON_H_
+
+#include <grilo.h>
+#include <libdmapsharing/dmap.h>
+
+typedef struct {
+ GrlSourceResultCb callback;
+ GrlSource *source;
+ GrlMedia *container;
+ guint op_id;
+ GHRFunc predicate;
+ gchar *predicate_data;
+ guint skip;
+ guint count;
+ gpointer user_data;
+} ResultCbAndArgs;
+
+typedef struct {
+ ResultCbAndArgs cb;
+ DMAPDb *db;
+} ResultCbAndArgsAndDb;
+
+gchar *grl_dmap_build_url (DMAPMdnsBrowserService *service);
+
+#endif /* _GRL_COMMON_H_ */
diff --git a/src/dmap/grl-daap-db.c b/src/dmap/grl-daap-db.c
index 5ddd40c..4200e88 100644
--- a/src/dmap/grl-daap-db.c
+++ b/src/dmap/grl-daap-db.c
@@ -151,9 +151,11 @@ set_insert (GHashTable *category, const char *category_name, char *set_name, Grl
}
static guint
-grl_daap_db_add (DMAPDb *_db, DMAPRecord *record)
+grl_daap_db_add (DMAPDb *_db, DMAPRecord *_record)
{
GrlDAAPDb *db = GRL_DAAP_DB (_db);
+ DAAPRecord *record = DAAP_RECORD (_record);
+
gint duration = 0;
gint32 bitrate = 0,
track = 0;
@@ -236,19 +238,6 @@ grl_daap_db_add (DMAPDb *_db, DMAPRecord *record)
return --nextid;
}
-static void
-grl_daap_db_interface_init (gpointer iface, gpointer data)
-{
- DMAPDbIface *daap_db = iface;
-
- g_assert (G_TYPE_FROM_INTERFACE (daap_db) == DMAP_TYPE_DB);
-
- daap_db->add = grl_daap_db_add;
- daap_db->lookup_by_id = grl_daap_db_lookup_by_id;
- daap_db->foreach = grl_daap_db_foreach;
- daap_db->count = grl_daap_db_count;
-}
-
static gboolean
same_media (GrlMedia *a, GrlMedia *b)
{
@@ -360,8 +349,19 @@ grl_daap_db_search (GrlDAAPDb *db,
}
}
+static void
+dmap_db_interface_init (gpointer iface, gpointer data)
+{
+ DMAPDbIface *daap_db = iface;
+
+ daap_db->add = grl_daap_db_add;
+ daap_db->lookup_by_id = grl_daap_db_lookup_by_id;
+ daap_db->foreach = grl_daap_db_foreach;
+ daap_db->count = grl_daap_db_count;
+}
+
G_DEFINE_TYPE_WITH_CODE (GrlDAAPDb, grl_daap_db, G_TYPE_OBJECT,
- G_IMPLEMENT_INTERFACE (DMAP_TYPE_DB, grl_daap_db_interface_init))
+ G_IMPLEMENT_INTERFACE (DMAP_TYPE_DB, dmap_db_interface_init))
static GObject*
grl_daap_db_constructor (GType type, guint n_construct_params, GObjectConstructParam *construct_params)
diff --git a/src/dmap/grl-daap.c b/src/dmap/grl-daap.c
index 0142bf7..2cb683a 100644
--- a/src/dmap/grl-daap.c
+++ b/src/dmap/grl-daap.c
@@ -33,6 +33,7 @@
#include <stdlib.h>
#include <libdmapsharing/dmap.h>
+#include "grl-common.h"
#include "grl-daap.h"
#include "grl-daap-db.h"
#include "grl-daap-record.h"
@@ -63,23 +64,6 @@ struct _GrlDaapSourcePrivate {
/* --- Data types --- */
-typedef struct _ResultCbAndArgs {
- GrlSourceResultCb callback;
- GrlSource *source;
- GrlMedia *container;
- guint op_id;
- GHRFunc predicate;
- gchar *predicate_data;
- guint skip;
- guint count;
- gpointer user_data;
-} ResultCbAndArgs;
-
-typedef struct _ResultCbAndArgsAndDb {
- ResultCbAndArgs cb;
- GrlDAAPDb *db;
-} ResultCbAndArgsAndDb;
-
static GrlDaapSource *grl_daap_source_new (DMAPMdnsBrowserService *service);
static void grl_daap_source_finalize (GObject *object);
@@ -97,13 +81,13 @@ static void grl_daap_source_search (GrlSource *source,
GrlSourceSearchSpec *ss);
-static void service_added_cb (DMAPMdnsBrowser *browser,
- DMAPMdnsBrowserService *service,
- GrlPlugin *plugin);
+static void grl_daap_service_added_cb (DMAPMdnsBrowser *browser,
+ DMAPMdnsBrowserService *service,
+ GrlPlugin *plugin);
-static void service_removed_cb (DMAPMdnsBrowser *browser,
- const gchar *service_name,
- GrlPlugin *plugin);
+static void grl_daap_service_removed_cb (DMAPMdnsBrowser *browser,
+ const gchar *service_name,
+ GrlPlugin *plugin);
/* ===================== Globals ======================= */
static DMAPMdnsBrowser *browser;
@@ -135,12 +119,12 @@ grl_daap_plugin_init (GrlRegistry *registry,
g_signal_connect (G_OBJECT (browser),
"service-added",
- G_CALLBACK (service_added_cb),
+ G_CALLBACK (grl_daap_service_added_cb),
(gpointer) plugin);
g_signal_connect (G_OBJECT (browser),
"service-removed",
- G_CALLBACK (service_removed_cb),
+ G_CALLBACK (grl_daap_service_removed_cb),
(gpointer) plugin);
if (!dmap_mdns_browser_start (browser, &error)) {
@@ -223,40 +207,31 @@ grl_daap_source_finalize (GObject *object)
/* ======================= Utilities ==================== */
-static gchar *
-build_url (DMAPMdnsBrowserService *service)
-{
- return g_strdup_printf ("%s://%s:%u",
- service->service_name,
- service->host,
- service->port);
-}
-
static void
-do_browse (ResultCbAndArgsAndDb *cb_and_db)
+grl_daap_do_browse (ResultCbAndArgsAndDb *cb_and_db)
{
- grl_daap_db_browse (cb_and_db->db,
- cb_and_db->cb.container,
- cb_and_db->cb.source,
- cb_and_db->cb.op_id,
- cb_and_db->cb.skip,
- cb_and_db->cb.count,
- cb_and_db->cb.callback,
- cb_and_db->cb.user_data);
+ grl_daap_db_browse(GRL_DAAP_DB(cb_and_db->db),
+ cb_and_db->cb.container,
+ cb_and_db->cb.source,
+ cb_and_db->cb.op_id,
+ cb_and_db->cb.skip,
+ cb_and_db->cb.count,
+ cb_and_db->cb.callback,
+ cb_and_db->cb.user_data);
g_free (cb_and_db);
}
static void
-do_search (ResultCbAndArgsAndDb *cb_and_db)
+grl_daap_do_search (ResultCbAndArgsAndDb *cb_and_db)
{
- grl_daap_db_search (cb_and_db->db,
- cb_and_db->cb.source,
- cb_and_db->cb.op_id,
- (GHRFunc) cb_and_db->cb.predicate,
- cb_and_db->cb.predicate_data,
- cb_and_db->cb.callback,
- cb_and_db->cb.user_data);
+ grl_daap_db_search(GRL_DAAP_DB(cb_and_db->db),
+ cb_and_db->cb.source,
+ cb_and_db->cb.op_id,
+ (GHRFunc) cb_and_db->cb.predicate,
+ cb_and_db->cb.predicate_data,
+ cb_and_db->cb.callback,
+ cb_and_db->cb.user_data);
g_free (cb_and_db);
}
@@ -282,7 +257,7 @@ browse_connected_cb (DMAPConnection *connection,
error);
g_error_free (error);
} else {
- do_browse (cb_and_db);
+ grl_daap_do_browse (cb_and_db);
}
}
@@ -307,14 +282,14 @@ search_connected_cb (DMAPConnection *connection,
error);
g_error_free (error);
} else {
- do_search (cb_and_db);
+ grl_daap_do_search (cb_and_db);
}
}
static void
-service_added_cb (DMAPMdnsBrowser *browser,
- DMAPMdnsBrowserService *service,
- GrlPlugin *plugin)
+grl_daap_service_added_cb (DMAPMdnsBrowser *browser,
+ DMAPMdnsBrowserService *service,
+ GrlPlugin *plugin)
{
GrlRegistry *registry = grl_registry_get_default ();
GrlDaapSource *source = grl_daap_source_new (service);
@@ -333,9 +308,9 @@ service_added_cb (DMAPMdnsBrowser *browser,
}
static void
-service_removed_cb (DMAPMdnsBrowser *browser,
- const gchar *service_name,
- GrlPlugin *plugin)
+grl_daap_service_removed_cb (DMAPMdnsBrowser *browser,
+ const gchar *service_name,
+ GrlPlugin *plugin)
{
GrlRegistry *registry = grl_registry_get_default ();
GrlDaapSource *source = g_hash_table_lookup (sources, service_name);
@@ -360,7 +335,7 @@ grl_daap_connect (gchar *name, gchar *host, guint port, ResultCbAndArgsAndDb *cb
}
static gboolean
-match (GrlMedia *media, gpointer val, gpointer user_data)
+grl_daap_match (GrlMedia *media, gpointer val, gpointer user_data)
{
g_assert (GRL_IS_MEDIA_AUDIO (media) || GRL_IS_MEDIA_VIDEO (media));
@@ -400,8 +375,8 @@ static void
grl_daap_source_browse (GrlSource *source,
GrlSourceBrowseSpec *bs)
{
- GrlDaapSource *daap_source = GRL_DAAP_SOURCE (source);
- gchar *url = build_url (daap_source->priv->service);
+ GrlDaapSource *dmap_source = GRL_DAAP_SOURCE (source);
+ gchar *url = grl_dmap_build_url (dmap_source->priv->service);
GRL_DEBUG (__func__);
@@ -422,11 +397,11 @@ grl_daap_source_browse (GrlSource *source,
browse_connected_cb (NULL, TRUE, NULL, cb_and_db);
} else {
/* Connect */
- cb_and_db->db = grl_daap_db_new ();
+ cb_and_db->db = DMAP_DB (grl_daap_db_new ());
- grl_daap_connect (daap_source->priv->service->name,
- daap_source->priv->service->host,
- daap_source->priv->service->port,
+ grl_daap_connect (dmap_source->priv->service->name,
+ dmap_source->priv->service->host,
+ dmap_source->priv->service->port,
cb_and_db,
(DMAPConnectionCallback) browse_connected_cb);
@@ -439,11 +414,11 @@ grl_daap_source_browse (GrlSource *source,
static void grl_daap_source_search (GrlSource *source,
GrlSourceSearchSpec *ss)
{
- GrlDaapSource *daap_source = GRL_DAAP_SOURCE (source);
+ GrlDaapSource *dmap_source = GRL_DAAP_SOURCE (source);
ResultCbAndArgsAndDb *cb_and_db;
- DMAPMdnsBrowserService *service = daap_source->priv->service;
- gchar *url = build_url (service);
+ DMAPMdnsBrowserService *service = dmap_source->priv->service;
+ gchar *url = grl_dmap_build_url (service);
cb_and_db = g_new (ResultCbAndArgsAndDb, 1);
@@ -451,7 +426,7 @@ static void grl_daap_source_search (GrlSource *source,
cb_and_db->cb.source = ss->source;
cb_and_db->cb.container = NULL;
cb_and_db->cb.op_id = ss->operation_id;
- cb_and_db->cb.predicate = (GHRFunc) match;
+ cb_and_db->cb.predicate = (GHRFunc) grl_daap_match;
cb_and_db->cb.predicate_data = ss->text;
cb_and_db->cb.user_data = ss->user_data;
@@ -460,7 +435,7 @@ static void grl_daap_source_search (GrlSource *source,
search_connected_cb (NULL, TRUE, NULL, cb_and_db);
} else {
/* Connect */
- cb_and_db->db = grl_daap_db_new ();
+ cb_and_db->db = DMAP_DB (grl_daap_db_new ());
grl_daap_connect (service->name, service->host, service->port, cb_and_db, (DMAPConnectionCallback) search_connected_cb);
g_hash_table_insert (connections, g_strdup (url), cb_and_db->db);
}