Merge lp:~thomas-voss/platform-api/add-controller-and-accuracy into lp:platform-api

Proposed by Thomas Voß
Status: Merged
Approved by: Ricardo Mendoza
Approved revision: 237
Merged at revision: 234
Proposed branch: lp:~thomas-voss/platform-api/add-controller-and-accuracy
Merge into: lp:platform-api
Diff against target: 724 lines (+351/-78)
15 files modified
debian/control (+1/-1)
debian/libubuntu-application-api2.symbols (+4/-0)
include/ubuntu/application/location/position_update.h (+40/-0)
include/ubuntu/visibility.h (+2/-0)
src/ubuntu/application/common/application/location/controller.cpp (+27/-1)
src/ubuntu/application/common/application/location/controller_p.h (+1/-0)
src/ubuntu/application/common/application/location/heading_update.cpp (+1/-1)
src/ubuntu/application/common/application/location/instance.h (+71/-0)
src/ubuntu/application/common/application/location/position_update.cpp (+32/-4)
src/ubuntu/application/common/application/location/ref_counted.h (+1/-1)
src/ubuntu/application/common/application/location/service.cpp (+16/-41)
src/ubuntu/application/common/application/location/session.cpp (+50/-24)
src/ubuntu/application/common/application/location/session_p.h (+100/-4)
src/ubuntu/application/common/application/location/velocity_update.cpp (+1/-1)
src/ubuntu/application/ubuntu_application_api.cpp (+4/-0)
To merge this branch: bzr merge lp:~thomas-voss/platform-api/add-controller-and-accuracy
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing
Ubuntu Phablet Team Pending
Review via email: mp+224107@code.launchpad.net

Commit message

Adjust to API changes in location service.
Implement controller interface.
Add functions to query the accuracy estimates for a position update.

Description of the change

Adjust to API changes in location service.
Implement controller interface.
Add functions to query the accuracy estimates for a position update.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
230. By Thomas Voß

Adjust flags value correctly.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
231. By Thomas Voß

Catch possible exceptions when interacting with the remote location service instance.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
232. By Thomas Voß

Remove Google log macros with sprintfs.

233. By Thomas Voß

sprintf really should be fprintf.

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: Needs Fixing (continuous-integration)
234. By Thomas Voß

[ Ricardo Mendoza ]
* Added orientation sensor, extended existing sensor API to allow
  for dynamic event rate setting.
[ Ubuntu daily release ]
* debian/*symbols: auto-update new symbols to released version

235. By Thomas Voß

Expose symbols for horizontal and vertical accuracy.

236. By Thomas Voß

Adjust symbols file.

237. By Thomas Voß

Add a versioned build-dependency on location service.

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: Needs Fixing (continuous-integration)
238. By Thomas Voß

[ Ricardo Mendoza ]
Add missing enable/disable functions for haptic

239. By Thomas Voß

Clean up event connections on destruction.

240. By Thomas Voß

Make destruction thread-safe.

241. By Thomas Voß

Make sure that handlers and contexts are setup before creating event connections.

242. By Thomas Voß

Make sure that refcounted elements are actually deleted.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/control'
--- debian/control 2014-06-13 16:31:35 +0000
+++ debian/control 2014-06-26 20:03:03 +0000
@@ -15,7 +15,7 @@
15 liburl-dispatcher1-dev,15 liburl-dispatcher1-dev,
16 libdbus-1-dev,16 libdbus-1-dev,
17 libdbus-cpp-dev (>= 2.0.0),17 libdbus-cpp-dev (>= 2.0.0),
18 libubuntu-location-service-dev,18 libubuntu-location-service-dev (>= 1.0.0),,
19 libgtest-dev,19 libgtest-dev,
20 libprocess-cpp-dev (>= 0.0.1+14.04.20131212),20 libprocess-cpp-dev (>= 0.0.1+14.04.20131212),
21 libproperties-cpp-dev,21 libproperties-cpp-dev,
2222
=== modified file 'debian/libubuntu-application-api2.symbols'
--- debian/libubuntu-application-api2.symbols 2014-06-23 16:39:57 +0000
+++ debian/libubuntu-application-api2.symbols 2014-06-26 20:03:03 +0000
@@ -25,10 +25,14 @@
25 ua_location_heading_update_ref@Base 0.18.3+13.10.2013080725 ua_location_heading_update_ref@Base 0.18.3+13.10.20130807
26 ua_location_heading_update_unref@Base 0.18.3+13.10.2013080726 ua_location_heading_update_unref@Base 0.18.3+13.10.20130807
27 ua_location_position_update_get_altitude_in_meter@Base 0.18.3+13.10.2013080727 ua_location_position_update_get_altitude_in_meter@Base 0.18.3+13.10.20130807
28 ua_location_position_update_get_horizontal_accuracy_in_meter@Base 0replaceme
28 ua_location_position_update_get_latitude_in_degree@Base 0.18.3+13.10.2013080729 ua_location_position_update_get_latitude_in_degree@Base 0.18.3+13.10.20130807
29 ua_location_position_update_get_longitude_in_degree@Base 0.18.3+13.10.2013080730 ua_location_position_update_get_longitude_in_degree@Base 0.18.3+13.10.20130807
30 ua_location_position_update_get_timestamp@Base 0.18.3+13.10.2013080731 ua_location_position_update_get_timestamp@Base 0.18.3+13.10.20130807
32 ua_location_position_update_get_vertical_accuracy_in_meter@Base 0replaceme
31 ua_location_position_update_has_altitude@Base 0.18.3+13.10.2013080733 ua_location_position_update_has_altitude@Base 0.18.3+13.10.20130807
34 ua_location_position_update_has_horizontal_accuracy@Base 0replaceme
35 ua_location_position_update_has_vertical_accuracy@Base 0replaceme
32 ua_location_position_update_ref@Base 0.18.3+13.10.2013080736 ua_location_position_update_ref@Base 0.18.3+13.10.20130807
33 ua_location_position_update_unref@Base 0.18.3+13.10.2013080737 ua_location_position_update_unref@Base 0.18.3+13.10.20130807
34 ua_location_service_controller_disable_gps@Base 0.18.3+13.10.2013082638 ua_location_service_controller_disable_gps@Base 0.18.3+13.10.20130826
3539
=== modified file 'include/ubuntu/application/location/position_update.h'
--- include/ubuntu/application/location/position_update.h 2013-08-22 07:03:49 +0000
+++ include/ubuntu/application/location/position_update.h 2014-06-26 20:03:03 +0000
@@ -103,6 +103,46 @@
103 ua_location_position_update_get_altitude_in_meter(103 ua_location_position_update_get_altitude_in_meter(
104 UALocationPositionUpdate *update);104 UALocationPositionUpdate *update);
105105
106 /**
107 * \brief Checks if the position update contains a horizontal accuracy estimate.
108 * \ingroup location_service
109 * \returns TRUE if the update contains a horizontal accuracy estimate, else FALSE.
110 * \param[in] update The position update instance to be queried.
111 */
112 UBUNTU_DLL_PUBLIC bool
113 ua_location_position_update_has_horizontal_accuracy(
114 UALocationPositionUpdate *update);
115
116 /**
117 * \brief Queries the horizontal accuracy contained in the position update.
118 * \ingroup location_service
119 * \returns The horizontal accuracy of the position update in [m].
120 * \param[in] update The position update instance to be queried.
121 */
122 UBUNTU_DLL_PUBLIC double
123 ua_location_position_update_get_horizontal_accuracy_in_meter(
124 UALocationPositionUpdate *update);
125
126 /**
127 * \brief Checks if the position update contains a vertical accuracy estimate.
128 * \ingroup location_service
129 * \returns TRUE if the update contains a vertical accuracy estimate, else FALSE.
130 * \param[in] update The position update instance to be queried.
131 */
132 UBUNTU_DLL_PUBLIC bool
133 ua_location_position_update_has_vertical_accuracy(
134 UALocationPositionUpdate *update);
135
136 /**
137 * \brief Queries the vertical accuracy contained in the position update.
138 * \ingroup location_service
139 * \returns The vertical accuracy of the position update in [m].
140 * \param[in] update The position update instance to be queried.
141 */
142 UBUNTU_DLL_PUBLIC double
143 ua_location_position_update_get_vertical_accuracy_in_meter(
144 UALocationPositionUpdate *update);
145
106#ifdef __cplusplus146#ifdef __cplusplus
107}147}
108#endif148#endif
109149
=== modified file 'include/ubuntu/visibility.h'
--- include/ubuntu/visibility.h 2013-08-22 06:32:14 +0000
+++ include/ubuntu/visibility.h 2014-06-26 20:03:03 +0000
@@ -21,8 +21,10 @@
2121
22#if __GNUC__ >= 422#if __GNUC__ >= 4
23#define UBUNTU_DLL_PUBLIC __attribute__ ((visibility ("default")))23#define UBUNTU_DLL_PUBLIC __attribute__ ((visibility ("default")))
24#define UBUNTU_DLL_LOCAL __attribute__ ((visibility ("hidden")))
24#else25#else
25#define UBUNTU_DLL_PUBLIC26#define UBUNTU_DLL_PUBLIC
27#define UBUNTU_DLL_LOCAL
26#endif28#endif
2729
28#endif /* UBUNTU_VISIBILITY_H_ */30#endif /* UBUNTU_VISIBILITY_H_ */
2931
=== modified file 'src/ubuntu/application/common/application/location/controller.cpp'
--- src/ubuntu/application/common/application/location/controller.cpp 2013-08-23 10:55:16 +0000
+++ src/ubuntu/application/common/application/location/controller.cpp 2014-06-26 20:03:03 +0000
@@ -19,6 +19,7 @@
19#include "ubuntu/application/location/controller.h"19#include "ubuntu/application/location/controller.h"
2020
21#include "controller_p.h"21#include "controller_p.h"
22#include "instance.h"
2223
23void24void
24ua_location_service_controller_ref(25ua_location_service_controller_ref(
@@ -51,7 +52,20 @@
51 UALocationServiceStatusFlags *out_flags)52 UALocationServiceStatusFlags *out_flags)
52{53{
53 (void) controller;54 (void) controller;
54 (void) out_flags;55
56 *out_flags = 0;
57
58 auto service = Instance::instance().get_service();
59
60 if (service->is_online().get())
61 *out_flags |= UA_LOCATION_SERVICE_ENABLED;
62 else
63 *out_flags |= UA_LOCATION_SERVICE_DISABLED;
64
65 if (service->does_satellite_based_positioning().get())
66 *out_flags |= UA_LOCATION_SERVICE_GPS_ENABLED;
67 else
68 *out_flags |= UA_LOCATION_SERVICE_GPS_DISABLED;
5569
56 return U_STATUS_SUCCESS;70 return U_STATUS_SUCCESS;
57}71}
@@ -62,6 +76,9 @@
62{76{
63 (void) controller;77 (void) controller;
6478
79 auto service = Instance::instance().get_service();
80 service->is_online().set(true);
81
65 return U_STATUS_SUCCESS;82 return U_STATUS_SUCCESS;
66}83}
6784
@@ -70,6 +87,9 @@
70 UALocationServiceController *controller)87 UALocationServiceController *controller)
71{88{
72 (void) controller;89 (void) controller;
90
91 auto service = Instance::instance().get_service();
92 service->is_online().set(false);
73 93
74 return U_STATUS_SUCCESS;94 return U_STATUS_SUCCESS;
75}95}
@@ -80,6 +100,9 @@
80{100{
81 (void) controller;101 (void) controller;
82102
103 auto service = Instance::instance().get_service();
104 service->does_satellite_based_positioning().set(true);
105
83 return U_STATUS_SUCCESS;106 return U_STATUS_SUCCESS;
84}107}
85108
@@ -89,5 +112,8 @@
89{112{
90 (void) controller;113 (void) controller;
91114
115 auto service = Instance::instance().get_service();
116 service->does_satellite_based_positioning().set(false);
117
92 return U_STATUS_SUCCESS;118 return U_STATUS_SUCCESS;
93}119}
94120
=== modified file 'src/ubuntu/application/common/application/location/controller_p.h'
--- src/ubuntu/application/common/application/location/controller_p.h 2013-08-21 14:59:45 +0000
+++ src/ubuntu/application/common/application/location/controller_p.h 2014-06-26 20:03:03 +0000
@@ -25,6 +25,7 @@
2525
26struct UbuntuApplicationLocationServiceController : public detail::RefCounted26struct UbuntuApplicationLocationServiceController : public detail::RefCounted
27{27{
28
28};29};
2930
30#endif // CONTROLLER_PRIVATE_H_31#endif // CONTROLLER_PRIVATE_H_
3132
=== modified file 'src/ubuntu/application/common/application/location/heading_update.cpp'
--- src/ubuntu/application/common/application/location/heading_update.cpp 2013-08-19 06:46:47 +0000
+++ src/ubuntu/application/common/application/location/heading_update.cpp 2014-06-26 20:03:03 +0000
@@ -51,5 +51,5 @@
51ua_location_heading_update_get_heading_in_degree(51ua_location_heading_update_get_heading_in_degree(
52 UALocationHeadingUpdate *update)52 UALocationHeadingUpdate *update)
53{53{
54 return update->update.value.value.value();54 return update->update.value.value();
55}55}
5656
=== added file 'src/ubuntu/application/common/application/location/instance.h'
--- src/ubuntu/application/common/application/location/instance.h 1970-01-01 00:00:00 +0000
+++ src/ubuntu/application/common/application/location/instance.h 2014-06-26 20:03:03 +0000
@@ -0,0 +1,71 @@
1/*
2 * Copyright © 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * 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/>.
15 *
16 * Authored by: Thomas Voß <thomas.voss@canonical.com>
17 */
18
19#ifndef INSTANCE_H_
20#define INSTANCE_H_
21
22#include "ubuntu/visibility.h"
23
24#include <com/ubuntu/location/service/stub.h>
25
26#include <core/dbus/resolver.h>
27#include <core/dbus/asio/executor.h>
28
29#include <thread>
30
31class UBUNTU_DLL_LOCAL Instance
32{
33 public:
34 static Instance& instance()
35 {
36 static Instance inst;
37 return inst;
38 }
39
40 const com::ubuntu::location::service::Interface::Ptr& get_service() const
41 {
42 return service;
43 }
44
45 private:
46 Instance() : bus(std::make_shared<core::dbus::Bus>(core::dbus::WellKnownBus::system)),
47 executor(core::dbus::asio::make_executor(bus)),
48 service(core::dbus::resolve_service_on_bus<
49 com::ubuntu::location::service::Interface,
50 com::ubuntu::location::service::Stub
51 >(bus))
52 {
53 bus->install_executor(executor);
54 worker = std::move(std::thread([&]() { bus->run(); }));
55 }
56
57 ~Instance() noexcept
58 {
59 bus->stop();
60
61 if (worker.joinable())
62 worker.join();
63 }
64
65 core::dbus::Bus::Ptr bus;
66 core::dbus::Executor::Ptr executor;
67 com::ubuntu::location::service::Interface::Ptr service;
68 std::thread worker;
69};
70
71#endif // INSTANCE_H_
072
=== modified file 'src/ubuntu/application/common/application/location/position_update.cpp'
--- src/ubuntu/application/common/application/location/position_update.cpp 2013-08-19 06:46:47 +0000
+++ src/ubuntu/application/common/application/location/position_update.cpp 2014-06-26 20:03:03 +0000
@@ -51,26 +51,54 @@
51ua_location_position_update_get_latitude_in_degree(51ua_location_position_update_get_latitude_in_degree(
52 UALocationPositionUpdate *update)52 UALocationPositionUpdate *update)
53{53{
54 return update->update.value.latitude().value.value();54 return update->update.value.latitude.value.value();
55}55}
5656
57double57double
58ua_location_position_update_get_longitude_in_degree(58ua_location_position_update_get_longitude_in_degree(
59 UALocationPositionUpdate *update)59 UALocationPositionUpdate *update)
60{60{
61 return update->update.value.longitude().value.value();61 return update->update.value.longitude.value.value();
62}62}
6363
64bool64bool
65ua_location_position_update_has_altitude(65ua_location_position_update_has_altitude(
66 UALocationPositionUpdate *update)66 UALocationPositionUpdate *update)
67{67{
68 return update->update.value.has_altitude();68 return update->update.value.altitude;
69}69}
7070
71double71double
72ua_location_position_update_get_altitude_in_meter(72ua_location_position_update_get_altitude_in_meter(
73 UALocationPositionUpdate *update)73 UALocationPositionUpdate *update)
74{74{
75 return update->update.value.altitude().value.value();75 return update->update.value.altitude->value.value();
76}
77
78bool
79ua_location_position_update_has_horizontal_accuracy(
80 UALocationPositionUpdate *update)
81{
82 return update->update.value.accuracy.horizontal;
83}
84
85double
86ua_location_position_update_get_horizontal_accuracy_in_meter(
87 UALocationPositionUpdate *update)
88{
89 return update->update.value.accuracy.horizontal->value();
90}
91
92bool
93ua_location_position_update_has_vertical_accuracy(
94 UALocationPositionUpdate *update)
95{
96 return update->update.value.accuracy.vertical;
97}
98
99double
100ua_location_position_update_get_vertical_accuracy_in_meter(
101 UALocationPositionUpdate *update)
102{
103 return update->update.value.accuracy.vertical->value();
76}104}
77105
=== modified file 'src/ubuntu/application/common/application/location/ref_counted.h'
--- src/ubuntu/application/common/application/location/ref_counted.h 2013-08-19 06:47:19 +0000
+++ src/ubuntu/application/common/application/location/ref_counted.h 2014-06-26 20:03:03 +0000
@@ -32,7 +32,7 @@
32 bool operator==(const RefCounted&) const = delete;32 bool operator==(const RefCounted&) const = delete;
3333
34 void ref() { counter.fetch_add(1); }34 void ref() { counter.fetch_add(1); }
35 void unref() { if (0 == counter.fetch_sub(1)) { delete this; } }35 void unref() { if (1 == counter.fetch_sub(1)) { delete this; } }
3636
37 protected:37 protected:
38 RefCounted() : counter(1)38 RefCounted() : counter(1)
3939
=== modified file 'src/ubuntu/application/common/application/location/service.cpp'
--- src/ubuntu/application/common/application/location/service.cpp 2014-01-31 13:35:28 +0000
+++ src/ubuntu/application/common/application/location/service.cpp 2014-06-26 20:03:03 +0000
@@ -19,6 +19,7 @@
19#include "ubuntu/application/location/service.h"19#include "ubuntu/application/location/service.h"
2020
21#include "controller_p.h"21#include "controller_p.h"
22#include "instance.h"
22#include "session_p.h"23#include "session_p.h"
2324
24#include <com/ubuntu/location/service/stub.h>25#include <com/ubuntu/location/service/stub.h>
@@ -30,45 +31,6 @@
30namespace cul = com::ubuntu::location;31namespace cul = com::ubuntu::location;
31namespace culs = com::ubuntu::location::service;32namespace culs = com::ubuntu::location::service;
3233
33namespace
34{
35class Instance
36{
37 public:
38 static Instance& instance()
39 {
40 static Instance inst;
41 return inst;
42 }
43
44 const culs::Interface::Ptr& get_service() const
45 {
46 return service;
47 }
48
49 private:
50 Instance() : bus(std::make_shared<dbus::Bus>(dbus::WellKnownBus::system)),
51 executor(dbus::asio::make_executor(bus)),
52 service(dbus::resolve_service_on_bus<culs::Interface, culs::Stub>(bus))
53 {
54 bus->install_executor(executor);
55 worker = std::move(std::thread([&]() { bus->run(); }));
56 }
57
58 ~Instance() noexcept
59 {
60 if (worker.joinable())
61 worker.join();
62 }
63
64 dbus::Bus::Ptr bus;
65 dbus::Executor::Ptr executor;
66 culs::Interface::Ptr service;
67 std::thread worker;
68};
69
70}
71
72UALocationServiceSession*34UALocationServiceSession*
73ua_location_service_create_session_for_low_accuracy(35ua_location_service_create_session_for_low_accuracy(
74 UALocationServiceRequirementsFlags /*flags*/)36 UALocationServiceRequirementsFlags /*flags*/)
@@ -81,8 +43,21 @@
81ua_location_service_create_session_for_high_accuracy(43ua_location_service_create_session_for_high_accuracy(
82 UALocationServiceRequirementsFlags /*flags*/)44 UALocationServiceRequirementsFlags /*flags*/)
83{45{
84 return new UbuntuApplicationLocationServiceSession{46 try
85 Instance::instance().get_service()->create_session_for_criteria(cul::Criteria{})};47 {
48 return new UbuntuApplicationLocationServiceSession
49 {
50 Instance::instance().get_service()->create_session_for_criteria(cul::Criteria{})
51 };
52 } catch(const std::exception& e)
53 {
54 fprintf(stderr, "Error creating session for high accuracy: %s \n", e.what());
55 } catch(...)
56 {
57 fprintf(stderr, "Error creating session for high accuracy.\n");
58 }
59
60 return NULL;
86}61}
8762
88UALocationServiceController*63UALocationServiceController*
8964
=== modified file 'src/ubuntu/application/common/application/location/session.cpp'
--- src/ubuntu/application/common/application/location/session.cpp 2013-08-19 06:46:47 +0000
+++ src/ubuntu/application/common/application/location/session.cpp 2014-06-26 20:03:03 +0000
@@ -24,6 +24,8 @@
24#include "position_update_p.h"24#include "position_update_p.h"
25#include "velocity_update_p.h"25#include "velocity_update_p.h"
2626
27namespace location = com::ubuntu::location;
28
27void29void
28ua_location_service_session_ref(30ua_location_service_session_ref(
29 UALocationServiceSession *session)31 UALocationServiceSession *session)
@@ -47,12 +49,18 @@
47 void *context)49 void *context)
48{50{
49 auto s = static_cast<UbuntuApplicationLocationServiceSession*>(session);51 auto s = static_cast<UbuntuApplicationLocationServiceSession*>(session);
50 s->session->install_position_updates_handler(52 try
51 [handler, context](const com::ubuntu::location::Update<com::ubuntu::location::Position>& new_position)53 {
52 {54 std::lock_guard<std::mutex> lg(s->position_updates.guard);
53 UbuntuApplicationLocationPositionUpdate pu{new_position};55 s->position_updates.handler = handler;
54 handler(std::addressof(pu), context);56 s->position_updates.context = context;
55 });57 } catch(const std::exception& e)
58 {
59 fprintf(stderr, "Error setting up position updates handler: %s \n", e.what());
60 } catch(...)
61 {
62 fprintf(stderr, "Error setting up position updates handler.\n");
63 }
56}64}
5765
58void66void
@@ -62,12 +70,18 @@
62 void *context)70 void *context)
63{71{
64 auto s = static_cast<UbuntuApplicationLocationServiceSession*>(session);72 auto s = static_cast<UbuntuApplicationLocationServiceSession*>(session);
65 s->session->install_heading_updates_handler(73 try
66 [handler, context](const com::ubuntu::location::Update<com::ubuntu::location::Heading>& new_heading) 74 {
67 {75 std::lock_guard<std::mutex> lg(s->heading_updates.guard);
68 UbuntuApplicationLocationHeadingUpdate hu{new_heading};76 s->heading_updates.handler = handler;
69 handler(std::addressof(hu), context);77 s->heading_updates.context = context;
70 });78 } catch(const std::exception& e)
79 {
80 fprintf(stderr, "Error setting up heading updates handler: %s \n", e.what());
81 } catch(...)
82 {
83 fprintf(stderr, "Error setting up heading updates handler. \n");
84 }
71}85}
7286
73void87void
@@ -77,12 +91,18 @@
77 void *context)91 void *context)
78{92{
79 auto s = static_cast<UbuntuApplicationLocationServiceSession*>(session);93 auto s = static_cast<UbuntuApplicationLocationServiceSession*>(session);
80 s->session->install_velocity_updates_handler(94 try
81 [handler, context](const com::ubuntu::location::Update<com::ubuntu::location::Velocity>& new_velocity) 95 {
82 {96 std::lock_guard<std::mutex> lg(s->velocity_updates.guard);
83 UbuntuApplicationLocationVelocityUpdate vu{new_velocity};97 s->velocity_updates.handler = handler;
84 handler(std::addressof(vu), context);98 s->velocity_updates.context = context;
85 });99 } catch(const std::exception& e)
100 {
101 fprintf(stderr, "Error setting up velocity updates handler: %s \n", e.what());
102 } catch(...)
103 {
104 fprintf(stderr, "Error setting up velocity updates handler.");
105 }
86}106}
87107
88UStatus108UStatus
@@ -95,7 +115,8 @@
95115
96 try116 try
97 {117 {
98 s->session->start_position_updates();118 s->session->updates().position_status.set(
119 location::service::session::Interface::Updates::Status::enabled);
99 } catch(...)120 } catch(...)
100 {121 {
101 return U_STATUS_ERROR;122 return U_STATUS_ERROR;
@@ -114,7 +135,8 @@
114135
115 try136 try
116 {137 {
117 s->session->stop_position_updates();138 s->session->updates().position_status.set(
139 location::service::session::Interface::Updates::Status::disabled);
118 } catch(...)140 } catch(...)
119 {141 {
120 } 142 }
@@ -130,7 +152,8 @@
130152
131 try153 try
132 {154 {
133 s->session->start_heading_updates();155 s->session->updates().heading_status.set(
156 location::service::session::Interface::Updates::Status::enabled);
134 } catch(...)157 } catch(...)
135 {158 {
136 return U_STATUS_ERROR;159 return U_STATUS_ERROR;
@@ -149,7 +172,8 @@
149172
150 try173 try
151 {174 {
152 s->session->stop_heading_updates();175 s->session->updates().heading_status.set(
176 location::service::session::Interface::Updates::Status::disabled);
153 } catch(...)177 } catch(...)
154 {178 {
155 }179 }
@@ -165,7 +189,8 @@
165189
166 try190 try
167 {191 {
168 s->session->start_velocity_updates();192 s->session->updates().velocity_status.set(
193 location::service::session::Interface::Updates::Status::enabled);
169 } catch(...)194 } catch(...)
170 {195 {
171 return U_STATUS_ERROR;196 return U_STATUS_ERROR;
@@ -184,7 +209,8 @@
184209
185 try210 try
186 {211 {
187 s->session->stop_velocity_updates();212 s->session->updates().velocity_status.set(
213 location::service::session::Interface::Updates::Status::disabled);
188 } catch(...)214 } catch(...)
189 {215 {
190 }216 }
191217
=== modified file 'src/ubuntu/application/common/application/location/session_p.h'
--- src/ubuntu/application/common/application/location/session_p.h 2013-08-19 06:46:47 +0000
+++ src/ubuntu/application/common/application/location/session_p.h 2014-06-26 20:03:03 +0000
@@ -22,18 +22,114 @@
2222
23#include "ref_counted.h"23#include "ref_counted.h"
2424
25#include "heading_update_p.h"
26#include "position_update_p.h"
27#include "velocity_update_p.h"
28
25#include <com/ubuntu/location/service/session/interface.h>29#include <com/ubuntu/location/service/session/interface.h>
2630
31#include <mutex>
32
33namespace cul = com::ubuntu::location;
27namespace culss = com::ubuntu::location::service::session;34namespace culss = com::ubuntu::location::service::session;
2835
29struct UbuntuApplicationLocationServiceSession : public detail::RefCounted36struct UbuntuApplicationLocationServiceSession : public detail::RefCounted
30{37{
31 UbuntuApplicationLocationServiceSession(const culss::Interface::Ptr& session)38 UbuntuApplicationLocationServiceSession(const culss::Interface::Ptr& session)
32 : session(session)39 : session(session),
33 {40 connections
34 }41 {
35 42 session->updates().position.changed().connect(
43 [this](const cul::Update<cul::Position>& new_position)
44 {
45 try
46 {
47 std::lock_guard<std::mutex> lg(position_updates.guard);
48
49 UbuntuApplicationLocationPositionUpdate pu{new_position};
50 if (position_updates.handler) position_updates.handler(
51 std::addressof(pu),
52 position_updates.context);
53 } catch(...)
54 {
55 // We silently ignore the issue and keep going.
56 }
57 }),
58 session->updates().heading.changed().connect(
59 [this](const cul::Update<cul::Heading>& new_heading)
60 {
61 try
62 {
63 std::lock_guard<std::mutex> lg(heading_updates.guard);
64 UbuntuApplicationLocationHeadingUpdate hu{new_heading};
65 if (heading_updates.handler) heading_updates.handler(
66 std::addressof(hu),
67 heading_updates.context);
68 } catch(...)
69 {
70 // We silently ignore the issue and keep going.
71 }
72 }),
73 session->updates().velocity.changed().connect(
74 [this](const cul::Update<cul::Velocity>& new_velocity)
75 {
76 try
77 {
78 std::lock_guard<std::mutex> lg(velocity_updates.guard);
79
80 UbuntuApplicationLocationVelocityUpdate vu{new_velocity};
81 if (velocity_updates.handler) velocity_updates.handler(
82 std::addressof(vu),
83 velocity_updates.context);
84 } catch(...)
85 {
86 // We silently ignore the issue and keep going.
87 }
88 }),
89 }
90 {
91 }
92
93 ~UbuntuApplicationLocationServiceSession()
94 {
95 std::lock_guard<std::mutex> lgp(position_updates.guard);
96 std::lock_guard<std::mutex> lgh(heading_updates.guard);
97 std::lock_guard<std::mutex> lgv(velocity_updates.guard);
98
99 position_updates.handler = nullptr;
100 heading_updates.handler = nullptr;
101 velocity_updates.handler = nullptr;
102 }
103
36 culss::Interface::Ptr session;104 culss::Interface::Ptr session;
105
106 struct
107 {
108 std::mutex guard;
109 UALocationServiceSessionPositionUpdatesHandler handler{nullptr};
110 void* context{nullptr};
111 } position_updates{};
112
113 struct
114 {
115 std::mutex guard;
116 UALocationServiceSessionHeadingUpdatesHandler handler{nullptr};
117 void* context{nullptr};
118 } heading_updates{};
119
120 struct
121 {
122 std::mutex guard;
123 UALocationServiceSessionVelocityUpdatesHandler handler{nullptr};
124 void* context{nullptr};
125 } velocity_updates{};
126
127 struct
128 {
129 core::ScopedConnection position_updates;
130 core::ScopedConnection heading_updates;
131 core::ScopedConnection velocity_updates;
132 } connections;
37};133};
38134
39#endif // SESSION_PRIVATE_H_135#endif // SESSION_PRIVATE_H_
40136
=== modified file 'src/ubuntu/application/common/application/location/velocity_update.cpp'
--- src/ubuntu/application/common/application/location/velocity_update.cpp 2013-08-19 06:46:47 +0000
+++ src/ubuntu/application/common/application/location/velocity_update.cpp 2014-06-26 20:03:03 +0000
@@ -51,5 +51,5 @@
51ua_location_velocity_update_get_velocity_in_meters_per_second(51ua_location_velocity_update_get_velocity_in_meters_per_second(
52 UALocationVelocityUpdate *update)52 UALocationVelocityUpdate *update)
53{53{
54 return update->update.value.value.value();54 return update->update.value.value();
55}55}
5656
=== modified file 'src/ubuntu/application/ubuntu_application_api.cpp'
--- src/ubuntu/application/ubuntu_application_api.cpp 2014-06-16 13:42:24 +0000
+++ src/ubuntu/application/ubuntu_application_api.cpp 2014-06-26 20:03:03 +0000
@@ -214,6 +214,10 @@
214IMPLEMENT_FUNCTION1(double, ua_location_position_update_get_longitude_in_degree, UALocationPositionUpdate*);214IMPLEMENT_FUNCTION1(double, ua_location_position_update_get_longitude_in_degree, UALocationPositionUpdate*);
215IMPLEMENT_FUNCTION1(bool, ua_location_position_update_has_altitude, UALocationPositionUpdate*);215IMPLEMENT_FUNCTION1(bool, ua_location_position_update_has_altitude, UALocationPositionUpdate*);
216IMPLEMENT_FUNCTION1(double, ua_location_position_update_get_altitude_in_meter, UALocationPositionUpdate*);216IMPLEMENT_FUNCTION1(double, ua_location_position_update_get_altitude_in_meter, UALocationPositionUpdate*);
217IMPLEMENT_FUNCTION1(bool, ua_location_position_update_has_horizontal_accuracy, UALocationPositionUpdate*);
218IMPLEMENT_FUNCTION1(double, ua_location_position_update_get_horizontal_accuracy_in_meter, UALocationPositionUpdate*);
219IMPLEMENT_FUNCTION1(bool, ua_location_position_update_has_vertical_accuracy, UALocationPositionUpdate*);
220IMPLEMENT_FUNCTION1(double, ua_location_position_update_get_vertical_accuracy_in_meter, UALocationPositionUpdate*);
217IMPLEMENT_FUNCTION1(UALocationServiceSession*, ua_location_service_create_session_for_low_accuracy, UALocationServiceRequirementsFlags);221IMPLEMENT_FUNCTION1(UALocationServiceSession*, ua_location_service_create_session_for_low_accuracy, UALocationServiceRequirementsFlags);
218IMPLEMENT_FUNCTION1(UALocationServiceSession*, ua_location_service_create_session_for_high_accuracy, UALocationServiceRequirementsFlags);222IMPLEMENT_FUNCTION1(UALocationServiceSession*, ua_location_service_create_session_for_high_accuracy, UALocationServiceRequirementsFlags);
219IMPLEMENT_CTOR0(UALocationServiceController*, ua_location_service_create_controller);223IMPLEMENT_CTOR0(UALocationServiceController*, ua_location_service_create_controller);

Subscribers

People subscribed via source and target branches