~thomas-voss/location-service/fix-1347887

« back to all changes in this revision

Viewing changes to src/location_service/com/ubuntu/location/providers/geoclue/provider.cpp

This MP consolidates multiple related changes together, with the goal of:

(1.) Make the service instance accessible via a cli. Useful for testing scenarios.
(2.) To cut down time-to-first-fix (ttff) by:
  (2.1) Leveraging SUPL and other supplementary data downloaded over ordinary data connections.
  (2.2) Enabling network-based positioning providers to acquire fast position estimates.

In more detail:

* Added tests for daemon and cli.
* Unified daemon and cli header and implementation files.
* Add a command-line interface to the service.
* Split up provider selection policy to rely on an interface ProviderEnumerator to ease in testing.
* Trimmed down on types.
* Removed connectivity API draft to prepare for simpler approach.
* Refactored includes.
* Added a configuration option to handle cell and wifi ID reporting.
* Add a mock for a connectivity API exposed to providers and reporters.
* Add units for connectivity api.
* Refactor cell class into namespace radio. Fixes: 1226204, 1248973, 1281817

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 *
16
16
 * Authored by: Thomas Voß <thomas.voss@canonical.com>
17
17
 */
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>
 
19
 
 
20
#include <com/ubuntu/location/providers/geoclue/geoclue.h>
 
21
 
 
22
#include <core/dbus/object.h>
 
23
#include <core/dbus/signal.h>
20
24
 
21
25
#include "core/dbus/object.h"
22
26
#include "core/dbus/signal.h"
39
43
 
40
44
struct culpg::Provider::Private
41
45
{
 
46
    typedef dbus::Signal<
 
47
        org::freedesktop::Geoclue::Position::Signals::PositionChanged,
 
48
        org::freedesktop::Geoclue::Position::Signals::PositionChanged::ArgumentType
 
49
    > PositionChanged;
 
50
 
 
51
    typedef dbus::Signal<
 
52
        org::freedesktop::Geoclue::Velocity::Signals::VelocityChanged,
 
53
        org::freedesktop::Geoclue::Velocity::Signals::VelocityChanged::ArgumentType
 
54
    > VelocityChanged;
 
55
 
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;
67
 
    dbus::Signal<
68
 
        org::freedesktop::Geoclue::Position::Signals::PositionChanged, 
69
 
        org::freedesktop::Geoclue::Position::Signals::PositionChanged::ArgumentType
70
 
        >::Ptr signal_position_changed;
71
 
    dbus::Signal<
72
 
        org::freedesktop::Geoclue::Velocity::Signals::VelocityChanged, 
73
 
        org::freedesktop::Geoclue::Velocity::Signals::VelocityChanged::ArgumentType
74
 
        >::Ptr signal_velocity_changed;
75
 
 
76
 
    typedef typename dbus::Signal<
77
 
        org::freedesktop::Geoclue::Position::Signals::PositionChanged,
78
 
        org::freedesktop::Geoclue::Position::Signals::PositionChanged::ArgumentType
79
 
    >::SubscriptionToken SignalPositionChangedSubscription;
80
 
 
81
 
    typedef typename dbus::Signal<
82
 
        org::freedesktop::Geoclue::Velocity::Signals::VelocityChanged,
83
 
        org::freedesktop::Geoclue::Velocity::Signals::VelocityChanged::ArgumentType
84
 
    >::SubscriptionToken SignalVelocityChangedSubscription;
85
 
 
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;
88
85
 
89
86
    std::thread worker;
90
87
};
97
94
    return cul::Provider::Ptr{new culpg::Provider{pConfig}};
98
95
}
99
96
 
100
 
const cul::Provider::FeatureFlags& culpg::Provider::default_feature_flags()
101
 
{
102
 
    static const cul::Provider::FeatureFlags flags{"001"};
103
 
    return flags;
104
 
}
105
 
 
106
 
const cul::Provider::RequirementFlags& culpg::Provider::default_requirement_flags()
107
 
{
108
 
    static const cul::Provider::RequirementFlags flags{"1010"};
109
 
    return flags;
110
 
}
111
 
 
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)
119
104
                {
120
105
                    org::freedesktop::Geoclue::Position::FieldFlags flags{static_cast<unsigned long>(std::get<0>(arg))};
121
 
                    cul::Update<cul::Position> update
 
106
                    cul::Position pos
122
107
                    {
123
 
                        {
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{}
130
 
                        },
131
 
                        cul::Clock::now()
 
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{}
132
112
                    };
133
 
                    this->deliver_position_updates(update);
 
113
 
 
114
                    if (flags.test(org::freedesktop::Geoclue::Position::Field::altitude))
 
115
                        pos.altitude = cul::wgs84::Altitude{std::get<4>(arg)* cul::units::Meters};
 
116
 
 
117
                    cul::Update<cul::Position> update(pos);
 
118
                    this->mutable_updates().position(update);
134
119
                });
135
120
 
136
121
    d->velocity_updates_connection = 
147
132
                            std::get<2>(arg) * cul::units::MetersPerSecond,
148
133
                            cul::Clock::now()
149
134
                        };
150
 
                        this->deliver_velocity_updates(update);
 
135
                        this->mutable_updates().velocity(update);
151
136
                    }
152
137
 
153
138
                    if (flags.test(org::freedesktop::Geoclue::Velocity::Field::direction))
158
143
                            cul::Clock::now()
159
144
                        };
160
145
                            
161
 
                        this->deliver_heading_updates(update);
 
146
                        this->mutable_updates().heading(update);
162
147
                    }
163
148
                });
164
149