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_ICHNAEA_REPORTER_H_
19
#define LOCATION_SERVICE_COM_UBUNTU_LOCATION_SERVICE_ICHNAEA_REPORTER_H_
21
#include <com/ubuntu/location/service/harvester.h>
23
#include <core/net/http/client.h>
24
#include <core/net/http/content_type.h>
25
#include <core/net/http/request.h>
26
#include <core/net/http/response.h>
27
#include <core/net/http/status.h>
29
#include <json/json.h>
33
namespace json = Json;
35
namespace com{namespace ubuntu{namespace location{namespace service
38
* @brief All types and functions that are used to communicate with instances
39
* of the Mozilla location service go here. Please see for further details:
41
* - https://mozilla-ichnaea.readthedocs.org/en/latest/api/index.html#submit
42
* - https://github.com/mozilla/MozStumbler
48
/** @brief Resource path for wifi- and cell-id submissions. */
49
constexpr const char* resource
53
/** @brief Http code marking errors for Mozilla location service instances. */
54
const core::net::http::Status error
56
core::net::http::Status::bad_request
58
/** @brief Http code marking a successful submission request to Mozilla location service instances. */
59
const core::net::http::Status success
61
core::net::http::Status::no_content
65
struct Reporter : public Harvester::Reporter
67
/** @brief Submissions can be tagged with a nick-name for tracking on leaderboards. */
68
static constexpr const char* nick_name_header{"X-Nickname"};
70
/** @brief The JSON-dialect of the Mozilla location service is described here. */
73
static constexpr const char* radio{"radio"};
74
static constexpr const char* lat{"lat"};
75
static constexpr const char* lon{"lon"};
76
static constexpr const char* accuracy{"accuracy"};
77
static constexpr const char* altitude{"altitude"};
78
static constexpr const char* altitude_accuracy{"altitude_accuracy"};
80
static constexpr const char* items{"items"};
82
static constexpr const char* cell{"cell"};
83
static constexpr const char* wifi{"wifi"};
87
static constexpr const char* radio{"radio"};
88
static constexpr const char* mcc{"mcc"};
89
static constexpr const char* mnc{"mnc"};
90
static constexpr const char* lac{"lac"};
91
static constexpr const char* cid{"cid"};
92
static constexpr const char* psc{"psc"};
93
static constexpr const char* asu{"asu"};
98
static constexpr const char* channel{"channel"};
99
static constexpr const char* frequency{"frequency"};
100
static constexpr const char* key{"key"};
101
static constexpr const char* signal{"signal"};
105
/** Creation-time options for the ICHNAEA reporter */
108
/** Uri of the ICHNAEA instance we want to submit to. */
110
/** API key for the submission */
112
/** Nickname for the submission */
113
std::string nick_name;
116
/** @brief Constructs a new instance with the given parameters. */
117
Reporter(const Configuration& configuration);
118
/** @brief Stops the reporter instance and frees all related resources. */
121
/** @brief Starts the reporter and prepares for submission. */
122
void start() override;
123
/** @brief Stops the reporter. */
124
void stop() override;
127
* @brief Announced a position update, together with visible wifis and cells to the reporter.
128
* @throws std::runtime_error if wifis and cells are empty.
131
const Update<Position>& update,
132
const std::vector<connectivity::WirelessNetwork::Ptr>& wifis,
133
const std::vector<connectivity::RadioCell::Ptr>& cells) override;
135
/** @brief Encodes a collection of wifis into the Mozilla loation service JSON dialect. */
136
static void convert_wifis_to_json(
137
const std::vector<connectivity::WirelessNetwork::Ptr>& wifis,
138
json::Value& destination);
140
/** @brief Encodes a collection of radio cells into the Mozilla loation service JSON dialect. */
141
static void convert_cells_to_json(
142
const std::vector<connectivity::RadioCell::Ptr>& cells,
143
json::Value& destination);
145
/** @brief The http request configuration for submissions to the mozilla location service. */
146
core::net::http::Request::Configuration submit_request_config;
147
/** @brief The http client instance used to talk to Mozilla location service instances. */
148
std::shared_ptr<core::net::http::Client> http_client;
149
/** @brief Worker thread for dispatching the http client instance. */
150
std::thread http_client_worker;
155
#endif // LOCATION_SERVICE_COM_UBUNTU_LOCATION_SERVICE_ICHNAEA_REPORTER_H_