Re: [PATCH 2/3] vala: cloned grl-inspect
- From: Víctor M. Jáquez L. <vjaquez igalia com>
- To: Simón Pena <spenap gmail com>
- Cc: grilo-list gnome org
- Subject: Re: [PATCH 2/3] vala: cloned grl-inspect
- Date: Sun, 21 Nov 2010 17:02:27 +0100
On Sun, Nov 21, 2010 at 12:12:59AM +0100, Simón Pena wrote:
> Cloned C's grl-inspect in Vala, to add another test of its bindings.
> ---
> tools/vala/grl-inspect.vala | 205 +++++++++++++++++++++++++++++++++++++++++++
> 1 files changed, 205 insertions(+), 0 deletions(-)
> create mode 100644 tools/vala/grl-inspect.vala
>
> diff --git a/tools/vala/grl-inspect.vala b/tools/vala/grl-inspect.vala
> new file mode 100644
> index 0000000..d5deaf9
> --- /dev/null
> +++ b/tools/vala/grl-inspect.vala
> @@ -0,0 +1,205 @@
> +using Grl;
> +
> +public class SourcesInspector : Object {
> +
> + static int delay;
> + static MainLoop main_loop = new MainLoop ();
> +
> + private unowned List<string> introspect_sources;
> + private PluginRegistry registry;
> + private Config youtube_config;
> + private Config vimeo_config;
> + private Config flickr_config;
> +
> + const string FLICKR_KEY = "fa037bee8120a921b34f8209d715a2fa";
> + const string FLICKR_SECRET = "9f6523b9c52e3317";
> + const string VIMEO_KEY = "4d908c69e05a9d5b5c6669d302f920cb";
> + const string VIMEO_SECRET = "4a923ffaab6238eb";
> + const string YOUTUBE_KEY = "AI39si4EfscPllSfUy1IwexMf__kntTL_" +
> + "G5dfSr2iUEVN45RHGq92Aq0lX25OlnOkG6" +
> + "KTN-4soVAkAf67fWYXuHfVADZYr7S1A";
I'm pretty worried about this. It seems that our plugins do network operations
with the service just as soon they are loaded. I don't think this is right,
and the perfect example is this application: we only want to display the
plugin keys and properties. We shouldn't need to configure them.
> + const OptionEntry[] options = {
> + { "delay", 'p', 0, OptionArg.INT, ref delay,
> + "Wait some seconds before showing results", null },
> + /* { "", '\0', 0, OptionArg.STRING_ARRAY,
> + ref introspect_sources,
> + "Sources to introspect", null }, */
> + { null }
> + };
> +
> + public SourcesInspector (List<string> sources) {
> + registry = PluginRegistry.get_default ();
> +
> + introspect_sources = sources;
> +
> + configure_plugins ();
> +
> + if (registry.load_all () == false) {
> + error ("Failed to load plugins.");
> + }
> + }
> +
> + private void configure_plugins () {
> + youtube_config = new Config ("grl-youtube", null);
> + youtube_config.set_api_key (YOUTUBE_KEY);
> +
> + vimeo_config = new Config ("grl-vimeo", null);
> + vimeo_config.set_api_key (VIMEO_KEY);
> + vimeo_config.set_api_secret (VIMEO_SECRET);
> +
> + flickr_config = new Config ("grl-flickr", null);
> + flickr_config.set_api_key (FLICKR_KEY);
> + flickr_config.set_api_secret (FLICKR_SECRET);
> +
> + registry.add_config (youtube_config);
> + registry.add_config (vimeo_config);
> + registry.add_config (flickr_config);
> + }
> +
> + private static void print_keys (List<KeyID>? keys) {
> + foreach (unowned KeyID key in keys) {
> + print ("%s, ", metadata_key_get_name (key));
> + }
> + print ("\n");
> + }
> +
> + public void list_all_sources () {
> + var sources = registry.get_sources (false);
> +
> + foreach (MediaPlugin source in sources) {
> + print ("%s: %s\n",
> + (source as MediaPlugin).get_id (),
> + (source as MetadataSource).get_id ());
> + }
> + }
> +
> + private void print_source_details (MetadataSource source) {
> + print ("Source Details\n");
> + print (" %-20s %s\n", "Identifier:", source.get_id ());
> + print (" %-20s %s\n", "Type:",
> + (source is MediaSource) ?
> + "Media Provider" : "Metadata Provider");
> + print (" %-20s %s\n", "Name:", source.get_name ());
> + print (" %-20s %s\n", "Description:",
> + source.get_description ());
> + print ("\n");
> + }
> +
> + private void print_supported_ops (MetadataSource source) {
> + var supported_ops = source.supported_operations ();
> + print ("Supported operations:\n");
> + if ((supported_ops & SupportedOps.RESOLVE) == SupportedOps.RESOLVE) {
> + print (" grl_metadata_source_resolve():\tResolve Metadata\n");
> + }
> + if ((supported_ops & SupportedOps.METADATA) == SupportedOps.METADATA) {
> + print (" grl_media_source_metadata():\t\tRetrieve Metadata\n");
> + }
> + if ((supported_ops & SupportedOps.BROWSE) == SupportedOps.BROWSE) {
> + print (" grl_media_source_browse():\t\tBrowse\n");
> + }
> + if ((supported_ops & SupportedOps.SEARCH) == SupportedOps.SEARCH) {
> + print (" grl_media_source_search():\t\tSearch\n");
> + }
> + if ((supported_ops & SupportedOps.QUERY) == SupportedOps.QUERY) {
> + print (" grl_media_source_query():\t\tQuery\n");
> + }
> + if ((supported_ops & SupportedOps.STORE) == SupportedOps.STORE) {
> + print (" grl_metadata_source_set_metadata():\tUpdate Metadata\n");
> + }
> + if ((supported_ops & SupportedOps.STORE_PARENT) == SupportedOps.STORE_PARENT) {
> + print (" grl_media_source_store():\t\tAdd New Media\n");
> + }
> + if ((supported_ops & SupportedOps.REMOVE) == SupportedOps.REMOVE) {
> + print (" grl_media_source_remove():\t\tRemove Media\n");
> + }
> + print ("\n");
> + }
> +
> + private void print_supported_keys (MetadataSource source) {
> + print ("Supported keys:\n");
> + print (" Readable Keys:\t");
> + print_keys (source.supported_keys ());
> + print (" Writable Keys:\t");
> + print_keys (source.writable_keys ());
> + print ("\n");
> + }
> +
> + private void print_plugin_details (MediaPlugin source) {
> + print ("Plugin Details\n");
> + print (" %-20s %s\n", "Identifier:", source.get_id ());
> + print (" %-20s %s\n", "Filename:",
> + source.get_filename ());
> + print (" %-20s %d\n", "Rank:", source.get_rank ());
> +
> + var info_keys = source.get_info_keys ();
> + foreach (string key in info_keys) {
> + var value = source.get_info (key);
> + print (" %-20s %s\n", key, value);
> + }
> + print ("\n");
> + }
> +
> + public void introspect_source (string source_id) {
> +
> + var source = registry.lookup_source (source_id);
> + if (source != null) {
> + print_plugin_details (source);
> +
> + print_source_details (source as MetadataSource);
> +
> + print_supported_ops (source as MetadataSource);
> +
> + print_supported_keys (source as MetadataSource);
> +
> + } else {
> + print ("Source Not Found: %s\n", source_id);
> + }
> + }
> +
> + public bool run () {
> +
> + if (introspect_sources != null) {
> + foreach (string source in introspect_sources) {
> + introspect_source (source);
> + }
> + } else {
> + list_all_sources ();
> + }
> +
> + main_loop.quit ();
> +
> + return false;
> + }
> +
> + public static void main (string[] args) {
> +
> + List<string> sources = null;
> + try {
> + var option_context = new OptionContext (" - introspect Grilo sources");
> + option_context.add_main_entries (options, null);
> + option_context.add_group (init_get_option_group ());
> + option_context.parse (ref args);
> +
> + if (args.length>1) {
> + sources = new List<string> ();
> + for (int i = 1; i < args.length; i ++) {
> + sources.append (args[i]);
> + }
> + }
> + } catch (OptionError e) {
> + error (e.message);
> + }
> +
> + init (ref args);
> +
> + var sources_inspector = new SourcesInspector (sources);
> + if (delay > 0) {
> + Timeout.add_seconds ((uint) delay,
> + sources_inspector.run);
> + } else {
> + Idle.add (sources_inspector.run);
> + }
> + main_loop.run ();
> + }
> +
> +}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]