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
=== modified file 'liburl-dispatcher/url-dispatcher.c'
--- liburl-dispatcher/url-dispatcher.c 2014-07-16 19:16:10 +0000
+++ liburl-dispatcher/url-dispatcher.c 2014-08-19 21:02:22 +0000
@@ -16,11 +16,10 @@
16 */16 */
1717
18#include "url-dispatcher.h"18#include "url-dispatcher.h"
19#include "service-iface.h"19#include <gio/gio.h>
2020
21typedef struct _dispatch_data_t dispatch_data_t;21typedef struct _dispatch_data_t dispatch_data_t;
22struct _dispatch_data_t {22struct _dispatch_data_t {
23 ServiceIfaceComCanonicalURLDispatcher * proxy;
24 URLDispatchCallback cb;23 URLDispatchCallback cb;
25 gpointer user_data;24 gpointer user_data;
26 gchar * url;25 gchar * url;
@@ -33,8 +32,8 @@
33 GError * error = NULL;32 GError * error = NULL;
34 dispatch_data_t * dispatch_data = (dispatch_data_t *)user_data;33 dispatch_data_t * dispatch_data = (dispatch_data_t *)user_data;
3534
36 service_iface_com_canonical_urldispatcher_call_dispatch_url_finish(35 g_dbus_connection_call_finish(
37 SERVICE_IFACE_COM_CANONICAL_URLDISPATCHER(obj),36 G_DBUS_CONNECTION(obj),
38 res,37 res,
39 &error);38 &error);
4039
@@ -51,7 +50,6 @@
51 }50 }
52 }51 }
5352
54 g_clear_object(&dispatch_data->proxy);
55 g_free(dispatch_data->url);53 g_free(dispatch_data->url);
56 g_free(dispatch_data->package);54 g_free(dispatch_data->package);
57 g_free(dispatch_data);55 g_free(dispatch_data);
@@ -59,38 +57,6 @@
59 return;57 return;
60}58}
6159
62static void
63got_proxy (GObject * obj, GAsyncResult * res, gpointer user_data)
64{
65 GError * error = NULL;
66 dispatch_data_t * dispatch_data = (dispatch_data_t *)user_data;
67
68 dispatch_data->proxy = service_iface_com_canonical_urldispatcher_proxy_new_for_bus_finish(res, &error);
69
70 if (error != NULL) {
71 g_warning("Unable to get proxy for URL Dispatcher: %s", error->message);
72 g_error_free(error);
73
74 if (dispatch_data->cb != NULL) {
75 dispatch_data->cb(dispatch_data->url, FALSE, dispatch_data->user_data);
76 }
77
78 g_free(dispatch_data->url);
79 g_free(dispatch_data);
80 return;
81 }
82
83 service_iface_com_canonical_urldispatcher_call_dispatch_url(
84 dispatch_data->proxy,
85 dispatch_data->url,
86 dispatch_data->package ? dispatch_data->package : "",
87 NULL, /* cancelable */
88 url_dispatched,
89 dispatch_data);
90
91 return;
92}
93
94void60void
95url_dispatch_send (const gchar * url, URLDispatchCallback cb, gpointer user_data)61url_dispatch_send (const gchar * url, URLDispatchCallback cb, gpointer user_data)
96{62{
@@ -100,22 +66,44 @@
100void66void
101url_dispatch_send_restricted (const gchar * url, const gchar * package, URLDispatchCallback cb, gpointer user_data)67url_dispatch_send_restricted (const gchar * url, const gchar * package, URLDispatchCallback cb, gpointer user_data)
102{68{
103 dispatch_data_t * dispatch_data = g_new0(dispatch_data_t, 1);69 GError * error = NULL;
10470 GDBusConnection * bus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
105 dispatch_data->cb = cb;71
106 dispatch_data->user_data = user_data;72 if (error != NULL) {
107 dispatch_data->url = g_strdup(url);73 g_warning("Unable to get session bus: %s", error->message);
108 dispatch_data->package = g_strdup(package);74 g_error_free(error);
10975 return;
110 service_iface_com_canonical_urldispatcher_proxy_new_for_bus(76 }
111 G_BUS_TYPE_SESSION,77
112 G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,78 dispatch_data_t * dispatch_data = NULL;
113 "com.canonical.URLDispatcher",79
114 "/com/canonical/URLDispatcher",80 if (cb != NULL) {
115 NULL, /* cancellable */81 dispatch_data = g_new0(dispatch_data_t, 1);
116 got_proxy,82
117 dispatch_data83 dispatch_data->cb = cb;
118 );84 dispatch_data->user_data = user_data;
85 dispatch_data->url = g_strdup(url);
86 dispatch_data->package = g_strdup(package);
87 }
88
89 g_dbus_connection_call(bus,
90 "com.canonical.URLDispatcher",
91 "/com/canonical/URLDispatcher",
92 "com.canonical.URLDispatcher",
93 "DispatchURL",
94 g_variant_new("(ss)", url, package ? package : ""),
95 NULL,
96 G_DBUS_CALL_FLAGS_NO_AUTO_START,
97 -1, /* timeout */
98 NULL, /* cancelable */
99 cb != NULL ? url_dispatched : NULL,
100 dispatch_data);
101
102 if (cb == NULL) {
103 g_dbus_connection_flush_sync(bus, NULL, NULL);
104 }
105
106 g_object_unref(bus);
119107
120 return;108 return;
121}109}
122110
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2014-07-20 11:45:00 +0000
+++ tests/CMakeLists.txt 2014-08-19 21:02:22 +0000
@@ -71,6 +71,10 @@
71# lib test71# lib test
72###########################72###########################
7373
74add_executable (lib-test-no-main lib-test-no-main.c)
75target_link_libraries (lib-test-no-main dispatcher)
76add_definitions ( -DLIB_TEST_NO_MAIN_HELPER="${CMAKE_CURRENT_BINARY_DIR}/lib-test-no-main" )
77
74add_executable (lib-test lib-test.cc)78add_executable (lib-test lib-test.cc)
75target_link_libraries (lib-test79target_link_libraries (lib-test
76 dispatcher80 dispatcher
7781
=== added file 'tests/lib-test-no-main.c'
--- tests/lib-test-no-main.c 1970-01-01 00:00:00 +0000
+++ tests/lib-test-no-main.c 2014-08-19 21:02:22 +0000
@@ -0,0 +1,25 @@
1/**
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18#include <gio/gio.h>
19#include <liburl-dispatcher/url-dispatcher.h>
20
21int
22main (int argc, char * argv[]) {
23 url_dispatch_send("foo://bar/barish", NULL, NULL);
24 return 0;
25}
026
=== modified file 'tests/lib-test.cc'
--- tests/lib-test.cc 2014-07-16 19:36:10 +0000
+++ tests/lib-test.cc 2014-08-19 21:02:22 +0000
@@ -101,6 +101,21 @@
101 g_variant_unref(check);101 g_variant_unref(check);
102}102}
103103
104TEST_F(LibTest, NoMain) {
105 /* Spawning a non-main caller */
106 g_spawn_command_line_sync(LIB_TEST_NO_MAIN_HELPER, NULL, NULL, NULL, NULL);
107
108 guint callslen = 0;
109 const DbusTestDbusMockCall * calls = dbus_test_dbus_mock_object_get_method_calls(mock, obj, "DispatchURL", &callslen, NULL);
110
111 // ASSERT_NE(calls, nullptr);
112 ASSERT_EQ(callslen, 1);
113 GVariant * check = g_variant_new_parsed("('foo://bar/barish', '')");
114 g_variant_ref_sink(check);
115 ASSERT_TRUE(g_variant_equal(calls->params, check));
116 g_variant_unref(check);
117}
118
104TEST_F(LibTest, RestrictedTest) {119TEST_F(LibTest, RestrictedTest) {
105 GMainLoop * main = g_main_loop_new(NULL, FALSE);120 GMainLoop * main = g_main_loop_new(NULL, FALSE);
106121
107122
=== modified file 'tests/url_dispatcher_testability/CMakeLists.txt'
--- tests/url_dispatcher_testability/CMakeLists.txt 2014-07-22 13:09:42 +0000
+++ tests/url_dispatcher_testability/CMakeLists.txt 2014-08-19 21:02:22 +0000
@@ -10,4 +10,4 @@
10 "${PROJECT_SOURCE_DIR}/tests/url_dispatcher_testability/test_fake_dispatcher.py"10 "${PROJECT_SOURCE_DIR}/tests/url_dispatcher_testability/test_fake_dispatcher.py"
11 )11 )
1212
13add_test(fake-dispatcher dbus-launch --exit-with-session nosetests3 ${PROJECT_SOURCE_DIR}/tests/url_dispatcher_testability/test_fake_dispatcher.py)13add_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