diff options
author | Rob Staudinger <robsta@linux.intel.com> | 2011-09-06 17:06:20 +0200 |
---|---|---|
committer | Rob Staudinger <robsta@linux.intel.com> | 2011-09-06 17:06:20 +0200 |
commit | 5c3aa321267cfee0d0804fb914ed9610aee2bf47 (patch) | |
tree | afcda145e18dfa1d7a69cc9ee5e002815b52c0c2 /examples | |
parent | cc3834729b53aec08cc020849d97070e96050a0a (diff) |
examples: Update video-profile remote so it can take a remote app id.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/video-profile/remote.c | 165 |
1 files changed, 88 insertions, 77 deletions
diff --git a/examples/video-profile/remote.c b/examples/video-profile/remote.c index a8088fe..c84bf21 100644 --- a/examples/video-profile/remote.c +++ b/examples/video-profile/remote.c @@ -26,7 +26,7 @@ #include <ytstenut/ytstenut.h> typedef enum { - COMMAND_NONE, + COMMAND_NONE = 0, COMMAND_PLAYER_PLAYING, COMMAND_PLAYER_VOLUME, COMMAND_PLAYER_PLAYABLE_URI, @@ -38,6 +38,8 @@ typedef enum { typedef struct { + char const *remote_id; + Command command; /* Player */ @@ -49,7 +51,10 @@ typedef struct { bool player_next; bool player_prev; -} Options; + YtsVPPlayer *player; + YtsVPTranscript *transcript; + +} Remote; static GMainLoop *_mainloop = NULL; @@ -134,68 +139,63 @@ _player_prev_response (YtsVPPlayer *player, } static void -use_player (YtsVPPlayer *player, - Options *options) +use_player (Remote *remote) { - // FIXME - g_object_ref (player); - - g_signal_connect (player, "notify::playing", + g_signal_connect (remote->player, "notify::playing", G_CALLBACK (_player_notify_playing), NULL); - g_signal_connect (player, "notify::volume", + g_signal_connect (remote->player, "notify::volume", G_CALLBACK (_player_notify_volume), NULL); - g_signal_connect (player, "notify::playable-uri", + g_signal_connect (remote->player, "notify::playable-uri", G_CALLBACK (_player_notify_playable_uri), NULL); - g_signal_connect (player, "next-response", + g_signal_connect (remote->player, "next-response", G_CALLBACK (_player_next_response), NULL); - g_signal_connect (player, "prev-response", + g_signal_connect (remote->player, "prev-response", G_CALLBACK (_player_prev_response), NULL); - switch (options->command) { + switch (remote->command) { case COMMAND_PLAYER_PLAYING: - if (0 == g_strcmp0 (options->player_playing, "true")) { - yts_vp_player_set_playing (YTS_VP_PLAYER (player), true); - } else if (0 == g_strcmp0 (options->player_playing, "false")) { - yts_vp_player_set_playing (YTS_VP_PLAYER (player), false); + if (0 == g_strcmp0 (remote->player_playing, "true")) { + yts_vp_player_set_playing (YTS_VP_PLAYER (remote->player), true); + } else if (0 == g_strcmp0 (remote->player_playing, "false")) { + yts_vp_player_set_playing (YTS_VP_PLAYER (remote->player), false); } else { - bool playing = yts_vp_player_get_playing (YTS_VP_PLAYER (player)); + bool playing = yts_vp_player_get_playing (remote->player); g_debug ("YtsVPPlayer.playing = %s", playing ? "true" : "false"); } break; case COMMAND_PLAYER_VOLUME: - if (options->player_volume >= 0.0) { - yts_vp_player_set_volume (YTS_VP_PLAYER (player), - options->player_volume); + if (remote->player_volume >= 0.0) { + yts_vp_player_set_volume (remote->player, remote->player_volume); } else { - double volume = yts_vp_player_get_volume (YTS_VP_PLAYER (player)); + double volume = yts_vp_player_get_volume (remote->player); g_debug ("YtsVPPlayer.volume = %.2f", volume); } break; case COMMAND_PLAYER_PLAYABLE_URI: - if (options->player_playable_uri) { - yts_vp_player_set_playable_uri (YTS_VP_PLAYER (player), - options->player_playable_uri); + if (remote->player_playable_uri) { + yts_vp_player_set_playable_uri (remote->player, + remote->player_playable_uri); } else { char *playable_uri = yts_vp_player_get_playable_uri ( - YTS_VP_PLAYER (player)); + remote->player); g_debug ("YtsVPPlayer.playable_uri = %s", playable_uri); g_free (playable_uri); } break; case COMMAND_PLAYER_PLAY: - yts_vp_player_play (YTS_VP_PLAYER (player)); + yts_vp_player_play (remote->player); break; case COMMAND_PLAYER_PAUSE: - yts_vp_player_pause (YTS_VP_PLAYER (player)); + yts_vp_player_pause (remote->player); break; case COMMAND_PLAYER_NEXT: - yts_vp_player_next (YTS_VP_PLAYER (player), NULL); + yts_vp_player_next (remote->player, NULL); break; case COMMAND_PLAYER_PREV: - yts_vp_player_prev (YTS_VP_PLAYER (player), NULL); + yts_vp_player_prev (remote->player, NULL); break; default: - g_debug ("%s : command %i not handled", G_STRLOC, options->command); + g_debug ("%s : command %i not handled", G_STRLOC, remote->command); } } @@ -212,22 +212,18 @@ _transcript_notify_current_text (YtsVPTranscript *transcript, } static void -use_transcript (YtsVPTranscript *transcript, - Options *options) +use_transcript (Remote *remote) { char **locales; char *locales_str; char *locale; - // FIXME - g_object_ref (transcript); - - locales = yts_vp_transcript_get_available_locales (transcript); + locales = yts_vp_transcript_get_available_locales (remote->transcript); locales_str = g_strjoinv (", ", locales); - locale = yts_vp_transcript_get_locale (transcript); + locale = yts_vp_transcript_get_locale (remote->transcript); - g_signal_connect (transcript, "notify::current-text", + g_signal_connect (remote->transcript, "notify::current-text", G_CALLBACK (_transcript_notify_current_text), NULL); g_debug ("Transcript create with locales %s, currently using %s", @@ -241,15 +237,22 @@ use_transcript (YtsVPTranscript *transcript, static void _proxy_service_proxy_created (YtsProxyService *service, YtsProxy *proxy, - Options *options) + Remote *remote) { if (YTS_VP_IS_PLAYER (proxy)) { - use_player (YTS_VP_PLAYER (proxy), options); + remote->player = g_object_ref (proxy); + + if (remote->command != COMMAND_NONE) { + use_player (remote); + } else { + g_debug ("No command given, not using the player."); + } } else if (YTS_VP_IS_TRANSCRIPT (proxy)) { - use_transcript (YTS_VP_TRANSCRIPT (proxy), options); + remote->transcript = g_object_ref (proxy); + use_transcript (remote); } else { @@ -262,7 +265,7 @@ _proxy_service_proxy_created (YtsProxyService *service, static void _roster_service_added (YtsRoster *roster, YtsService *service, - Options *options) + Remote *remote) { char const *uid; char const *jid; @@ -272,12 +275,13 @@ _roster_service_added (YtsRoster *roster, g_debug ("%s() %s %s", __FUNCTION__, uid, jid); - if (0 == g_strcmp0 (uid, "org.freedesktop.ytstenut.MockPlayer")) { + if (0 == g_strcmp0 (uid, remote->remote_id) || + 0 == g_strcmp0 (uid, "org.freedesktop.ytstenut.MockPlayer")) { bool ret; g_signal_connect (service, "proxy-created", - G_CALLBACK (_proxy_service_proxy_created), options); + G_CALLBACK (_proxy_service_proxy_created), remote); ret = yts_proxy_service_create_proxy (YTS_PROXY_SERVICE (service), YTS_VP_PLAYER_FQC_ID); @@ -303,28 +307,30 @@ main (int argc, YtsRoster *roster; GError *error = NULL; - Options options; + Remote remote; GOptionEntry player_entries[] = { - { "playing", 0, 0, G_OPTION_ARG_STRING, &options.player_playing, "Property 'playing'", "<true/false/get>" }, - { "volume", 0, 0, G_OPTION_ARG_DOUBLE, &options.player_volume, "Property 'volume'", NULL }, - { "playable-uri", 0, 0, G_OPTION_ARG_STRING, &options.player_playable_uri, "Property 'playable-uri'", NULL }, - - { "play", 0, 0, G_OPTION_ARG_NONE, &options.player_play, "Invoke 'play'", NULL }, - { "pause", 0, 0, G_OPTION_ARG_NONE, &options.player_pause, "Invoke 'pause'", NULL }, - { "next", 0, 0, G_OPTION_ARG_NONE, &options.player_next, "Invoke 'next'", NULL }, - { "prev", 0, 0, G_OPTION_ARG_NONE, &options.player_prev, "Invoke 'prev'", NULL }, + { "remote-id", 0, 0, G_OPTION_ARG_STRING, &remote.remote_id, "Remote-id to connect to", "<remote-id>" }, + + { "playing", 0, 0, G_OPTION_ARG_STRING, &remote.player_playing, "Property 'playing'", "<true/false/get>" }, + { "volume", 0, 0, G_OPTION_ARG_DOUBLE, &remote.player_volume, "Property 'volume'", NULL }, + { "playable-uri", 0, 0, G_OPTION_ARG_STRING, &remote.player_playable_uri, "Property 'playable-uri'", NULL }, + + { "play", 0, 0, G_OPTION_ARG_NONE, &remote.player_play, "Invoke 'play'", NULL }, + { "pause", 0, 0, G_OPTION_ARG_NONE, &remote.player_pause, "Invoke 'pause'", NULL }, + { "next", 0, 0, G_OPTION_ARG_NONE, &remote.player_next, "Invoke 'next'", NULL }, + { "prev", 0, 0, G_OPTION_ARG_NONE, &remote.player_prev, "Invoke 'prev'", NULL }, { NULL } }; - memset (&options, 0, sizeof (options)); - options.player_volume = -1.0; + memset (&remote, 0, sizeof (remote)); + remote.player_volume = -1.0; context = g_option_context_new ("- mock player remote"); group = g_option_group_new ("player", - "VideoProfile.Player options", - "This set of options can be used to exercise the Player interface.", + "VideoProfile.Player remote", + "This set of remote can be used to exercise the Player interface.", NULL, NULL); g_option_group_add_entries (group, player_entries); @@ -338,20 +344,20 @@ main (int argc, return EXIT_FAILURE; } - if (options.player_playing) { - options.command = COMMAND_PLAYER_PLAYING; - } else if (options.player_volume >= 0.0) { - options.command = COMMAND_PLAYER_VOLUME; - } else if (options.player_playable_uri) { - options.command = COMMAND_PLAYER_PLAYABLE_URI; - } else if (options.player_play) { - options.command = COMMAND_PLAYER_PLAY; - } else if (options.player_pause) { - options.command = COMMAND_PLAYER_PAUSE; - } else if (options.player_next) { - options.command = COMMAND_PLAYER_NEXT; - } else if (options.player_prev) { - options.command = COMMAND_PLAYER_PREV; + if (remote.player_playing) { + remote.command = COMMAND_PLAYER_PLAYING; + } else if (remote.player_volume >= 0.0) { + remote.command = COMMAND_PLAYER_VOLUME; + } else if (remote.player_playable_uri) { + remote.command = COMMAND_PLAYER_PLAYABLE_URI; + } else if (remote.player_play) { + remote.command = COMMAND_PLAYER_PLAY; + } else if (remote.player_pause) { + remote.command = COMMAND_PLAYER_PAUSE; + } else if (remote.player_next) { + remote.command = COMMAND_PLAYER_NEXT; + } else if (remote.player_prev) { + remote.command = COMMAND_PLAYER_PREV; } else { g_debug ("No command given, use --help to display commands."); } @@ -359,17 +365,17 @@ main (int argc, client = yts_client_new (YTS_PROTOCOL_LOCAL_XMPP, "org.freedesktop.ytstenut.MockPlayerRemote"); g_signal_connect (client, "authenticated", - G_CALLBACK (_client_authenticated), &options); + G_CALLBACK (_client_authenticated), &remote); g_signal_connect (client, "ready", - G_CALLBACK (_client_ready), &options); + G_CALLBACK (_client_ready), &remote); g_signal_connect (client, "disconnected", - G_CALLBACK (_client_disconnected), &options); + G_CALLBACK (_client_disconnected), &remote); g_signal_connect (client, "message", - G_CALLBACK (_client_message), &options); + G_CALLBACK (_client_message), &remote); roster = yts_client_get_roster (client); g_signal_connect (roster, "service-added", - G_CALLBACK (_roster_service_added), &options); + G_CALLBACK (_roster_service_added), &remote); yts_client_connect (client); @@ -377,6 +383,11 @@ main (int argc, g_main_loop_run (_mainloop); g_main_loop_unref (_mainloop); + if (remote.player) + g_object_unref (remote.player); + if (remote.transcript) + g_object_unref (remote.transcript); + return EXIT_SUCCESS; } |