~ps-jenkins/ubuntu-app-launch/utopic-proposed

« back to all changes in this revision

Viewing changes to tools/upstart-app-launch.c

  • Committer: CI bot
  • Author(s): Ted Gould
  • Date: 2014-02-20 12:04:12 UTC
  • mfrom: (87.8.4 started-failed-focused)
  • Revision ID: ps-jenkins@lists.canonical.com-20140220120412-lc0uthms3u9e6b3d
Add observers in the launch tool so that we stick around to handle events 

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *     Ted Gould <ted.gould@canonical.com>
18
18
 */
19
19
 
 
20
#include <glib.h>
20
21
#include "libupstart-app-launch/upstart-app-launch.h"
21
22
 
 
23
const gchar * global_appid = NULL;
 
24
int retval = 0;
 
25
 
 
26
static void
 
27
good_observer (const gchar * appid, gpointer user_data)
 
28
{
 
29
        if (g_strcmp0(appid, global_appid) != 0) {
 
30
                return;
 
31
        }
 
32
 
 
33
        g_debug("Application '%s' running", appid);
 
34
        g_main_loop_quit((GMainLoop *)user_data);
 
35
}
 
36
 
 
37
static void
 
38
bad_observer (const gchar * appid, upstart_app_launch_app_failed_t failure_type, gpointer user_data)
 
39
{
 
40
        if (g_strcmp0(appid, global_appid) != 0) {
 
41
                return;
 
42
        }
 
43
 
 
44
        g_debug("Application '%s' failed: %s", appid, failure_type == UPSTART_APP_LAUNCH_APP_FAILED_CRASH ? "crash" : "startup failure");
 
45
        retval = -1;
 
46
        g_main_loop_quit((GMainLoop *)user_data);
 
47
}
 
48
 
22
49
int
23
50
main (int argc, gchar * argv[]) {
24
 
 
25
51
        if (argc < 2) {
26
52
                g_printerr("Usage: %s <app id> [uris]\n", argv[0]);
27
53
                return 1;
28
54
        }
29
55
 
 
56
        global_appid = argv[1];
 
57
        GMainLoop * mainloop = g_main_loop_new(NULL, FALSE);
 
58
 
30
59
        gchar ** uris = NULL;
31
60
        if (argc > 2) {
32
61
                int i;
38
67
                }
39
68
        }
40
69
 
41
 
        upstart_app_launch_start_application(argv[1], (const gchar * const *)uris);
42
 
 
 
70
        upstart_app_launch_observer_add_app_started(good_observer, mainloop);
 
71
        upstart_app_launch_observer_add_app_focus(good_observer, mainloop);
 
72
 
 
73
        upstart_app_launch_observer_add_app_failed(bad_observer, mainloop);
 
74
 
 
75
        upstart_app_launch_start_application(global_appid, (const gchar * const *)uris);
 
76
 
 
77
        g_main_loop_run(mainloop);
 
78
 
 
79
        upstart_app_launch_observer_delete_app_started(good_observer, mainloop);
 
80
        upstart_app_launch_observer_delete_app_focus(good_observer, mainloop);
 
81
        upstart_app_launch_observer_delete_app_failed(bad_observer, mainloop);
 
82
 
 
83
        g_main_loop_unref(mainloop);
43
84
        g_free(uris);
44
85
 
45
 
        return 0;
 
86
        return retval;
46
87
}