Merge lp:~thomas-voss/platform-api/fix-1348334 into lp:platform-api

Proposed by Thomas Voß
Status: Merged
Approved by: Pete Woods
Approved revision: 256
Merged at revision: 260
Proposed branch: lp:~thomas-voss/platform-api/fix-1348334
Merge into: lp:platform-api
Diff against target: 130 lines (+84/-9)
2 files modified
src/ubuntu/application/common/application/location/controller.cpp (+11/-2)
src/ubuntu/application/common/application/location/instance.h (+73/-7)
To merge this branch: bzr merge lp:~thomas-voss/platform-api/fix-1348334
Reviewer Review Type Date Requested Status
Pete Woods (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+229816@code.launchpad.net

Commit message

Implement installation of changed handlers.
Subscribe to state properties.

Description of the change

Implement installation of changed handlers.
Subscribe to state properties.

To post a comment you must log in.
255. By Thomas Voß

Fix FTBFS.

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 :

comments inline

256. By Thomas Voß

Address reviewer comments.

Revision history for this message
Pete Woods (pete-woods) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/ubuntu/application/common/application/location/controller.cpp'
2--- src/ubuntu/application/common/application/location/controller.cpp 2014-07-28 20:14:23 +0000
3+++ src/ubuntu/application/common/application/location/controller.cpp 2014-08-12 09:17:31 +0000
4@@ -42,8 +42,17 @@
5 void *context)
6 {
7 (void) controller;
8- (void) handler;
9- (void) context;
10+
11+ try
12+ {
13+ Instance::instance().set_changed_handler_with_context(handler, context);
14+ } catch(const std::exception& e)
15+ {
16+ std::cerr << "ua_location_service_controller_set_status_changed_handler: error accessing instance: " << e.what() << std::endl;
17+ } catch(...)
18+ {
19+ std::cerr << "ua_location_service_controller_set_status_changed_handler: error accessing instance." << std::endl;
20+ }
21 }
22
23 UStatus
24
25=== modified file 'src/ubuntu/application/common/application/location/instance.h'
26--- src/ubuntu/application/common/application/location/instance.h 2014-07-28 20:14:23 +0000
27+++ src/ubuntu/application/common/application/location/instance.h 2014-08-12 09:17:31 +0000
28@@ -21,6 +21,8 @@
29
30 #include "ubuntu/visibility.h"
31
32+#include "ubuntu/application/location/controller.h"
33+
34 #include <com/ubuntu/location/service/stub.h>
35
36 #include <core/dbus/resolver.h>
37@@ -42,13 +44,64 @@
38 return service;
39 }
40
41+ void set_changed_handler_with_context(
42+ UALocationServiceStatusChangedHandler handler,
43+ void* context)
44+ {
45+ changed_handler = handler;
46+ changed_handler_context = context;
47+ }
48+
49 private:
50- Instance() : bus(std::make_shared<core::dbus::Bus>(core::dbus::WellKnownBus::system)),
51- executor(core::dbus::asio::make_executor(bus)),
52- service(core::dbus::resolve_service_on_bus<
53- com::ubuntu::location::service::Interface,
54- com::ubuntu::location::service::Stub
55- >(bus))
56+ Instance()
57+ : bus(std::make_shared<core::dbus::Bus>(core::dbus::WellKnownBus::system)),
58+ executor(core::dbus::asio::make_executor(bus)),
59+ service(core::dbus::resolve_service_on_bus<
60+ com::ubuntu::location::service::Interface,
61+ com::ubuntu::location::service::Stub
62+ >(bus)),
63+ connections
64+ {
65+ service->does_satellite_based_positioning().changed().connect([this](bool value)
66+ {
67+ // Update our cached value.
68+ if (value)
69+ {
70+ cached_state_flags |= UA_LOCATION_SERVICE_GPS_ENABLED;
71+ cached_state_flags &= ~UA_LOCATION_SERVICE_GPS_DISABLED;
72+ }
73+ else
74+ {
75+ cached_state_flags |= UA_LOCATION_SERVICE_GPS_DISABLED;
76+ cached_state_flags &= ~UA_LOCATION_SERVICE_GPS_ENABLED;
77+ }
78+
79+ // And notify change handler if one is set.
80+ if (changed_handler)
81+ changed_handler(cached_state_flags, changed_handler_context);
82+ }),
83+ service->is_online().changed().connect([this](bool value)
84+ {
85+ // Update our cached value.
86+ if (value)
87+ {
88+ cached_state_flags |= UA_LOCATION_SERVICE_ENABLED;
89+ cached_state_flags &= ~UA_LOCATION_SERVICE_DISABLED;
90+ }
91+ else
92+ {
93+ cached_state_flags |= UA_LOCATION_SERVICE_DISABLED;
94+ cached_state_flags &= ~UA_LOCATION_SERVICE_ENABLED;
95+ }
96+
97+ // And notify change handler if one is set.
98+ if (changed_handler)
99+ changed_handler(cached_state_flags, changed_handler_context);
100+ })
101+ },
102+ cached_state_flags{0},
103+ changed_handler{nullptr},
104+ changed_handler_context{nullptr}
105 {
106 bus->install_executor(executor);
107 worker = std::move(std::thread([&]() { bus->run(); }));
108@@ -70,8 +123,21 @@
109
110 core::dbus::Bus::Ptr bus;
111 core::dbus::Executor::Ptr executor;
112+ std::thread worker;
113+
114 com::ubuntu::location::service::Interface::Ptr service;
115- std::thread worker;
116+
117+ // All event connections go here.
118+ struct
119+ {
120+ core::ScopedConnection on_does_satellite_based_positioning_changed;
121+ core::ScopedConnection on_is_online_changed;
122+ } connections;
123+
124+ // All change-handler specifics go here.
125+ UALocationServiceStatusFlags cached_state_flags;
126+ UALocationServiceStatusChangedHandler changed_handler;
127+ void* changed_handler_context;
128 };
129
130 #endif // INSTANCE_H_

Subscribers

People subscribed via source and target branches