[rygel] media-export: Persist change tracking properties
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel] media-export: Persist change tracking properties
- Date: Wed, 12 Dec 2012 18:25:21 +0000 (UTC)
commit 950a2c622148e98cd00b6df0383a74e78492198f
Author: Jens Georg <jensg openismus com>
Date: Thu Dec 6 16:55:07 2012 +0100
media-export: Persist change tracking properties
https://bugzilla.gnome.org/show_bug.cgi?id=689135
src/plugins/media-export/Makefile.am | 3 +-
.../rygel-media-export-database-cursor.vala | 2 +
.../rygel-media-export-media-cache.vala | 31 ++++++++---
.../rygel-media-export-object-factory.vala | 2 +-
.../rygel-media-export-root-container.vala | 24 +-------
.../rygel-media-export-sql-factory.vala | 19 +++++--
.../rygel-media-export-trackable-db-container.vala | 60 ++++++++++++++++++++
.../rygel-media-export-writable-db-container.vala | 10 ++-
8 files changed, 111 insertions(+), 40 deletions(-)
---
diff --git a/src/plugins/media-export/Makefile.am b/src/plugins/media-export/Makefile.am
index 013f42c..c7b394e 100644
--- a/src/plugins/media-export/Makefile.am
+++ b/src/plugins/media-export/Makefile.am
@@ -1,4 +1,4 @@
-include ../../../common.am
+include $(top_srcdir)/common.am
plugin_LTLIBRARIES = librygel-media-export.la
@@ -40,6 +40,7 @@ librygel_media_export_la_SOURCES = \
rygel-media-export-video-item.vala \
rygel-media-export-photo-item.vala \
rygel-media-export-playlist-item.vala \
+ rygel-media-export-trackable-db-container.vala \
rygel-media-export-collate.c
librygel_media_export_la_VALAFLAGS = \
diff --git a/src/plugins/media-export/rygel-media-export-database-cursor.vala b/src/plugins/media-export/rygel-media-export-database-cursor.vala
index d305532..836a7c8 100644
--- a/src/plugins/media-export/rygel-media-export-database-cursor.vala
+++ b/src/plugins/media-export/rygel-media-export-database-cursor.vala
@@ -66,6 +66,8 @@ internal class Rygel.MediaExport.DatabaseCursor : SqliteWrapper {
statement.bind_int64 (i, (int64) current_value.get_uint64 ());
} else if (current_value.holds (typeof (long))) {
statement.bind_int64 (i, current_value.get_long ());
+ } else if (current_value.holds (typeof (uint))) {
+ statement.bind_int64 (i, current_value.get_uint ());
} else if (current_value.holds (typeof (string))) {
statement.bind_text (i, current_value.get_string ());
} else if (current_value.holds (typeof (void *))) {
diff --git a/src/plugins/media-export/rygel-media-export-media-cache.vala b/src/plugins/media-export/rygel-media-export-media-cache.vala
index 6b2f537..62737b4 100644
--- a/src/plugins/media-export/rygel-media-export-media-cache.vala
+++ b/src/plugins/media-export/rygel-media-export-media-cache.vala
@@ -583,27 +583,36 @@ public class Rygel.MediaExport.MediaCache : Object {
this.db.exec (this.sql.make (SQLString.SAVE_METADATA), values);
}
- private void create_object (MediaObject item) throws Error {
+ private void create_object (MediaObject object) throws Error {
int type = ObjectType.CONTAINER;
GLib.Value parent;
- if (item is MediaItem) {
+ if (object is MediaItem) {
type = ObjectType.ITEM;
}
- if (item.parent == null) {
+ if (object.parent == null) {
parent = Database null ();
} else {
- parent = item.parent.id;
+ parent = object.parent.id;
}
- GLib.Value[] values = { item.id,
- item.title,
+ GLib.Value[] values = { object.id,
+ object.title,
type,
parent,
- item.modified,
- item.uris.size == 0 ? null : item.uris[0]
+ object.modified,
+ object.uris.size == 0 ? null : object.uris[0],
+ object.object_update_id,
+ -1,
+ -1
};
+ if (object is MediaContainer) {
+ var container = object as MediaContainer;
+ values[7] = container.total_deleted_child_count;
+ values[8] = container.update_id;
+ }
+
this.db.exec (this.sql.make (SQLString.INSERT), values);
}
@@ -652,6 +661,10 @@ public class Rygel.MediaExport.MediaCache : Object {
if (uri != null) {
container.uris.add (uri);
}
+ container.total_deleted_child_count = (uint32) statement.column_int64
+ (DetailColumn.DELETED_CHILD_COUNT);
+ container.update_id = (uint) statement.column_int64
+ (DetailColumn.CONTAINER_UPDATE_ID);
break;
case 1:
// this is an item
@@ -678,6 +691,8 @@ public class Rygel.MediaExport.MediaCache : Object {
object.modified = 0;
(object as MediaItem).place_holder = true;
}
+ object.object_update_id = (uint) statement.column_int64
+ (DetailColumn.OBJECT_UPDATE_ID);
}
return object;
diff --git a/src/plugins/media-export/rygel-media-export-object-factory.vala b/src/plugins/media-export/rygel-media-export-object-factory.vala
index 3773bb4..a56c154 100644
--- a/src/plugins/media-export/rygel-media-export-object-factory.vala
+++ b/src/plugins/media-export/rygel-media-export-object-factory.vala
@@ -56,7 +56,7 @@ internal class Rygel.MediaExport.ObjectFactory : Object {
}
if (uri == null) {
- return new DBContainer (media_db, id, title);
+ return new TrackableDbContainer (media_db, id, title);
}
return new WritableDbContainer (media_db, id, title);
diff --git a/src/plugins/media-export/rygel-media-export-root-container.vala b/src/plugins/media-export/rygel-media-export-root-container.vala
index 8bcbcfb..23b5188 100644
--- a/src/plugins/media-export/rygel-media-export-root-container.vala
+++ b/src/plugins/media-export/rygel-media-export-root-container.vala
@@ -40,8 +40,7 @@ const Rygel.MediaExport.FolderDefinition[] VIRTUAL_FOLDERS_MUSIC = {
/**
* Represents the root container.
*/
-public class Rygel.MediaExport.RootContainer : Rygel.TrackableContainer,
- Rygel.MediaExport.DBContainer {
+public class Rygel.MediaExport.RootContainer : TrackableDbContainer {
private DBusService service;
private Harvester harvester;
private Cancellable cancellable;
@@ -191,14 +190,7 @@ public class Rygel.MediaExport.RootContainer : Rygel.TrackableContainer,
}
}
- // TrackableContainer overrides
- public string get_service_reset_token () {
- return this.media_db.get_reset_token ();
- }
-
- public void set_service_reset_token (string token) {
- this.media_db.save_reset_token (token);
- }
+ // Private methods
private ArrayList<File> get_shared_uris () {
ArrayList<string> uris;
@@ -375,7 +367,7 @@ public class Rygel.MediaExport.RootContainer : Rygel.TrackableContainer,
} catch (Error error) { } // do nothing
try {
- this.filesystem_container = new DBContainer
+ this.filesystem_container = new TrackableDbContainer
(media_db,
FILESYSTEM_FOLDER_ID,
_(FILESYSTEM_FOLDER_NAME));
@@ -491,14 +483,4 @@ public class Rygel.MediaExport.RootContainer : Rygel.TrackableContainer,
container.updated ();
}
}
-
- public async void add_child (MediaObject object) {
- // TODO: Implement
- assert_not_reached ();
- }
-
- public async void remove_child (MediaObject object) {
- // TODO: Implement
- assert_not_reached ();
- }
}
diff --git a/src/plugins/media-export/rygel-media-export-sql-factory.vala b/src/plugins/media-export/rygel-media-export-sql-factory.vala
index 35e808c..4b3f94a 100644
--- a/src/plugins/media-export/rygel-media-export-sql-factory.vala
+++ b/src/plugins/media-export/rygel-media-export-sql-factory.vala
@@ -44,7 +44,10 @@ internal enum Rygel.MediaExport.DetailColumn {
URI,
DLNA_PROFILE,
GENRE,
- DISC
+ DISC,
+ OBJECT_UPDATE_ID,
+ DELETED_CHILD_COUNT,
+ CONTAINER_UPDATE_ID
}
internal enum Rygel.MediaExport.SQLString {
@@ -82,8 +85,10 @@ internal class Rygel.MediaExport.SQLFactory : Object {
"(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
private const string INSERT_OBJECT_STRING =
- "INSERT OR REPLACE INTO Object (upnp_id, title, type_fk, parent, timestamp, uri) " +
- "VALUES (?,?,?,?,?,?)";
+ "INSERT OR REPLACE INTO Object " +
+ "(upnp_id, title, type_fk, parent, timestamp, uri, " +
+ " object_update_id, deleted_child_count, container_update_id) " +
+ "VALUES (?,?,?,?,?,?,?,?,?)";
private const string DELETE_BY_ID_STRING =
"DELETE FROM Object WHERE upnp_id IN " +
@@ -94,7 +99,8 @@ internal class Rygel.MediaExport.SQLFactory : Object {
"m.height, m.class, m.author, m.album, m.date, m.bitrate, " +
"m.sample_freq, m.bits_per_sample, m.channels, m.track, " +
"m.color_depth, m.duration, o.upnp_id, o.parent, o.timestamp, " +
- "o.uri, m.dlna_profile, m.genre, m.disc ";
+ "o.uri, m.dlna_profile, m.genre, m.disc, o.object_update_id, " +
+ "o.deleted_child_count, o.container_update_id ";
private const string GET_OBJECT_WITH_PATH =
"SELECT DISTINCT " + ALL_DETAILS_STRING +
@@ -197,7 +203,10 @@ internal class Rygel.MediaExport.SQLFactory : Object {
"title TEXT NOT NULL, " +
"timestamp INTEGER NOT NULL, " +
"uri TEXT, " +
- "flags TEXT);" +
+ "flags TEXT, " +
+ "object_update_id INTEGER, " +
+ "deleted_child_count INTEGER, " +
+ "container_update_id INTEGER);" +
"INSERT INTO schema_info (version) VALUES ('" +
SQLFactory.SCHEMA_VERSION + "'); ";
diff --git a/src/plugins/media-export/rygel-media-export-trackable-db-container.vala b/src/plugins/media-export/rygel-media-export-trackable-db-container.vala
new file mode 100644
index 0000000..dd6ee28
--- /dev/null
+++ b/src/plugins/media-export/rygel-media-export-trackable-db-container.vala
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2012 Intel Corporation.
+ *
+ * Author: Jens Georg <jensg openismus com>
+ *
+ * This file is part of Rygel.
+ *
+ * Rygel 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; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Rygel 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 program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+using Gee;
+
+public class Rygel.MediaExport.TrackableDbContainer : TrackableContainer,
+ DBContainer {
+ public TrackableDbContainer (MediaCache cache, string id, string title) {
+ base (cache, id, title);
+ }
+
+ public async void add_child (MediaObject object) {
+ try {
+ if (object is MediaItem) {
+ this.media_db.save_item (object as MediaItem);
+ } else if (object is MediaContainer) {
+ this.media_db.save_container (object as MediaContainer);
+ } else {
+ assert_not_reached ();
+ }
+ } catch (Error error) {
+ warning ("Failed to add object: %s", error.message);
+ }
+ }
+
+ public async void remove_child (MediaObject object) {
+ try {
+ this.media_db.remove_object (object);
+ } catch (Error error) {
+ warning ("Failed to remove object: %s", error.message);
+ }
+ }
+
+ // TrackableContainer overrides
+ public virtual string get_service_reset_token () {
+ return this.media_db.get_reset_token ();
+ }
+
+ public virtual void set_service_reset_token (string token) {
+ this.media_db.save_reset_token (token);
+ }
+}
diff --git a/src/plugins/media-export/rygel-media-export-writable-db-container.vala b/src/plugins/media-export/rygel-media-export-writable-db-container.vala
index 20746f0..2d16967 100644
--- a/src/plugins/media-export/rygel-media-export-writable-db-container.vala
+++ b/src/plugins/media-export/rygel-media-export-writable-db-container.vala
@@ -21,8 +21,8 @@
*/
using Gee;
-internal class Rygel.MediaExport.WritableDbContainer : DBContainer,
- Rygel.WritableContainer {
+internal class Rygel.MediaExport.WritableDbContainer : TrackableDbContainer,
+ Rygel.WritableContainer {
public ArrayList<string> create_classes { get; set; }
public WritableDbContainer (MediaCache media_db, string id, string title) {
@@ -46,11 +46,13 @@ internal class Rygel.MediaExport.WritableDbContainer : DBContainer,
item.modified = int64.MAX;
}
item.id = MediaCache.get_id (file);
- this.media_db.save_item (item);
+ yield this.add_child_tracked (item);
}
public async void remove_item (string id, Cancellable? cancellable)
throws Error {
- this.media_db.remove_by_id (id);
+ var object = this.media_db.get_object (id);
+
+ yield this.remove_child_tracked (object);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]