[rygel] media-export: Clean-up search code
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel] media-export: Clean-up search code
- Date: Mon, 12 Jul 2010 17:19:03 +0000 (UTC)
commit 4c4d99171e141c408fd50d27adbe2736ccb6394c
Author: Jens Georg <mail jensge org>
Date: Thu Jul 8 23:47:30 2010 +0300
media-export: Clean-up search code
Since it is now possible to override find_object, the heuristics in
search is not needed anymore. Code looks now more straight-forward. Also
the plain get_object should be a little bit faster than going through
search
.../rygel-media-export-db-container.vala | 6 +++
.../rygel-media-export-root-container.vala | 48 +++++--------------
2 files changed, 19 insertions(+), 35 deletions(-)
---
diff --git a/src/plugins/media-export/rygel-media-export-db-container.vala b/src/plugins/media-export/rygel-media-export-db-container.vala
index 68bff75..f32783e 100644
--- a/src/plugins/media-export/rygel-media-export-db-container.vala
+++ b/src/plugins/media-export/rygel-media-export-db-container.vala
@@ -100,4 +100,10 @@ public class Rygel.MediaExport.DBContainer : MediaContainer {
return children;
}
+
+ public override async MediaObject? find_object (string id,
+ Cancellable? cancellable)
+ throws Error {
+ return this.media_db.get_object (id);
+ }
}
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 331f840..09924f9 100644
--- a/src/plugins/media-export/rygel-media-export-root-container.vala
+++ b/src/plugins/media-export/rygel-media-export-root-container.vala
@@ -126,28 +126,6 @@ public class Rygel.MediaExport.RootContainer : Rygel.MediaExport.DBContainer {
}
/**
- * Check if the passed search expression is a simple find_object
- * operation.
- * (@id = id)
- *
- * @param search_expression expression to test
- * @param id containts id of container on successful return
- * @return true if expression was a find object
- */
- private bool is_find_object (SearchExpression search_expression,
- out string id) {
- if (!(search_expression is RelationalExpression)) {
- return false;
- }
-
- var expression = search_expression as RelationalExpression;
- id = expression.operand2;
-
- return (expression.operand1 == "@id" &&
- expression.op == SearchCriteriaOp.EQ);
- }
-
- /**
* Check if a passed search expression is a simple search in a virtual
* container.
*
@@ -212,6 +190,19 @@ public class Rygel.MediaExport.RootContainer : Rygel.MediaExport.DBContainer {
return true;
}
+ public override async MediaObject? find_object (string id,
+ Cancellable? cancellable)
+ throws Error {
+ if (id.has_prefix (QueryContainer.PREFIX)) {
+ var container = new QueryContainer (this.media_db, id);
+ container.parent = this;
+
+ return container;
+ } else {
+ return yield base.find_object (id, cancellable);
+ }
+ }
+
public override async Gee.List<MediaObject>? search (
SearchExpression expression,
uint offset,
@@ -221,21 +212,8 @@ public class Rygel.MediaExport.RootContainer : Rygel.MediaExport.DBContainer {
throws GLib.Error {
Gee.List<MediaObject> list;
MediaContainer query_container = null;
- string id;
string upnp_class = null;
- if (is_find_object (expression, out id) &&
- id.has_prefix (QueryContainer.PREFIX)) {
- query_container = new QueryContainer (this.media_db, id);
- query_container.parent = this;
-
- list = new ArrayList<MediaObject> ();
- list.add (query_container);
- total_matches = list.size;
-
- return list;
- }
-
if (expression is RelationalExpression) {
var relational_expression = expression as RelationalExpression;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]