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

« back to all changes in this revision

Viewing changes to src/location_service/com/ubuntu/location/connectivity/radio_cell.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:
 
1
/*
 
2
 * Copyright © 2012-2013 Canonical Ltd.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it
 
5
 * under the terms of the GNU Lesser General Public License version 3,
 
6
 * as 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
#include <com/ubuntu/location/connectivity/radio_cell.h>
 
20
 
 
21
namespace location = com::ubuntu::location;
 
22
 
 
23
bool location::connectivity::operator==(const location::connectivity::RadioCell::Gsm& lhs,
 
24
                                        const location::connectivity::RadioCell::Gsm& rhs)
 
25
{
 
26
    return lhs.mobile_country_code == rhs.mobile_country_code &&
 
27
           lhs.mobile_network_code == rhs.mobile_network_code &&
 
28
           lhs.location_area_code == rhs.location_area_code &&
 
29
           lhs.id == rhs.id &&
 
30
           lhs.strength == rhs.strength;
 
31
}
 
32
 
 
33
std::ostream& location::connectivity::operator<<(std::ostream& out, const location::connectivity::RadioCell::Gsm& gsm)
 
34
{
 
35
    out << "("
 
36
        << "mcc: " << gsm.mobile_country_code << ", "
 
37
        << "mnc: " << gsm.mobile_network_code << ", "
 
38
        << "lac: " << gsm.location_area_code << ", "
 
39
        << "id: " << gsm.id << ", "
 
40
        << "asu: " << gsm.strength << ")";
 
41
 
 
42
    return out;
 
43
}
 
44
 
 
45
bool location::connectivity::operator==(const location::connectivity::RadioCell::Umts& lhs, const location::connectivity::RadioCell::Umts& rhs)
 
46
{
 
47
    return lhs.mobile_country_code == rhs.mobile_country_code &&
 
48
            lhs.mobile_network_code == rhs.mobile_network_code &&
 
49
            lhs.location_area_code == rhs.location_area_code &&
 
50
            lhs.id == rhs.id &&
 
51
            lhs.strength == rhs.strength;
 
52
}
 
53
 
 
54
std::ostream& location::connectivity::operator<<(std::ostream& out, const location::connectivity::RadioCell::Umts& umts)
 
55
{
 
56
    out << "("
 
57
        << "mcc: " << umts.mobile_country_code << ", "
 
58
        << "mnc: " << umts.mobile_network_code << ", "
 
59
        << "lac: " << umts.location_area_code << ", "
 
60
        << "id: " << umts.id << ", "
 
61
        << "asu: " << umts.strength << ")";
 
62
 
 
63
    return out;
 
64
}
 
65
 
 
66
bool location::connectivity::operator==(const location::connectivity::RadioCell::Lte& lhs,
 
67
                                        const location::connectivity::RadioCell::Lte& rhs)
 
68
{
 
69
    return lhs.mobile_country_code == rhs.mobile_country_code &&
 
70
            lhs.mobile_network_code == rhs.mobile_network_code &&
 
71
            lhs.tracking_area_code == rhs.tracking_area_code &&
 
72
            lhs.id == rhs.id &&
 
73
            lhs.physical_id == rhs.physical_id &&
 
74
            lhs.strength == rhs.strength;
 
75
}
 
76
 
 
77
std::ostream& location::connectivity::operator<<(std::ostream& out, const location::connectivity::RadioCell::Lte& lte)
 
78
{
 
79
    out << "("
 
80
        << "mcc: " << lte.mobile_country_code << ", "
 
81
        << "mnc: " << lte.mobile_network_code << ", "
 
82
        << "lac: " << lte.tracking_area_code << ", "
 
83
        << "id: " << lte.id << ", "
 
84
        << "id: " << lte.physical_id << ", "
 
85
        << "asu: " << lte.strength << ")";
 
86
 
 
87
    return out;
 
88
}
 
89
 
 
90
bool location::connectivity::operator==(const location::connectivity::RadioCell& lhs,
 
91
                                        const location::connectivity::RadioCell& rhs)
 
92
{
 
93
    if (lhs.type() != rhs.type())
 
94
        return false;
 
95
 
 
96
    switch(lhs.type())
 
97
    {
 
98
    case location::connectivity::RadioCell::Type::gsm: return lhs.gsm() == rhs.gsm();
 
99
    case location::connectivity::RadioCell::Type::umts: return lhs.umts() == rhs.umts();
 
100
    case location::connectivity::RadioCell::Type::lte: return lhs.lte() == rhs.lte();
 
101
    default: return true;
 
102
    }
 
103
 
 
104
    return false;
 
105
}
 
106
 
 
107
std::ostream& location::connectivity::operator<<(std::ostream& out, const location::connectivity::RadioCell& cell)
 
108
{
 
109
    switch (cell.type())
 
110
    {
 
111
    case location::connectivity::RadioCell::Type::gsm: out << "gsm" << cell.gsm(); break;
 
112
    case location::connectivity::RadioCell::Type::umts: out << "umts" << cell.umts(); break;
 
113
    case location::connectivity::RadioCell::Type::lte: out << "lte" << cell.lte(); break;
 
114
    case location::connectivity::RadioCell::Type::unknown: break;
 
115
    }
 
116
 
 
117
    return out;
 
118
}