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

« back to all changes in this revision

Viewing changes to src/location_service/com/ubuntu/location/service/daemon.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
#ifndef LOCATION_SERVICE_COM_UBUNTU_LOCATION_SERVICE_DAEMON_H_
 
19
#define LOCATION_SERVICE_COM_UBUNTU_LOCATION_SERVICE_DAEMON_H_
 
20
 
 
21
#include <com/ubuntu/location/configuration.h>
 
22
 
 
23
#include <core/dbus/bus.h>
 
24
 
 
25
#include <iosfwd>
 
26
#include <string>
 
27
 
 
28
namespace com
 
29
{
 
30
namespace ubuntu
 
31
{
 
32
namespace location
 
33
{
 
34
namespace service
 
35
{
 
36
/**
 
37
 * @brief The Daemon struct encapsulates main functions for the location service and its cli.
 
38
 */
 
39
struct Daemon
 
40
{
 
41
    /** @brief Function signature for creating DBus connections. */
 
42
    typedef std::function<core::dbus::Bus::Ptr(core::dbus::WellKnownBus)> DBusConnectionFactory;
 
43
 
 
44
    /** @brief Returns the default connection factory. */
 
45
    static DBusConnectionFactory default_dbus_connection_factory()
 
46
    {
 
47
        return [](core::dbus::WellKnownBus bus)
 
48
        {
 
49
            return core::dbus::Bus::Ptr
 
50
            {
 
51
                new core::dbus::Bus(bus)
 
52
            };
 
53
        };
 
54
    }
 
55
 
 
56
    /** @brief Describes the command-line interface to the daemon. */
 
57
    struct Cli
 
58
    {
 
59
        Cli() = delete;
 
60
 
 
61
        /** @brief Enumerates all commands known to the cli. */
 
62
        enum class Command
 
63
        {
 
64
            /** @brief Marks the unknown command. */
 
65
            unknown,
 
66
            /** @brief Request to query a property value of the running service. */
 
67
            get,
 
68
            /** @brief Request to adjust a property value of the running service. */
 
69
            set
 
70
        };
 
71
 
 
72
        /** @brief Enumerates all properties known to the cli. */
 
73
        enum class Property
 
74
        {
 
75
            /** @brief Marks the unknown property. */
 
76
            unknown,
 
77
            /** @brief Indicates whether the positioning engine is online. */
 
78
            is_online,
 
79
            /** @brief Indicates whether the positioning engine uses satellite-based positioning. */
 
80
            does_satellite_based_positioning,
 
81
            /** @brief Indicates whether the positioning engine leverages wifi and cell ids for positioning. */
 
82
            does_report_wifi_and_cell_ids,
 
83
            /** @brief The list of currently visible space-vehicles. */
 
84
            visible_space_vehicles
 
85
        };
 
86
 
 
87
        /** @brief Parameters for an invocation of the CLI. */
 
88
        struct Configuration
 
89
        {
 
90
            /** @brief Parses a configuration from the command line.
 
91
             *
 
92
             * --bus arg (=session)      The well-known bus to connect to the service upon
 
93
             * --help                    Produces this help message
 
94
             * --property arg (=unknown) Property to set/get from a running service, known
 
95
                                         properties are:
 
96
                                            is_online [get/set]
 
97
                                            does_satellite_based_positioning [get/set]
 
98
                                            does_report_wifi_and_cell_ids [get/set]
 
99
                                            visible_space_vehicles [get]
 
100
             * --set arg                 Adjust the value of the property.
 
101
             * --get                     Query the value of the property.
 
102
             */
 
103
            static Configuration from_command_line_args(
 
104
                    int argc,
 
105
                    char** argv,
 
106
                    DBusConnectionFactory factory = default_dbus_connection_factory());
 
107
 
 
108
            /** @brief The bus to connect to. */
 
109
            core::dbus::Bus::Ptr bus;
 
110
 
 
111
            /** @brief The command to execute against a running daemon. */
 
112
            Command command
 
113
            {
 
114
                Command::unknown
 
115
            };
 
116
 
 
117
            /** @brief If command is get/set/monitor, the property to act upon. */
 
118
            Property property
 
119
            {
 
120
                Property::unknown
 
121
            };
 
122
 
 
123
            /** @brief The new, string-based value for a property. */
 
124
            std::string new_value;
 
125
        };
 
126
 
 
127
        /** @brief Pretty-prints the CLI's help text to the given output stream. */
 
128
        static void print_help(std::ostream& out);
 
129
 
 
130
        /**
 
131
         * @brief main of the command-line interface to the location service.
 
132
         * @return EXIT_SUCCESS or EXIT_FAILURE.
 
133
         */
 
134
        static int main(const Configuration& configuration);
 
135
    };
 
136
 
 
137
    Daemon() = delete;
 
138
 
 
139
    /** @brief Parameters for an invocation of the daemon. */
 
140
    struct Configuration
 
141
    {
 
142
        /** @brief Parses a configuration from the command line.
 
143
         *
 
144
         *   --bus arg (=session)  The well-known bus to connect to the service upon
 
145
         *   --help                Produces this help message
 
146
         *   --testing             Enables executing the service without selected providers
 
147
         *   --provider arg        The providers that should be added to the engine
 
148
         */
 
149
        static Configuration from_command_line_args(
 
150
                int argc,
 
151
                char** argv,
 
152
                DBusConnectionFactory factory = default_dbus_connection_factory());
 
153
 
 
154
        /** @brief The bus to expose the service upon. */
 
155
        core::dbus::Bus::Ptr incoming;
 
156
 
 
157
        /** @brief The bus to use for querying other services. */
 
158
        core::dbus::Bus::Ptr outgoing;
 
159
 
 
160
        /** @brief Configures the daemon for testing mode. */
 
161
        bool is_testing_enabled
 
162
        {
 
163
            false
 
164
        };
 
165
        /** @brief Providers that have been requested on the command line. */
 
166
        std::vector<std::string> providers;
 
167
        /** @brief Provider-specific options keyed on the provider name. */
 
168
        std::map< std::string, location::Configuration > provider_options;
 
169
    };
 
170
 
 
171
    /** @brief Pretty-prints the CLI's help text to the given output stream. */
 
172
    static void print_help(std::ostream& out);
 
173
 
 
174
    /**
 
175
     * @brief Executes the daemon with the given configuration.
 
176
     * @return EXIT_SUCCESS or EXIT_FAILURE.
 
177
     */
 
178
    static int main(const Configuration& config);
 
179
};
 
180
 
 
181
/** @brief Parses a Cli property from the given input stream, throws std::runtime_error. */
 
182
std::istream& operator>>(std::istream& in, Daemon::Cli::Property& property);
 
183
 
 
184
/** @brief Pretty-prints a property value */
 
185
std::ostream& operator<<(std::ostream& out, Daemon::Cli::Property property);
 
186
}
 
187
}
 
188
}
 
189
}
 
190
 
 
191
#endif // LOCATION_SERVICE_COM_UBUNTU_LOCATION_SERVICE_DAEMON_H_