Merge lp:~ted/url-dispatcher/lp1356077-send-without-mainloop into lp:url-dispatcher/14.10

Proposed by Ted Gould
Status: Merged
Approved by: Charles Kerr
Approved revision: 66
Merged at revision: 64
Proposed branch: lp:~ted/url-dispatcher/lp1356077-send-without-mainloop
Merge into: lp:url-dispatcher/14.10
Diff against target: 216 lines (+86/-54)
5 files modified
liburl-dispatcher/url-dispatcher.c (+41/-53)
tests/CMakeLists.txt (+4/-0)
tests/lib-test-no-main.c (+25/-0)
tests/lib-test.cc (+15/-0)
tests/url_dispatcher_testability/CMakeLists.txt (+1/-1)
To merge this branch: bzr merge lp:~ted/url-dispatcher/lp1356077-send-without-mainloop
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+231009@code.launchpad.net

Commit message

Ensure send works even without a mainloop

Description of the change

Just needed to ensure we didn't have a callback if we didn't have a callback (yes, that makes sense if you think about it), but it turned out to clean up a lot if we just removed getting the proxy. So I did that.

To post a comment you must log in.
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: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

+1, I agree with the premise and it really did simplify things.

review: Approve
67. By Ted Gould

Use dbus-test-runner for the tests

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'liburl-dispatcher/url-dispatcher.c'
2--- liburl-dispatcher/url-dispatcher.c 2014-07-16 19:16:10 +0000
3+++ liburl-dispatcher/url-dispatcher.c 2014-08-19 21:02:22 +0000
4@@ -16,11 +16,10 @@
5 */
6
7 #include "url-dispatcher.h"
8-#include "service-iface.h"
9+#include <gio/gio.h>
10
11 typedef struct _dispatch_data_t dispatch_data_t;
12 struct _dispatch_data_t {
13- ServiceIfaceComCanonicalURLDispatcher * proxy;
14 URLDispatchCallback cb;
15 gpointer user_data;
16 gchar * url;
17@@ -33,8 +32,8 @@
18 GError * error = NULL;
19 dispatch_data_t * dispatch_data = (dispatch_data_t *)user_data;
20
21- service_iface_com_canonical_urldispatcher_call_dispatch_url_finish(
22- SERVICE_IFACE_COM_CANONICAL_URLDISPATCHER(obj),
23+ g_dbus_connection_call_finish(
24+ G_DBUS_CONNECTION(obj),
25 res,
26 &error);
27
28@@ -51,7 +50,6 @@
29 }
30 }
31
32- g_clear_object(&dispatch_data->proxy);
33 g_free(dispatch_data->url);
34 g_free(dispatch_data->package);
35 g_free(dispatch_data);
36@@ -59,38 +57,6 @@
37 return;
38 }
39
40-static void
41-got_proxy (GObject * obj, GAsyncResult * res, gpointer user_data)
42-{
43- GError * error = NULL;
44- dispatch_data_t * dispatch_data = (dispatch_data_t *)user_data;
45-
46- dispatch_data->proxy = service_iface_com_canonical_urldispatcher_proxy_new_for_bus_finish(res, &error);
47-
48- if (error != NULL) {
49- g_warning("Unable to get proxy for URL Dispatcher: %s", error->message);
50- g_error_free(error);
51-
52- if (dispatch_data->cb != NULL) {
53- dispatch_data->cb(dispatch_data->url, FALSE, dispatch_data->user_data);
54- }
55-
56- g_free(dispatch_data->url);
57- g_free(dispatch_data);
58- return;
59- }
60-
61- service_iface_com_canonical_urldispatcher_call_dispatch_url(
62- dispatch_data->proxy,
63- dispatch_data->url,
64- dispatch_data->package ? dispatch_data->package : "",
65- NULL, /* cancelable */
66- url_dispatched,
67- dispatch_data);
68-
69- return;
70-}
71-
72 void
73 url_dispatch_send (const gchar * url, URLDispatchCallback cb, gpointer user_data)
74 {
75@@ -100,22 +66,44 @@
76 void
77 url_dispatch_send_restricted (const gchar * url, const gchar * package, URLDispatchCallback cb, gpointer user_data)
78 {
79- dispatch_data_t * dispatch_data = g_new0(dispatch_data_t, 1);
80-
81- dispatch_data->cb = cb;
82- dispatch_data->user_data = user_data;
83- dispatch_data->url = g_strdup(url);
84- dispatch_data->package = g_strdup(package);
85-
86- service_iface_com_canonical_urldispatcher_proxy_new_for_bus(
87- G_BUS_TYPE_SESSION,
88- G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
89- "com.canonical.URLDispatcher",
90- "/com/canonical/URLDispatcher",
91- NULL, /* cancellable */
92- got_proxy,
93- dispatch_data
94- );
95+ GError * error = NULL;
96+ GDBusConnection * bus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
97+
98+ if (error != NULL) {
99+ g_warning("Unable to get session bus: %s", error->message);
100+ g_error_free(error);
101+ return;
102+ }
103+
104+ dispatch_data_t * dispatch_data = NULL;
105+
106+ if (cb != NULL) {
107+ dispatch_data = g_new0(dispatch_data_t, 1);
108+
109+ dispatch_data->cb = cb;
110+ dispatch_data->user_data = user_data;
111+ dispatch_data->url = g_strdup(url);
112+ dispatch_data->package = g_strdup(package);
113+ }
114+
115+ g_dbus_connection_call(bus,
116+ "com.canonical.URLDispatcher",
117+ "/com/canonical/URLDispatcher",
118+ "com.canonical.URLDispatcher",
119+ "DispatchURL",
120+ g_variant_new("(ss)", url, package ? package : ""),
121+ NULL,
122+ G_DBUS_CALL_FLAGS_NO_AUTO_START,
123+ -1, /* timeout */
124+ NULL, /* cancelable */
125+ cb != NULL ? url_dispatched : NULL,
126+ dispatch_data);
127+
128+ if (cb == NULL) {
129+ g_dbus_connection_flush_sync(bus, NULL, NULL);
130+ }
131+
132+ g_object_unref(bus);
133
134 return;
135 }
136
137=== modified file 'tests/CMakeLists.txt'
138--- tests/CMakeLists.txt 2014-07-20 11:45:00 +0000
139+++ tests/CMakeLists.txt 2014-08-19 21:02:22 +0000
140@@ -71,6 +71,10 @@
141 # lib test
142 ###########################
143
144+add_executable (lib-test-no-main lib-test-no-main.c)
145+target_link_libraries (lib-test-no-main dispatcher)
146+add_definitions ( -DLIB_TEST_NO_MAIN_HELPER="${CMAKE_CURRENT_BINARY_DIR}/lib-test-no-main" )
147+
148 add_executable (lib-test lib-test.cc)
149 target_link_libraries (lib-test
150 dispatcher
151
152=== added file 'tests/lib-test-no-main.c'
153--- tests/lib-test-no-main.c 1970-01-01 00:00:00 +0000
154+++ tests/lib-test-no-main.c 2014-08-19 21:02:22 +0000
155@@ -0,0 +1,25 @@
156+/**
157+ * Copyright (C) 2013 Canonical, Ltd.
158+ *
159+ * This program is free software: you can redistribute it and/or modify it under
160+ * the terms of the GNU Lesser General Public License version 3, as published by
161+ * the Free Software Foundation.
162+ *
163+ * This program is distributed in the hope that it will be useful, but WITHOUT
164+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
165+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
166+ * Lesser General Public License for more details.
167+ *
168+ * You should have received a copy of the GNU Lesser General Public License
169+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
170+ *
171+ */
172+
173+#include <gio/gio.h>
174+#include <liburl-dispatcher/url-dispatcher.h>
175+
176+int
177+main (int argc, char * argv[]) {
178+ url_dispatch_send("foo://bar/barish", NULL, NULL);
179+ return 0;
180+}
181
182=== modified file 'tests/lib-test.cc'
183--- tests/lib-test.cc 2014-07-16 19:36:10 +0000
184+++ tests/lib-test.cc 2014-08-19 21:02:22 +0000
185@@ -101,6 +101,21 @@
186 g_variant_unref(check);
187 }
188
189+TEST_F(LibTest, NoMain) {
190+ /* Spawning a non-main caller */
191+ g_spawn_command_line_sync(LIB_TEST_NO_MAIN_HELPER, NULL, NULL, NULL, NULL);
192+
193+ guint callslen = 0;
194+ const DbusTestDbusMockCall * calls = dbus_test_dbus_mock_object_get_method_calls(mock, obj, "DispatchURL", &callslen, NULL);
195+
196+ // ASSERT_NE(calls, nullptr);
197+ ASSERT_EQ(callslen, 1);
198+ GVariant * check = g_variant_new_parsed("('foo://bar/barish', '')");
199+ g_variant_ref_sink(check);
200+ ASSERT_TRUE(g_variant_equal(calls->params, check));
201+ g_variant_unref(check);
202+}
203+
204 TEST_F(LibTest, RestrictedTest) {
205 GMainLoop * main = g_main_loop_new(NULL, FALSE);
206
207
208=== modified file 'tests/url_dispatcher_testability/CMakeLists.txt'
209--- tests/url_dispatcher_testability/CMakeLists.txt 2014-07-22 13:09:42 +0000
210+++ tests/url_dispatcher_testability/CMakeLists.txt 2014-08-19 21:02:22 +0000
211@@ -10,4 +10,4 @@
212 "${PROJECT_SOURCE_DIR}/tests/url_dispatcher_testability/test_fake_dispatcher.py"
213 )
214
215-add_test(fake-dispatcher dbus-launch --exit-with-session nosetests3 ${PROJECT_SOURCE_DIR}/tests/url_dispatcher_testability/test_fake_dispatcher.py)
216+add_test(fake-dispatcher dbus-test-runner --task nosetests3 --parameter ${PROJECT_SOURCE_DIR}/tests/url_dispatcher_testability/test_fake_dispatcher.py)

Subscribers

People subscribed via source and target branches