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
1=== modified file 'click-exec-trace.tp'
2--- click-exec-trace.tp 2013-12-04 12:55:59 +0000
3+++ click-exec-trace.tp 2013-12-06 12:27:28 +0000
4@@ -1,6 +1,10 @@
5
6 TRACEPOINT_EVENT(upstart_app_launch, click_start, TP_ARGS(0), TP_FIELDS())
7+TRACEPOINT_EVENT(upstart_app_launch, click_starting_sent, TP_ARGS(0), TP_FIELDS())
8 TRACEPOINT_EVENT(upstart_app_launch, click_found_pkgdir, TP_ARGS(0), TP_FIELDS())
9 TRACEPOINT_EVENT(upstart_app_launch, click_configured_env, TP_ARGS(0), TP_FIELDS())
10 TRACEPOINT_EVENT(upstart_app_launch, click_read_manifest, TP_ARGS(0), TP_FIELDS())
11 TRACEPOINT_EVENT(upstart_app_launch, click_read_desktop, TP_ARGS(0), TP_FIELDS())
12+TRACEPOINT_EVENT(upstart_app_launch, click_handshake_wait, TP_ARGS(0), TP_FIELDS())
13+TRACEPOINT_EVENT(upstart_app_launch, click_handshake_complete, TP_ARGS(0), TP_FIELDS())
14+
15
16=== modified file 'click-exec.c'
17--- click-exec.c 2013-12-04 12:55:59 +0000
18+++ click-exec.c 2013-12-06 12:27:28 +0000
19@@ -55,6 +55,13 @@
20
21 tracepoint(upstart_app_launch, click_start);
22
23+ handshake_t * handshake = starting_handshake_start(app_id);
24+ if (handshake == NULL) {
25+ g_warning("Unable to setup starting handshake");
26+ }
27+
28+ tracepoint(upstart_app_launch, click_starting_sent);
29+
30 GError * error = NULL;
31 gchar * package = NULL;
32 /* 'Parse' the App ID */
33@@ -140,5 +147,11 @@
34 g_free(userdesktopfile);
35 g_free(userdesktoppath);
36
37+ tracepoint(upstart_app_launch, click_handshake_wait);
38+
39+ starting_handshake_wait(handshake);
40+
41+ tracepoint(upstart_app_launch, click_handshake_complete);
42+
43 return 0;
44 }
45
46=== added directory 'data'
47=== added file 'data/com.canonical.UpstartAppLaunch.xml'
48--- data/com.canonical.UpstartAppLaunch.xml 1970-01-01 00:00:00 +0000
49+++ data/com.canonical.UpstartAppLaunch.xml 2013-12-06 12:27:28 +0000
50@@ -0,0 +1,20 @@
51+<?xml version="1.0" encoding="UTF-8"?>
52+<node>
53+ <interface name="com.canonical.UpstartAppLaunch">
54+ <signal name="UnityResumeRequest">
55+ <arg type="s" name="appid" />
56+ </signal>
57+ <signal name="UnityResumeResponse">
58+ <arg type="s" name="appid" />
59+ </signal>
60+ <signal name="UnityFocusRequest">
61+ <arg type="s" name="appid" />
62+ </signal>
63+ <signal name="UnityStartingBroadcast">
64+ <arg type="s" name="appid" />
65+ </signal>
66+ <signal name="UnityStartingSignal">
67+ <arg type="s" name="appid" />
68+ </signal>
69+ </interface>
70+</node>
71
72=== modified file 'debian/control'
73--- debian/control 2013-12-06 10:38:35 +0000
74+++ debian/control 2013-12-06 12:27:28 +0000
75@@ -49,7 +49,7 @@
76 .
77 This package provides tools for working with the Upstart App Launch.
78
79-Package: libupstart-app-launch1
80+Package: libupstart-app-launch2
81 Section: libs
82 Architecture: any
83 Depends: ${misc:Depends},
84@@ -62,15 +62,17 @@
85 .
86 This package contains shared libraries to be used by applications.
87
88-Package: libupstart-app-launch1-dev
89+Package: libupstart-app-launch2-dev
90 Section: libdevel
91 Architecture: any
92 Depends: ${misc:Depends},
93 ${shlibs:Depends},
94 libglib2.0-dev,
95- libupstart-app-launch1 (= ${binary:Version}),
96+ libupstart-app-launch2 (= ${binary:Version}),
97 Pre-Depends: ${misc:Pre-Depends},
98 Multi-Arch: same
99+Replaces: libupstart-app-launch1-dev
100+Conflicts: libupstart-app-launch1-dev
101 Description: library for sending requests to the upstart app launch
102 Upstart Job file and associated utilities that is used to launch
103 applications in a standard and confined way.
104
105=== renamed file 'debian/libupstart-app-launch1-dev.install' => 'debian/libupstart-app-launch2-dev.install'
106=== renamed file 'debian/libupstart-app-launch1.install' => 'debian/libupstart-app-launch2.install'
107--- debian/libupstart-app-launch1.install 2013-08-02 13:24:59 +0000
108+++ debian/libupstart-app-launch2.install 2013-12-06 12:27:28 +0000
109@@ -1,1 +1,1 @@
110-usr/lib/*/libupstart-app-launch.so.1*
111+usr/lib/*/libupstart-app-launch.so.2*
112
113=== renamed file 'debian/libupstart-app-launch1.symbols' => 'debian/libupstart-app-launch2.symbols'
114--- debian/libupstart-app-launch1.symbols 2013-10-08 19:38:15 +0000
115+++ debian/libupstart-app-launch2.symbols 2013-12-06 12:27:28 +0000
116@@ -1,15 +1,17 @@
117-libupstart-app-launch.so.1 libupstart-app-launch1 #MINVER#
118+libupstart-app-launch.so.2 libupstart-app-launch2 #MINVER#
119 upstart_app_launch_get_primary_pid@Base 0.2
120 upstart_app_launch_list_running_apps@Base 0.2
121 upstart_app_launch_observer_add_app_failed@Base 0.2
122 upstart_app_launch_observer_add_app_focus@Base 0.2
123 upstart_app_launch_observer_add_app_resume@Base 0.2
124- upstart_app_launch_observer_add_app_start@Base 0.2
125+ upstart_app_launch_observer_add_app_started@Base 0replaceme
126+ upstart_app_launch_observer_add_app_starting@Base 0replaceme
127 upstart_app_launch_observer_add_app_stop@Base 0.2
128 upstart_app_launch_observer_delete_app_failed@Base 0.2
129 upstart_app_launch_observer_delete_app_focus@Base 0.2
130 upstart_app_launch_observer_delete_app_resume@Base 0.2
131- upstart_app_launch_observer_delete_app_start@Base 0.2
132+ upstart_app_launch_observer_delete_app_started@Base 0replaceme
133+ upstart_app_launch_observer_delete_app_starting@Base 0replaceme
134 upstart_app_launch_observer_delete_app_stop@Base 0.2
135 upstart_app_launch_pid_in_app_id@Base 0.2
136 upstart_app_launch_start_application@Base 0.2
137
138=== modified file 'desktop-exec-trace.tp'
139--- desktop-exec-trace.tp 2013-12-04 17:07:09 +0000
140+++ desktop-exec-trace.tp 2013-12-06 12:27:28 +0000
141@@ -1,5 +1,7 @@
142
143 TRACEPOINT_EVENT(upstart_app_launch, desktop_start, TP_ARGS(0), TP_FIELDS())
144+TRACEPOINT_EVENT(upstart_app_launch, desktop_starting_sent, TP_ARGS(0), TP_FIELDS())
145 TRACEPOINT_EVENT(upstart_app_launch, desktop_found, TP_ARGS(0), TP_FIELDS())
146-TRACEPOINT_EVENT(upstart_app_launch, desktop_finished, TP_ARGS(0), TP_FIELDS())
147+TRACEPOINT_EVENT(upstart_app_launch, desktop_handshake_wait, TP_ARGS(0), TP_FIELDS())
148+TRACEPOINT_EVENT(upstart_app_launch, desktop_handshake_complete, TP_ARGS(0), TP_FIELDS())
149
150
151=== modified file 'desktop-exec.c'
152--- desktop-exec.c 2013-12-05 17:08:13 +0000
153+++ desktop-exec.c 2013-12-06 12:27:28 +0000
154@@ -44,6 +44,13 @@
155 g_setenv("LTTNG_UST_REGISTER_TIMEOUT", "0", FALSE); /* Set to zero if not set */
156 tracepoint(upstart_app_launch, desktop_start);
157
158+ handshake_t * handshake = starting_handshake_start(app_id);
159+ if (handshake == NULL) {
160+ g_warning("Unable to setup starting handshake");
161+ }
162+
163+ tracepoint(upstart_app_launch, desktop_starting_sent);
164+
165 gchar * desktopfilename = NULL;
166 GKeyFile * keyfile = keyfile_for_appid(app_id, &desktopfilename);
167
168@@ -84,7 +91,11 @@
169 g_free(desktopfilename);
170 }
171
172- tracepoint(upstart_app_launch, desktop_finished);
173+ tracepoint(upstart_app_launch, desktop_handshake_wait);
174+
175+ starting_handshake_wait(handshake);
176+
177+ tracepoint(upstart_app_launch, desktop_handshake_complete);
178
179 return 0;
180 }
181
182=== modified file 'helpers.c'
183--- helpers.c 2013-11-22 16:35:27 +0000
184+++ helpers.c 2013-12-06 12:27:28 +0000
185@@ -582,3 +582,85 @@
186
187 return;
188 }
189+
190+static void
191+unity_signal_cb (GDBusConnection * con, const gchar * sender, const gchar * path, const gchar * interface, const gchar * signal, GVariant * params, gpointer user_data)
192+{
193+ GMainLoop * mainloop = (GMainLoop *)user_data;
194+ g_main_loop_quit(mainloop);
195+}
196+
197+struct _handshake_t {
198+ GDBusConnection * con;
199+ GMainLoop * mainloop;
200+ guint signal_subscribe;
201+ guint timeout;
202+};
203+
204+static gboolean
205+unity_too_slow_cb (gpointer user_data)
206+{
207+ handshake_t * handshake = (handshake_t *)user_data;
208+ g_main_loop_quit(handshake->mainloop);
209+ handshake->timeout = 0;
210+ return G_SOURCE_REMOVE;
211+}
212+
213+handshake_t *
214+starting_handshake_start (const gchar * app_id)
215+{
216+ GError * error = NULL;
217+ handshake_t * handshake = g_new0(handshake_t, 1);
218+
219+ handshake->mainloop = g_main_loop_new(NULL, FALSE);
220+ handshake->con = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
221+
222+ if (error != NULL) {
223+ g_critical("Unable to connect to session bus: %s", error->message);
224+ g_error_free(error);
225+ g_free(handshake);
226+ return NULL;
227+ }
228+
229+ /* Set up listening for the unfrozen signal from Unity */
230+ handshake->signal_subscribe = g_dbus_connection_signal_subscribe(handshake->con,
231+ NULL, /* sender */
232+ "com.canonical.UpstartAppLaunch", /* interface */
233+ "UnityStartingSignal", /* signal */
234+ "/", /* path */
235+ app_id, /* arg0 */
236+ G_DBUS_SIGNAL_FLAGS_NONE,
237+ unity_signal_cb, handshake->mainloop,
238+ NULL); /* user data destroy */
239+
240+ /* Send unfreeze to to Unity */
241+ g_dbus_connection_emit_signal(handshake->con,
242+ NULL, /* destination */
243+ "/", /* path */
244+ "com.canonical.UpstartAppLaunch", /* interface */
245+ "UnityStartingBroadcast", /* signal */
246+ g_variant_new("(s)", app_id),
247+ &error);
248+
249+ /* Really, Unity? */
250+ handshake->timeout = g_timeout_add_seconds(1, unity_too_slow_cb, handshake);
251+
252+ return handshake;
253+}
254+
255+void
256+starting_handshake_wait (handshake_t * handshake)
257+{
258+ if (handshake == NULL)
259+ return;
260+
261+ g_main_loop_run(handshake->mainloop);
262+
263+ if (handshake->timeout != 0)
264+ g_source_remove(handshake->timeout);
265+ g_main_loop_unref(handshake->mainloop);
266+ g_dbus_connection_signal_unsubscribe(handshake->con, handshake->signal_subscribe);
267+ g_object_unref(handshake->con);
268+
269+ g_free(handshake);
270+}
271
272=== modified file 'helpers.h'
273--- helpers.h 2013-11-12 21:06:02 +0000
274+++ helpers.h 2013-12-06 12:27:28 +0000
275@@ -36,3 +36,7 @@
276 void set_confined_envvars (const gchar * package,
277 const gchar * app_dir);
278
279+typedef struct _handshake_t handshake_t;
280+handshake_t * starting_handshake_start (const gchar * app_id);
281+void starting_handshake_wait (handshake_t * handshake);
282+
283
284=== modified file 'libupstart-app-launch/CMakeLists.txt'
285--- libupstart-app-launch/CMakeLists.txt 2013-08-08 03:54:36 +0000
286+++ libupstart-app-launch/CMakeLists.txt 2013-12-06 12:27:28 +0000
287@@ -3,8 +3,8 @@
288 # Version Info
289 ##########################
290
291-set(API_VERSION 1)
292-set(ABI_VERSION 1)
293+set(API_VERSION 2)
294+set(ABI_VERSION 2)
295
296
297 ##########################
298
299=== modified file 'libupstart-app-launch/upstart-app-launch.c'
300--- libupstart-app-launch/upstart-app-launch.c 2013-11-25 14:44:42 +0000
301+++ libupstart-app-launch/upstart-app-launch.c 2013-12-06 12:27:28 +0000
302@@ -163,8 +163,6 @@
303 g_free(app);
304 g_free(inst);
305 nih_unref(job_proxy, NULL);
306-
307- return;
308 }
309
310 static void
311@@ -257,7 +255,8 @@
312 };
313
314 /* The lists of Observers */
315-static GList * start_array = NULL;
316+static GList * starting_array = NULL;
317+static GList * started_array = NULL;
318 static GList * stop_array = NULL;
319 static GList * focus_array = NULL;
320 static GList * resume_array = NULL;
321@@ -301,8 +300,6 @@
322 }
323
324 g_free(instance);
325-
326- return;
327 }
328
329 /* Creates the observer structure and registers for the signal with
330@@ -339,9 +336,9 @@
331 }
332
333 gboolean
334-upstart_app_launch_observer_add_app_start (upstart_app_launch_app_observer_t observer, gpointer user_data)
335+upstart_app_launch_observer_add_app_started (upstart_app_launch_app_observer_t observer, gpointer user_data)
336 {
337- return add_app_generic(observer, user_data, "started", &start_array);
338+ return add_app_generic(observer, user_data, "started", &started_array);
339 }
340
341 gboolean
342@@ -394,8 +391,6 @@
343 g_variant_get(params, "(&s)", &appid);
344 observer->func(appid, observer->user_data);
345 }
346-
347- return;
348 }
349
350 gboolean
351@@ -423,8 +418,6 @@
352 g_warning("Unable to emit response signal: %s", error->message);
353 g_error_free(error);
354 }
355-
356- return;
357 }
358
359 gboolean
360@@ -433,6 +426,33 @@
361 return add_session_generic(observer, user_data, "UnityResumeRequest", &resume_array, resume_signal_cb);
362 }
363
364+/* Handle the starting signal when it occurs, call the observer, then send a signal back when we're done */
365+static void
366+starting_signal_cb (GDBusConnection * conn, const gchar * sender, const gchar * object, const gchar * interface, const gchar * signal, GVariant * params, gpointer user_data)
367+{
368+ focus_signal_cb(conn, sender, object, interface, signal, params, user_data);
369+
370+ GError * error = NULL;
371+ g_dbus_connection_emit_signal(conn,
372+ sender, /* destination */
373+ "/", /* path */
374+ "com.canonical.UpstartAppLaunch", /* interface */
375+ "UnityStartingSignal", /* signal */
376+ params, /* params, the same */
377+ &error);
378+
379+ if (error != NULL) {
380+ g_warning("Unable to emit response signal: %s", error->message);
381+ g_error_free(error);
382+ }
383+}
384+
385+gboolean
386+upstart_app_launch_observer_add_app_starting (upstart_app_launch_app_observer_t observer, gpointer user_data)
387+{
388+ return add_session_generic(observer, user_data, "UnityStartingBroadcast", &starting_array, starting_signal_cb);
389+}
390+
391 gboolean
392 upstart_app_launch_observer_add_app_failed (upstart_app_launch_app_failed_observer_t observer, gpointer user_data)
393 {
394@@ -467,9 +487,9 @@
395 }
396
397 gboolean
398-upstart_app_launch_observer_delete_app_start (upstart_app_launch_app_observer_t observer, gpointer user_data)
399+upstart_app_launch_observer_delete_app_started (upstart_app_launch_app_observer_t observer, gpointer user_data)
400 {
401- return delete_app_generic(observer, user_data, &start_array);
402+ return delete_app_generic(observer, user_data, &started_array);
403 }
404
405 gboolean
406@@ -491,6 +511,12 @@
407 }
408
409 gboolean
410+upstart_app_launch_observer_delete_app_starting (upstart_app_launch_app_observer_t observer, gpointer user_data)
411+{
412+ return delete_app_generic(observer, user_data, &starting_array);
413+}
414+
415+gboolean
416 upstart_app_launch_observer_delete_app_failed (upstart_app_launch_app_failed_observer_t observer, gpointer user_data)
417 {
418 return FALSE;
419@@ -549,8 +575,6 @@
420
421 nih_unref(instance_proxy, NULL);
422 }
423-
424- return;
425 }
426
427 gchar **
428
429=== modified file 'libupstart-app-launch/upstart-app-launch.h'
430--- libupstart-app-launch/upstart-app-launch.h 2013-09-26 15:19:22 +0000
431+++ libupstart-app-launch/upstart-app-launch.h 2013-12-06 12:27:28 +0000
432@@ -80,16 +80,29 @@
433 gboolean upstart_app_launch_stop_application (const gchar * appid);
434
435 /**
436- * upstart_app_launch_observer_add_app_start:
437- * @observer: Callback when an application starts
438- * @user_data: (allow none): Data to pass to the observer
439- *
440- * Sets up a callback to get called each time an application
441- * starts.
442- *
443- * Return value: Whether adding the observer was successful.
444- */
445-gboolean upstart_app_launch_observer_add_app_start (upstart_app_launch_app_observer_t observer,
446+ * upstart_app_launch_observer_add_app_starting:
447+ * @observer: Callback when an application is about to start
448+ * @user_data: (allow none): Data to pass to the observer
449+ *
450+ * Sets up a callback to get called each time an application
451+ * is about to start. The application will not start until the
452+ * function returns.
453+ *
454+ * Return value: Whether adding the observer was successful.
455+ */
456+gboolean upstart_app_launch_observer_add_app_starting (upstart_app_launch_app_observer_t observer,
457+ gpointer user_data);
458+/**
459+ * upstart_app_launch_observer_add_app_started:
460+ * @observer: Callback when an application started
461+ * @user_data: (allow none): Data to pass to the observer
462+ *
463+ * Sets up a callback to get called each time an application
464+ * has been started.
465+ *
466+ * Return value: Whether adding the observer was successful.
467+ */
468+gboolean upstart_app_launch_observer_add_app_started (upstart_app_launch_app_observer_t observer,
469 gpointer user_data);
470 /**
471 * upstart_app_launch_observer_add_app_stop:
472@@ -145,16 +158,28 @@
473 gpointer user_data);
474
475 /**
476- * upstart_app_launch_observer_delete_app_start:
477- * @observer: Callback to remove
478- * @user_data: (allow none): Data that was passed to the observer
479- *
480- * Removes a previously registered callback to ensure it no longer
481- * gets signaled.
482- *
483- * Return value: Whether deleting the observer was successful.
484- */
485-gboolean upstart_app_launch_observer_delete_app_start (upstart_app_launch_app_observer_t observer,
486+ * upstart_app_launch_observer_delete_app_starting:
487+ * @observer: Callback to remove
488+ * @user_data: (allow none): Data that was passed to the observer
489+ *
490+ * Removes a previously registered callback to ensure it no longer
491+ * gets signaled.
492+ *
493+ * Return value: Whether deleting the observer was successful.
494+ */
495+gboolean upstart_app_launch_observer_delete_app_starting (upstart_app_launch_app_observer_t observer,
496+ gpointer user_data);
497+/**
498+ * upstart_app_launch_observer_delete_app_started:
499+ * @observer: Callback to remove
500+ * @user_data: (allow none): Data that was passed to the observer
501+ *
502+ * Removes a previously registered callback to ensure it no longer
503+ * gets signaled.
504+ *
505+ * Return value: Whether deleting the observer was successful.
506+ */
507+gboolean upstart_app_launch_observer_delete_app_started (upstart_app_launch_app_observer_t observer,
508 gpointer user_data);
509 /**
510 * upstart_app_launch_observer_delete_app_stop:
511
512=== modified file 'tests/CMakeLists.txt'
513--- tests/CMakeLists.txt 2013-12-04 17:48:47 +0000
514+++ tests/CMakeLists.txt 2013-12-06 12:27:28 +0000
515@@ -18,6 +18,13 @@
516
517 add_test (helper-test helper-test)
518
519+# Helper test
520+
521+add_executable (helper-handshake-test helper-handshake-test.cc)
522+target_link_libraries (helper-handshake-test helpers gtest ${GTEST_LIBS})
523+
524+add_test (helper-handshake-test helper-handshake-test)
525+
526 # Second Exec Test
527
528 include_directories("${CMAKE_SOURCE_DIR}/libupstart-app-launch")
529@@ -42,6 +49,7 @@
530 add_test (NAME libual-test-pid COMMAND libual-test --gtest_filter=*ApplicationPid)
531 add_test (NAME libual-test-list COMMAND libual-test --gtest_filter=*ApplicationList)
532 add_test (NAME libual-test-observer COMMAND libual-test --gtest_filter=*StartStopObserver)
533+add_test (NAME libual-test-starting COMMAND libual-test --gtest_filter=*StartingResponses)
534
535 # ZG Test
536
537
538=== added file 'tests/helper-handshake-test.cc'
539--- tests/helper-handshake-test.cc 1970-01-01 00:00:00 +0000
540+++ tests/helper-handshake-test.cc 2013-12-06 12:27:28 +0000
541@@ -0,0 +1,120 @@
542+/*
543+ * Copyright 2013 Canonical Ltd.
544+ *
545+ * This program is free software: you can redistribute it and/or modify it
546+ * under the terms of the GNU General Public License version 3, as published
547+ * by the Free Software Foundation.
548+ *
549+ * This program is distributed in the hope that it will be useful, but
550+ * WITHOUT ANY WARRANTY; without even the implied warranties of
551+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
552+ * PURPOSE. See the GNU General Public License for more details.
553+ *
554+ * You should have received a copy of the GNU General Public License along
555+ * with this program. If not, see <http://www.gnu.org/licenses/>.
556+ *
557+ * Authors:
558+ * Ted Gould <ted.gould@canonical.com>
559+ */
560+
561+#include <gtest/gtest.h>
562+#include <glib/gstdio.h>
563+#include <gio/gio.h>
564+
565+extern "C" {
566+#include "../helpers.h"
567+}
568+
569+class HelperHandshakeTest : public ::testing::Test
570+{
571+ private:
572+ GTestDBus * testbus = NULL;
573+
574+ protected:
575+ GMainLoop * mainloop = NULL;
576+
577+ virtual void SetUp() {
578+ mainloop = g_main_loop_new(NULL, FALSE);
579+ testbus = g_test_dbus_new(G_TEST_DBUS_NONE);
580+ g_test_dbus_up(testbus);
581+ }
582+
583+ virtual void TearDown() {
584+ g_test_dbus_down(testbus);
585+ g_clear_object(&testbus);
586+ g_main_loop_unref(mainloop);
587+ mainloop = NULL;
588+ return;
589+ }
590+
591+ public:
592+ GDBusMessage * FilterFunc (GDBusConnection * conn, GDBusMessage * message, gboolean incomming) {
593+ if (g_strcmp0(g_dbus_message_get_member(message), "UnityStartingBroadcast") == 0) {
594+ GVariant * body = g_dbus_message_get_body(message);
595+ GVariant * correct_body = g_variant_new("(s)", "fooapp");
596+ g_variant_ref_sink(correct_body);
597+
598+ [body, correct_body]() {
599+ ASSERT_TRUE(g_variant_equal(body, correct_body));
600+ }();
601+
602+ g_variant_unref(correct_body);
603+ g_main_loop_quit(mainloop);
604+ }
605+
606+ return message;
607+ }
608+
609+};
610+
611+static GDBusMessage *
612+filter_func (GDBusConnection * conn, GDBusMessage * message, gboolean incomming, gpointer user_data) {
613+ return static_cast<HelperHandshakeTest *>(user_data)->FilterFunc(conn, message, incomming);
614+}
615+
616+TEST_F(HelperHandshakeTest, BaseHandshake)
617+{
618+ GDBusConnection * con = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
619+ guint filter = g_dbus_connection_add_filter(con, filter_func, this, NULL);
620+
621+ handshake_t * handshake = starting_handshake_start("fooapp");
622+
623+ g_main_loop_run(mainloop);
624+
625+ g_dbus_connection_remove_filter(con, filter);
626+
627+ g_dbus_connection_emit_signal(con,
628+ g_dbus_connection_get_unique_name(con), /* destination */
629+ "/", /* path */
630+ "com.canonical.UpstartAppLaunch", /* interface */
631+ "UnityStartingSignal", /* signal */
632+ g_variant_new("(s)", "fooapp"), /* params, the same */
633+ NULL);
634+
635+ starting_handshake_wait(handshake);
636+
637+ g_object_unref(con);
638+
639+ return;
640+}
641+
642+static gboolean
643+two_second_reached (gpointer user_data)
644+{
645+ bool * reached = static_cast<bool *>(user_data);
646+ *reached = true;
647+}
648+
649+TEST_F(HelperHandshakeTest, HandshakeTimeout)
650+{
651+ bool timeout_reached = false;
652+ handshake_t * handshake = starting_handshake_start("fooapp");
653+
654+ guint outertimeout = g_timeout_add_seconds(2, two_second_reached, &timeout_reached);
655+
656+ starting_handshake_wait(handshake);
657+
658+ ASSERT_FALSE(timeout_reached);
659+
660+ return;
661+}
662
663=== modified file 'tests/libual-test.cc'
664--- tests/libual-test.cc 2013-11-25 14:49:12 +0000
665+++ tests/libual-test.cc 2013-12-06 12:27:28 +0000
666@@ -182,6 +182,27 @@
667
668 return found;
669 }
670+
671+ static gboolean pause_helper (gpointer pmainloop) {
672+ g_main_loop_quit((GMainLoop *)pmainloop);
673+ return G_SOURCE_REMOVE;
674+ }
675+
676+ void pause (guint time) {
677+ if (time > 0) {
678+ GMainLoop * mainloop = g_main_loop_new(NULL, FALSE);
679+ guint timer = g_timeout_add(time, pause_helper, mainloop);
680+
681+ g_main_loop_run(mainloop);
682+
683+ g_source_remove(timer);
684+ g_main_loop_unref(mainloop);
685+ }
686+
687+ while (g_main_pending()) {
688+ g_main_iteration(TRUE);
689+ }
690+ }
691 };
692
693 TEST_F(LibUAL, StartApplication)
694@@ -307,7 +328,7 @@
695 .name = nullptr
696 };
697
698- ASSERT_TRUE(upstart_app_launch_observer_add_app_start(observer_cb, &start_data));
699+ ASSERT_TRUE(upstart_app_launch_observer_add_app_started(observer_cb, &start_data));
700 ASSERT_TRUE(upstart_app_launch_observer_add_app_stop(observer_cb, &stop_data));
701 ASSERT_FALSE(upstart_app_launch_observer_add_app_failed(NULL, NULL)); /* Not yet implemented */
702
703@@ -417,7 +438,59 @@
704
705
706 /* Remove */
707- ASSERT_TRUE(upstart_app_launch_observer_delete_app_start(observer_cb, &start_data));
708+ ASSERT_TRUE(upstart_app_launch_observer_delete_app_started(observer_cb, &start_data));
709 ASSERT_TRUE(upstart_app_launch_observer_delete_app_stop(observer_cb, &stop_data));
710 ASSERT_FALSE(upstart_app_launch_observer_delete_app_failed(NULL, NULL)); /* Not yet implemented */
711 }
712+
713+static GDBusMessage *
714+filter_starting (GDBusConnection * conn, GDBusMessage * message, gboolean incomming, gpointer user_data)
715+{
716+ if (g_strcmp0(g_dbus_message_get_member(message), "UnityStartingSignal") == 0) {
717+ unsigned int * count = static_cast<unsigned int *>(user_data);
718+ (*count)++;
719+ g_object_unref(message);
720+ return NULL;
721+ }
722+
723+ return message;
724+}
725+
726+static void
727+starting_observer (const gchar * appid, gpointer user_data)
728+{
729+ std::string * last = static_cast<std::string *>(user_data);
730+ *last = appid;
731+ return;
732+}
733+
734+TEST_F(LibUAL, StartingResponses)
735+{
736+ std::string last_observer;
737+ unsigned int starting_count = 0;
738+ GDBusConnection * session = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
739+ guint filter = g_dbus_connection_add_filter(session,
740+ filter_starting,
741+ &starting_count,
742+ NULL);
743+
744+ EXPECT_TRUE(upstart_app_launch_observer_add_app_starting(starting_observer, &last_observer));
745+
746+ g_dbus_connection_emit_signal(session,
747+ NULL, /* destination */
748+ "/", /* path */
749+ "com.canonical.UpstartAppLaunch", /* interface */
750+ "UnityStartingBroadcast", /* signal */
751+ g_variant_new("(s)", "foo"), /* params, the same */
752+ NULL);
753+
754+ pause(100);
755+
756+ EXPECT_EQ("foo", last_observer);
757+ EXPECT_EQ(1, starting_count);
758+
759+ EXPECT_TRUE(upstart_app_launch_observer_delete_app_starting(starting_observer, &last_observer));
760+
761+ g_dbus_connection_remove_filter(session, filter);
762+ g_object_unref(session);
763+}
764
765=== modified file 'tests/second-exec-test.cc'
766--- tests/second-exec-test.cc 2013-10-04 19:22:41 +0000
767+++ tests/second-exec-test.cc 2013-12-06 12:27:28 +0000
768@@ -58,8 +58,6 @@
769
770 upstart_app_launch_observer_add_app_focus(focus_cb, this);
771 upstart_app_launch_observer_add_app_resume(resume_cb, this);
772-
773- return;
774 }
775 virtual void TearDown() {
776 upstart_app_launch_observer_delete_app_focus(focus_cb, this);
777@@ -67,8 +65,6 @@
778
779 g_test_dbus_down(testbus);
780 g_object_unref(testbus);
781-
782- return;
783 }
784
785 static gboolean pause_helper (gpointer pmainloop) {
786@@ -90,8 +86,6 @@
787 while (g_main_pending()) {
788 g_main_iteration(TRUE);
789 }
790-
791- return;
792 }
793 };
794
795
796=== modified file 'upstart-app-watch.c'
797--- upstart-app-watch.c 2013-09-24 22:18:11 +0000
798+++ upstart-app-watch.c 2013-12-06 12:27:28 +0000
799@@ -20,30 +20,37 @@
800 #include "libupstart-app-launch/upstart-app-launch.h"
801
802 void
803+starting (const gchar * appid, gpointer user_data)
804+{
805+ g_print("Starting %s\n", appid);
806+ return;
807+}
808+
809+void
810 started (const gchar * appid, gpointer user_data)
811 {
812- g_print("Start %s\n", appid);
813+ g_print("Started %s\n", appid);
814 return;
815 }
816
817 void
818 stopped (const gchar * appid, gpointer user_data)
819 {
820- g_print("Stop %s\n", appid);
821+ g_print("Stop %s\n", appid);
822 return;
823 }
824
825 void
826 resume (const gchar * appid, gpointer user_data)
827 {
828- g_print("Resume %s\n", appid);
829+ g_print("Resume %s\n", appid);
830 return;
831 }
832
833 void
834 focus (const gchar * appid, gpointer user_data)
835 {
836- g_print("Focus %s\n", appid);
837+ g_print("Focus %s\n", appid);
838 return;
839 }
840
841@@ -60,7 +67,7 @@
842 break;
843 }
844
845- g_print("Focus %s (%s)\n", appid, failstr);
846+ g_print("Fail %s (%s)\n", appid, failstr);
847 return;
848 }
849
850@@ -68,7 +75,8 @@
851 int
852 main (int argc, gchar * argv[])
853 {
854- upstart_app_launch_observer_add_app_start(started, NULL);
855+ upstart_app_launch_observer_add_app_starting(starting, NULL);
856+ upstart_app_launch_observer_add_app_started(started, NULL);
857 upstart_app_launch_observer_add_app_stop(stopped, NULL);
858 upstart_app_launch_observer_add_app_focus(focus, NULL);
859 upstart_app_launch_observer_add_app_resume(resume, NULL);
860@@ -77,7 +85,8 @@
861 GMainLoop * mainloop = g_main_loop_new(NULL, FALSE);
862 g_main_loop_run(mainloop);
863
864- upstart_app_launch_observer_delete_app_start(started, NULL);
865+ upstart_app_launch_observer_delete_app_starting(starting, NULL);
866+ upstart_app_launch_observer_delete_app_started(started, NULL);
867 upstart_app_launch_observer_delete_app_stop(stopped, NULL);
868 upstart_app_launch_observer_delete_app_focus(focus, NULL);
869 upstart_app_launch_observer_delete_app_resume(resume, NULL);

Subscribers

People subscribed via source and target branches