Merge lp:~dobey/indicator-sound/initial-cpp into lp:indicator-sound

Proposed by dobey on 2017-03-24
Status: Approved
Approved by: dobey on 2017-03-29
Approved revision: 554
Proposed branch: lp:~dobey/indicator-sound/initial-cpp
Merge into: lp:indicator-sound
Prerequisite: lp:~dobey/indicator-sound/drop-greeeter
Diff against target: 152 lines (+46/-50)
2 files modified
src/CMakeLists.txt (+1/-1)
src/main.cpp (+45/-49)
To merge this branch: bzr merge lp:~dobey/indicator-sound/initial-cpp
Reviewer Review Type Date Requested Status
unity-api-1-bot continuous-integration Approve on 2017-03-30
Charles Kerr (community) 2017-03-24 Approve on 2017-03-24
Review via email: mp+320974@code.launchpad.net

Commit message

Move the core mainloop code to C++.

To post a comment you must log in.
Charles Kerr (charlesk) wrote :

It's a start. :)

On a side note, you might want to disable the tests that we know will be failing (PA?) so that we can benefit from Jenkins checking things as the port from vala to C++ progresses.

review: Approve
unity-api-1-bot (unity-api-1-bot) wrote :

PASSED: Continuous integration, rev:554
https://jenkins.canonical.com/unity-api-1/job/lp-indicator-sound-ci/25/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build/1895
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/1902
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1684
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1684/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/1684
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/1684/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1684
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1684/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/1684
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/1684/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/1684
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/1684/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/1684
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/1684/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-indicator-sound-ci/25/rebuild

review: Approve (continuous-integration)

Unmerged revisions

554. By dobey on 2017-03-24

More use of glib memory helpers.

553. By dobey on 2017-03-24

Move some of mainloop code to C++.

552. By dobey on 2017-03-23

Strip out the complicated non-working greeter support.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/CMakeLists.txt'
2--- src/CMakeLists.txt 2017-03-24 18:01:58 +0000
3+++ src/CMakeLists.txt 2017-03-24 18:01:58 +0000
4@@ -235,7 +235,7 @@
5
6 add_executable(
7 indicator-sound-service-bin
8- main.c
9+ main.cpp
10 )
11
12 set_target_properties(
13
14=== renamed file 'src/main.c' => 'src/main.cpp'
15--- src/main.c 2017-03-24 18:01:58 +0000
16+++ src/main.cpp 2017-03-24 18:01:58 +0000
17@@ -1,5 +1,5 @@
18 /*
19- * Copyright © 2015 Canonical Ltd.
20+ * Copyright © 2015-2017 Canonical Ltd.
21 *
22 * This program is free software; you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24@@ -14,23 +14,23 @@
25 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 */
27
28+#include "indicator-sound-service.h"
29+#include "config.h"
30+
31 #include <glib.h>
32+#include <glib-unix.h>
33+#include <libintl.h>
34 #include <locale.h>
35 #include <libnotify/notify.h>
36
37-#include "indicator-sound-service.h"
38-#include "config.h"
39-
40-static IndicatorSoundService * service = NULL;
41-static pa_glib_mainloop * pgloop = NULL;
42-
43-static gboolean
44-sigterm_handler (gpointer data)
45-{
46- g_debug("Got SIGTERM");
47- g_main_loop_quit((GMainLoop *)data);
48- return G_SOURCE_REMOVE;
49-}
50+#include <memory>
51+#include <unity/util/GObjectMemory.h>
52+#include <unity/util/GlibMemory.h>
53+
54+using namespace unity::util;
55+
56+static std::shared_ptr<IndicatorSoundService> service;
57+static std::shared_ptr<pa_glib_mainloop> pgloop;
58
59 static void
60 on_name_lost(GDBusConnection * connection,
61@@ -46,61 +46,57 @@
62 const gchar *name,
63 gpointer user_data)
64 {
65- MediaPlayerList * playerlist = NULL;
66- IndicatorSoundOptions * options = NULL;
67- VolumeControlPulse * volume = NULL;
68- AccountsServiceUser * accounts = NULL;
69- VolumeWarning * warning = NULL;
70- AccountsServiceAccess * accounts_service_access = NULL;
71-
72-
73- playerlist = MEDIA_PLAYER_LIST(media_player_list_mpris_new());
74- accounts = accounts_service_user_new();
75-
76- pgloop = pa_glib_mainloop_new(NULL);
77- options = indicator_sound_options_gsettings_new();
78- accounts_service_access = accounts_service_access_new();
79- volume = volume_control_pulse_new(options, pgloop, accounts_service_access);
80- warning = volume_warning_pulse_new(options, pgloop);
81-
82- service = indicator_sound_service_new (playerlist, volume, accounts, options, warning, accounts_service_access);
83-
84- g_clear_object(&playerlist);
85- g_clear_object(&options);
86- g_clear_object(&volume);
87- g_clear_object(&accounts);
88- g_clear_object(&warning);
89+ pgloop = share_gobject(pa_glib_mainloop_new(nullptr));
90+
91+ auto playerlist = unique_gobject(media_player_list_mpris_new());
92+ auto accounts = unique_gobject(accounts_service_user_new());
93+ auto options = unique_gobject(indicator_sound_options_gsettings_new());
94+ auto accounts_service_access = unique_gobject(accounts_service_access_new());
95+ auto volume = unique_gobject(volume_control_pulse_new(INDICATOR_SOUND_OPTIONS(options.get()),
96+ pgloop.get(),
97+ accounts_service_access.get()));
98+ auto warning = unique_gobject(volume_warning_pulse_new(INDICATOR_SOUND_OPTIONS(options.get()),
99+ pgloop.get()));
100+
101+ service = share_gobject(indicator_sound_service_new(MEDIA_PLAYER_LIST(playerlist.get()),
102+ VOLUME_CONTROL(volume.get()),
103+ accounts.get(),
104+ INDICATOR_SOUND_OPTIONS(options.get()),
105+ VOLUME_WARNING(warning.get()),
106+ accounts_service_access.get()));
107 }
108
109 int
110 main (int argc, char ** argv)
111 {
112- GMainLoop * loop = NULL;
113 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
114 setlocale (LC_ALL, "");
115 bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
116
117 /* Build Mainloop */
118- loop = g_main_loop_new(NULL, FALSE);
119+ auto loop = unique_glib(g_main_loop_new(nullptr, false));
120
121- g_unix_signal_add(SIGTERM, sigterm_handler, loop);
122+ g_unix_signal_add(SIGTERM,
123+ [](gpointer data) {
124+ g_main_loop_quit(static_cast<GMainLoop*>(data));
125+ return G_SOURCE_REMOVE;
126+ },
127+ loop.get());
128
129 /* Initialize libnotify */
130 notify_init ("indicator-sound");
131
132+ // TODO: Move bus ownership out of main() once vala is gone
133 g_bus_own_name(G_BUS_TYPE_SESSION,
134 "com.canonical.indicator.sound",
135 G_BUS_NAME_OWNER_FLAGS_NONE,
136 on_bus_acquired,
137- NULL, /* name acquired */
138+ nullptr, /* name acquired */
139 on_name_lost,
140- loop,
141- NULL);
142-
143- g_main_loop_run(loop);
144-
145- g_clear_object(&service);
146- g_clear_pointer(&pgloop, pa_glib_mainloop_free);
147+ loop.get(),
148+ nullptr);
149+
150+ g_main_loop_run(loop.get());
151
152 notify_uninit();
153

Subscribers

People subscribed via source and target branches