2
* Copyright © 2012-2013 Canonical Ltd.
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.
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.
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/>.
16
* Authored by: Thomas Voß <thomas.voss@canonical.com>
18
#ifndef LOCATION_SERVICE_COM_UBUNTU_LOCATION_SERVICE_HARVESTER_H_
19
#define LOCATION_SERVICE_COM_UBUNTU_LOCATION_SERVICE_HARVESTER_H_
21
#include <com/ubuntu/location/engine.h>
22
#include <com/ubuntu/location/connectivity/manager.h>
24
#include <com/ubuntu/location/logging.h>
36
/** @brief Models a wifi- and cell-id harvester for crowd-sourcing purposes. */
41
/** @brief Models a reporter of position updates, augmented with wifi and cell ids. */
45
typedef std::shared_ptr<Reporter> Ptr;
48
virtual ~Reporter() = default;
51
/** @brief Tell the reporter that it should start operating. */
52
virtual void start() = 0;
54
/** @brief Tell the reporter to shut down its operation. */
55
virtual void stop() = 0;
58
* @brief Triggers the reporter to send off the information.
60
virtual void report(const Update<Position>& update,
61
const std::vector<connectivity::WirelessNetwork::Ptr>& wifis,
62
const std::vector<connectivity::RadioCell>& cells) = 0;
65
/** @brief Configuration encapsulates all creation time options of class Harvester */
68
/** The position engine that the harvester should use. */
69
std::shared_ptr<Engine> engine;
70
/** The connectivity manager that the harvester should use. */
71
std::shared_ptr<connectivity::Manager> connectivity_manager;
72
/** The reporter implementation */
73
std::shared_ptr<Reporter> reporter;
76
/** @brief Creates a new instance and wires up to system components for receiving
77
* location updates, and wifi and cell id measurements.
79
Harvester(const Configuration& configuration)
80
: config(configuration),
83
config.engine->updates.reference_location.changed().connect([this](const Update<Position>& update)
85
VLOG(10) << "Reference location changed: " << update;
87
if (not is_running.load())
90
auto visible_wifis = config.connectivity_manager->visible_wireless_networks().get();
91
auto connected_cells = config.connectivity_manager->connected_radio_cells().get();
93
config.reporter->report(update, visible_wifis, connected_cells);
104
if (is_running.load())
107
is_running.exchange(true);
109
config.reporter->start();
114
if (not is_running.load())
117
is_running.exchange(false);
119
config.reporter->stop();
123
Configuration config;
124
std::atomic<bool> is_running;
131
#endif // LOCATION_SERVICE_COM_UBUNTU_LOCATION_SERVICE_HARVESTER_H_