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

« back to all changes in this revision

Viewing changes to include/location_service/com/ubuntu/location/heading.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_HEADING_H_
19
19
#define LOCATION_SERVICE_COM_UBUNTU_LOCATION_HEADING_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 Heading
35
 
{
36
 
    typedef units::PlaneAngle Unit;
37
 
    typedef units::Quantity<Unit> Quantity;
38
 
 
39
 
    static const Quantity& min()
40
 
    {
41
 
        static const auto instance = Heading::Quantity::from_value(0.);
42
 
        return instance;
43
 
    }
44
 
    static const Quantity& max()
45
 
    {
46
 
        static const auto instance = Heading::Quantity::from_value(360.);
47
 
        return instance;
48
 
    }
49
 
 
50
 
    Heading(const Quantity& value = Quantity()) : value(value)
51
 
    {
52
 
        if (value < min())
53
 
            throw std::out_of_range("");
54
 
        if (value > max())
55
 
            throw std::out_of_range("");
56
 
    }
57
 
 
58
 
    bool operator==(const Heading& rhs) const
59
 
    {
60
 
        return value == rhs.value;
61
 
    }
62
 
 
63
 
    bool operator!=(const Heading& rhs) const
64
 
    {
65
 
        return value != rhs.value;
66
 
    }
67
 
 
68
 
    Quantity value;
69
 
};
70
 
 
71
 
inline std::ostream& operator<<(std::ostream& out, const Heading& heading)
72
 
{
73
 
    out << "Heading(" << heading.value << ")";
74
 
    return out;
75
 
}
76
 
 
77
 
template<>
78
 
struct AccuracyTraits<Heading>
79
 
{
80
 
    static AccuracyLevel classify(const Heading& h)
81
 
    {
82
 
        static const auto half = 0.5 * Heading::max();
83
 
        if(h.value > half)
84
 
            return AccuracyLevel::worst;
85
 
 
86
 
        if(h.value < half)
87
 
            return AccuracyLevel::best;
88
 
 
89
 
        return AccuracyLevel::worst;
90
 
    }
91
 
 
92
 
    static Accuracy<Heading> best()
93
 
    {
94
 
        return Accuracy<Heading>{Heading{Heading::min()}};
95
 
    }
96
 
 
97
 
    static Accuracy<Heading> worst()
98
 
    {
99
 
        return Accuracy<Heading>{Heading{Heading::max()}};
100
 
    }
101
 
};
 
29
/** Heading is measured in ° deviation from true north. */
 
30
typedef units::Quantity<units::PlaneAngle> Heading;
102
31
}
103
32
}
104
33
}