[rygel-gst-0-10-plugins/wip/tracking: 4/8] Update media cache to store tracking properties.



commit 1f6dcc0bcf8db630829803d249b499165f359a88
Author: Krzesimir Nowak <krnowak openismus com>
Date:   Tue Feb 19 13:27:09 2013 +0100

    Update media cache to store tracking properties.

 configure.ac                                      |    3 +-
 src/media-export/rygel-media-export-media-cache.c |  198 ++++++++++++++++++++-
 src/media-export/rygel-media-export-media-cache.h |   17 ++
 3 files changed, 211 insertions(+), 7 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 7929d9f..b0c18b4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -35,6 +35,7 @@ GSTREAMER_REQUIRED=0.10.36
 GSTPBU_REQUIRED=0.10.35
 GIO_REQUIRED=2.26
 GEE_REQUIRED=0.8.0
+UUID_REQUIRED=1.41.3
 
 dnl Additional requirements for media-export plugin
 GSTREAMER_TAG_REQUIRED=0.10.28
@@ -44,7 +45,7 @@ LIBSQLITE3_REQUIRED=3.5
 
 RYGEL_BASE_MODULES="gupnp-1.0 >= $GUPNP_REQUIRED gee-0.8 >= $GEE_REQUIRED"
 RYGEL_COMMON_MODULES="$RYGEL_BASE_MODULES gupnp-av-1.0 >= $GUPNP_AV_REQUIRED"
-PKG_CHECK_MODULES([DEPS], [$RYGEL_COMMON_MODULES rygel-server-2.0 >= $LIBRYGEL_SERVER_REQUIRED gio-2.0 >= 
$GIO_REQUIRED gstreamer-0.10 >= $GSTREAMER_REQUIRED gstreamer-pbutils-0.10 >= $GSTPBU_REQUIRED gupnp-dlna-2.0 
= $GUPNP_DLNA_REQUIRED gupnp-dlna-gst-legacy-2.0 >= $GUPNP_DLNA_REQUIRED gstreamer-tag-0.10 >= 
$GSTREAMER_TAG_REQUIRED gstreamer-app-0.10 >= $GSTREAMER_TAG_REQUIRED sqlite3 >= $LIBSQLITE3_REQUIRED])
+PKG_CHECK_MODULES([DEPS], [$RYGEL_COMMON_MODULES rygel-server-2.0 >= $LIBRYGEL_SERVER_REQUIRED gio-2.0 >= 
$GIO_REQUIRED gstreamer-0.10 >= $GSTREAMER_REQUIRED gstreamer-pbutils-0.10 >= $GSTPBU_REQUIRED gupnp-dlna-2.0 
= $GUPNP_DLNA_REQUIRED gupnp-dlna-gst-legacy-2.0 >= $GUPNP_DLNA_REQUIRED gstreamer-tag-0.10 >= 
$GSTREAMER_TAG_REQUIRED gstreamer-app-0.10 >= $GSTREAMER_TAG_REQUIRED sqlite3 >= $LIBSQLITE3_REQUIRED uuid >= 
$UUID_REQUIRED])
 
 AC_CHECK_HEADER([unistr.h],
                 AC_CHECK_LIB([unistring],
diff --git a/src/media-export/rygel-media-export-media-cache.c 
b/src/media-export/rygel-media-export-media-cache.c
index b767457..7cb3dfb 100644
--- a/src/media-export/rygel-media-export-media-cache.c
+++ b/src/media-export/rygel-media-export-media-cache.c
@@ -34,6 +34,7 @@
 #include "rygel-media-export-sql-function.h"
 #include "rygel-media-export-sql-operator.h"
 #include "rygel-media-export-string-utils.h"
+#include "rygel-media-export-uuid.h"
 #include "rygel-media-export-video-item.h"
 
 /**
@@ -425,6 +426,86 @@ rygel_media_export_media_cache_get_child_count (RygelMediaExportMediaCache  *sel
   return count;
 }
 
+guint32
+rygel_media_export_media_cache_get_update_id (RygelMediaExportMediaCache *self)
+{
+  GError *inner_error;
+  guint32 id;
+
+  g_return_val_if_fail (RYGEL_MEDIA_EXPORT_IS_MEDIA_CACHE (self), 0);
+
+  inner_error = NULL;
+  id = (guint32) rygel_media_export_media_cache_query_value (self,
+                                                             RYGEL_MEDIA_EXPORT_SQL_STRING_MAX_UPDATE_ID,
+                                                             NULL,
+                                                             0,
+                                                             &inner_error);
+
+  if (inner_error) {
+    g_error_free (inner_error);
+    id = 0;
+  }
+
+  return id;
+}
+
+#define TRACK_PROPERTIES_SQL \
+  "SELECT object_update_id, " \
+  "container_update_id, " \
+  "deleted_child_count " \
+  "FROM Object WHERE upnp_id = ?"
+
+void
+rygel_media_export_media_cache_get_track_properties (RygelMediaExportMediaCache *self,
+                                                     const gchar                *id,
+                                                     guint32                    *object_update_id,
+                                                     guint32                    *container_update_id,
+                                                     guint32                    *total_deleted_child_count)
+{
+  GValue value = G_VALUE_INIT;
+  GError *inner_error;
+  RygelMediaExportDatabaseCursor *cursor;
+  sqlite3_stmt *statement;
+
+  g_return_if_fail (RYGEL_MEDIA_EXPORT_IS_MEDIA_CACHE (self));
+
+  inner_error = NULL;
+  g_value_init (&value, G_TYPE_STRING);
+  g_value_set_string (&value, id);
+  cursor = rygel_media_export_database_exec_cursor (self->priv->db,
+                                                    TRACK_PROPERTIES_SQL,
+                                                    &value,
+                                                    1,
+                                                    &inner_error);
+  g_value_unset (&value);
+  if (inner_error) {
+    goto out;
+  }
+
+  statement = rygel_media_export_database_cursor_next (cursor, &inner_error);
+  if (inner_error) {
+    g_object_unref (cursor);
+    goto out;
+  }
+
+  if (object_update_id) {
+    *object_update_id = (guint32) sqlite3_column_int64 (statement, 0);
+  }
+  if (container_update_id) {
+    *container_update_id = (guint32) sqlite3_column_int64 (statement, 1);
+  }
+  if (total_deleted_child_count) {
+    *total_deleted_child_count = (guint32) sqlite3_column_int64 (statement, 2);
+  }
+  g_object_unref (cursor);
+
+ out:
+  if (inner_error) {
+    g_warning ("Failed to get updated ids: %s", inner_error->message);
+    g_error_free (inner_error);
+  }
+}
+
 gboolean
 rygel_media_export_media_cache_exists (RygelMediaExportMediaCache  *self,
                                        GFile                       *file,
@@ -1078,6 +1159,73 @@ rygel_media_export_media_cache_get_flagged_uris (RygelMediaExportMediaCache  *se
   return GEE_LIST (uris);
 }
 
+gchar *
+rygel_media_export_media_cache_get_reset_token (RygelMediaExportMediaCache *self)
+{
+  GError *inner_error;
+  RygelMediaExportDatabaseCursor *cursor;
+  sqlite3_stmt *statement;
+  gchar *token;
+
+  g_return_val_if_fail (RYGEL_MEDIA_EXPORT_IS_MEDIA_CACHE (self), NULL);
+
+  inner_error = NULL;
+  cursor = rygel_media_export_media_cache_exec_cursor (self,
+                                                       RYGEL_MEDIA_EXPORT_SQL_STRING_RESET_TOKEN,
+                                                       NULL,
+                                                       0,
+                                                       &inner_error);
+  if (inner_error) {
+    goto out;
+  }
+
+  statement = rygel_media_export_database_cursor_next (cursor, &inner_error);
+  if (inner_error) {
+    g_object_unref (cursor);
+    goto out;
+  }
+
+  token = g_strdup ((const gchar *) sqlite3_column_text (statement, 0));
+  g_object_unref (cursor);
+
+ out:
+  if (inner_error) {
+    g_warning ("Failed to get reset token: %s", inner_error->message);
+    g_error_free (inner_error);
+    token = rygel_media_export_uuid_get ();
+  }
+
+  return token;
+}
+
+#define SAVE_RESET_TOKEN_SQL \
+  "UPDATE schema_info SET reset_token = ?"
+
+void
+rygel_media_export_media_cache_save_reset_token (RygelMediaExportMediaCache *self,
+                                                 const gchar                *token)
+{
+  GValue value = G_VALUE_INIT;
+  GError *inner_error;
+
+  g_return_if_fail (RYGEL_MEDIA_EXPORT_IS_MEDIA_CACHE (self));
+  g_return_if_fail (token != NULL);
+
+  inner_error = NULL;
+  g_value_init (&value, G_TYPE_STRING);
+  g_value_set_string (&value, token);
+  rygel_media_export_database_exec (self->priv->db,
+                                    SAVE_RESET_TOKEN_SQL,
+                                    &value,
+                                    1,
+                                    &inner_error);
+  g_value_unset (&value);
+  if (inner_error) {
+    g_warning ("Failed to persist ServiceResetToken: %s", inner_error->message);
+    g_error_free (inner_error);
+  }
+}
+
 static void
 rygel_media_export_media_cache_get_exists_cache (RygelMediaExportMediaCache  *self,
                                                  GError                     **error) {
@@ -1387,7 +1535,10 @@ rygel_media_export_media_cache_create_object (RygelMediaExportMediaCache  *self,
                      G_VALUE_INIT,  /* type */
                      G_VALUE_INIT,  /* parent */
                      G_VALUE_INIT,  /* object modified */
-                     G_VALUE_INIT}; /* object uri */
+                     G_VALUE_INIT,  /* object uri */
+                     G_VALUE_INIT,  /* object update id */
+                     G_VALUE_INIT,  /* total deleted child count */
+                     G_VALUE_INIT}; /* container update id */
   gint type;
   GError *inner_error;
   RygelMediaObject *object_parent;
@@ -1433,6 +1584,25 @@ rygel_media_export_media_cache_create_object (RygelMediaExportMediaCache  *self,
   g_value_init (&(values[5]), G_TYPE_STRING);
   g_value_take_string (&(values[5]), uri);
 
+  g_value_init (&(values[6]), G_TYPE_UINT);
+  g_value_set_uint (&(values[6]), rygel_media_object_get_object_update_id (object));
+
+  if (RYGEL_IS_MEDIA_CONTAINER (object)) {
+    RygelMediaContainer *container = RYGEL_MEDIA_CONTAINER (object);
+
+    g_value_init (&(values[7]), G_TYPE_INT64);
+    g_value_set_int64 (&(values[7]), container->total_deleted_child_count);
+
+    g_value_init (&(values[8]), G_TYPE_UINT);
+    g_value_set_uint (&(values[8]), container->update_id);
+  } else {
+    g_value_init (&(values[7]), G_TYPE_INT);
+    g_value_set_int (&(values[7]), -1);
+
+    g_value_init (&(values[8]), G_TYPE_INT);
+    g_value_set_int (&(values[8]), -1);
+  }
+
   inner_error = NULL;
   rygel_media_export_database_exec (priv->db,
                                     rygel_media_export_sql_factory_make (priv->sql, 
RYGEL_MEDIA_EXPORT_SQL_STRING_INSERT),
@@ -1460,6 +1630,7 @@ static gboolean
 rygel_media_export_media_cache_create_schema (RygelMediaExportMediaCache *self) {
   GError *inner_error;
   RygelMediaExportMediaCachePrivate *priv;
+  gchar *uu;
 
   g_return_val_if_fail (RYGEL_MEDIA_EXPORT_IS_MEDIA_CACHE (self), FALSE);
 
@@ -1521,6 +1692,10 @@ rygel_media_export_media_cache_create_schema (RygelMediaExportMediaCache *self)
   }
 
   rygel_media_export_database_analyze (priv->db);
+
+  uu = rygel_media_export_uuid_get ();
+  rygel_media_export_media_cache_save_reset_token (self, uu);
+  g_free (uu);
  out:
   if (inner_error) {
     g_warning ("Failed to create schema: %s", inner_error->message);
@@ -1550,14 +1725,19 @@ rygel_media_export_media_cache_get_object_from_statement (RygelMediaExportMediaC
   uri = (const gchar *) sqlite3_column_text (statement, (gint) RYGEL_MEDIA_EXPORT_DETAIL_COLUMN_URI);
   switch (sqlite3_column_int (statement, (gint) RYGEL_MEDIA_EXPORT_DETAIL_COLUMN_TYPE)) {
   case 0: { /* container */
-    object = RYGEL_MEDIA_OBJECT (rygel_media_export_object_factory_get_container (priv->factory,
-                                                                                  object_id,
-                                                                                  title,
-                                                                                  (guint) 0,
-                                                                                  uri));
+    RygelMediaContainer *container = RYGEL_MEDIA_CONTAINER (rygel_media_export_object_factory_get_container 
(priv->factory,
+                                                                                                             
object_id,
+                                                                                                             
title,
+                                                                                                             
(guint) 0,
+                                                                                                             
uri));
+
+    object = RYGEL_MEDIA_OBJECT (container);
     if (uri) {
       gee_abstract_collection_add (GEE_ABSTRACT_COLLECTION (object->uris), uri);
     }
+    container->total_deleted_child_count = (guint32) sqlite3_column_int64 (statement, (gint) 
RYGEL_MEDIA_EXPORT_DETAIL_COLUMN_DELETED_CHILD_COUNT);
+    container->update_id = (guint) sqlite3_column_int64 (statement, (gint) 
RYGEL_MEDIA_EXPORT_DETAIL_COLUMN_CONTAINER_UPDATE_ID);
+
     break;
   }
 
@@ -1589,6 +1769,8 @@ rygel_media_export_media_cache_get_object_from_statement (RygelMediaExportMediaC
       rygel_media_object_set_modified (object, 0);
       rygel_media_item_set_place_holder (RYGEL_MEDIA_ITEM (object), TRUE);
     }
+
+    rygel_media_object_set_object_update_id (object, (guint) sqlite3_column_int64 (statement, (gint) 
RYGEL_MEDIA_EXPORT_DETAIL_COLUMN_OBJECT_UPDATE_ID));
   }
 
   return object;
@@ -1797,6 +1979,10 @@ rygel_media_export_media_cache_map_operand_to_column (const gchar  *operand,
     column = "m.track";
   } else if (!g_strcmp0 (operand, "rygel:originalVolumeNumber")) {
     column = "m.disc";
+  } else if (!g_strcmp0 (operand, "upnp:objectUpdateID")) {
+    column = "o.object_update_id";
+  } else if (!g_strcmp0 (operand, "upnp:containerUpdateID")) {
+    column = "o.container_update_id";
   } else {
     g_set_error (error,
                  RYGEL_MEDIA_EXPORT_MEDIA_CACHE_ERROR,
diff --git a/src/media-export/rygel-media-export-media-cache.h 
b/src/media-export/rygel-media-export-media-cache.h
index 7201e3a..dcfd40e 100644
--- a/src/media-export/rygel-media-export-media-cache.h
+++ b/src/media-export/rygel-media-export-media-cache.h
@@ -100,6 +100,16 @@ rygel_media_export_media_cache_get_child_count (RygelMediaExportMediaCache  *sel
                                                 const gchar                 *container_id,
                                                 GError                     **error);
 
+guint32
+rygel_media_export_media_cache_get_update_id (RygelMediaExportMediaCache *self);
+
+void
+rygel_media_export_media_cache_get_track_properties (RygelMediaExportMediaCache *self,
+                                                     const gchar                *id,
+                                                     guint32                    *object_update_id,
+                                                     guint32                    *container_update_id,
+                                                     guint32                    *total_deleted_child_count);
+
 gboolean
 rygel_media_export_media_cache_exists (RygelMediaExportMediaCache  *self,
                                        GFile                       *file,
@@ -184,6 +194,13 @@ rygel_media_export_media_cache_get_flagged_uris (RygelMediaExportMediaCache  *se
                                                  const gchar                 *flag,
                                                  GError                     **error);
 
+gchar *
+rygel_media_export_media_cache_get_reset_token (RygelMediaExportMediaCache *self);
+
+void
+rygel_media_export_media_cache_save_reset_token (RygelMediaExportMediaCache *self,
+                                                 const gchar                *token);
+
 G_END_DECLS
 
 #endif /* __RYGEL_0_10_PLUGINS_MEDIA_EXPORT_MEDIA_CACHE_H__ */


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