Merge lp:~dobey/url-dispatcher/initial-cpp into lp:url-dispatcher

Proposed by dobey
Status: Merged
Approved by: dobey
Approved revision: 118
Merged at revision: 120
Proposed branch: lp:~dobey/url-dispatcher/initial-cpp
Merge into: lp:url-dispatcher
Prerequisite: lp:~dobey/url-dispatcher/use-libwhoopsie
Diff against target: 218 lines (+73/-76)
5 files modified
service/CMakeLists.txt (+1/-1)
service/service.cpp (+37/-43)
tests/url_dispatcher_testability/test_fake_dispatcher.py.in (+7/-1)
tools/CMakeLists.txt (+1/-1)
tools/url-dispatcher.cpp (+27/-30)
To merge this branch: bzr merge lp:~dobey/url-dispatcher/initial-cpp
Reviewer Review Type Date Requested Status
Ted Gould (community) Approve
unity-api-1-bot continuous-integration Needs Fixing
Review via email: mp+320201@code.launchpad.net

Commit message

Convert service main process and url-dispatcher tool code to C++.

To post a comment you must log in.
Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

FAILED: Continuous integration, rev:118
https://jenkins.canonical.com/unity-api-1/job/lp-url-dispatcher-ci/56/
Executed test runs:
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build/1822/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/1829
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1605
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1605/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/1605
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/1605/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1605
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1605/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/1605
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/1605/artifact/output/*zip*/output.zip
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/1605/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/1605/console

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-url-dispatcher-ci/56/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Ted Gould (ted) wrote :

No issue with this code, but I think it might be a good time to introduce the GLib/GObject pointer helpers that Pete wrote. They're not needed here, but we'll want them in future branches anyways.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'service/CMakeLists.txt'
2--- service/CMakeLists.txt 2017-03-17 14:45:26 +0000
3+++ service/CMakeLists.txt 2017-03-17 14:45:27 +0000
4@@ -87,7 +87,7 @@
5
6 include_directories(${CMAKE_CURRENT_BINARY_DIR})
7
8-add_executable(service-exec service.c)
9+add_executable(service-exec service.cpp)
10
11 set_target_properties(service-exec PROPERTIES OUTPUT_NAME "url-dispatcher")
12
13
14=== renamed file 'service/service.c' => 'service/service.cpp'
15--- service/service.c 2016-08-10 18:38:30 +0000
16+++ service/service.cpp 2017-03-17 14:45:27 +0000
17@@ -1,5 +1,5 @@
18 /**
19- * Copyright (C) 2013 Canonical, Ltd.
20+ * Copyright (C) 2013-2017 Canonical, Ltd.
21 *
22 * This program is free software: you can redistribute it and/or modify it under
23 * the terms of the GNU Lesser General Public License version 3, as published by
24@@ -13,53 +13,47 @@
25 * You should have received a copy of the GNU Lesser General Public License
26 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 *
28- * Author: Ted Gould <ted@canonical.com>
29- *
30 */
31
32+extern "C" {
33+#include "dispatcher.h"
34+}
35+
36 #include <glib.h>
37 #include <glib-unix.h>
38-#include "dispatcher.h"
39-
40-GMainLoop * mainloop = NULL;
41-
42-static gboolean
43-sig_term (gpointer user_data)
44-{
45- g_debug("SIGTERM");
46- g_main_loop_quit((GMainLoop *)user_data);
47- return G_SOURCE_CONTINUE;
48-}
49+#include <memory>
50
51 /* Where it all begins */
52-int
53-main (int argc, char * argv[])
54+int main (int argc, char * argv[])
55 {
56- mainloop = g_main_loop_new(NULL, FALSE);
57-
58- guint term_source = g_unix_signal_add(SIGTERM, sig_term, mainloop);
59-
60- OverlayTracker * tracker = overlay_tracker_new();
61-
62- ScopeChecker * checker = NULL;
63- /* Allow disabing for testing */
64- if (g_getenv("URL_DISPATCHER_DISABLE_SCOPE_CHECKING") == NULL)
65- checker = scope_checker_new();
66-
67- /* Initialize Dispatcher */
68- if (!dispatcher_init(mainloop, tracker, checker)) {
69- return -1;
70- }
71-
72- /* Run Main */
73- g_main_loop_run(mainloop);
74-
75- /* Clean up globals */
76- dispatcher_shutdown();
77- overlay_tracker_delete(tracker);
78- scope_checker_delete(checker);
79- g_source_remove(term_source);
80- g_main_loop_unref(mainloop);
81-
82- return 0;
83+ auto mainloop = g_main_loop_new(nullptr, false);
84+
85+ g_unix_signal_add(SIGTERM, [](gpointer user_data) {
86+ g_main_loop_quit(static_cast<GMainLoop*>(user_data));
87+ return G_SOURCE_REMOVE;
88+ }, mainloop);
89+
90+ auto tracker = overlay_tracker_new();
91+
92+ ScopeChecker* checker = nullptr;
93+ /* Allow disabing for testing */
94+ if (g_getenv("URL_DISPATCHER_DISABLE_SCOPE_CHECKING") == nullptr) {
95+ checker = scope_checker_new();
96+ }
97+
98+ /* Initialize Dispatcher */
99+ if (!dispatcher_init(mainloop, tracker, checker)) {
100+ return -1;
101+ }
102+
103+ /* Run Main */
104+ g_main_loop_run(mainloop);
105+
106+ /* Clean up globals */
107+ dispatcher_shutdown();
108+ overlay_tracker_delete(tracker);
109+ scope_checker_delete(checker);
110+ g_main_loop_unref(mainloop);
111+
112+ return 0;
113 }
114
115=== modified file 'tests/url_dispatcher_testability/test_fake_dispatcher.py.in'
116--- tests/url_dispatcher_testability/test_fake_dispatcher.py.in 2014-07-22 13:09:42 +0000
117+++ tests/url_dispatcher_testability/test_fake_dispatcher.py.in 2017-03-17 14:45:27 +0000
118@@ -29,9 +29,15 @@
119
120 def test_url_dispatcher(self):
121 bin_dir = "@PROJECT_BINARY_DIR@"
122- call([bin_dir + '/tools/url-dispatcher', 'test://testurl'])
123+ result = call([bin_dir + '/tools/url-dispatcher', 'test://testurl'])
124+ self.assertEqual(0, result)
125 try:
126 last_url = self.dispatcher.get_last_dispatch_url_call_parameter()
127 except fake_dispatcher.FakeDispatcherException:
128 last_url = None
129 self.assertEqual(last_url, 'test://testurl')
130+
131+ def test_url_dispatcher_no_args(self):
132+ bin_dir = "@PROJECT_BINARY_DIR@"
133+ result = call([bin_dir + '/tools/url-dispatcher'])
134+ self.assertEqual(1, result)
135
136=== modified file 'tools/CMakeLists.txt'
137--- tools/CMakeLists.txt 2017-03-03 21:40:40 +0000
138+++ tools/CMakeLists.txt 2017-03-17 14:45:27 +0000
139@@ -5,7 +5,7 @@
140
141 include_directories(${CMAKE_SOURCE_DIR}/liburl-dispatcher)
142
143-add_executable(url-dispatcher url-dispatcher.c)
144+add_executable(url-dispatcher url-dispatcher.cpp)
145
146 target_link_libraries(url-dispatcher
147 dispatcher
148
149=== renamed file 'tools/url-dispatcher.c' => 'tools/url-dispatcher.cpp'
150--- tools/url-dispatcher.c 2013-07-10 11:37:31 +0000
151+++ tools/url-dispatcher.cpp 2017-03-17 14:45:27 +0000
152@@ -1,5 +1,5 @@
153 /**
154- * Copyright (C) 2013 Canonical, Ltd.
155+ * Copyright (C) 2017 Canonical, Ltd.
156 *
157 * This program is free software: you can redistribute it and/or modify it under
158 * the terms of the GNU Lesser General Public License version 3, as published by
159@@ -17,33 +17,30 @@
160
161 #include "url-dispatcher.h"
162
163-static gboolean global_success = FALSE;
164-
165-static void
166-callback (const gchar * url, gboolean success, gpointer user_data)
167-{
168- global_success = success;
169- g_main_loop_quit((GMainLoop *)user_data);
170- return;
171-}
172-
173-int
174-main (int argc, char * argv[])
175-{
176- if (argc != 2) {
177- g_printerr("Usage: %s <url>\n", argv[0]);
178- return 1;
179- }
180-
181- GMainLoop * mainloop = g_main_loop_new(NULL, FALSE);
182-
183- url_dispatch_send(argv[1], callback, mainloop);
184-
185- g_main_loop_run(mainloop);
186-
187- if (global_success) {
188- return 0;
189- } else {
190- return 1;
191- }
192+int main (int argc, char * argv[])
193+{
194+ struct Data {
195+ GMainLoop* loop = nullptr;
196+ bool success = false;
197+ };
198+
199+ if (argc != 2) {
200+ g_printerr("Usage: %s <url>\n", argv[0]);
201+ return 1;
202+ }
203+
204+ Data data;
205+ data.loop = g_main_loop_new(nullptr, FALSE);
206+
207+ url_dispatch_send(argv[1], [](const gchar* url, gboolean success,
208+ gpointer user_data) {
209+ auto cbdata = static_cast<Data*>(user_data);
210+ cbdata->success = success;
211+ g_main_loop_quit(cbdata->loop);
212+ },
213+ &data);
214+
215+ g_main_loop_run(data.loop);
216+
217+ return !data.success;
218 }

Subscribers

People subscribed via source and target branches