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
=== modified file 'service/CMakeLists.txt'
--- service/CMakeLists.txt 2017-03-17 14:45:26 +0000
+++ service/CMakeLists.txt 2017-03-17 14:45:27 +0000
@@ -87,7 +87,7 @@
8787
88include_directories(${CMAKE_CURRENT_BINARY_DIR})88include_directories(${CMAKE_CURRENT_BINARY_DIR})
8989
90add_executable(service-exec service.c)90add_executable(service-exec service.cpp)
9191
92set_target_properties(service-exec PROPERTIES OUTPUT_NAME "url-dispatcher")92set_target_properties(service-exec PROPERTIES OUTPUT_NAME "url-dispatcher")
9393
9494
=== renamed file 'service/service.c' => 'service/service.cpp'
--- service/service.c 2016-08-10 18:38:30 +0000
+++ service/service.cpp 2017-03-17 14:45:27 +0000
@@ -1,5 +1,5 @@
1/**1/**
2 * Copyright (C) 2013 Canonical, Ltd.2 * Copyright (C) 2013-2017 Canonical, Ltd.
3 *3 *
4 * This program is free software: you can redistribute it and/or modify it under4 * 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 by5 * the terms of the GNU Lesser General Public License version 3, as published by
@@ -13,53 +13,47 @@
13 * You should have received a copy of the GNU Lesser General Public License13 * 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/>.14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *15 *
16 * Author: Ted Gould <ted@canonical.com>
17 *
18 */16 */
1917
18extern "C" {
19#include "dispatcher.h"
20}
21
20#include <glib.h>22#include <glib.h>
21#include <glib-unix.h>23#include <glib-unix.h>
22#include "dispatcher.h"24#include <memory>
23
24GMainLoop * mainloop = NULL;
25
26static gboolean
27sig_term (gpointer user_data)
28{
29 g_debug("SIGTERM");
30 g_main_loop_quit((GMainLoop *)user_data);
31 return G_SOURCE_CONTINUE;
32}
3325
34/* Where it all begins */26/* Where it all begins */
35int27int main (int argc, char * argv[])
36main (int argc, char * argv[])
37{28{
38 mainloop = g_main_loop_new(NULL, FALSE);29 auto mainloop = g_main_loop_new(nullptr, false);
3930
40 guint term_source = g_unix_signal_add(SIGTERM, sig_term, mainloop);31 g_unix_signal_add(SIGTERM, [](gpointer user_data) {
4132 g_main_loop_quit(static_cast<GMainLoop*>(user_data));
42 OverlayTracker * tracker = overlay_tracker_new();33 return G_SOURCE_REMOVE;
4334 }, mainloop);
44 ScopeChecker * checker = NULL;35
45 /* Allow disabing for testing */36 auto tracker = overlay_tracker_new();
46 if (g_getenv("URL_DISPATCHER_DISABLE_SCOPE_CHECKING") == NULL)37
47 checker = scope_checker_new();38 ScopeChecker* checker = nullptr;
4839 /* Allow disabing for testing */
49 /* Initialize Dispatcher */40 if (g_getenv("URL_DISPATCHER_DISABLE_SCOPE_CHECKING") == nullptr) {
50 if (!dispatcher_init(mainloop, tracker, checker)) {41 checker = scope_checker_new();
51 return -1;42 }
52 }43
5344 /* Initialize Dispatcher */
54 /* Run Main */45 if (!dispatcher_init(mainloop, tracker, checker)) {
55 g_main_loop_run(mainloop);46 return -1;
5647 }
57 /* Clean up globals */48
58 dispatcher_shutdown();49 /* Run Main */
59 overlay_tracker_delete(tracker);50 g_main_loop_run(mainloop);
60 scope_checker_delete(checker);51
61 g_source_remove(term_source);52 /* Clean up globals */
62 g_main_loop_unref(mainloop);53 dispatcher_shutdown();
6354 overlay_tracker_delete(tracker);
64 return 0;55 scope_checker_delete(checker);
56 g_main_loop_unref(mainloop);
57
58 return 0;
65}59}
6660
=== modified file 'tests/url_dispatcher_testability/test_fake_dispatcher.py.in'
--- tests/url_dispatcher_testability/test_fake_dispatcher.py.in 2014-07-22 13:09:42 +0000
+++ tests/url_dispatcher_testability/test_fake_dispatcher.py.in 2017-03-17 14:45:27 +0000
@@ -29,9 +29,15 @@
2929
30 def test_url_dispatcher(self):30 def test_url_dispatcher(self):
31 bin_dir = "@PROJECT_BINARY_DIR@"31 bin_dir = "@PROJECT_BINARY_DIR@"
32 call([bin_dir + '/tools/url-dispatcher', 'test://testurl'])32 result = call([bin_dir + '/tools/url-dispatcher', 'test://testurl'])
33 self.assertEqual(0, result)
33 try:34 try:
34 last_url = self.dispatcher.get_last_dispatch_url_call_parameter()35 last_url = self.dispatcher.get_last_dispatch_url_call_parameter()
35 except fake_dispatcher.FakeDispatcherException:36 except fake_dispatcher.FakeDispatcherException:
36 last_url = None37 last_url = None
37 self.assertEqual(last_url, 'test://testurl')38 self.assertEqual(last_url, 'test://testurl')
39
40 def test_url_dispatcher_no_args(self):
41 bin_dir = "@PROJECT_BINARY_DIR@"
42 result = call([bin_dir + '/tools/url-dispatcher'])
43 self.assertEqual(1, result)
3844
=== modified file 'tools/CMakeLists.txt'
--- tools/CMakeLists.txt 2017-03-03 21:40:40 +0000
+++ tools/CMakeLists.txt 2017-03-17 14:45:27 +0000
@@ -5,7 +5,7 @@
55
6include_directories(${CMAKE_SOURCE_DIR}/liburl-dispatcher)6include_directories(${CMAKE_SOURCE_DIR}/liburl-dispatcher)
77
8add_executable(url-dispatcher url-dispatcher.c)8add_executable(url-dispatcher url-dispatcher.cpp)
99
10target_link_libraries(url-dispatcher10target_link_libraries(url-dispatcher
11 dispatcher11 dispatcher
1212
=== renamed file 'tools/url-dispatcher.c' => 'tools/url-dispatcher.cpp'
--- tools/url-dispatcher.c 2013-07-10 11:37:31 +0000
+++ tools/url-dispatcher.cpp 2017-03-17 14:45:27 +0000
@@ -1,5 +1,5 @@
1/**1/**
2 * Copyright (C) 2013 Canonical, Ltd.2 * Copyright (C) 2017 Canonical, Ltd.
3 *3 *
4 * This program is free software: you can redistribute it and/or modify it under4 * 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 by5 * the terms of the GNU Lesser General Public License version 3, as published by
@@ -17,33 +17,30 @@
1717
18#include "url-dispatcher.h"18#include "url-dispatcher.h"
1919
20static gboolean global_success = FALSE;20int main (int argc, char * argv[])
2121{
22static void22 struct Data {
23callback (const gchar * url, gboolean success, gpointer user_data)23 GMainLoop* loop = nullptr;
24{24 bool success = false;
25 global_success = success;25 };
26 g_main_loop_quit((GMainLoop *)user_data);26
27 return;27 if (argc != 2) {
28}28 g_printerr("Usage: %s <url>\n", argv[0]);
2929 return 1;
30int30 }
31main (int argc, char * argv[])31
32{32 Data data;
33 if (argc != 2) {33 data.loop = g_main_loop_new(nullptr, FALSE);
34 g_printerr("Usage: %s <url>\n", argv[0]);34
35 return 1;35 url_dispatch_send(argv[1], [](const gchar* url, gboolean success,
36 }36 gpointer user_data) {
3737 auto cbdata = static_cast<Data*>(user_data);
38 GMainLoop * mainloop = g_main_loop_new(NULL, FALSE);38 cbdata->success = success;
3939 g_main_loop_quit(cbdata->loop);
40 url_dispatch_send(argv[1], callback, mainloop);40 },
4141 &data);
42 g_main_loop_run(mainloop);42
4343 g_main_loop_run(data.loop);
44 if (global_success) {44
45 return 0;45 return !data.success;
46 } else {
47 return 1;
48 }
49}46}

Subscribers

People subscribed via source and target branches