[gnome-online-miners] media-server: Added implementation for searchable servers
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-online-miners] media-server: Added implementation for searchable servers
- Date: Thu, 28 Aug 2014 00:45:32 +0000 (UTC)
commit 9732941f83fbe7823f3d164b9fbd1279692d5145
Author: Pranav Kant <pranav913 gmail com>
Date: Fri Jun 20 03:16:14 2014 +0530
media-server: Added implementation for searchable servers
https://bugzilla.gnome.org/show_bug.cgi?id=728912
configure.ac | 2 +-
src/gom-media-server-miner.c | 208 +++++++++++++++++++++++++++++++++++++++++-
src/gom-media-server-miner.h | 3 +
3 files changed, 211 insertions(+), 2 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 93d354a..395c56a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -22,7 +22,7 @@ AC_HEADER_STDC
GDATA_MIN_VERSION=0.15.2
GFBGRAPH_MIN_VERSION=0.2.2
GLIB_MIN_VERSION=2.35.1
-GOA_MIN_VERSION=3.7.3
+GOA_MIN_VERSION=3.13.3
GRILO_MIN_VERSION=0.2.6
ZAPOJIT_MIN_VERSION=0.0.2
diff --git a/src/gom-media-server-miner.c b/src/gom-media-server-miner.c
index 863ef04..eb46ce5 100644
--- a/src/gom-media-server-miner.c
+++ b/src/gom-media-server-miner.c
@@ -25,16 +25,220 @@
#include <goa/goa.h>
+#include "gom-dlna-server.h"
+#include "gom-dlna-servers-manager.h"
#include "gom-media-server-miner.h"
#define MINER_IDENTIFIER "gd:media-server:miner:a4a47a3e-eb55-11e3-b983-14feb59cfa0e"
-G_DEFINE_TYPE (GomMediaServerMiner, gom_media_server_miner, GOM_TYPE_MINER)
+struct _GomMediaServerMinerPrivate {
+ GomDlnaServersManager *mngr;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (GomMediaServerMiner, gom_media_server_miner, GOM_TYPE_MINER)
+
+typedef struct {
+ gchar *name;
+ gchar *mimetype;
+ gchar *path;
+ gchar *url;
+} PhotoItem;
+
+static PhotoItem *
+photo_item_new (GVariant *var)
+{
+ GVariant *tmp;
+ PhotoItem *photo;
+ const gchar *str;
+
+ photo = g_slice_new0 (PhotoItem);
+
+ g_variant_lookup (var, "DisplayName", "&s", &str);
+ photo->name = g_strdup (str);
+
+ g_variant_lookup (var, "MIMEType", "&s", &str);
+ photo->mimetype = g_strdup (str);
+
+ g_variant_lookup (var, "Path", "&o", &str);
+ photo->path = g_strdup (str);
+
+ g_variant_lookup (var, "URLs", "@as", &tmp);
+ g_variant_get_child (tmp, 0, "&s", &str);
+ photo->url = g_strdup (str);
+ g_variant_unref (tmp);
+
+ return photo;
+}
+
+static void
+photo_item_free (PhotoItem *photo)
+{
+ g_free (photo->name);
+ g_free (photo->mimetype);
+ g_free (photo->path);
+ g_free (photo->url);
+ g_slice_free (PhotoItem, photo);
+}
+
+static gboolean
+account_miner_job_process_photo (GomAccountMinerJob *job,
+ PhotoItem *photo,
+ GError **error)
+{
+ const gchar *photo_id;
+ gchar *identifier;
+ const gchar *class = "nmm:Photo";
+ gchar *resource = NULL;
+ gboolean resource_exists;
+ gchar **tmp_arr;
+
+ tmp_arr = g_strsplit_set (photo->path, "/", -1);
+ photo_id = tmp_arr[g_strv_length (tmp_arr) - 1];
+ identifier = g_strdup_printf ("media-server:%s", photo_id);
+
+ /* remove from the list of the previous resources */
+ g_hash_table_remove (job->previous_resources, identifier);
+
+ resource = gom_tracker_sparql_connection_ensure_resource
+ (job->connection,
+ job->cancellable, error,
+ &resource_exists,
+ job->datasource_urn, identifier,
+ "nfo:RemoteDataObject", class, NULL);
+
+ if (*error != NULL)
+ goto out;
+
+ gom_tracker_update_datasource (job->connection, job->datasource_urn,
+ resource_exists, identifier, resource,
+ job->cancellable, error);
+ if (*error != NULL)
+ goto out;
+
+ /* the resource changed - just set all the properties again */
+ gom_tracker_sparql_connection_insert_or_replace_triple
+ (job->connection,
+ job->cancellable, error,
+ job->datasource_urn, resource,
+ "nie:url", photo->url);
+
+ if (*error != NULL)
+ goto out;
+
+ gom_tracker_sparql_connection_insert_or_replace_triple
+ (job->connection,
+ job->cancellable, error,
+ job->datasource_urn, resource,
+ "nie:mimeType", photo->mimetype);
+
+ if (*error != NULL)
+ goto out;
+
+ gom_tracker_sparql_connection_insert_or_replace_triple
+ (job->connection,
+ job->cancellable, error,
+ job->datasource_urn, resource,
+ "nie:title", photo->name);
+
+ if (*error != NULL)
+ goto out;
+
+ out:
+ g_free (resource);
+ g_free (identifier);
+ g_strfreev (tmp_arr);
+
+ if (*error != NULL)
+ return FALSE;
+
+ return TRUE;
+}
+
+static GList *
+get_photos (GomMediaServerMiner *self,
+ const gchar *udn)
+{
+ GomDlnaServer *server;
+ GList *photos_list = NULL;
+ GError *error = NULL;
+ GVariant *out, *var;
+ GVariantIter *iter = NULL;
+ PhotoItem *photo;
+
+ server = gom_dlna_servers_manager_get_server (self->priv->mngr, udn);
+ if (server == NULL)
+ return NULL; /* Server is offline. */
+
+ if (gom_dlna_server_get_searchable (server))
+ {
+ out = gom_dlna_server_search_objects (server, &error);
+ if (error != NULL)
+ {
+ g_warning ("Unable to search objects on server : %s",
+ error->message);
+ g_error_free (error);
+ return NULL;
+ }
+
+ g_variant_get (out, "aa{sv}", &iter);
+ while (g_variant_iter_loop (iter, "@a{sv}", &var))
+ {
+ photo = photo_item_new (var);
+ photos_list = g_list_prepend (photos_list, photo);
+ }
+
+ g_variant_iter_free (iter);
+ }
+ else
+ {
+ /* TODO: Implement an algo here for !searchable devices. */
+ }
+
+ return photos_list;
+}
static void
query_media_server (GomAccountMinerJob *job,
GError **error)
{
+ GomMediaServerMiner *self = GOM_MEDIA_SERVER_MINER (job->miner);
+ GomMediaServerMinerPrivate *priv = self->priv;
+ GError *local_error = NULL;
+ GoaMediaServer *server;
+ GList *l;
+ GList *photos_list;
+ GoaObject *object;
+ const gchar *udn;
+
+ object = GOA_OBJECT (g_hash_table_lookup (job->services, "photos"));
+ if (object == NULL)
+ {
+ /* FIXME: use proper #defines and enumerated types */
+ g_set_error (error,
+ g_quark_from_static_string ("gom-error"),
+ 0,
+ "Can not query without a service");
+ return;
+ }
+
+ server = goa_object_get_media_server (object);
+ udn = goa_media_server_get_udn (server);
+
+ photos_list = get_photos (self, udn);
+ for (l = photos_list; l != NULL; l = l->next)
+ {
+ PhotoItem *photo = (PhotoItem *) l->data;
+
+ account_miner_job_process_photo (job, photo, &local_error);
+ if (local_error != NULL)
+ {
+ g_warning ("Unable to process photo: %s", local_error->message);
+ g_clear_error (&local_error);
+ }
+ }
+
+ g_list_free_full (photos_list, (GDestroyNotify) photo_item_free);
+ g_object_unref (server);
}
static GHashTable *
@@ -55,6 +259,8 @@ create_services (GomMiner *self,
static void
gom_media_server_miner_init (GomMediaServerMiner *miner)
{
+ miner->priv = gom_media_server_miner_get_instance_private (miner);
+ miner->priv->mngr = gom_dlna_servers_manager_dup_singleton ();
}
static void
diff --git a/src/gom-media-server-miner.h b/src/gom-media-server-miner.h
index e6b4afb..a8c6411 100644
--- a/src/gom-media-server-miner.h
+++ b/src/gom-media-server-miner.h
@@ -53,9 +53,12 @@ G_BEGIN_DECLS
typedef struct _GomMediaServerMiner GomMediaServerMiner;
typedef struct _GomMediaServerMinerClass GomMediaServerMinerClass;
+typedef struct _GomMediaServerMinerPrivate GomMediaServerMinerPrivate;
struct _GomMediaServerMiner {
GomMiner parent;
+
+ GomMediaServerMinerPrivate *priv;
};
struct _GomMediaServerMinerClass {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]