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



commit ce885836bc43dd928f2cbd068a04d94ef655ff26
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 |  153 +++++++++++++++++++++
 src/media-export/rygel-media-export-media-cache.h |   17 +++
 3 files changed, 172 insertions(+), 1 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..8e0a31a 100644
--- a/src/media-export/rygel-media-export-media-cache.c
+++ b/src/media-export/rygel-media-export-media-cache.c
@@ -21,6 +21,7 @@
 
 #include <glib/gi18n-lib.h>
 #include <sqlite3.h>
+#include <uuid.h>
 
 #include "rygel-media-export-database-cursor.h"
 #include "rygel-media-export-database.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,78 @@ 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) {
+    uuid_t uu;
+
+    g_warning ("Failed to get reset token: %s", inner_error->message);
+    g_error_free (inner_error);
+    uuid_generate (uu);
+    token = g_malloc (51);
+    uuid_unparse (uu, token);
+    token[50] = '\0';
+  }
+
+  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) {
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]