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

« back to all changes in this revision

Viewing changes to src/location_service/com/ubuntu/location/service/harvester.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/service/harvester.h>
 
20
 
 
21
#include <com/ubuntu/location/logging.h>
 
22
 
 
23
namespace location = com::ubuntu::location;
 
24
 
 
25
location::service::Harvester::Harvester(const location::service::Harvester::Configuration& configuration)
 
26
    : config(configuration),
 
27
      is_running{false}
 
28
{
 
29
}
 
30
 
 
31
location::service::Harvester::~Harvester()
 
32
{
 
33
    stop();
 
34
}
 
35
 
 
36
/** @brief Report updated position to the harvester instance. */
 
37
void location::service::Harvester::report_position_update(const location::Update<location::Position>& update)
 
38
{
 
39
    VLOG(10) << "Reference location changed: " << update;
 
40
 
 
41
    if (not is_running.load())
 
42
        return;
 
43
 
 
44
    std::vector<location::connectivity::WirelessNetwork::Ptr> visible_wifis;
 
45
    config.connectivity_manager->enumerate_visible_wireless_networks([&visible_wifis](location::connectivity::WirelessNetwork::Ptr wifi)
 
46
    {
 
47
        VLOG(10) << "Got a visible wifi: " << *wifi << std::endl;
 
48
        visible_wifis.push_back(wifi);
 
49
    });
 
50
 
 
51
    std::vector<location::connectivity::RadioCell::Ptr> connected_cells;
 
52
    config.connectivity_manager->enumerate_connected_radio_cells([&connected_cells](location::connectivity::RadioCell::Ptr cell)
 
53
    {
 
54
        VLOG(10) << "Got a cell: " << *cell << std::endl;
 
55
        connected_cells.push_back(cell);
 
56
    });
 
57
 
 
58
    config.reporter->report(update, visible_wifis, connected_cells);
 
59
}
 
60
 
 
61
void location::service::Harvester::start()
 
62
{
 
63
    if (is_running.load())
 
64
        return;
 
65
 
 
66
    is_running.exchange(true);
 
67
 
 
68
    config.reporter->start();
 
69
}
 
70
 
 
71
void location::service::Harvester::stop()
 
72
{
 
73
    if (not is_running.load())
 
74
        return;
 
75
 
 
76
    is_running.exchange(false);
 
77
 
 
78
    config.reporter->stop();
 
79
}