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

« back to all changes in this revision

Viewing changes to include/location_service/com/ubuntu/location/velocity.h

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:
18
18
#ifndef LOCATION_SERVICE_COM_UBUNTU_LOCATION_VELOCITY_H_
19
19
#define LOCATION_SERVICE_COM_UBUNTU_LOCATION_VELOCITY_H_
20
20
 
21
 
#include "com/ubuntu/location/accuracy.h"
22
 
#include "com/ubuntu/location/units/units.h"
23
 
 
24
 
#include <limits>
25
 
#include <ostream>
26
 
#include <stdexcept>
 
21
#include <com/ubuntu/location/units/units.h>
27
22
 
28
23
namespace com
29
24
{
31
26
{
32
27
namespace location
33
28
{
34
 
struct Velocity
35
 
{
36
 
    typedef units::Velocity Unit;
37
 
    typedef units::Quantity<Unit> Quantity;
38
 
 
39
 
    static inline const Quantity& min()
40
 
    {
41
 
        static const Quantity instance = Quantity::from_value(0.);
42
 
        return instance;
43
 
    }
44
 
 
45
 
    static inline const Quantity max()
46
 
    {
47
 
        static const Quantity instance = Quantity::from_value(std::numeric_limits<double>::max());
48
 
        return instance;
49
 
    }
50
 
 
51
 
    Velocity(const Quantity& value = Quantity()) : value(value)
52
 
    {
53
 
        if (value < Velocity::min())
54
 
            throw std::out_of_range("");
55
 
        if (value > Velocity::max())
56
 
            throw std::out_of_range("");
57
 
    }
58
 
 
59
 
    inline bool operator==(const Velocity& rhs) const
60
 
    {
61
 
        return value == rhs.value;
62
 
    }
63
 
 
64
 
    inline bool operator!=(const Velocity& rhs) const
65
 
    {
66
 
        return value != rhs.value;
67
 
    }
68
 
 
69
 
    Quantity value;
70
 
};
71
 
 
72
 
inline std::ostream& operator<<(std::ostream& out, const Velocity& velocity)
73
 
{
74
 
    out << "Velocity(" << velocity.value << ")";
75
 
    return out;
76
 
}
77
 
 
78
 
template<>
79
 
struct AccuracyTraits<Velocity>
80
 
{
81
 
    static AccuracyLevel classify(const Velocity& h)
82
 
    {
83
 
        if (h.value > (1.f * units::MetersPerSecond))
84
 
            return AccuracyLevel::worst;
85
 
        
86
 
        if (h.value <= (1.f * units::MetersPerSecond))
87
 
            return AccuracyLevel::best;
88
 
 
89
 
        return AccuracyLevel::worst;
90
 
    }
91
 
 
92
 
    static Accuracy<Velocity> best()
93
 
    {
94
 
        return Accuracy<Velocity>{Velocity{Velocity::min()}};
95
 
    }
96
 
 
97
 
    static Accuracy<Velocity> worst()
98
 
    {
99
 
        return Accuracy<Velocity>{Velocity{2*units::MetersPerSecond}};
100
 
    }
101
 
};
 
29
/** @brief Velocity is measured in m/s. */
 
30
typedef units::Quantity<units::Velocity> Velocity;
102
31
}
103
32
}
104
33
}