-I$(top_srcdir)/src/rygel -DDATA_DIR='"$(datadir)"'
librygel_media_export_la_SOURCES = rygel-media-export-plugin.vala \
+ rygel-media-export-null-container.vala \
rygel-media-export-root-container.vala \
rygel-media-export-recursive-file-monitor.vala \
rygel-media-export-harvester.vala \
--- /dev/null
+/*
+ * Copyright (C) 2009 Jens Georg <mail@jensge.org>.
+ *
+ * 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 Rygel;
+using Gee;
+
+/**
+ * This is an empty container used to satisfy rygel if no mediadb could be
+ * created
+ */
+internal class Rygel.NullContainer : MediaContainer {
+ public NullContainer () {
+ base.root ("MediaExport", 0);
+ }
+
+ public override void get_children (uint offset,
+ uint max_count,
+ Cancellable? cancellable,
+ AsyncReadyCallback callback) {
+ var res = new SimpleAsyncResult<int> (this, callback);
+ res.complete_in_idle ();
+ }
+
+ public override Gee.List<MediaObject>? get_children_finish (AsyncResult res)
+ throws Error {
+ return new Gee.ArrayList<MediaObject>();
+ }
+
+ public override void find_object (string id,
+ Cancellable? cancellable,
+ AsyncReadyCallback callback) {
+ var res = new SimpleAsyncResult<int> (this, callback);
+ res.complete_in_idle ();
+ }
+
+ public override MediaObject? find_object_finish (AsyncResult res)
+ throws Error {
+ return null;
+ }
+
+}
private HashMap<File, MediaExportHarvester> harvester;
private MediaExportRecursiveFileMonitor monitor;
- private static MediaExportRootContainer instance = null;
+ private static MediaContainer instance = null;
private ArrayList<string> get_uris () {
ArrayList<string> uris;
return uris;
}
- public static MediaExportRootContainer get_instance() {
+ public static MediaContainer get_instance() {
if (MediaExportRootContainer.instance == null) {
- MediaExportRootContainer.instance = new MediaExportRootContainer ();
+ try {
+ var db = MediaDB.create("media-export");
+ MediaExportRootContainer.instance =
+ new MediaExportRootContainer (db);
+ } catch (MediaDBError err) {
+ warning("Failed to create instance of database");
+ MediaExportRootContainer.instance = new NullContainer ();
+ }
}
return MediaExportRootContainer.instance;
/**
* Create a new root container.
*/
- private MediaExportRootContainer () {
- var db = new MediaDB("media-export");
+ private MediaExportRootContainer (MediaDB db) {
base (db, "0", "MediaExportRoot");
this.extractor = new MetadataExtractor ();
if (schema_info[1] == schema_version) {
debug ("Media DB schema has current version");
} else {
- debug ("Schema version differs... checking for upgrade");
- // FIXME implement if necessary
+ int old_version = schema_info[1].to_int();
+ int new_version = schema_version.to_int();
+ if (schema_info[1].to_int() < schema_version.to_int()) {
+ debug ("Older schema detected. Upgrading...");
+ } else {
+ // FIXME implement if necessary
+ warning("The version \"%d\" of the detected database" +
+ " is newer than our supported version \"%d\"",
+ old_version, new_version);
+ db = null;
+ }
}
} else {
warning ("Incompatible schema... cannot proceed");
if (rc != Sqlite.OK) {
warning ("Something weird going on: %s",
db.errmsg ());
- db = null;
+ this.db = null;
return;
}
debug ("Empty database, creating new schema version %s",
schema_version);
if (!create_schema ()) {
+ this.db = null;
return;
}
} else {
warning ("Incompatible schema... cannot proceed");
+ this.db = null;
return;
}
}
}
- public MediaDB (string name) {
+ private MediaDB (string name, MediaDBObjectFactory factory) {
open_db (name);
- this.factory = new MediaDBObjectFactory ();
+ this.factory = factory;
}
- public MediaDB.with_factory (string name, MediaDBObjectFactory factory) {
- open_db (name);
- this.factory = factory;
+ public static MediaDB? create (string name) throws MediaDBError {
+ var instance = new MediaDB (name, new MediaDBObjectFactory());
+ if (instance.db != null) {
+ return instance;
+ }
+
+ throw new MediaDBError.GENERAL_ERROR("Invalid database");
+ }
+
+ public static MediaDB? create_with_factory (string name,
+ MediaDBObjectFactory factory)
+ throws MediaDBError {
+ var instance = new MediaDB (name, new MediaDBObjectFactory());
+ if (instance.db != null) {
+ return instance;
+ }
+
+ throw new MediaDBError.GENERAL_ERROR("Invalid database");
}
private bool sweeper () {