Merge lp:~charlesk/indicator-location/use-properties-cpp into lp:indicator-location/16.04
- use-properties-cpp
- Merge into trunk.16.04
Proposed by
Charles Kerr
| Status: | Merged |
|---|---|
| Approved by: | Charles Kerr |
| Approved revision: | 161 |
| Merged at revision: | 152 |
| Proposed branch: | lp:~charlesk/indicator-location/use-properties-cpp |
| Merge into: | lp:indicator-location/16.04 |
| Prerequisite: | lp:~charlesk/indicator-location/lp-1535353-remove-here-tos |
| Diff against target: |
764 lines (+141/-190) 13 files modified
CMakeLists.txt (+2/-1) src/controller.cc (+0/-46) src/controller.h (+8/-34) src/location-service-controller.cc (+26/-33) src/location-service-controller.h (+6/-6) src/phone.cc (+44/-27) src/phone.h (+7/-4) src/service.cc (+12/-12) src/service.h (+1/-1) tests/controller-mock.h (+8/-12) tests/gtest-dbus-fixture.h (+3/-3) tests/gtest-dbus-indicator-fixture.h (+5/-5) tests/phone-test.cc (+19/-6) |
| To merge this branch: | bzr merge lp:~charlesk/indicator-location/use-properties-cpp |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| Xavi Garcia | Approve | ||
| PS Jenkins bot (community) | continuous-integration | Approve | |
|
Review via email:
|
|||
Commit message
Use core::Property<X> fields to notify the indicator when location settings change
Description of the change
A minor cleanup branch of something that's irritated me for awhile in indicator-location, the use of Java-style Listener interface classes for observer/observable to know when CUALC's location settings change.
This MP replaces the Listener interfaces with use of core::Property<X> objects to signal when a value changes.
To post a comment you must log in.
Revision history for this message
| PS Jenkins bot (ps-jenkins) wrote : | # |
review:
Approve
(continuous-integration)
Revision history for this message
| Xavi Garcia (xavi-garcia-mena) wrote : | # |
LGTM, thanks
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
| 1 | === modified file 'CMakeLists.txt' |
| 2 | --- CMakeLists.txt 2015-04-16 00:44:22 +0000 |
| 3 | +++ CMakeLists.txt 2016-01-22 18:23:42 +0000 |
| 4 | @@ -35,7 +35,8 @@ |
| 5 | ubuntu-app-launch-2 |
| 6 | url-dispatcher-1 |
| 7 | gio-unix-2.0>=2.36 |
| 8 | - glib-2.0>=2.36) |
| 9 | + glib-2.0>=2.36 |
| 10 | + properties-cpp>=0.0.1) |
| 11 | include_directories (SYSTEM ${SERVICE_DEPS_INCLUDE_DIRS}) |
| 12 | |
| 13 | ## |
| 14 | |
| 15 | === removed file 'src/controller.cc' |
| 16 | --- src/controller.cc 2013-08-25 20:31:26 +0000 |
| 17 | +++ src/controller.cc 1970-01-01 00:00:00 +0000 |
| 18 | @@ -1,46 +0,0 @@ |
| 19 | -/* |
| 20 | - * Copyright 2013 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 | - * the Free Software Foundation; version 3. |
| 25 | - * |
| 26 | - * This program is distributed in the hope that it will be useful, |
| 27 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 28 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 29 | - * GNU Lesser General Public License for more details. |
| 30 | - * |
| 31 | - * You should have received a copy of the GNU Lesser General Public License |
| 32 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 33 | - * |
| 34 | - * Authors: |
| 35 | - * Charles Kerr <[email protected]> |
| 36 | - */ |
| 37 | - |
| 38 | -#include "controller.h" |
| 39 | - |
| 40 | -void |
| 41 | -Controller :: add_listener (ControllerListener * l) |
| 42 | -{ |
| 43 | - listeners.insert (l); |
| 44 | -} |
| 45 | - |
| 46 | -void |
| 47 | -Controller :: remove_listener (ControllerListener * l) |
| 48 | -{ |
| 49 | - listeners.erase (l); |
| 50 | -} |
| 51 | - |
| 52 | -void |
| 53 | -Controller :: notify_gps_enabled (bool enabled) |
| 54 | -{ |
| 55 | - for (auto it : listeners) |
| 56 | - it->on_gps_enabled_changed (enabled); |
| 57 | -} |
| 58 | - |
| 59 | -void |
| 60 | -Controller :: notify_location_service_enabled (bool enabled) |
| 61 | -{ |
| 62 | - for (auto it : listeners) |
| 63 | - it->on_location_service_enabled_changed (enabled); |
| 64 | -} |
| 65 | |
| 66 | === modified file 'src/controller.h' |
| 67 | --- src/controller.h 2015-04-15 13:42:24 +0000 |
| 68 | +++ src/controller.h 2016-01-22 18:23:42 +0000 |
| 69 | @@ -20,48 +20,22 @@ |
| 70 | #ifndef __INDICATOR_LOCATION_CONTROLLER_H__ |
| 71 | #define __INDICATOR_LOCATION_CONTROLLER_H__ |
| 72 | |
| 73 | -#include <set> |
| 74 | - |
| 75 | #include <core/property.h> |
| 76 | |
| 77 | -class ControllerListener |
| 78 | -{ |
| 79 | - public: |
| 80 | - ControllerListener() {} |
| 81 | - virtual ~ControllerListener() {} |
| 82 | - |
| 83 | - public: |
| 84 | - virtual void on_gps_enabled_changed (bool is_enabled) = 0; |
| 85 | - virtual void on_location_service_enabled_changed (bool is_enabled) = 0; |
| 86 | -}; |
| 87 | - |
| 88 | class Controller |
| 89 | { |
| 90 | - public: |
| 91 | - |
| 92 | - Controller () {} |
| 93 | - virtual ~Controller() {} |
| 94 | - |
| 95 | - void add_listener (ControllerListener *); |
| 96 | - void remove_listener (ControllerListener *); |
| 97 | +public: |
| 98 | + Controller(); |
| 99 | + virtual ~Controller(); |
| 100 | |
| 101 | /// True iff we've gotten status info from the location service |
| 102 | virtual const core::Property<bool>& is_valid() const =0; |
| 103 | |
| 104 | - virtual bool is_gps_enabled () const = 0; |
| 105 | - virtual bool is_location_service_enabled () const = 0; |
| 106 | - |
| 107 | - virtual void set_gps_enabled (bool enabled) = 0; |
| 108 | - virtual void set_location_service_enabled (bool enabled) = 0; |
| 109 | - |
| 110 | - private: |
| 111 | - |
| 112 | - std::set<ControllerListener*> listeners; |
| 113 | - |
| 114 | - protected: |
| 115 | - |
| 116 | - void notify_gps_enabled (bool); |
| 117 | - void notify_location_service_enabled (bool); |
| 118 | + virtual const core::Property<bool>& gps_enabled() const =0; |
| 119 | + virtual const core::Property<bool>& location_service_enabled() const =0; |
| 120 | + |
| 121 | + virtual void set_gps_enabled (bool enabled) =0; |
| 122 | + virtual void set_location_service_enabled (bool enabled) =0; |
| 123 | }; |
| 124 | |
| 125 | #endif // __INDICATOR_LOCATION_CONTROLLER_H__ |
| 126 | |
| 127 | === modified file 'src/location-service-controller.cc' |
| 128 | --- src/location-service-controller.cc 2015-04-17 16:44:53 +0000 |
| 129 | +++ src/location-service-controller.cc 2016-01-22 18:23:42 +0000 |
| 130 | @@ -31,21 +31,13 @@ |
| 131 | { |
| 132 | public: |
| 133 | |
| 134 | - Impl(LocationServiceController& owner) |
| 135 | + Impl() |
| 136 | { |
| 137 | m_cancellable.reset(g_cancellable_new(), [](GCancellable* c) { |
| 138 | g_cancellable_cancel(c); |
| 139 | g_object_unref(c); |
| 140 | }); |
| 141 | |
| 142 | - m_gps_enabled.changed().connect([&owner](bool b){ |
| 143 | - owner.notify_gps_enabled(b); |
| 144 | - }); |
| 145 | - |
| 146 | - m_loc_enabled.changed().connect([&owner](bool b){ |
| 147 | - owner.notify_location_service_enabled(b); |
| 148 | - }); |
| 149 | - |
| 150 | g_bus_get(G_BUS_TYPE_SYSTEM, |
| 151 | m_cancellable.get(), |
| 152 | on_system_bus_ready, |
| 153 | @@ -59,14 +51,14 @@ |
| 154 | return m_is_valid; |
| 155 | } |
| 156 | |
| 157 | - bool is_gps_enabled() const |
| 158 | + const core::Property<bool>& gps_enabled() const |
| 159 | { |
| 160 | - return m_gps_enabled.get(); |
| 161 | + return m_gps_enabled; |
| 162 | } |
| 163 | |
| 164 | - bool is_location_service_enabled() const |
| 165 | + const core::Property<bool>& location_service_enabled() const |
| 166 | { |
| 167 | - return m_loc_enabled.get(); |
| 168 | + return m_loc_enabled; |
| 169 | } |
| 170 | |
| 171 | void set_gps_enabled(bool enabled) |
| 172 | @@ -108,9 +100,9 @@ |
| 173 | nullptr); |
| 174 | |
| 175 | // manage the name_tag's lifespan |
| 176 | - self->m_name_tag.reset(new guint{name_tag}, [](guint* name_tag){ |
| 177 | - g_bus_unwatch_name(*name_tag); |
| 178 | - delete name_tag; |
| 179 | + self->m_name_tag.reset(new guint{name_tag}, [](guint* tag){ |
| 180 | + g_bus_unwatch_name(*tag); |
| 181 | + delete tag; |
| 182 | }); |
| 183 | } |
| 184 | else if (error != nullptr) |
| 185 | @@ -122,9 +114,9 @@ |
| 186 | } |
| 187 | |
| 188 | static void on_name_appeared(GDBusConnection * system_bus, |
| 189 | - const gchar * bus_name, |
| 190 | + const gchar * /*bus_name*/, |
| 191 | const gchar * name_owner, |
| 192 | - gpointer gself) |
| 193 | + gpointer gself) |
| 194 | { |
| 195 | auto self = static_cast<Impl*>(gself); |
| 196 | |
| 197 | @@ -275,7 +267,7 @@ |
| 198 | { |
| 199 | bool success, value; |
| 200 | std::tie(success, value) = get_bool_reply_from_call(source_object, res); |
| 201 | - g_debug("service loc reply: success %d value %d", (int)success, (int)value); |
| 202 | + g_debug("service loc reply: success %d value %d", int(success), int(value)); |
| 203 | if (success) |
| 204 | static_cast<Impl*>(gself)->m_loc_enabled.set(value); |
| 205 | } |
| 206 | @@ -286,7 +278,7 @@ |
| 207 | { |
| 208 | bool success, value; |
| 209 | std::tie(success, value) = get_bool_reply_from_call(source_object, res); |
| 210 | - g_debug("service gps reply: success %d value %d", (int)success, (int)value); |
| 211 | + g_debug("service gps reply: success %d value %d", int(success), int(value)); |
| 212 | if (success) |
| 213 | static_cast<Impl*>(gself)->m_gps_enabled.set(value); |
| 214 | } |
| 215 | @@ -319,7 +311,7 @@ |
| 216 | |
| 217 | static void check_method_call_reply(GObject *connection, |
| 218 | GAsyncResult *res, |
| 219 | - gpointer gself) |
| 220 | + gpointer /*gself*/) |
| 221 | { |
| 222 | GError * error; |
| 223 | GVariant * v; |
| 224 | @@ -368,7 +360,7 @@ |
| 225 | ***/ |
| 226 | |
| 227 | LocationServiceController::LocationServiceController(): |
| 228 | - impl{new Impl{*this}} |
| 229 | + impl{new Impl{}} |
| 230 | { |
| 231 | } |
| 232 | |
| 233 | @@ -382,17 +374,18 @@ |
| 234 | return impl->is_valid(); |
| 235 | } |
| 236 | |
| 237 | -bool |
| 238 | -LocationServiceController::is_gps_enabled() const |
| 239 | -{ |
| 240 | - return impl->is_gps_enabled(); |
| 241 | -} |
| 242 | - |
| 243 | -bool |
| 244 | -LocationServiceController::is_location_service_enabled() const |
| 245 | -{ |
| 246 | - return impl->is_location_service_enabled(); |
| 247 | -} |
| 248 | +const core::Property<bool>& |
| 249 | +LocationServiceController::gps_enabled() const |
| 250 | +{ |
| 251 | + return impl->gps_enabled(); |
| 252 | +} |
| 253 | + |
| 254 | +const core::Property<bool>& |
| 255 | +LocationServiceController::location_service_enabled() const |
| 256 | +{ |
| 257 | + return impl->location_service_enabled(); |
| 258 | +} |
| 259 | + |
| 260 | void |
| 261 | LocationServiceController::set_gps_enabled(bool enabled) |
| 262 | { |
| 263 | |
| 264 | === modified file 'src/location-service-controller.h' |
| 265 | --- src/location-service-controller.h 2015-04-17 16:51:19 +0000 |
| 266 | +++ src/location-service-controller.h 2016-01-22 18:23:42 +0000 |
| 267 | @@ -20,26 +20,26 @@ |
| 268 | #ifndef INDICATOR_LOCATION_CONTROLLER_LOCATION_SERVICE |
| 269 | #define INDICATOR_LOCATION_CONTROLLER_LOCATION_SERVICE |
| 270 | |
| 271 | -#include "controller.h" |
| 272 | +#include "controller.h" // parent class |
| 273 | |
| 274 | #include <memory> // std::unique_ptr |
| 275 | |
| 276 | class LocationServiceController: public Controller |
| 277 | { |
| 278 | - public: |
| 279 | +public: |
| 280 | LocationServiceController(); |
| 281 | virtual ~LocationServiceController(); |
| 282 | |
| 283 | - virtual const core::Property<bool>& is_valid() const override; |
| 284 | - bool is_gps_enabled () const override; |
| 285 | - bool is_location_service_enabled () const override; |
| 286 | + const core::Property<bool>& is_valid() const override; |
| 287 | + const core::Property<bool>& gps_enabled() const override; |
| 288 | + const core::Property<bool>& location_service_enabled() const override; |
| 289 | void set_gps_enabled (bool enabled) override; |
| 290 | void set_location_service_enabled (bool enabled) override; |
| 291 | |
| 292 | LocationServiceController(const LocationServiceController&) =delete; |
| 293 | LocationServiceController& operator=(const LocationServiceController&) =delete; |
| 294 | |
| 295 | - private: |
| 296 | +private: |
| 297 | friend class Impl; |
| 298 | class Impl; |
| 299 | std::unique_ptr<Impl> impl; |
| 300 | |
| 301 | === modified file 'src/phone.cc' |
| 302 | --- src/phone.cc 2016-01-22 18:23:42 +0000 |
| 303 | +++ src/phone.cc 2016-01-22 18:23:42 +0000 |
| 304 | @@ -38,7 +38,29 @@ |
| 305 | action_group (action_group_) |
| 306 | { |
| 307 | create_menu (); |
| 308 | - controller->add_listener (this); |
| 309 | + |
| 310 | + auto on_gps = [this](bool enabled){ |
| 311 | + update_gps_enabled_action(); |
| 312 | + update_header(); |
| 313 | + }; |
| 314 | + controller_connections.push_back( |
| 315 | + controller->gps_enabled().changed().connect(on_gps) |
| 316 | + ); |
| 317 | + |
| 318 | + auto on_loc = [this](bool enabled){ |
| 319 | + update_detection_enabled_action(); |
| 320 | + update_header(); |
| 321 | + }; |
| 322 | + controller_connections.push_back( |
| 323 | + controller->location_service_enabled().changed().connect(on_loc) |
| 324 | + ); |
| 325 | + |
| 326 | + auto on_valid = [this](bool valid){ |
| 327 | + update_actions_enabled(); |
| 328 | + }; |
| 329 | + controller_connections.push_back( |
| 330 | + controller->is_valid().changed().connect(on_valid) |
| 331 | + ); |
| 332 | |
| 333 | /* create the actions & add them to the group */ |
| 334 | std::array<GSimpleAction*, 4> actions = { create_root_action(), |
| 335 | @@ -51,14 +73,11 @@ |
| 336 | g_object_unref (a); |
| 337 | } |
| 338 | |
| 339 | - // the profile should track whether the controller is valid or not |
| 340 | - controller->is_valid().changed().connect([this](bool){on_is_valid_changed();}); |
| 341 | - on_is_valid_changed(); |
| 342 | + update_actions_enabled(); |
| 343 | } |
| 344 | |
| 345 | Phone :: ~Phone () |
| 346 | { |
| 347 | - controller->remove_listener (this); |
| 348 | } |
| 349 | |
| 350 | /*** |
| 351 | @@ -73,7 +92,7 @@ |
| 352 | |
| 353 | // as per "Indicators - RTM Usability Fix" document: |
| 354 | // visible iff location is enabled |
| 355 | - return controller->is_location_service_enabled(); |
| 356 | + return controller->location_service_enabled().get(); |
| 357 | } |
| 358 | |
| 359 | GVariant * |
| 360 | @@ -123,7 +142,7 @@ |
| 361 | } |
| 362 | |
| 363 | void |
| 364 | -Phone :: on_is_valid_changed() |
| 365 | +Phone :: update_actions_enabled() |
| 366 | { |
| 367 | const auto map = G_ACTION_MAP(action_group.get()); |
| 368 | const bool is_valid = controller->is_valid().get(); |
| 369 | @@ -141,15 +160,7 @@ |
| 370 | GVariant * |
| 371 | Phone :: action_state_for_location_detection () |
| 372 | { |
| 373 | - return g_variant_new_boolean (controller->is_location_service_enabled()); |
| 374 | -} |
| 375 | - |
| 376 | -void |
| 377 | -Phone :: on_location_service_enabled_changed (bool is_enabled G_GNUC_UNUSED) |
| 378 | -{ |
| 379 | - GAction * action = g_action_map_lookup_action (G_ACTION_MAP(action_group.get()), LOCATION_ACTION_KEY); |
| 380 | - g_simple_action_set_state (G_SIMPLE_ACTION(action), action_state_for_location_detection()); |
| 381 | - update_header(); |
| 382 | + return g_variant_new_boolean (controller->location_service_enabled().get()); |
| 383 | } |
| 384 | |
| 385 | void |
| 386 | @@ -177,6 +188,13 @@ |
| 387 | return action; |
| 388 | } |
| 389 | |
| 390 | +void |
| 391 | +Phone::update_detection_enabled_action() |
| 392 | +{ |
| 393 | + GAction * action = g_action_map_lookup_action (G_ACTION_MAP(action_group.get()), LOCATION_ACTION_KEY); |
| 394 | + g_simple_action_set_state (G_SIMPLE_ACTION(action), action_state_for_location_detection()); |
| 395 | +} |
| 396 | + |
| 397 | /*** |
| 398 | **** |
| 399 | ***/ |
| 400 | @@ -184,15 +202,7 @@ |
| 401 | GVariant * |
| 402 | Phone :: action_state_for_gps_detection () |
| 403 | { |
| 404 | - return g_variant_new_boolean (controller->is_gps_enabled()); |
| 405 | -} |
| 406 | - |
| 407 | -void |
| 408 | -Phone :: on_gps_enabled_changed (bool is_enabled G_GNUC_UNUSED) |
| 409 | -{ |
| 410 | - GAction * action = g_action_map_lookup_action (G_ACTION_MAP(action_group.get()), GPS_ACTION_KEY); |
| 411 | - g_simple_action_set_state (G_SIMPLE_ACTION(action), action_state_for_gps_detection()); |
| 412 | - update_header(); |
| 413 | + return g_variant_new_boolean (controller->gps_enabled().get()); |
| 414 | } |
| 415 | |
| 416 | void |
| 417 | @@ -206,7 +216,7 @@ |
| 418 | } |
| 419 | |
| 420 | GSimpleAction * |
| 421 | -Phone :: create_gps_enabled_action () |
| 422 | +Phone :: create_gps_enabled_action() |
| 423 | { |
| 424 | GSimpleAction * action; |
| 425 | |
| 426 | @@ -220,6 +230,13 @@ |
| 427 | return action; |
| 428 | } |
| 429 | |
| 430 | +void |
| 431 | +Phone::update_gps_enabled_action() |
| 432 | +{ |
| 433 | + GAction * action = g_action_map_lookup_action (G_ACTION_MAP(action_group.get()), GPS_ACTION_KEY); |
| 434 | + g_simple_action_set_state (G_SIMPLE_ACTION(action), action_state_for_gps_detection()); |
| 435 | +} |
| 436 | + |
| 437 | /*** |
| 438 | **** |
| 439 | ***/ |
| 440 | @@ -230,7 +247,7 @@ |
| 441 | { |
| 442 | void |
| 443 | on_uri_dispatched (const gchar * uri, |
| 444 | - gboolean success G_GNUC_UNUSED, |
| 445 | + gboolean success, |
| 446 | gpointer user_data G_GNUC_UNUSED) |
| 447 | { |
| 448 | if (!success) |
| 449 | |
| 450 | === modified file 'src/phone.h' |
| 451 | --- src/phone.h 2016-01-22 18:23:42 +0000 |
| 452 | +++ src/phone.h 2016-01-22 18:23:42 +0000 |
| 453 | @@ -21,13 +21,14 @@ |
| 454 | #define __INDICATOR_LOCATION_PHONE_H__ |
| 455 | |
| 456 | #include <memory> |
| 457 | +#include <vector> |
| 458 | |
| 459 | #include <glib.h> |
| 460 | #include <gio/gio.h> |
| 461 | |
| 462 | #include "controller.h" |
| 463 | |
| 464 | -class Phone: public ControllerListener |
| 465 | +class Phone |
| 466 | { |
| 467 | public: |
| 468 | Phone (const std::shared_ptr<Controller>& controller, |
| 469 | @@ -37,9 +38,7 @@ |
| 470 | |
| 471 | protected: |
| 472 | std::shared_ptr<Controller> controller; |
| 473 | - virtual void on_is_valid_changed(); |
| 474 | - virtual void on_gps_enabled_changed (bool is_enabled); |
| 475 | - virtual void on_location_service_enabled_changed (bool is_enabled); |
| 476 | + std::vector<core::ScopedConnection> controller_connections; |
| 477 | |
| 478 | private: |
| 479 | std::shared_ptr<GMenu> menu; |
| 480 | @@ -55,15 +54,19 @@ |
| 481 | GVariant * action_state_for_root () const; |
| 482 | GSimpleAction * create_root_action (); |
| 483 | void update_header(); |
| 484 | + void update_actions_enabled(); |
| 485 | |
| 486 | private: |
| 487 | GVariant * action_state_for_location_detection (); |
| 488 | GSimpleAction * create_detection_enabled_action (); |
| 489 | + void update_detection_enabled_action(); |
| 490 | static void on_detection_location_activated (GSimpleAction*, GVariant*, gpointer); |
| 491 | |
| 492 | + |
| 493 | private: |
| 494 | GVariant * action_state_for_gps_detection (); |
| 495 | GSimpleAction * create_gps_enabled_action (); |
| 496 | + void update_gps_enabled_action(); |
| 497 | static void on_detection_gps_activated (GSimpleAction*, GVariant*, gpointer); |
| 498 | |
| 499 | private: |
| 500 | |
| 501 | === modified file 'src/service.cc' |
| 502 | --- src/service.cc 2016-01-22 18:23:42 +0000 |
| 503 | +++ src/service.cc 2016-01-22 18:23:42 +0000 |
| 504 | @@ -84,44 +84,44 @@ |
| 505 | ***/ |
| 506 | |
| 507 | void |
| 508 | -Service :: on_name_lost (GDBusConnection * connection, |
| 509 | +Service :: on_name_lost (GDBusConnection * conn, |
| 510 | const char * name, |
| 511 | gpointer gself) |
| 512 | { |
| 513 | - g_debug ("%s::%s: %s %p", G_STRLOC, G_STRFUNC, name, connection); |
| 514 | + g_debug ("%s::%s: %s %p", G_STRLOC, G_STRFUNC, name, conn); |
| 515 | |
| 516 | - static_cast<Service*>(gself)->on_name_lost (connection, name); |
| 517 | + static_cast<Service*>(gself)->on_name_lost (conn, name); |
| 518 | } |
| 519 | void |
| 520 | -Service :: on_name_lost (GDBusConnection * connection, |
| 521 | +Service :: on_name_lost (GDBusConnection * conn, |
| 522 | const char * name) |
| 523 | { |
| 524 | - g_debug ("%s::%s: %s %p", G_STRLOC, G_STRFUNC, name, connection); |
| 525 | + g_debug ("%s::%s: %s %p", G_STRLOC, G_STRFUNC, name, conn); |
| 526 | |
| 527 | if (name_lost_callback != nullptr) |
| 528 | (name_lost_callback)(this, name_lost_user_data); |
| 529 | } |
| 530 | |
| 531 | void |
| 532 | -Service :: on_bus_acquired (GDBusConnection * connection, |
| 533 | +Service :: on_bus_acquired (GDBusConnection * conn, |
| 534 | const char * name, |
| 535 | gpointer gself) |
| 536 | { |
| 537 | - static_cast<Service*>(gself)->on_bus_acquired (connection, name); |
| 538 | + static_cast<Service*>(gself)->on_bus_acquired (conn, name); |
| 539 | } |
| 540 | void |
| 541 | -Service :: on_bus_acquired (GDBusConnection * connection, |
| 542 | +Service :: on_bus_acquired (GDBusConnection * conn, |
| 543 | const char * name) |
| 544 | { |
| 545 | - g_debug ("%s::%s: %s %p", G_STRLOC, G_STRFUNC, name, connection); |
| 546 | + g_debug ("%s::%s: %s %p", G_STRLOC, G_STRFUNC, name, conn); |
| 547 | |
| 548 | - this->connection.reset (G_DBUS_CONNECTION (g_object_ref(connection))); |
| 549 | + this->connection.reset (G_DBUS_CONNECTION (g_object_ref(conn))); |
| 550 | |
| 551 | GError * error = nullptr; |
| 552 | |
| 553 | /* export the action group */ |
| 554 | |
| 555 | - unsigned int export_id = g_dbus_connection_export_action_group (connection, |
| 556 | + unsigned int export_id = g_dbus_connection_export_action_group (conn, |
| 557 | INDICATOR_OBJECT_PATH, |
| 558 | G_ACTION_GROUP (action_group.get()), |
| 559 | &error); |
| 560 | @@ -146,7 +146,7 @@ |
| 561 | |
| 562 | for (unsigned int i=0, n=G_N_ELEMENTS(menus); i<n; i++) |
| 563 | { |
| 564 | - export_id = g_dbus_connection_export_menu_model (connection, |
| 565 | + export_id = g_dbus_connection_export_menu_model (conn, |
| 566 | menus[i].path, |
| 567 | G_MENU_MODEL (menus[i].menu.get()), |
| 568 | &error); |
| 569 | |
| 570 | === modified file 'src/service.h' |
| 571 | --- src/service.h 2016-01-22 18:23:42 +0000 |
| 572 | +++ src/service.h 2016-01-22 18:23:42 +0000 |
| 573 | @@ -30,7 +30,7 @@ |
| 574 | class Service |
| 575 | { |
| 576 | public: |
| 577 | - Service (const std::shared_ptr<Controller>& controller); |
| 578 | + explicit Service (const std::shared_ptr<Controller>& controller); |
| 579 | virtual ~Service (); |
| 580 | |
| 581 | private: |
| 582 | |
| 583 | === renamed file 'src/controller-mock.h' => 'tests/controller-mock.h' |
| 584 | --- src/controller-mock.h 2015-04-15 14:24:14 +0000 |
| 585 | +++ tests/controller-mock.h 2016-01-22 18:23:42 +0000 |
| 586 | @@ -17,10 +17,9 @@ |
| 587 | * Charles Kerr <[email protected]> |
| 588 | */ |
| 589 | |
| 590 | -#ifndef __INDICATOR_LOCATION_CONTROLLER_MOCK__H__ |
| 591 | -#define __INDICATOR_LOCATION_CONTROLLER_MOCK__H__ |
| 592 | +#pragma once |
| 593 | |
| 594 | -#include "controller.h" |
| 595 | +#include <src/controller.h> |
| 596 | |
| 597 | class MockController: public Controller |
| 598 | { |
| 599 | @@ -31,19 +30,16 @@ |
| 600 | |
| 601 | core::Property<bool>& is_valid() { return m_is_valid; } |
| 602 | const core::Property<bool>& is_valid() const override { return m_is_valid; } |
| 603 | - bool is_gps_enabled () const { return gps; } |
| 604 | - bool is_location_service_enabled () const { return loc; } |
| 605 | + const core::Property<bool>& gps_enabled() const override { return m_gps_enabled; } |
| 606 | + const core::Property<bool>& location_service_enabled() const override { return m_location_service_enabled; } |
| 607 | |
| 608 | - void set_gps_enabled (bool enabled) { notify_gps_enabled (gps=enabled); } |
| 609 | - void set_location_service_enabled (bool enabled) { notify_location_service_enabled (loc=enabled); } |
| 610 | + void set_gps_enabled (bool enabled) override { m_gps_enabled=enabled; } |
| 611 | + void set_location_service_enabled (bool enabled) override { m_location_service_enabled=enabled; } |
| 612 | |
| 613 | private: |
| 614 | |
| 615 | core::Property<bool> m_is_valid {true}; |
| 616 | - bool gps { false }; |
| 617 | - bool loc { false }; |
| 618 | + core::Property<bool> m_gps_enabled {false}; |
| 619 | + core::Property<bool> m_location_service_enabled {false}; |
| 620 | }; |
| 621 | |
| 622 | -#endif // __INDICATOR_LOCATION_CONTROLLER_MOCK__H__ |
| 623 | - |
| 624 | - |
| 625 | |
| 626 | === modified file 'tests/gtest-dbus-fixture.h' |
| 627 | --- tests/gtest-dbus-fixture.h 2014-01-27 00:02:51 +0000 |
| 628 | +++ tests/gtest-dbus-fixture.h 2016-01-22 18:23:42 +0000 |
| 629 | @@ -57,7 +57,7 @@ |
| 630 | static gboolean |
| 631 | wait_for_signal__timeout (gpointer name) |
| 632 | { |
| 633 | - g_error ("%s: timed out waiting for signal '%s'", G_STRLOC, (char*)name); |
| 634 | + g_error ("%s: timed out waiting for signal '%s'", G_STRLOC, name); |
| 635 | return G_SOURCE_REMOVE; |
| 636 | } |
| 637 | |
| 638 | @@ -113,7 +113,7 @@ |
| 639 | protected: |
| 640 | |
| 641 | /* convenience func to loop while waiting for a GObject's signal */ |
| 642 | - void wait_for_signal(gpointer o, const gchar * signal, const int timeout_seconds=5) |
| 643 | + void wait_for_signal(gpointer o, const gchar * signal, const guint timeout_seconds=5) |
| 644 | { |
| 645 | // wait for the signal or for timeout, whichever comes first |
| 646 | const auto handler_id = g_signal_connect_swapped(o, signal, |
| 647 | @@ -128,7 +128,7 @@ |
| 648 | } |
| 649 | |
| 650 | /* convenience func to loop for N msec */ |
| 651 | - void wait_msec(int msec=50) |
| 652 | + void wait_msec(guint msec=50) |
| 653 | { |
| 654 | const auto id = g_timeout_add(msec, wait_msec__timeout, loop); |
| 655 | g_main_loop_run(loop); |
| 656 | |
| 657 | === modified file 'tests/gtest-dbus-indicator-fixture.h' |
| 658 | --- tests/gtest-dbus-indicator-fixture.h 2015-04-15 14:24:14 +0000 |
| 659 | +++ tests/gtest-dbus-indicator-fixture.h 2016-01-22 18:23:42 +0000 |
| 660 | @@ -44,9 +44,9 @@ |
| 661 | gint position G_GNUC_UNUSED, |
| 662 | gint removed G_GNUC_UNUSED, |
| 663 | gint added G_GNUC_UNUSED, |
| 664 | - gpointer any_item_changed) |
| 665 | + gpointer gany_item_changed) |
| 666 | { |
| 667 | - *((gboolean*)any_item_changed) = true; |
| 668 | + *static_cast<gboolean*>(gany_item_changed) = true; |
| 669 | } |
| 670 | |
| 671 | protected: |
| 672 | @@ -83,7 +83,7 @@ |
| 673 | |
| 674 | void sync_menu (void) |
| 675 | { |
| 676 | - g_slist_free_full (menu_references, (GDestroyNotify)g_object_unref); |
| 677 | + g_slist_free_full (menu_references, GDestroyNotify(g_object_unref)); |
| 678 | menu_references = nullptr; |
| 679 | activate_subtree (G_MENU_MODEL (menu_model)); |
| 680 | } |
| 681 | @@ -111,7 +111,7 @@ |
| 682 | G_BUS_NAME_WATCHER_FLAGS_NONE, |
| 683 | on_name_appeared, // quits the loop |
| 684 | nullptr, this, nullptr); |
| 685 | - const guint timer_id = g_timeout_add_seconds (TIME_LIMIT_SEC, (GSourceFunc)g_main_loop_quit, loop); |
| 686 | + const guint timer_id = g_timeout_add_seconds (TIME_LIMIT_SEC, GSourceFunc(g_main_loop_quit), loop); |
| 687 | g_main_loop_run (loop); |
| 688 | g_source_remove (timer_id); |
| 689 | g_bus_unwatch_name (watch_id); |
| 690 | @@ -136,7 +136,7 @@ |
| 691 | { |
| 692 | g_clear_pointer (&timer, g_timer_destroy); |
| 693 | |
| 694 | - g_slist_free_full (menu_references, (GDestroyNotify)g_object_unref); |
| 695 | + g_slist_free_full (menu_references, GDestroyNotify(g_object_unref)); |
| 696 | menu_references = nullptr; |
| 697 | g_clear_object (&menu_model); |
| 698 | |
| 699 | |
| 700 | === modified file 'tests/phone-test.cc' |
| 701 | --- tests/phone-test.cc 2016-01-22 18:23:42 +0000 |
| 702 | +++ tests/phone-test.cc 2016-01-22 18:23:42 +0000 |
| 703 | @@ -21,12 +21,11 @@ |
| 704 | #define INDICATOR_PROFILE "phone" |
| 705 | #include "gtest-dbus-indicator-fixture.h" |
| 706 | |
| 707 | +#include "controller-mock.h" |
| 708 | #include "src/dbus-shared.h" |
| 709 | -#include "src/controller-mock.h" |
| 710 | #include "src/service.h" |
| 711 | |
| 712 | -class PhoneTest: public GTestDBusIndicatorFixture, |
| 713 | - public ControllerListener |
| 714 | +class PhoneTest: public GTestDBusIndicatorFixture |
| 715 | { |
| 716 | protected: |
| 717 | |
| 718 | @@ -37,6 +36,7 @@ |
| 719 | |
| 720 | std::shared_ptr<MockController> myController; |
| 721 | std::shared_ptr<Service> myService; |
| 722 | + std::vector<core::ScopedConnection> myConnections; |
| 723 | |
| 724 | public: |
| 725 | |
| 726 | @@ -72,14 +72,27 @@ |
| 727 | virtual void setup_service () |
| 728 | { |
| 729 | myController.reset (new MockController ()); |
| 730 | - myController->add_listener (this); |
| 731 | myService.reset (new Service (myController)); |
| 732 | + |
| 733 | + myConnections.push_back( |
| 734 | + myController->gps_enabled().changed().connect([this](bool enabled){ |
| 735 | + gps_enabled_changed = true; |
| 736 | + gps_enabled = enabled; |
| 737 | + }) |
| 738 | + ); |
| 739 | + |
| 740 | + myConnections.push_back( |
| 741 | + myController->location_service_enabled().changed().connect([this](bool enabled){ |
| 742 | + loc_enabled_changed = true; |
| 743 | + loc_enabled = enabled; |
| 744 | + }) |
| 745 | + ); |
| 746 | } |
| 747 | |
| 748 | virtual void teardown_service () |
| 749 | { |
| 750 | myService.reset (); |
| 751 | - myController->remove_listener (this); |
| 752 | + myConnections.clear (); |
| 753 | myController.reset (); |
| 754 | } |
| 755 | }; |
| 756 | @@ -123,7 +136,7 @@ |
| 757 | TEST_F (PhoneTest, IsValidVisible) |
| 758 | { |
| 759 | // make sure something's enabled so that the indicator should be visible |
| 760 | - if (!myController->is_location_service_enabled()) { |
| 761 | + if (!myController->location_service_enabled().get()) { |
| 762 | myController->set_location_service_enabled(true); |
| 763 | wait_for_action_state_change("location-detection-enabled"); |
| 764 | } |
PASSED: Continuous integration, rev:161 jenkins. qa.ubuntu. com/job/ indicator- location- ci/70/ jenkins. qa.ubuntu. com/job/ indicator- location- wily-amd64- ci/5 jenkins. qa.ubuntu. com/job/ indicator- location- wily-armhf- ci/5 jenkins. qa.ubuntu. com/job/ indicator- location- wily-armhf- ci/5/artifact/ work/output/ *zip*/output. zip
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/indicator- location- ci/70/rebuild
http://