[rygel] core: Move MediaObjectSearch into separate module
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [rygel] core: Move MediaObjectSearch into separate module
- Date: Sun, 20 Sep 2009 23:26:57 +0000 (UTC)
commit f50bfc6af62418cb95da06bf0a05470e5ea00de3
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Thu Sep 17 17:01:08 2009 +0300
core: Move MediaObjectSearch into separate module
src/rygel/Makefile.am | 1 +
src/rygel/rygel-media-object-search.vala | 85 ++++++++++++++++++++++++++++++
src/rygel/rygel-simple-container.vala | 54 -------------------
3 files changed, 86 insertions(+), 54 deletions(-)
---
diff --git a/src/rygel/Makefile.am b/src/rygel/Makefile.am
index e2e7e5f..c23535e 100644
--- a/src/rygel/Makefile.am
+++ b/src/rygel/Makefile.am
@@ -65,6 +65,7 @@ VAPI_SOURCE_FILES = rygel-configuration.vala \
rygel-media-object.vala \
rygel-media-container.vala \
rygel-simple-container.vala \
+ rygel-media-object-search.vala \
rygel-simple-async-result.vala \
rygel-media-item.vala \
rygel-thumbnail.vala \
diff --git a/src/rygel/rygel-media-object-search.vala b/src/rygel/rygel-media-object-search.vala
new file mode 100644
index 0000000..57e0b70
--- /dev/null
+++ b/src/rygel/rygel-media-object-search.vala
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2009 Zeeshan Ali (Khattak) <zeeshanak gnome org>.
+ * Copyright (C) 2009 Nokia Corporation.
+ *
+ * Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
+ * <zeeshan ali nokia 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;
+
+/**
+ * A utililty class to easy searching of media objects from a bunch of
+ * MediaContainer hierarchies. If search is successful, media_object is set
+ * accordingly so if it's null at the completion of the search, it means that
+ * search was unsuccesful.
+ */
+internal class Rygel.MediaObjectSearch<G> : GLib.Object, Rygel.StateMachine {
+ public string id;
+ private ArrayList<MediaContainer> containers;
+ public G data;
+
+ public Cancellable cancellable { get; set; }
+
+ public MediaObject media_object;
+
+ public MediaObjectSearch (string id,
+ ArrayList<MediaContainer> containers,
+ G data,
+ Cancellable? cancellable) {
+ this.id = id;
+ this.containers = containers;
+ this.data = data;
+ this.cancellable = cancellable;
+ }
+
+ public void run () {
+ var container = this.containers.get (0);
+
+ if (container != null) {
+ container.find_object (this.id,
+ this.cancellable,
+ this.on_object_found);
+ } else {
+ this.completed ();
+ }
+ }
+
+ private void on_object_found (Object source_object,
+ AsyncResult res) {
+ try {
+ var container = source_object as MediaContainer;
+ this.media_object = container.find_object_finish (res);
+
+ if (this.media_object == null) {
+ // continue the search
+ this.containers.remove_at (0);
+
+ this.run ();
+ } else {
+ this.completed ();
+ }
+ } catch (Error err) {
+ warning ("Error while searching for '%s': %s\n",
+ this.id,
+ err.message);
+ this.completed ();
+ }
+ }
+}
diff --git a/src/rygel/rygel-simple-container.vala b/src/rygel/rygel-simple-container.vala
index 1cdc463..68fbbfc 100644
--- a/src/rygel/rygel-simple-container.vala
+++ b/src/rygel/rygel-simple-container.vala
@@ -131,57 +131,3 @@ public class Rygel.SimpleContainer : Rygel.MediaContainer {
this.searches.remove (search);
}
}
-
-private class Rygel.MediaObjectSearch<G> : GLib.Object, Rygel.StateMachine {
- public string id;
- public ArrayList<MediaContainer> containers;
- public G data;
-
- public Cancellable cancellable { get; set; }
-
- public MediaObject media_object;
-
- public MediaObjectSearch (string id,
- ArrayList<MediaContainer> containers,
- G data,
- Cancellable? cancellable) {
- this.id = id;
- this.containers = containers;
- this.data = data;
- this.cancellable = cancellable;
- }
-
- public void run () {
- var container = this.containers.get (0);
-
- if (container != null) {
- container.find_object (this.id,
- this.cancellable,
- this.on_object_found);
- } else {
- this.completed ();
- }
- }
-
- private void on_object_found (Object source_object,
- AsyncResult res) {
- try {
- var container = source_object as MediaContainer;
- this.media_object = container.find_object_finish (res);
-
- if (this.media_object == null) {
- // continue the search
- this.containers.remove_at (0);
-
- this.run ();
- } else {
- this.completed ();
- }
- } catch (Error err) {
- warning ("Error while searching for '%s': %s\n",
- this.id,
- err.message);
- this.completed ();
- }
- }
-}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]