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

« back to all changes in this revision

Viewing changes to src/location_service/com/ubuntu/location/connectivity/ofono_nm_connectivity_manager.h

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
#ifndef OFONO_NM_CONNECTIVITY_MANAGER_H_
 
20
#define OFONO_NM_CONNECTIVITY_MANAGER_H_
 
21
 
 
22
#include <com/ubuntu/location/connectivity/manager.h>
 
23
 
 
24
#include <com/ubuntu/location/logging.h>
 
25
 
 
26
#include "cached_radio_cell.h"
 
27
#include "cached_wireless_network.h"
 
28
#include "nm.h"
 
29
#include "ofono.h"
 
30
 
 
31
#include <core/dbus/bus.h>
 
32
#include <core/dbus/object.h>
 
33
#include <core/dbus/property.h>
 
34
#include <core/dbus/service.h>
 
35
#include <core/dbus/types/object_path.h>
 
36
#include <core/dbus/types/struct.h>
 
37
#include <core/dbus/types/stl/map.h>
 
38
#include <core/dbus/types/stl/string.h>
 
39
#include <core/dbus/types/stl/tuple.h>
 
40
#include <core/dbus/types/stl/vector.h>
 
41
 
 
42
#include <core/dbus/asio/executor.h>
 
43
 
 
44
#include "../set_name_for_thread.h"
 
45
 
 
46
#include <chrono>
 
47
 
 
48
namespace dbus = core::dbus;
 
49
 
 
50
namespace impl
 
51
{
 
52
struct OfonoNmConnectivityManager : public com::ubuntu::location::connectivity::Manager
 
53
{
 
54
    const core::Property<com::ubuntu::location::connectivity::State>& state() const override;
 
55
 
 
56
    void request_scan_for_wireless_networks() override;
 
57
 
 
58
    const core::Signal<>& wireless_network_scan_finished() const override;
 
59
    const core::Signal<com::ubuntu::location::connectivity::WirelessNetwork::Ptr>& wireless_network_added() const override;
 
60
    const core::Signal<com::ubuntu::location::connectivity::WirelessNetwork::Ptr>& wireless_network_removed() const override;
 
61
 
 
62
    void enumerate_visible_wireless_networks(const std::function<void(const com::ubuntu::location::connectivity::WirelessNetwork::Ptr&)>& f) const override;
 
63
 
 
64
    const core::Signal<com::ubuntu::location::connectivity::RadioCell::Ptr>& connected_cell_added() const override;
 
65
    const core::Signal<com::ubuntu::location::connectivity::RadioCell::Ptr>& connected_cell_removed() const override;
 
66
 
 
67
    void enumerate_connected_radio_cells(const std::function<void(const com::ubuntu::location::connectivity::RadioCell::Ptr&)>& f) const override;
 
68
 
 
69
    struct Private
 
70
    {
 
71
        Private();
 
72
        ~Private();
 
73
 
 
74
        void setup_radio_stack_access();
 
75
        void on_modem_added(const core::dbus::types::ObjectPath& path);
 
76
        void on_modem_removed(const core::dbus::types::ObjectPath& path);
 
77
        void on_modem_interfaces_changed(const core::dbus::types::ObjectPath& path, const std::vector<std::string>& interfaces);
 
78
 
 
79
        void setup_network_stack_access();
 
80
        void on_access_point_added(const core::dbus::types::ObjectPath& ap_path, const core::dbus::types::ObjectPath& device_path);
 
81
        void on_access_point_removed(const core::dbus::types::ObjectPath& ap_path);
 
82
 
 
83
        core::dbus::Bus::Ptr system_bus;
 
84
        core::dbus::Executor::Ptr executor;
 
85
 
 
86
        std::thread worker;
 
87
 
 
88
        org::freedesktop::NetworkManager::Ptr network_manager;
 
89
        org::Ofono::Manager::Ptr modem_manager;
 
90
 
 
91
        struct
 
92
        {
 
93
            mutable std::mutex guard;
 
94
            std::map<core::dbus::types::ObjectPath, CachedRadioCell::Ptr> cells;
 
95
            std::map<core::dbus::types::ObjectPath, org::Ofono::Manager::Modem> modems;
 
96
            std::map<core::dbus::types::ObjectPath, CachedWirelessNetwork::Ptr> wifis;
 
97
            std::map<core::dbus::types::ObjectPath, org::freedesktop::NetworkManager::Device> wireless_devices;
 
98
        } cached;
 
99
 
 
100
        struct
 
101
        {
 
102
            core::Signal<> wireless_network_scan_finished;
 
103
            core::Signal<com::ubuntu::location::connectivity::RadioCell::Ptr> connected_cell_added;
 
104
            core::Signal<com::ubuntu::location::connectivity::RadioCell::Ptr> connected_cell_removed;
 
105
            core::Signal<com::ubuntu::location::connectivity::WirelessNetwork::Ptr> wireless_network_added;
 
106
            core::Signal<com::ubuntu::location::connectivity::WirelessNetwork::Ptr> wireless_network_removed;
 
107
        } signals;
 
108
 
 
109
        core::Property<com::ubuntu::location::connectivity::State> state;
 
110
    } d;
 
111
};
 
112
}
 
113
 
 
114
#endif // OFONO_NM_CONNECTIVITY_MANAGER_H_