Merge lp:~ted/ubuntu-app-launch/application-starting into lp:ubuntu-app-launch/14.04

Proposed by Ted Gould
Status: Merged
Approved by: Charles Kerr
Approved revision: 120
Merged at revision: 92
Proposed branch: lp:~ted/ubuntu-app-launch/application-starting
Merge into: lp:ubuntu-app-launch/14.04
Diff against target: 869 lines (+454/-61)
18 files modified
click-exec-trace.tp (+4/-0)
click-exec.c (+13/-0)
data/com.canonical.UpstartAppLaunch.xml (+20/-0)
debian/control (+5/-3)
debian/libupstart-app-launch2.install (+1/-1)
debian/libupstart-app-launch2.symbols (+5/-3)
desktop-exec-trace.tp (+3/-1)
desktop-exec.c (+12/-1)
helpers.c (+82/-0)
helpers.h (+4/-0)
libupstart-app-launch/CMakeLists.txt (+2/-2)
libupstart-app-launch/upstart-app-launch.c (+39/-15)
libupstart-app-launch/upstart-app-launch.h (+45/-20)
tests/CMakeLists.txt (+8/-0)
tests/helper-handshake-test.cc (+120/-0)
tests/libual-test.cc (+75/-2)
tests/second-exec-test.cc (+0/-6)
upstart-app-watch.c (+16/-7)
To merge this branch: bzr merge lp:~ted/ubuntu-app-launch/application-starting
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Gerry Boland (community) Needs Fixing
Review via email: mp+198027@code.launchpad.net

Commit message

Handshake for starting applications

Description of the change

Adding a other observer with a handshake so that we can ensure that Unity knows about an app before we start it.

To post a comment you must log in.
108. By Ted Gould

Merging trunk with lttng support

109. By Ted Gould

Fixing the XML

110. By Ted Gould

Be dependent on the lib we use :-)

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
111. By Ted Gould

Unsubscribe to the signal when cleaning up

112. By Ted Gould

Track the timer and clean it up

113. By Ted Gould

Make sure to clean up on tear down not in the test

114. By Ted Gould

Clear the timeout signal handler when it gets hit

115. By Ted Gould

Killing some returns

116. By Ted Gould

Putting expected value first to clean up error messages

117. By Ted Gould

Removing duplicate definitions

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
118. By Ted Gould

Killing more returns

Revision history for this message
Gerry Boland (gerboland) wrote :

If you must change the package name, please have it replace the old package.

Selecting previously unselected package libupstart-app-launch2-dev:amd64.
Unpacking libupstart-app-launch2-dev:amd64 (from libupstart-app-launch2-dev_0.3+14.04.20131126-0ubuntu1_amd64.deb) ...
dpkg: error processing libupstart-app-launch2-dev_0.3+14.04.20131126-0ubuntu1_amd64.deb (--install):
 trying to overwrite '/usr/lib/x86_64-linux-gnu/libupstart-app-launch.so', which is also in package libupstart-app-launch1-dev:amd64 0.3+14.04.20131126-0ubuntu1

Why not just increment the package version?

review: Needs Fixing
119. By Ted Gould

Removing the filter at the end of the test

120. By Ted Gould

Adding replace/conflicts with the previous dev package

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Gerry Boland (gerboland) wrote :

Reasoning behind name change was explained to me, withdrawing objection.

FYI, here is the branch that implements support for this change in unity-mir if it eases testing
https://code.launchpad.net/~gerboland/unity-mir/wait-for-upstart-notification/+merge/198041

Revision history for this message
Charles Kerr (charlesk) wrote :

Ted, thanks for fixing all those nitpicks I threw at you.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'click-exec-trace.tp'
--- click-exec-trace.tp 2013-12-04 12:55:59 +0000
+++ click-exec-trace.tp 2013-12-06 12:27:28 +0000
@@ -1,6 +1,10 @@
11
2TRACEPOINT_EVENT(upstart_app_launch, click_start, TP_ARGS(0), TP_FIELDS())2TRACEPOINT_EVENT(upstart_app_launch, click_start, TP_ARGS(0), TP_FIELDS())
3TRACEPOINT_EVENT(upstart_app_launch, click_starting_sent, TP_ARGS(0), TP_FIELDS())
3TRACEPOINT_EVENT(upstart_app_launch, click_found_pkgdir, TP_ARGS(0), TP_FIELDS())4TRACEPOINT_EVENT(upstart_app_launch, click_found_pkgdir, TP_ARGS(0), TP_FIELDS())
4TRACEPOINT_EVENT(upstart_app_launch, click_configured_env, TP_ARGS(0), TP_FIELDS())5TRACEPOINT_EVENT(upstart_app_launch, click_configured_env, TP_ARGS(0), TP_FIELDS())
5TRACEPOINT_EVENT(upstart_app_launch, click_read_manifest, TP_ARGS(0), TP_FIELDS())6TRACEPOINT_EVENT(upstart_app_launch, click_read_manifest, TP_ARGS(0), TP_FIELDS())
6TRACEPOINT_EVENT(upstart_app_launch, click_read_desktop, TP_ARGS(0), TP_FIELDS())7TRACEPOINT_EVENT(upstart_app_launch, click_read_desktop, TP_ARGS(0), TP_FIELDS())
8TRACEPOINT_EVENT(upstart_app_launch, click_handshake_wait, TP_ARGS(0), TP_FIELDS())
9TRACEPOINT_EVENT(upstart_app_launch, click_handshake_complete, TP_ARGS(0), TP_FIELDS())
10
711
=== modified file 'click-exec.c'
--- click-exec.c 2013-12-04 12:55:59 +0000
+++ click-exec.c 2013-12-06 12:27:28 +0000
@@ -55,6 +55,13 @@
5555
56 tracepoint(upstart_app_launch, click_start);56 tracepoint(upstart_app_launch, click_start);
5757
58 handshake_t * handshake = starting_handshake_start(app_id);
59 if (handshake == NULL) {
60 g_warning("Unable to setup starting handshake");
61 }
62
63 tracepoint(upstart_app_launch, click_starting_sent);
64
58 GError * error = NULL;65 GError * error = NULL;
59 gchar * package = NULL;66 gchar * package = NULL;
60 /* 'Parse' the App ID */67 /* 'Parse' the App ID */
@@ -140,5 +147,11 @@
140 g_free(userdesktopfile);147 g_free(userdesktopfile);
141 g_free(userdesktoppath);148 g_free(userdesktoppath);
142149
150 tracepoint(upstart_app_launch, click_handshake_wait);
151
152 starting_handshake_wait(handshake);
153
154 tracepoint(upstart_app_launch, click_handshake_complete);
155
143 return 0;156 return 0;
144}157}
145158
=== added directory 'data'
=== added file 'data/com.canonical.UpstartAppLaunch.xml'
--- data/com.canonical.UpstartAppLaunch.xml 1970-01-01 00:00:00 +0000
+++ data/com.canonical.UpstartAppLaunch.xml 2013-12-06 12:27:28 +0000
@@ -0,0 +1,20 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<node>
3 <interface name="com.canonical.UpstartAppLaunch">
4 <signal name="UnityResumeRequest">
5 <arg type="s" name="appid" />
6 </signal>
7 <signal name="UnityResumeResponse">
8 <arg type="s" name="appid" />
9 </signal>
10 <signal name="UnityFocusRequest">
11 <arg type="s" name="appid" />
12 </signal>
13 <signal name="UnityStartingBroadcast">
14 <arg type="s" name="appid" />
15 </signal>
16 <signal name="UnityStartingSignal">
17 <arg type="s" name="appid" />
18 </signal>
19 </interface>
20</node>
021
=== modified file 'debian/control'
--- debian/control 2013-12-06 10:38:35 +0000
+++ debian/control 2013-12-06 12:27:28 +0000
@@ -49,7 +49,7 @@
49 .49 .
50 This package provides tools for working with the Upstart App Launch.50 This package provides tools for working with the Upstart App Launch.
5151
52Package: libupstart-app-launch152Package: libupstart-app-launch2
53Section: libs53Section: libs
54Architecture: any54Architecture: any
55Depends: ${misc:Depends},55Depends: ${misc:Depends},
@@ -62,15 +62,17 @@
62 .62 .
63 This package contains shared libraries to be used by applications.63 This package contains shared libraries to be used by applications.
6464
65Package: libupstart-app-launch1-dev65Package: libupstart-app-launch2-dev
66Section: libdevel66Section: libdevel
67Architecture: any67Architecture: any
68Depends: ${misc:Depends},68Depends: ${misc:Depends},
69 ${shlibs:Depends},69 ${shlibs:Depends},
70 libglib2.0-dev,70 libglib2.0-dev,
71 libupstart-app-launch1 (= ${binary:Version}),71 libupstart-app-launch2 (= ${binary:Version}),
72Pre-Depends: ${misc:Pre-Depends},72Pre-Depends: ${misc:Pre-Depends},
73Multi-Arch: same73Multi-Arch: same
74Replaces: libupstart-app-launch1-dev
75Conflicts: libupstart-app-launch1-dev
74Description: library for sending requests to the upstart app launch76Description: library for sending requests to the upstart app launch
75 Upstart Job file and associated utilities that is used to launch77 Upstart Job file and associated utilities that is used to launch
76 applications in a standard and confined way.78 applications in a standard and confined way.
7779
=== renamed file 'debian/libupstart-app-launch1-dev.install' => 'debian/libupstart-app-launch2-dev.install'
=== renamed file 'debian/libupstart-app-launch1.install' => 'debian/libupstart-app-launch2.install'
--- debian/libupstart-app-launch1.install 2013-08-02 13:24:59 +0000
+++ debian/libupstart-app-launch2.install 2013-12-06 12:27:28 +0000
@@ -1,1 +1,1 @@
1usr/lib/*/libupstart-app-launch.so.1*1usr/lib/*/libupstart-app-launch.so.2*
22
=== renamed file 'debian/libupstart-app-launch1.symbols' => 'debian/libupstart-app-launch2.symbols'
--- debian/libupstart-app-launch1.symbols 2013-10-08 19:38:15 +0000
+++ debian/libupstart-app-launch2.symbols 2013-12-06 12:27:28 +0000
@@ -1,15 +1,17 @@
1libupstart-app-launch.so.1 libupstart-app-launch1 #MINVER#1libupstart-app-launch.so.2 libupstart-app-launch2 #MINVER#
2 upstart_app_launch_get_primary_pid@Base 0.22 upstart_app_launch_get_primary_pid@Base 0.2
3 upstart_app_launch_list_running_apps@Base 0.23 upstart_app_launch_list_running_apps@Base 0.2
4 upstart_app_launch_observer_add_app_failed@Base 0.24 upstart_app_launch_observer_add_app_failed@Base 0.2
5 upstart_app_launch_observer_add_app_focus@Base 0.25 upstart_app_launch_observer_add_app_focus@Base 0.2
6 upstart_app_launch_observer_add_app_resume@Base 0.26 upstart_app_launch_observer_add_app_resume@Base 0.2
7 upstart_app_launch_observer_add_app_start@Base 0.27 upstart_app_launch_observer_add_app_started@Base 0replaceme
8 upstart_app_launch_observer_add_app_starting@Base 0replaceme
8 upstart_app_launch_observer_add_app_stop@Base 0.29 upstart_app_launch_observer_add_app_stop@Base 0.2
9 upstart_app_launch_observer_delete_app_failed@Base 0.210 upstart_app_launch_observer_delete_app_failed@Base 0.2
10 upstart_app_launch_observer_delete_app_focus@Base 0.211 upstart_app_launch_observer_delete_app_focus@Base 0.2
11 upstart_app_launch_observer_delete_app_resume@Base 0.212 upstart_app_launch_observer_delete_app_resume@Base 0.2
12 upstart_app_launch_observer_delete_app_start@Base 0.213 upstart_app_launch_observer_delete_app_started@Base 0replaceme
14 upstart_app_launch_observer_delete_app_starting@Base 0replaceme
13 upstart_app_launch_observer_delete_app_stop@Base 0.215 upstart_app_launch_observer_delete_app_stop@Base 0.2
14 upstart_app_launch_pid_in_app_id@Base 0.216 upstart_app_launch_pid_in_app_id@Base 0.2
15 upstart_app_launch_start_application@Base 0.217 upstart_app_launch_start_application@Base 0.2
1618
=== modified file 'desktop-exec-trace.tp'
--- desktop-exec-trace.tp 2013-12-04 17:07:09 +0000
+++ desktop-exec-trace.tp 2013-12-06 12:27:28 +0000
@@ -1,5 +1,7 @@
11
2TRACEPOINT_EVENT(upstart_app_launch, desktop_start, TP_ARGS(0), TP_FIELDS())2TRACEPOINT_EVENT(upstart_app_launch, desktop_start, TP_ARGS(0), TP_FIELDS())
3TRACEPOINT_EVENT(upstart_app_launch, desktop_starting_sent, TP_ARGS(0), TP_FIELDS())
3TRACEPOINT_EVENT(upstart_app_launch, desktop_found, TP_ARGS(0), TP_FIELDS())4TRACEPOINT_EVENT(upstart_app_launch, desktop_found, TP_ARGS(0), TP_FIELDS())
4TRACEPOINT_EVENT(upstart_app_launch, desktop_finished, TP_ARGS(0), TP_FIELDS())5TRACEPOINT_EVENT(upstart_app_launch, desktop_handshake_wait, TP_ARGS(0), TP_FIELDS())
6TRACEPOINT_EVENT(upstart_app_launch, desktop_handshake_complete, TP_ARGS(0), TP_FIELDS())
57
68
=== modified file 'desktop-exec.c'
--- desktop-exec.c 2013-12-05 17:08:13 +0000
+++ desktop-exec.c 2013-12-06 12:27:28 +0000
@@ -44,6 +44,13 @@
44 g_setenv("LTTNG_UST_REGISTER_TIMEOUT", "0", FALSE); /* Set to zero if not set */44 g_setenv("LTTNG_UST_REGISTER_TIMEOUT", "0", FALSE); /* Set to zero if not set */
45 tracepoint(upstart_app_launch, desktop_start);45 tracepoint(upstart_app_launch, desktop_start);
4646
47 handshake_t * handshake = starting_handshake_start(app_id);
48 if (handshake == NULL) {
49 g_warning("Unable to setup starting handshake");
50 }
51
52 tracepoint(upstart_app_launch, desktop_starting_sent);
53
47 gchar * desktopfilename = NULL;54 gchar * desktopfilename = NULL;
48 GKeyFile * keyfile = keyfile_for_appid(app_id, &desktopfilename);55 GKeyFile * keyfile = keyfile_for_appid(app_id, &desktopfilename);
4956
@@ -84,7 +91,11 @@
84 g_free(desktopfilename);91 g_free(desktopfilename);
85 }92 }
8693
87 tracepoint(upstart_app_launch, desktop_finished);94 tracepoint(upstart_app_launch, desktop_handshake_wait);
95
96 starting_handshake_wait(handshake);
97
98 tracepoint(upstart_app_launch, desktop_handshake_complete);
8899
89 return 0;100 return 0;
90}101}
91102
=== modified file 'helpers.c'
--- helpers.c 2013-11-22 16:35:27 +0000
+++ helpers.c 2013-12-06 12:27:28 +0000
@@ -582,3 +582,85 @@
582582
583 return;583 return;
584}584}
585
586static void
587unity_signal_cb (GDBusConnection * con, const gchar * sender, const gchar * path, const gchar * interface, const gchar * signal, GVariant * params, gpointer user_data)
588{
589 GMainLoop * mainloop = (GMainLoop *)user_data;
590 g_main_loop_quit(mainloop);
591}
592
593struct _handshake_t {
594 GDBusConnection * con;
595 GMainLoop * mainloop;
596 guint signal_subscribe;
597 guint timeout;
598};
599
600static gboolean
601unity_too_slow_cb (gpointer user_data)
602{
603 handshake_t * handshake = (handshake_t *)user_data;
604 g_main_loop_quit(handshake->mainloop);
605 handshake->timeout = 0;
606 return G_SOURCE_REMOVE;
607}
608
609handshake_t *
610starting_handshake_start (const gchar * app_id)
611{
612 GError * error = NULL;
613 handshake_t * handshake = g_new0(handshake_t, 1);
614
615 handshake->mainloop = g_main_loop_new(NULL, FALSE);
616 handshake->con = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
617
618 if (error != NULL) {
619 g_critical("Unable to connect to session bus: %s", error->message);
620 g_error_free(error);
621 g_free(handshake);
622 return NULL;
623 }
624
625 /* Set up listening for the unfrozen signal from Unity */
626 handshake->signal_subscribe = g_dbus_connection_signal_subscribe(handshake->con,
627 NULL, /* sender */
628 "com.canonical.UpstartAppLaunch", /* interface */
629 "UnityStartingSignal", /* signal */
630 "/", /* path */
631 app_id, /* arg0 */
632 G_DBUS_SIGNAL_FLAGS_NONE,
633 unity_signal_cb, handshake->mainloop,
634 NULL); /* user data destroy */
635
636 /* Send unfreeze to to Unity */
637 g_dbus_connection_emit_signal(handshake->con,
638 NULL, /* destination */
639 "/", /* path */
640 "com.canonical.UpstartAppLaunch", /* interface */
641 "UnityStartingBroadcast", /* signal */
642 g_variant_new("(s)", app_id),
643 &error);
644
645 /* Really, Unity? */
646 handshake->timeout = g_timeout_add_seconds(1, unity_too_slow_cb, handshake);
647
648 return handshake;
649}
650
651void
652starting_handshake_wait (handshake_t * handshake)
653{
654 if (handshake == NULL)
655 return;
656
657 g_main_loop_run(handshake->mainloop);
658
659 if (handshake->timeout != 0)
660 g_source_remove(handshake->timeout);
661 g_main_loop_unref(handshake->mainloop);
662 g_dbus_connection_signal_unsubscribe(handshake->con, handshake->signal_subscribe);
663 g_object_unref(handshake->con);
664
665 g_free(handshake);
666}
585667
=== modified file 'helpers.h'
--- helpers.h 2013-11-12 21:06:02 +0000
+++ helpers.h 2013-12-06 12:27:28 +0000
@@ -36,3 +36,7 @@
36void set_confined_envvars (const gchar * package,36void set_confined_envvars (const gchar * package,
37 const gchar * app_dir);37 const gchar * app_dir);
3838
39typedef struct _handshake_t handshake_t;
40handshake_t * starting_handshake_start (const gchar * app_id);
41void starting_handshake_wait (handshake_t * handshake);
42
3943
=== modified file 'libupstart-app-launch/CMakeLists.txt'
--- libupstart-app-launch/CMakeLists.txt 2013-08-08 03:54:36 +0000
+++ libupstart-app-launch/CMakeLists.txt 2013-12-06 12:27:28 +0000
@@ -3,8 +3,8 @@
3# Version Info3# Version Info
4##########################4##########################
55
6set(API_VERSION 1)6set(API_VERSION 2)
7set(ABI_VERSION 1)7set(ABI_VERSION 2)
88
99
10##########################10##########################
1111
=== modified file 'libupstart-app-launch/upstart-app-launch.c'
--- libupstart-app-launch/upstart-app-launch.c 2013-11-25 14:44:42 +0000
+++ libupstart-app-launch/upstart-app-launch.c 2013-12-06 12:27:28 +0000
@@ -163,8 +163,6 @@
163 g_free(app);163 g_free(app);
164 g_free(inst);164 g_free(inst);
165 nih_unref(job_proxy, NULL);165 nih_unref(job_proxy, NULL);
166
167 return;
168}166}
169167
170static void168static void
@@ -257,7 +255,8 @@
257};255};
258256
259/* The lists of Observers */257/* The lists of Observers */
260static GList * start_array = NULL;258static GList * starting_array = NULL;
259static GList * started_array = NULL;
261static GList * stop_array = NULL;260static GList * stop_array = NULL;
262static GList * focus_array = NULL;261static GList * focus_array = NULL;
263static GList * resume_array = NULL;262static GList * resume_array = NULL;
@@ -301,8 +300,6 @@
301 }300 }
302301
303 g_free(instance);302 g_free(instance);
304
305 return;
306}303}
307304
308/* Creates the observer structure and registers for the signal with305/* Creates the observer structure and registers for the signal with
@@ -339,9 +336,9 @@
339}336}
340337
341gboolean338gboolean
342upstart_app_launch_observer_add_app_start (upstart_app_launch_app_observer_t observer, gpointer user_data)339upstart_app_launch_observer_add_app_started (upstart_app_launch_app_observer_t observer, gpointer user_data)
343{340{
344 return add_app_generic(observer, user_data, "started", &start_array);341 return add_app_generic(observer, user_data, "started", &started_array);
345}342}
346343
347gboolean344gboolean
@@ -394,8 +391,6 @@
394 g_variant_get(params, "(&s)", &appid);391 g_variant_get(params, "(&s)", &appid);
395 observer->func(appid, observer->user_data);392 observer->func(appid, observer->user_data);
396 }393 }
397
398 return;
399}394}
400395
401gboolean396gboolean
@@ -423,8 +418,6 @@
423 g_warning("Unable to emit response signal: %s", error->message);418 g_warning("Unable to emit response signal: %s", error->message);
424 g_error_free(error);419 g_error_free(error);
425 }420 }
426
427 return;
428}421}
429422
430gboolean423gboolean
@@ -433,6 +426,33 @@
433 return add_session_generic(observer, user_data, "UnityResumeRequest", &resume_array, resume_signal_cb);426 return add_session_generic(observer, user_data, "UnityResumeRequest", &resume_array, resume_signal_cb);
434}427}
435428
429/* Handle the starting signal when it occurs, call the observer, then send a signal back when we're done */
430static void
431starting_signal_cb (GDBusConnection * conn, const gchar * sender, const gchar * object, const gchar * interface, const gchar * signal, GVariant * params, gpointer user_data)
432{
433 focus_signal_cb(conn, sender, object, interface, signal, params, user_data);
434
435 GError * error = NULL;
436 g_dbus_connection_emit_signal(conn,
437 sender, /* destination */
438 "/", /* path */
439 "com.canonical.UpstartAppLaunch", /* interface */
440 "UnityStartingSignal", /* signal */
441 params, /* params, the same */
442 &error);
443
444 if (error != NULL) {
445 g_warning("Unable to emit response signal: %s", error->message);
446 g_error_free(error);
447 }
448}
449
450gboolean
451upstart_app_launch_observer_add_app_starting (upstart_app_launch_app_observer_t observer, gpointer user_data)
452{
453 return add_session_generic(observer, user_data, "UnityStartingBroadcast", &starting_array, starting_signal_cb);
454}
455
436gboolean456gboolean
437upstart_app_launch_observer_add_app_failed (upstart_app_launch_app_failed_observer_t observer, gpointer user_data)457upstart_app_launch_observer_add_app_failed (upstart_app_launch_app_failed_observer_t observer, gpointer user_data)
438{458{
@@ -467,9 +487,9 @@
467}487}
468488
469gboolean489gboolean
470upstart_app_launch_observer_delete_app_start (upstart_app_launch_app_observer_t observer, gpointer user_data)490upstart_app_launch_observer_delete_app_started (upstart_app_launch_app_observer_t observer, gpointer user_data)
471{491{
472 return delete_app_generic(observer, user_data, &start_array);492 return delete_app_generic(observer, user_data, &started_array);
473}493}
474494
475gboolean495gboolean
@@ -491,6 +511,12 @@
491}511}
492512
493gboolean513gboolean
514upstart_app_launch_observer_delete_app_starting (upstart_app_launch_app_observer_t observer, gpointer user_data)
515{
516 return delete_app_generic(observer, user_data, &starting_array);
517}
518
519gboolean
494upstart_app_launch_observer_delete_app_failed (upstart_app_launch_app_failed_observer_t observer, gpointer user_data)520upstart_app_launch_observer_delete_app_failed (upstart_app_launch_app_failed_observer_t observer, gpointer user_data)
495{521{
496 return FALSE;522 return FALSE;
@@ -549,8 +575,6 @@
549575
550 nih_unref(instance_proxy, NULL);576 nih_unref(instance_proxy, NULL);
551 }577 }
552
553 return;
554}578}
555579
556gchar **580gchar **
557581
=== modified file 'libupstart-app-launch/upstart-app-launch.h'
--- libupstart-app-launch/upstart-app-launch.h 2013-09-26 15:19:22 +0000
+++ libupstart-app-launch/upstart-app-launch.h 2013-12-06 12:27:28 +0000
@@ -80,16 +80,29 @@
80gboolean upstart_app_launch_stop_application (const gchar * appid);80gboolean upstart_app_launch_stop_application (const gchar * appid);
8181
82/**82/**
83 * upstart_app_launch_observer_add_app_start:83 * upstart_app_launch_observer_add_app_starting:
84 * @observer: Callback when an application starts84 * @observer: Callback when an application is about to start
85 * @user_data: (allow none): Data to pass to the observer85 * @user_data: (allow none): Data to pass to the observer
86 *86 *
87 * Sets up a callback to get called each time an application87 * Sets up a callback to get called each time an application
88 * starts.88 * is about to start. The application will not start until the
89 *89 * function returns.
90 * Return value: Whether adding the observer was successful.90 *
91 */91 * Return value: Whether adding the observer was successful.
92gboolean upstart_app_launch_observer_add_app_start (upstart_app_launch_app_observer_t observer,92 */
93gboolean upstart_app_launch_observer_add_app_starting (upstart_app_launch_app_observer_t observer,
94 gpointer user_data);
95/**
96 * upstart_app_launch_observer_add_app_started:
97 * @observer: Callback when an application started
98 * @user_data: (allow none): Data to pass to the observer
99 *
100 * Sets up a callback to get called each time an application
101 * has been started.
102 *
103 * Return value: Whether adding the observer was successful.
104 */
105gboolean upstart_app_launch_observer_add_app_started (upstart_app_launch_app_observer_t observer,
93 gpointer user_data);106 gpointer user_data);
94/**107/**
95 * upstart_app_launch_observer_add_app_stop:108 * upstart_app_launch_observer_add_app_stop:
@@ -145,16 +158,28 @@
145 gpointer user_data);158 gpointer user_data);
146159
147/**160/**
148 * upstart_app_launch_observer_delete_app_start:161 * upstart_app_launch_observer_delete_app_starting:
149 * @observer: Callback to remove162 * @observer: Callback to remove
150 * @user_data: (allow none): Data that was passed to the observer163 * @user_data: (allow none): Data that was passed to the observer
151 *164 *
152 * Removes a previously registered callback to ensure it no longer165 * Removes a previously registered callback to ensure it no longer
153 * gets signaled.166 * gets signaled.
154 *167 *
155 * Return value: Whether deleting the observer was successful.168 * Return value: Whether deleting the observer was successful.
156 */169 */
157gboolean upstart_app_launch_observer_delete_app_start (upstart_app_launch_app_observer_t observer,170gboolean upstart_app_launch_observer_delete_app_starting (upstart_app_launch_app_observer_t observer,
171 gpointer user_data);
172/**
173 * upstart_app_launch_observer_delete_app_started:
174 * @observer: Callback to remove
175 * @user_data: (allow none): Data that was passed to the observer
176 *
177 * Removes a previously registered callback to ensure it no longer
178 * gets signaled.
179 *
180 * Return value: Whether deleting the observer was successful.
181 */
182gboolean upstart_app_launch_observer_delete_app_started (upstart_app_launch_app_observer_t observer,
158 gpointer user_data);183 gpointer user_data);
159/**184/**
160 * upstart_app_launch_observer_delete_app_stop:185 * upstart_app_launch_observer_delete_app_stop:
161186
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2013-12-04 17:48:47 +0000
+++ tests/CMakeLists.txt 2013-12-06 12:27:28 +0000
@@ -18,6 +18,13 @@
1818
19add_test (helper-test helper-test)19add_test (helper-test helper-test)
2020
21# Helper test
22
23add_executable (helper-handshake-test helper-handshake-test.cc)
24target_link_libraries (helper-handshake-test helpers gtest ${GTEST_LIBS})
25
26add_test (helper-handshake-test helper-handshake-test)
27
21# Second Exec Test28# Second Exec Test
2229
23include_directories("${CMAKE_SOURCE_DIR}/libupstart-app-launch")30include_directories("${CMAKE_SOURCE_DIR}/libupstart-app-launch")
@@ -42,6 +49,7 @@
42add_test (NAME libual-test-pid COMMAND libual-test --gtest_filter=*ApplicationPid)49add_test (NAME libual-test-pid COMMAND libual-test --gtest_filter=*ApplicationPid)
43add_test (NAME libual-test-list COMMAND libual-test --gtest_filter=*ApplicationList)50add_test (NAME libual-test-list COMMAND libual-test --gtest_filter=*ApplicationList)
44add_test (NAME libual-test-observer COMMAND libual-test --gtest_filter=*StartStopObserver)51add_test (NAME libual-test-observer COMMAND libual-test --gtest_filter=*StartStopObserver)
52add_test (NAME libual-test-starting COMMAND libual-test --gtest_filter=*StartingResponses)
4553
46# ZG Test54# ZG Test
4755
4856
=== added file 'tests/helper-handshake-test.cc'
--- tests/helper-handshake-test.cc 1970-01-01 00:00:00 +0000
+++ tests/helper-handshake-test.cc 2013-12-06 12:27:28 +0000
@@ -0,0 +1,120 @@
1/*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Ted Gould <ted.gould@canonical.com>
18 */
19
20#include <gtest/gtest.h>
21#include <glib/gstdio.h>
22#include <gio/gio.h>
23
24extern "C" {
25#include "../helpers.h"
26}
27
28class HelperHandshakeTest : public ::testing::Test
29{
30 private:
31 GTestDBus * testbus = NULL;
32
33 protected:
34 GMainLoop * mainloop = NULL;
35
36 virtual void SetUp() {
37 mainloop = g_main_loop_new(NULL, FALSE);
38 testbus = g_test_dbus_new(G_TEST_DBUS_NONE);
39 g_test_dbus_up(testbus);
40 }
41
42 virtual void TearDown() {
43 g_test_dbus_down(testbus);
44 g_clear_object(&testbus);
45 g_main_loop_unref(mainloop);
46 mainloop = NULL;
47 return;
48 }
49
50 public:
51 GDBusMessage * FilterFunc (GDBusConnection * conn, GDBusMessage * message, gboolean incomming) {
52 if (g_strcmp0(g_dbus_message_get_member(message), "UnityStartingBroadcast") == 0) {
53 GVariant * body = g_dbus_message_get_body(message);
54 GVariant * correct_body = g_variant_new("(s)", "fooapp");
55 g_variant_ref_sink(correct_body);
56
57 [body, correct_body]() {
58 ASSERT_TRUE(g_variant_equal(body, correct_body));
59 }();
60
61 g_variant_unref(correct_body);
62 g_main_loop_quit(mainloop);
63 }
64
65 return message;
66 }
67
68};
69
70static GDBusMessage *
71filter_func (GDBusConnection * conn, GDBusMessage * message, gboolean incomming, gpointer user_data) {
72 return static_cast<HelperHandshakeTest *>(user_data)->FilterFunc(conn, message, incomming);
73}
74
75TEST_F(HelperHandshakeTest, BaseHandshake)
76{
77 GDBusConnection * con = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
78 guint filter = g_dbus_connection_add_filter(con, filter_func, this, NULL);
79
80 handshake_t * handshake = starting_handshake_start("fooapp");
81
82 g_main_loop_run(mainloop);
83
84 g_dbus_connection_remove_filter(con, filter);
85
86 g_dbus_connection_emit_signal(con,
87 g_dbus_connection_get_unique_name(con), /* destination */
88 "/", /* path */
89 "com.canonical.UpstartAppLaunch", /* interface */
90 "UnityStartingSignal", /* signal */
91 g_variant_new("(s)", "fooapp"), /* params, the same */
92 NULL);
93
94 starting_handshake_wait(handshake);
95
96 g_object_unref(con);
97
98 return;
99}
100
101static gboolean
102two_second_reached (gpointer user_data)
103{
104 bool * reached = static_cast<bool *>(user_data);
105 *reached = true;
106}
107
108TEST_F(HelperHandshakeTest, HandshakeTimeout)
109{
110 bool timeout_reached = false;
111 handshake_t * handshake = starting_handshake_start("fooapp");
112
113 guint outertimeout = g_timeout_add_seconds(2, two_second_reached, &timeout_reached);
114
115 starting_handshake_wait(handshake);
116
117 ASSERT_FALSE(timeout_reached);
118
119 return;
120}
0121
=== modified file 'tests/libual-test.cc'
--- tests/libual-test.cc 2013-11-25 14:49:12 +0000
+++ tests/libual-test.cc 2013-12-06 12:27:28 +0000
@@ -182,6 +182,27 @@
182182
183 return found;183 return found;
184 }184 }
185
186 static gboolean pause_helper (gpointer pmainloop) {
187 g_main_loop_quit((GMainLoop *)pmainloop);
188 return G_SOURCE_REMOVE;
189 }
190
191 void pause (guint time) {
192 if (time > 0) {
193 GMainLoop * mainloop = g_main_loop_new(NULL, FALSE);
194 guint timer = g_timeout_add(time, pause_helper, mainloop);
195
196 g_main_loop_run(mainloop);
197
198 g_source_remove(timer);
199 g_main_loop_unref(mainloop);
200 }
201
202 while (g_main_pending()) {
203 g_main_iteration(TRUE);
204 }
205 }
185};206};
186207
187TEST_F(LibUAL, StartApplication)208TEST_F(LibUAL, StartApplication)
@@ -307,7 +328,7 @@
307 .name = nullptr328 .name = nullptr
308 };329 };
309330
310 ASSERT_TRUE(upstart_app_launch_observer_add_app_start(observer_cb, &start_data));331 ASSERT_TRUE(upstart_app_launch_observer_add_app_started(observer_cb, &start_data));
311 ASSERT_TRUE(upstart_app_launch_observer_add_app_stop(observer_cb, &stop_data));332 ASSERT_TRUE(upstart_app_launch_observer_add_app_stop(observer_cb, &stop_data));
312 ASSERT_FALSE(upstart_app_launch_observer_add_app_failed(NULL, NULL)); /* Not yet implemented */333 ASSERT_FALSE(upstart_app_launch_observer_add_app_failed(NULL, NULL)); /* Not yet implemented */
313334
@@ -417,7 +438,59 @@
417438
418439
419 /* Remove */440 /* Remove */
420 ASSERT_TRUE(upstart_app_launch_observer_delete_app_start(observer_cb, &start_data));441 ASSERT_TRUE(upstart_app_launch_observer_delete_app_started(observer_cb, &start_data));
421 ASSERT_TRUE(upstart_app_launch_observer_delete_app_stop(observer_cb, &stop_data));442 ASSERT_TRUE(upstart_app_launch_observer_delete_app_stop(observer_cb, &stop_data));
422 ASSERT_FALSE(upstart_app_launch_observer_delete_app_failed(NULL, NULL)); /* Not yet implemented */443 ASSERT_FALSE(upstart_app_launch_observer_delete_app_failed(NULL, NULL)); /* Not yet implemented */
423}444}
445
446static GDBusMessage *
447filter_starting (GDBusConnection * conn, GDBusMessage * message, gboolean incomming, gpointer user_data)
448{
449 if (g_strcmp0(g_dbus_message_get_member(message), "UnityStartingSignal") == 0) {
450 unsigned int * count = static_cast<unsigned int *>(user_data);
451 (*count)++;
452 g_object_unref(message);
453 return NULL;
454 }
455
456 return message;
457}
458
459static void
460starting_observer (const gchar * appid, gpointer user_data)
461{
462 std::string * last = static_cast<std::string *>(user_data);
463 *last = appid;
464 return;
465}
466
467TEST_F(LibUAL, StartingResponses)
468{
469 std::string last_observer;
470 unsigned int starting_count = 0;
471 GDBusConnection * session = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
472 guint filter = g_dbus_connection_add_filter(session,
473 filter_starting,
474 &starting_count,
475 NULL);
476
477 EXPECT_TRUE(upstart_app_launch_observer_add_app_starting(starting_observer, &last_observer));
478
479 g_dbus_connection_emit_signal(session,
480 NULL, /* destination */
481 "/", /* path */
482 "com.canonical.UpstartAppLaunch", /* interface */
483 "UnityStartingBroadcast", /* signal */
484 g_variant_new("(s)", "foo"), /* params, the same */
485 NULL);
486
487 pause(100);
488
489 EXPECT_EQ("foo", last_observer);
490 EXPECT_EQ(1, starting_count);
491
492 EXPECT_TRUE(upstart_app_launch_observer_delete_app_starting(starting_observer, &last_observer));
493
494 g_dbus_connection_remove_filter(session, filter);
495 g_object_unref(session);
496}
424497
=== modified file 'tests/second-exec-test.cc'
--- tests/second-exec-test.cc 2013-10-04 19:22:41 +0000
+++ tests/second-exec-test.cc 2013-12-06 12:27:28 +0000
@@ -58,8 +58,6 @@
5858
59 upstart_app_launch_observer_add_app_focus(focus_cb, this);59 upstart_app_launch_observer_add_app_focus(focus_cb, this);
60 upstart_app_launch_observer_add_app_resume(resume_cb, this);60 upstart_app_launch_observer_add_app_resume(resume_cb, this);
61
62 return;
63 }61 }
64 virtual void TearDown() {62 virtual void TearDown() {
65 upstart_app_launch_observer_delete_app_focus(focus_cb, this);63 upstart_app_launch_observer_delete_app_focus(focus_cb, this);
@@ -67,8 +65,6 @@
6765
68 g_test_dbus_down(testbus);66 g_test_dbus_down(testbus);
69 g_object_unref(testbus);67 g_object_unref(testbus);
70
71 return;
72 }68 }
7369
74 static gboolean pause_helper (gpointer pmainloop) {70 static gboolean pause_helper (gpointer pmainloop) {
@@ -90,8 +86,6 @@
90 while (g_main_pending()) {86 while (g_main_pending()) {
91 g_main_iteration(TRUE);87 g_main_iteration(TRUE);
92 }88 }
93
94 return;
95 }89 }
96};90};
9791
9892
=== modified file 'upstart-app-watch.c'
--- upstart-app-watch.c 2013-09-24 22:18:11 +0000
+++ upstart-app-watch.c 2013-12-06 12:27:28 +0000
@@ -20,30 +20,37 @@
20#include "libupstart-app-launch/upstart-app-launch.h"20#include "libupstart-app-launch/upstart-app-launch.h"
2121
22void22void
23starting (const gchar * appid, gpointer user_data)
24{
25 g_print("Starting %s\n", appid);
26 return;
27}
28
29void
23started (const gchar * appid, gpointer user_data)30started (const gchar * appid, gpointer user_data)
24{31{
25 g_print("Start %s\n", appid);32 g_print("Started %s\n", appid);
26 return;33 return;
27}34}
2835
29void36void
30stopped (const gchar * appid, gpointer user_data)37stopped (const gchar * appid, gpointer user_data)
31{38{
32 g_print("Stop %s\n", appid);39 g_print("Stop %s\n", appid);
33 return;40 return;
34}41}
3542
36void43void
37resume (const gchar * appid, gpointer user_data)44resume (const gchar * appid, gpointer user_data)
38{45{
39 g_print("Resume %s\n", appid);46 g_print("Resume %s\n", appid);
40 return;47 return;
41}48}
4249
43void50void
44focus (const gchar * appid, gpointer user_data)51focus (const gchar * appid, gpointer user_data)
45{52{
46 g_print("Focus %s\n", appid);53 g_print("Focus %s\n", appid);
47 return;54 return;
48}55}
4956
@@ -60,7 +67,7 @@
60 break;67 break;
61 }68 }
6269
63 g_print("Focus %s (%s)\n", appid, failstr);70 g_print("Fail %s (%s)\n", appid, failstr);
64 return;71 return;
65}72}
6673
@@ -68,7 +75,8 @@
68int75int
69main (int argc, gchar * argv[])76main (int argc, gchar * argv[])
70{77{
71 upstart_app_launch_observer_add_app_start(started, NULL);78 upstart_app_launch_observer_add_app_starting(starting, NULL);
79 upstart_app_launch_observer_add_app_started(started, NULL);
72 upstart_app_launch_observer_add_app_stop(stopped, NULL);80 upstart_app_launch_observer_add_app_stop(stopped, NULL);
73 upstart_app_launch_observer_add_app_focus(focus, NULL);81 upstart_app_launch_observer_add_app_focus(focus, NULL);
74 upstart_app_launch_observer_add_app_resume(resume, NULL);82 upstart_app_launch_observer_add_app_resume(resume, NULL);
@@ -77,7 +85,8 @@
77 GMainLoop * mainloop = g_main_loop_new(NULL, FALSE);85 GMainLoop * mainloop = g_main_loop_new(NULL, FALSE);
78 g_main_loop_run(mainloop);86 g_main_loop_run(mainloop);
7987
80 upstart_app_launch_observer_delete_app_start(started, NULL);88 upstart_app_launch_observer_delete_app_starting(starting, NULL);
89 upstart_app_launch_observer_delete_app_started(started, NULL);
81 upstart_app_launch_observer_delete_app_stop(stopped, NULL);90 upstart_app_launch_observer_delete_app_stop(stopped, NULL);
82 upstart_app_launch_observer_delete_app_focus(focus, NULL);91 upstart_app_launch_observer_delete_app_focus(focus, NULL);
83 upstart_app_launch_observer_delete_app_resume(resume, NULL);92 upstart_app_launch_observer_delete_app_resume(resume, NULL);

Subscribers

People subscribed via source and target branches