16
16
* Authored by: Thomas Voß <thomas.voss@canonical.com>
18
#include "com/ubuntu/location/providers/geoclue/provider.h"
19
#include "com/ubuntu/location/providers/geoclue/geoclue.h"
18
#include <com/ubuntu/location/providers/geoclue/provider.h>
20
#include <com/ubuntu/location/providers/geoclue/geoclue.h>
22
#include <core/dbus/object.h>
23
#include <core/dbus/signal.h>
21
25
#include "core/dbus/object.h"
22
26
#include "core/dbus/signal.h"
40
44
struct culpg::Provider::Private
47
org::freedesktop::Geoclue::Position::Signals::PositionChanged,
48
org::freedesktop::Geoclue::Position::Signals::PositionChanged::ArgumentType
52
org::freedesktop::Geoclue::Velocity::Signals::VelocityChanged,
53
org::freedesktop::Geoclue::Velocity::Signals::VelocityChanged::ArgumentType
42
56
Private(const culpg::Provider::Configuration& config)
43
57
: bus(the_session_bus()),
44
58
service(dbus::Service::use_service(bus, config.name)),
64
78
dbus::Bus::Ptr bus;
65
79
dbus::Service::Ptr service;
66
80
dbus::Object::Ptr object;
68
org::freedesktop::Geoclue::Position::Signals::PositionChanged,
69
org::freedesktop::Geoclue::Position::Signals::PositionChanged::ArgumentType
70
>::Ptr signal_position_changed;
72
org::freedesktop::Geoclue::Velocity::Signals::VelocityChanged,
73
org::freedesktop::Geoclue::Velocity::Signals::VelocityChanged::ArgumentType
74
>::Ptr signal_velocity_changed;
76
typedef typename dbus::Signal<
77
org::freedesktop::Geoclue::Position::Signals::PositionChanged,
78
org::freedesktop::Geoclue::Position::Signals::PositionChanged::ArgumentType
79
>::SubscriptionToken SignalPositionChangedSubscription;
81
typedef typename dbus::Signal<
82
org::freedesktop::Geoclue::Velocity::Signals::VelocityChanged,
83
org::freedesktop::Geoclue::Velocity::Signals::VelocityChanged::ArgumentType
84
>::SubscriptionToken SignalVelocityChangedSubscription;
86
SignalPositionChangedSubscription position_updates_connection;
87
SignalVelocityChangedSubscription velocity_updates_connection;
81
PositionChanged::Ptr signal_position_changed;
82
VelocityChanged::Ptr signal_velocity_changed;
83
PositionChanged::SubscriptionToken position_updates_connection;
84
VelocityChanged::SubscriptionToken velocity_updates_connection;
89
86
std::thread worker;
97
94
return cul::Provider::Ptr{new culpg::Provider{pConfig}};
100
const cul::Provider::FeatureFlags& culpg::Provider::default_feature_flags()
102
static const cul::Provider::FeatureFlags flags{"001"};
106
const cul::Provider::RequirementFlags& culpg::Provider::default_requirement_flags()
108
static const cul::Provider::RequirementFlags flags{"1010"};
112
97
culpg::Provider::Provider(const culpg::Provider::Configuration& config)
113
98
: com::ubuntu::location::Provider(config.features, config.requirements),
114
99
d(new Private(config))
118
103
[this](const org::freedesktop::Geoclue::Position::Signals::PositionChanged::ArgumentType& arg)
120
105
org::freedesktop::Geoclue::Position::FieldFlags flags{static_cast<unsigned long>(std::get<0>(arg))};
121
cul::Update<cul::Position> update
124
flags.test(org::freedesktop::Geoclue::Position::Field::latitude) ?
125
cul::wgs84::Latitude{std::get<2>(arg)* cul::units::Degrees} : cul::wgs84::Latitude{},
126
flags.test(org::freedesktop::Geoclue::Position::Field::longitude) ?
127
cul::wgs84::Longitude{std::get<3>(arg)* cul::units::Degrees} : cul::wgs84::Longitude{},
128
flags.test(org::freedesktop::Geoclue::Position::Field::altitude) ?
129
cul::wgs84::Altitude{std::get<4>(arg)* cul::units::Meters} : cul::wgs84::Altitude{}
108
flags.test(org::freedesktop::Geoclue::Position::Field::latitude) ?
109
cul::wgs84::Latitude{std::get<2>(arg)* cul::units::Degrees} : cul::wgs84::Latitude{},
110
flags.test(org::freedesktop::Geoclue::Position::Field::longitude) ?
111
cul::wgs84::Longitude{std::get<3>(arg)* cul::units::Degrees} : cul::wgs84::Longitude{}
133
this->deliver_position_updates(update);
114
if (flags.test(org::freedesktop::Geoclue::Position::Field::altitude))
115
pos.altitude = cul::wgs84::Altitude{std::get<4>(arg)* cul::units::Meters};
117
cul::Update<cul::Position> update(pos);
118
this->mutable_updates().position(update);
136
121
d->velocity_updates_connection =
147
132
std::get<2>(arg) * cul::units::MetersPerSecond,
148
133
cul::Clock::now()
150
this->deliver_velocity_updates(update);
135
this->mutable_updates().velocity(update);
153
138
if (flags.test(org::freedesktop::Geoclue::Velocity::Field::direction))