diff options
author | Zeeshan Ali (Khattak) <zeeshanak@src.gnome.org> | 2008-08-05 15:49:51 +0000 |
---|---|---|
committer | Zeeshan Ali (Khattak) <zeeshanak@src.gnome.org> | 2008-08-05 15:49:51 +0000 |
commit | 4ea729fbfdb235ab8e80d64ac1534dc74f5ab514 (patch) | |
tree | 97a9295ed57d5daada1490977de6f03893f5c0bf | |
parent | 667f6272e3a930062a48fd5ed234d5143b7a85fc (diff) | |
download | rygel-4ea729fbfdb235ab8e80d64ac1534dc74f5ab514.tar.gz |
Introduce MediaManager.
It implements MediaProvider interface and will be responsible to manage all
MediaProviders. Currently it uses MediaTracker directly since it currently
doesn't have a plugin system.
svn path=/trunk/; revision=228
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | src/Makefile.am | 7 | ||||
-rw-r--r-- | src/gupnp-media-manager.vala | 237 |
3 files changed, 252 insertions, 1 deletions
@@ -1,3 +1,12 @@ +2008-08-02 Zeeshan Ali Khattak <zeenix@gmail.com> + + * src/Makefile.am: + * src/gupnp-media-manager.vala: + + Introduce MediaManager. It implements MediaProvider interface and will + be responsible to manage all MediaProviders. Currently it uses + MediaTracker directly since it currently doesn't have a plugin system. + 2008-07-31 Zeeshan Ali Khattak <zeenix@gmail.com> * src/gupnp-media-tracker.vala: diff --git a/src/Makefile.am b/src/Makefile.am index fad5be6b..ddc7332e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -26,7 +26,9 @@ BUILT_SOURCES = gupnp-media-server.stamp \ gupnp-media-tracker.h \ gupnp-media-tracker.c \ gupnp-media-provider.h \ - gupnp-media-provider.c + gupnp-media-provider.c \ + gupnp-media-manager.h \ + gupnp-media-manager.c gupnp_media_server_SOURCES = cstuff.c \ cstuff.h \ @@ -48,6 +50,9 @@ gupnp_media_server_SOURCES = cstuff.c \ gupnp-media-provider.h \ gupnp-media-provider.c \ gupnp-media-provider.vala \ + gupnp-media-manager.h \ + gupnp-media-manager.c \ + gupnp-media-manager.vala \ gupnp-metadata-extractor.c \ gupnp-metadata-extractor.h \ gupnp-metadata-extractor.vala diff --git a/src/gupnp-media-manager.vala b/src/gupnp-media-manager.vala new file mode 100644 index 00000000..d019691a --- /dev/null +++ b/src/gupnp-media-manager.vala @@ -0,0 +1,237 @@ +/* + * Copyright (C) 2008 Zeeshan Ali <zeenix@gmail.com>. + * + * Author: Zeeshan Ali <zeenix@gmail.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU 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. + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + */ + +public class GUPnP.MediaManager : GLib.Object, MediaProvider { + private DIDLLiteWriter didl_writer; + + /* Properties */ + public string# root_id { get; construct; } + public GUPnP.Context context { get; construct; } + public uint32 system_update_id { get; private set; } + + /* HashTable of Media Providers + * keys -> root-id assigned to Media Provider + * values -> Media Provider objects + */ + HashTable<string, MediaProvider> providers; + + construct { + this.providers = new HashTable<string, MediaProvider> + ((HashFunc) id_hash_func, + (EqualFunc) is_root_equal); + + MediaTracker tracker = new MediaTracker ("1", this.context); + providers.insert ("1", tracker); + + this.didl_writer = new DIDLLiteWriter (); + + this.system_update_id = 0; + } + + /* Pubic methods */ + public MediaManager (string root_id, + GUPnP.Context context) { + this.root_id = root_id; + this.context = context; + } + + public string? browse (string container_id, + string filter, + uint starting_index, + uint requested_count, + string sort_criteria, + out uint number_returned, + out uint total_matches, + out uint update_id) { + string didl; + + string id = this.remove_root_id_prefix (container_id); + + if (id == this.root_id) { + didl = this.browse_root_container (out number_returned, + out total_matches, + out update_id); + } else { + weak MediaProvider provider = this.providers.lookup (id); + if (provider != null) { + didl = provider.browse (id, + filter, + starting_index, + requested_count, + sort_criteria, + out number_returned, + out total_matches, + out update_id); + + if (update_id == uint32.MAX) { + update_id = this.system_update_id; + } + } else { + didl = null; + } + } + + return didl; + } + + public string get_metadata (string object_id, + string filter, + string sort_criteria, + out uint update_id) { + string didl; + + string id = this.remove_root_id_prefix (object_id); + + if (id == this.root_id) { + didl = this.get_root_container_metadata (out update_id); + } else { + weak MediaProvider provider = this.providers.lookup (id); + if (provider != null) { + didl = provider.get_metadata (id, + filter, + sort_criteria, + out update_id); + if (update_id == uint32.MAX) { + update_id = this.system_update_id; + } + } else { + didl = null; + } + } + + return didl; + } + + /* Private methods */ + private string browse_root_container (out uint number_returned, + out uint total_matches, + out uint update_id) { + /* Start DIDL-Lite fragment */ + this.didl_writer.start_didl_lite (null, null, true); + + this.providers.for_each ((key, value) => { + add_container ((string) key, + this.root_id, + (string) key, /* FIXME */ + -1); /* FIXME */ + }); + + number_returned = total_matches = this.providers.size (); + + /* End DIDL-Lite fragment */ + this.didl_writer.end_didl_lite (); + + /* Retrieve generated string */ + string didl = this.didl_writer.get_string (); + + /* Reset the parser state */ + this.didl_writer.reset (); + + update_id = this.system_update_id; + + return didl; + } + + private string get_root_container_metadata (out uint update_id) { + /* Start DIDL-Lite fragment */ + this.didl_writer.start_didl_lite (null, null, true); + + add_container (this.root_id, + "-1", /* FIXME */ + this.root_id, /* FIXME */ + this.providers.size ()); + + /* End DIDL-Lite fragment */ + this.didl_writer.end_didl_lite (); + + /* Retrieve generated string */ + string didl = this.didl_writer.get_string (); + + /* Reset the parser state */ + this.didl_writer.reset (); + + update_id = this.system_update_id; + + return didl; + } + + private void add_container (string id, + string parent_id, + string title, + uint child_count) { + string exported_id, exported_parent_id; + + if (id == this.root_id) + exported_id = id; + else + exported_id = this.root_id + ":" + id; + + if (parent_id == this.root_id) + exported_parent_id = parent_id; + else + exported_parent_id = this.root_id + ":" + parent_id; + + this.didl_writer.start_container (this.root_id + ":" + id, + exported_parent_id, + (int) child_count, + false, + false); + + this.didl_writer.add_string ("class", + DIDLLiteWriter.NAMESPACE_UPNP, + null, + "object.container.storageFolder"); + + this.didl_writer.add_string ("title", + DIDLLiteWriter.NAMESPACE_DC, + null, + title); + + /* End of Container */ + this.didl_writer.end_container (); + } + + string remove_root_id_prefix (string id) { + string[] tokens; + + tokens = id.split (":", 2); + + if (tokens[1] != null) + return tokens[1]; + else + return tokens[0]; + } + + private static uint id_hash_func (string id) { + return id[0]; + } + + private static bool is_root_equal (string id1, string id2) { + string[] id1_tokens = id1.split (":", 2); + string[] id2_tokens = id2.split (":", 2); + + return id1_tokens[0] == id2_tokens[0]; + } +} + |