=== modified file 'debian/ubuntu-location-service-examples.install'
--- debian/ubuntu-location-service-examples.install 2014-05-20 09:45:02 +0000
+++ debian/ubuntu-location-service-examples.install 2016-05-25 21:01:56 +0000
@@ -1,3 +1,4 @@
+usr/lib/*/ubuntu-location-service/examples/connectivity
usr/lib/*/ubuntu-location-service/examples/client
usr/lib/*/ubuntu-location-service/examples/service
usr/share/ubuntu-location-service
=== modified file 'examples/CMakeLists.txt'
--- examples/CMakeLists.txt 2014-05-20 09:45:02 +0000
+++ examples/CMakeLists.txt 2016-05-25 21:01:56 +0000
@@ -1,5 +1,6 @@
add_subdirectory(service)
+add_subdirectory(connectivity)
install(
DIRECTORY standalone
- DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${CMAKE_PROJECT_NAME}/examples)
\ No newline at end of file
+ DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${CMAKE_PROJECT_NAME}/examples)
=== added directory 'examples/connectivity'
=== added file 'examples/connectivity/CMakeLists.txt'
--- examples/connectivity/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ examples/connectivity/CMakeLists.txt 2016-05-25 21:01:56 +0000
@@ -0,0 +1,7 @@
+add_executable(connectivity connectivity.cpp)
+target_link_libraries(connectivity ubuntu-location-service ubuntu-location-service-connectivity)
+
+install(
+ TARGETS connectivity
+ DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/examples/
+)
=== added file 'examples/connectivity/connectivity.cpp'
--- examples/connectivity/connectivity.cpp 1970-01-01 00:00:00 +0000
+++ examples/connectivity/connectivity.cpp 2016-05-25 21:01:56 +0000
@@ -0,0 +1,188 @@
+/*
+ * Copyright © 2016 Canonical Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ *
+ * Authored by: Thomas Voß
+ */
+
+#include
+#include
+
+#include
+#include
+
+#include
+
+namespace connectivity = com::ubuntu::location::connectivity;
+namespace ichnaea = com::ubuntu::location::service::ichnaea;
+namespace http = core::net::http;
+
+namespace com { namespace ubuntu { namespace location { namespace service { namespace ichnaea
+{
+class Client
+{
+public:
+ Client()
+ : client{http::make_client()},
+ worker{[this]() { client->run(); }},
+ request_config(http::Request::Configuration::from_uri_as_string("https://location.services.mozilla.com/v1/geolocate?key=test"))
+ {
+ request_config.ssl.verify_host = request_config.ssl.verify_peer = false;
+ }
+
+ ~Client()
+ {
+ client->stop();
+ if (worker.joinable()) worker.join();
+ }
+
+ void geolocate(const std::vector& wifis, const std::vector& cells)
+ {
+ json::Object object = json::Object::create_object();
+
+ // Explicitly disable fallback methods to make sure that
+ // we are getting clear errors for the manual example and help with
+ // tracking down bugs.
+ json::Object fallbacks = json::Object::create_object();
+ fallbacks.put_boolean("lacf", false);
+ fallbacks.put_boolean("ipf", false);
+
+ json::Object cell_towers = json::Object::create_array();
+ json::Object wifi_access_points = json::Object::create_array();
+
+ ichnaea::Reporter::convert_cells_to_json(cells, cell_towers);
+ ichnaea::Reporter::convert_wifis_to_json(wifis, wifi_access_points);
+
+ object.put_array("cellTowers", cell_towers);
+ object.put_array("wifiAccessPoints", wifi_access_points);
+ object.put_object("fallbacks", fallbacks);
+
+ auto request = client->post(request_config, object.to_plain_string(), http::ContentType::json);
+ auto response = request->execute([](const http::Request::Progress& progress)
+ {
+ return http::Request::Progress::Next::continue_operation;
+ });
+
+ auto result = json::Object::parse_from_string(response.body);
+ auto location = result.get("location");
+ auto accuracy = result.get("accuracy");
+
+ std::cout << "Query for position estimate succeeded: " << std::endl
+ << " lat: " << location.get("lat").to_double() << std::endl
+ << " lng: " << location.get("lng").to_double() << std::endl
+ << " accuracy: " << accuracy.to_double() << std::endl;
+ }
+
+private:
+ std::shared_ptr client;
+ std::thread worker;
+ http::Request::Configuration request_config;
+};
+}}}}}
+
+// Sampler periodically requests scans for wireless networks.
+class Sampler
+{
+public:
+ // Sampler initializes a new instance with the given manager instance.
+ Sampler(const std::shared_ptr& manager)
+ : manager{manager},
+ running{true},
+ worker{[this]()
+ {
+ while (running)
+ {
+ Sampler::manager->request_scan_for_wireless_networks();
+ std::this_thread::sleep_for(std::chrono::seconds{15});
+ }
+ }}
+ {
+ }
+
+ ~Sampler()
+ {
+ running = false;
+ if (worker.joinable()) worker.join();
+ }
+
+private:
+ std::shared_ptr manager;
+ bool running;
+ std::thread worker;
+};
+
+int main(int, char)
+{
+ auto trap = core::posix::trap_signals_for_all_subsequent_threads({core::posix::Signal::sig_term});
+ trap->signal_raised().connect([trap](core::posix::Signal) { trap->stop(); });
+
+ auto client = std::make_shared();
+ auto manager = connectivity::platform_default_manager();
+ auto sampler = std::make_shared(manager);
+
+ manager->state().changed().connect([](connectivity::State state)
+ {
+ std::cout << "State changed: " << state << std::endl;
+ });
+
+ manager->is_wifi_enabled().changed().connect([](bool b)
+ {
+ std::cout << "is_wifi_enabled changed: " << std::boolalpha << b << std::endl;
+ });
+
+ manager->is_wifi_hardware_enabled().changed().connect([](bool b)
+ {
+ std::cout << "is_wifi_hardware_enabled changed: " << std::boolalpha << b << std::endl;
+ });
+
+ manager->is_wwan_enabled().changed().connect([](bool b)
+ {
+ std::cout << "is_wwan_enabled changed: " << std::boolalpha << b << std::endl;
+ });
+
+ manager->is_wwan_hardware_enabled().changed().connect([](bool b)
+ {
+ std::cout << "is_wwan_hardware_enabled changed: " << std::boolalpha << b << std::endl;
+ });
+
+ manager->active_connection_characteristics().changed().connect([](connectivity::Characteristics characteristics)
+ {
+ std::cout << "Active connection characteristics changed: " << characteristics << std::endl;
+ });
+
+ std::weak_ptr wp{manager};
+ manager->wireless_network_scan_finished().connect([wp, client]()
+ {
+ std::cout << "Wireless network scan finished" << std::endl;
+ if (auto manager = wp.lock())
+ {
+ std::vector cells;
+ manager->enumerate_connected_radio_cells([&cells](const connectivity::RadioCell::Ptr& cell)
+ {
+ cells.push_back(cell);
+ });
+
+ std::vector wifis;
+ manager->enumerate_visible_wireless_networks([&wifis](const connectivity::WirelessNetwork::Ptr& wifi)
+ {
+ wifis.push_back(wifi);
+ });
+
+ client->geolocate(wifis, cells);
+ }
+ });
+
+ trap->run();
+ return EXIT_SUCCESS;
+}
=== modified file 'src/location_service/com/ubuntu/location/service/ichnaea_reporter.cpp'
--- src/location_service/com/ubuntu/location/service/ichnaea_reporter.cpp 2016-05-24 09:44:01 +0000
+++ src/location_service/com/ubuntu/location/service/ichnaea_reporter.cpp 2016-05-25 21:01:56 +0000
@@ -317,7 +317,7 @@
continue;
json::Object w = json::Object::create_object();
- w.put_string(Json::Wifi::key, wifi->bssid().get());
+ w.put_string(Json::Wifi::mac_address, wifi->bssid().get());
if (wifi->frequency().get().is_valid())
w.put_int32(Json::Wifi::frequency, static_cast(wifi->frequency().get()));
@@ -342,60 +342,60 @@
{
case connectivity::RadioCell::Type::gsm:
{
- c.put_string(Json::Cell::radio, "gsm");
+ c.put_string(Json::Cell::radio_type, "gsm");
const auto& details = cell->gsm();
if (details.mobile_country_code.is_valid())
- c.put_int32(Json::Cell::mcc, details.mobile_country_code.get());
+ c.put_int32(Json::Cell::mobile_country_code, details.mobile_country_code.get());
if (details.mobile_network_code.is_valid())
- c.put_int32(Json::Cell::mnc, details.mobile_network_code.get());
+ c.put_int32(Json::Cell::mobile_network_code, details.mobile_network_code.get());
if (details.location_area_code.is_valid())
- c.put_int32(Json::Cell::lac, details.location_area_code.get());
+ c.put_int32(Json::Cell::location_area_code, details.location_area_code.get());
if (details.id.is_valid())
- c.put_int32(Json::Cell::cid, details.id.get());
+ c.put_int32(Json::Cell::cell_id, details.id.get());
if (details.strength.is_valid())
- c.put_int32(Json::Cell::asu, details.strength.get());
+ c.put_int32(Json::Cell::signal_strength, details.strength.get());
break;
}
case connectivity::RadioCell::Type::umts:
{
- c.put_string(Json::Cell::radio, "umts");
+ c.put_string(Json::Cell::radio_type, "umts");
const auto& details = cell->umts();
if (details.mobile_country_code.is_valid())
- c.put_int32(Json::Cell::mcc, details.mobile_country_code.get());
+ c.put_int32(Json::Cell::mobile_country_code, details.mobile_country_code.get());
if (details.mobile_network_code.is_valid())
- c.put_int32(Json::Cell::mnc, details.mobile_network_code.get());
+ c.put_int32(Json::Cell::mobile_network_code, details.mobile_network_code.get());
if (details.location_area_code.is_valid())
- c.put_int32(Json::Cell::lac, details.location_area_code.get());
+ c.put_int32(Json::Cell::location_area_code, details.location_area_code.get());
if (details.id.is_valid())
- c.put_int32(Json::Cell::cid, details.id.get());
+ c.put_int32(Json::Cell::cell_id, details.id.get());
if (details.strength.is_valid())
- c.put_int32(Json::Cell::asu, details.strength.get());
+ c.put_int32(Json::Cell::signal_strength, details.strength.get());
break;
}
case connectivity::RadioCell::Type::lte:
{
- c.put_string(Json::Cell::radio, "lte");
+ c.put_string(Json::Cell::radio_type, "lte");
const auto& details = cell->lte();
if (details.mobile_country_code.is_valid())
- c.put_int32(Json::Cell::mcc, details.mobile_country_code.get());
+ c.put_int32(Json::Cell::mobile_country_code, details.mobile_country_code.get());
if (details.mobile_network_code.is_valid())
- c.put_int32(Json::Cell::mnc, details.mobile_network_code.get());
+ c.put_int32(Json::Cell::mobile_network_code, details.mobile_network_code.get());
if (details.tracking_area_code.is_valid())
- c.put_int32(Json::Cell::lac, details.tracking_area_code.get());
+ c.put_int32(Json::Cell::location_area_code, details.tracking_area_code.get());
if (details.id.is_valid())
- c.put_int32(Json::Cell::cid, details.id.get());
+ c.put_int32(Json::Cell::cell_id, details.id.get());
if (details.physical_id.is_valid())
c.put_int32(Json::Cell::psc, details.physical_id.get());
if (details.strength.is_valid())
- c.put_int32(Json::Cell::asu, details.strength.get());
+ c.put_int32(Json::Cell::signal_strength, details.strength.get());
break;
}
default:
=== modified file 'src/location_service/com/ubuntu/location/service/ichnaea_reporter.h'
--- src/location_service/com/ubuntu/location/service/ichnaea_reporter.h 2014-07-11 12:56:40 +0000
+++ src/location_service/com/ubuntu/location/service/ichnaea_reporter.h 2016-05-25 21:01:56 +0000
@@ -168,19 +168,20 @@
struct Cell
{
- static constexpr const char* radio{"radio"};
- static constexpr const char* mcc{"mcc"};
- static constexpr const char* mnc{"mnc"};
- static constexpr const char* lac{"lac"};
- static constexpr const char* cid{"cid"};
+ static constexpr const char* radio_type{"radio_type"};
+ static constexpr const char* mobile_country_code{"mobileCountryCode"};
+ static constexpr const char* mobile_network_code{"mobileNetworkCode"};
+ static constexpr const char* location_area_code{"locationAreaCode"};
+ static constexpr const char* cell_id{"cellId"};
static constexpr const char* psc{"psc"};
- static constexpr const char* asu{"asu"};
+ static constexpr const char* signal_strength{"signalStrength"};
};
struct Wifi
{
static constexpr const char* channel{"channel"};
static constexpr const char* frequency{"frequency"};
+ static constexpr const char* mac_address{"macAddress"};
static constexpr const char* key{"key"};
static constexpr const char* signal{"signal"};
};
=== modified file 'tests/ichnaea_reporter_test.cpp'
--- tests/ichnaea_reporter_test.cpp 2016-05-24 09:44:01 +0000
+++ tests/ichnaea_reporter_test.cpp 2016-05-25 21:01:56 +0000
@@ -200,11 +200,11 @@
EXPECT_EQ(1u, cells.array_size());
auto cell = cells.get_object_for_index(0);
- EXPECT_EQ(ref_cell->gsm().mobile_country_code.get(), cell.get(Reporter::Json::Cell::mcc).to_int32());
- EXPECT_EQ(ref_cell->gsm().mobile_network_code.get(), cell.get(Reporter::Json::Cell::mnc).to_int32());
- EXPECT_EQ(ref_cell->gsm().location_area_code.get(), cell.get(Reporter::Json::Cell::lac).to_int32());
- EXPECT_EQ(ref_cell->gsm().id.get(), cell.get(Reporter::Json::Cell::cid).to_int32());
- EXPECT_EQ(ref_cell->gsm().strength.get(), cell.get(Reporter::Json::Cell::asu).to_int32());
+ EXPECT_EQ(ref_cell->gsm().mobile_country_code.get(), cell.get(Reporter::Json::Cell::mobile_country_code).to_int32());
+ EXPECT_EQ(ref_cell->gsm().mobile_network_code.get(), cell.get(Reporter::Json::Cell::mobile_network_code).to_int32());
+ EXPECT_EQ(ref_cell->gsm().location_area_code.get(), cell.get(Reporter::Json::Cell::location_area_code).to_int32());
+ EXPECT_EQ(ref_cell->gsm().id.get(), cell.get(Reporter::Json::Cell::cell_id).to_int32());
+ EXPECT_EQ(ref_cell->gsm().strength.get(), cell.get(Reporter::Json::Cell::signal_strength).to_int32());
mg_send_status(conn, static_cast(submit::success));
return MG_TRUE;