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_DAEMON_H_
19
#define LOCATION_SERVICE_COM_UBUNTU_LOCATION_SERVICE_DAEMON_H_
21
#include <com/ubuntu/location/configuration.h>
23
#include <core/dbus/bus.h>
37
* @brief The Daemon struct encapsulates main functions for the location service and its cli.
41
/** @brief Function signature for creating DBus connections. */
42
typedef std::function<core::dbus::Bus::Ptr(core::dbus::WellKnownBus)> DBusConnectionFactory;
44
/** @brief Returns the default connection factory. */
45
static DBusConnectionFactory default_dbus_connection_factory()
47
return [](core::dbus::WellKnownBus bus)
49
return core::dbus::Bus::Ptr
51
new core::dbus::Bus(bus)
56
/** @brief Describes the command-line interface to the daemon. */
61
/** @brief Enumerates all commands known to the cli. */
64
/** @brief Marks the unknown command. */
66
/** @brief Request to query a property value of the running service. */
68
/** @brief Request to adjust a property value of the running service. */
72
/** @brief Enumerates all properties known to the cli. */
75
/** @brief Marks the unknown property. */
77
/** @brief Indicates whether the positioning engine 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
87
/** @brief Parameters for an invocation of the CLI. */
90
/** @brief Parses a configuration from the command line.
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
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.
103
static Configuration from_command_line_args(
106
DBusConnectionFactory factory = default_dbus_connection_factory());
108
/** @brief The bus to connect to. */
109
core::dbus::Bus::Ptr bus;
111
/** @brief The command to execute against a running daemon. */
117
/** @brief If command is get/set/monitor, the property to act upon. */
123
/** @brief The new, string-based value for a property. */
124
std::string new_value;
127
/** @brief Pretty-prints the CLI's help text to the given output stream. */
128
static void print_help(std::ostream& out);
131
* @brief main of the command-line interface to the location service.
132
* @return EXIT_SUCCESS or EXIT_FAILURE.
134
static int main(const Configuration& configuration);
139
/** @brief Parameters for an invocation of the daemon. */
142
/** @brief Parses a configuration from the command line.
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
149
static Configuration from_command_line_args(
152
DBusConnectionFactory factory = default_dbus_connection_factory());
154
/** @brief The bus to expose the service upon. */
155
core::dbus::Bus::Ptr incoming;
157
/** @brief The bus to use for querying other services. */
158
core::dbus::Bus::Ptr outgoing;
160
/** @brief Configures the daemon for testing mode. */
161
bool is_testing_enabled
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;
171
/** @brief Pretty-prints the CLI's help text to the given output stream. */
172
static void print_help(std::ostream& out);
175
* @brief Executes the daemon with the given configuration.
176
* @return EXIT_SUCCESS or EXIT_FAILURE.
178
static int main(const Configuration& config);
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);
184
/** @brief Pretty-prints a property value */
185
std::ostream& operator<<(std::ostream& out, Daemon::Cli::Property property);
191
#endif // LOCATION_SERVICE_COM_UBUNTU_LOCATION_SERVICE_DAEMON_H_