Merge lp:~mardy/location-service/runtime-log-switch into lp:location-service/15.04

Proposed by Alberto Mardegan on 2015-10-23
Status: Needs review
Proposed branch: lp:~mardy/location-service/runtime-log-switch
Merge into: lp:location-service/15.04
Diff against target: 317 lines (+132/-5)
10 files modified
include/location_service/com/ubuntu/location/service/interface.h (+22/-0)
include/location_service/com/ubuntu/location/service/skeleton.h (+5/-0)
include/location_service/com/ubuntu/location/service/stub.h (+1/-0)
src/location_service/com/ubuntu/location/service/daemon.cpp (+36/-1)
src/location_service/com/ubuntu/location/service/daemon.h (+3/-1)
src/location_service/com/ubuntu/location/service/implementation.cpp (+9/-0)
src/location_service/com/ubuntu/location/service/implementation.h (+1/-0)
src/location_service/com/ubuntu/location/service/skeleton.cpp (+28/-2)
src/location_service/com/ubuntu/location/service/stub.cpp (+8/-1)
tests/daemon_and_cli_tests.cpp (+19/-0)
To merge this branch: bzr merge lp:~mardy/location-service/runtime-log-switch
Reviewer Review Type Date Requested Status
Thomas Voß (community) 2015-10-23 Approve on 2015-10-26
Review via email: mp+275538@code.launchpad.net

Commit message

Add the possibility to enable logging at runtime

Description of the change

Add the possibility to enable logging at runtime

To post a comment you must log in.
Thomas Voß (thomas-voss) wrote :

LGTM.

review: Approve

Unmerged revisions

198. By Alberto Mardegan on 2015-10-23

Add a runtime option to set verbosity level

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/location_service/com/ubuntu/location/service/interface.h'
2--- include/location_service/com/ubuntu/location/service/interface.h 2014-08-01 15:59:25 +0000
3+++ include/location_service/com/ubuntu/location/service/interface.h 2015-10-23 13:57:58 +0000
4@@ -155,6 +155,22 @@
5 static const bool readable = true;
6 static const bool writable = false;
7 };
8+
9+ struct VerbosityLevel
10+ {
11+ inline static const std::string& name()
12+ {
13+ static const std::string s
14+ {
15+ "VerbosityLevel"
16+ };
17+ return s;
18+ }
19+ typedef com::ubuntu::location::service::Interface Interface;
20+ typedef int ValueType;
21+ static const bool readable = true;
22+ static const bool writable = true;
23+ };
24 };
25
26 Interface() = default;
27@@ -204,6 +220,12 @@
28 virtual core::Property<std::map<SpaceVehicle::Key, SpaceVehicle>>& visible_space_vehicles() = 0;
29
30 /**
31+ * @brief The service verbosity level.
32+ * @return A setable/getable/observable property.
33+ */
34+ virtual core::Property<int>& verbosity_level() = 0;
35+
36+ /**
37 * @brief Starts a new session for the given criteria
38 * @throw std::runtime_error in case of errors.
39 * @param criteria The client's requirements in terms of accuraccy and functionality
40
41=== modified file 'include/location_service/com/ubuntu/location/service/skeleton.h'
42--- include/location_service/com/ubuntu/location/service/skeleton.h 2015-02-13 13:19:18 +0000
43+++ include/location_service/com/ubuntu/location/service/skeleton.h 2015-10-23 13:57:58 +0000
44@@ -115,6 +115,7 @@
45 core::Property<bool>& does_report_cell_and_wifi_ids();
46 core::Property<bool>& is_online();
47 core::Property<std::map<SpaceVehicle::Key, SpaceVehicle>>& visible_space_vehicles();
48+ core::Property<int>& verbosity_level();
49
50 private:
51 // Handles incoming message calls for create_session_for_criteria.
52@@ -137,6 +138,8 @@
53 void on_does_report_cell_and_wifi_ids_changed(bool value);
54 // Called whenever the value of the respective property changes.
55 void on_is_online_changed(bool value);
56+ // Called whenever the value of the respective property changes.
57+ void on_verbosity_level_changed(int value);
58
59 // Stores the configuration passed in at creation time.
60 Configuration configuration;
61@@ -158,6 +161,7 @@
62 std::shared_ptr< core::dbus::Property<Interface::Properties::DoesReportCellAndWifiIds> > does_report_cell_and_wifi_ids;
63 std::shared_ptr< core::dbus::Property<Interface::Properties::IsOnline> > is_online;
64 std::shared_ptr< core::dbus::Property<Interface::Properties::VisibleSpaceVehicles> > visible_space_vehicles;
65+ std::shared_ptr< core::dbus::Property<Interface::Properties::VerbosityLevel> > verbosity_level;
66 } properties;
67 // We sign up to property changes here, to be able to report them to the bus
68 struct
69@@ -165,6 +169,7 @@
70 core::ScopedConnection does_satellite_based_positioning;
71 core::ScopedConnection does_report_cell_and_wifi_ids;
72 core::ScopedConnection is_online;
73+ core::ScopedConnection verbosity_level;
74 } connections;
75 // Guards the session store.
76 std::mutex guard;
77
78=== modified file 'include/location_service/com/ubuntu/location/service/stub.h'
79--- include/location_service/com/ubuntu/location/service/stub.h 2014-02-03 13:52:21 +0000
80+++ include/location_service/com/ubuntu/location/service/stub.h 2015-10-23 13:57:58 +0000
81@@ -44,6 +44,7 @@
82 core::Property<bool>& does_report_cell_and_wifi_ids();
83 core::Property<bool>& is_online();
84 core::Property<std::map<SpaceVehicle::Key, SpaceVehicle>>& visible_space_vehicles();
85+ core::Property<int>& verbosity_level();
86
87 private:
88 struct Private;
89
90=== modified file 'src/location_service/com/ubuntu/location/service/daemon.cpp'
91--- src/location_service/com/ubuntu/location/service/daemon.cpp 2015-04-16 10:03:29 +0000
92+++ src/location_service/com/ubuntu/location/service/daemon.cpp 2015-10-23 13:57:58 +0000
93@@ -486,6 +486,38 @@
94 }
95 break;
96 }
97+ case Property::verbosity_level:
98+ {
99+ switch (config.command)
100+ {
101+ case Command::get:
102+ {
103+ auto vl = location_service->verbosity_level().get();
104+ std::cout << "Verbosity level:" << vl << std::endl;
105+ break;
106+ }
107+ case Command::set:
108+ {
109+ std::stringstream ss(config.new_value);
110+ int vl = location_service->verbosity_level();
111+ ss >> std::dec >> vl;
112+
113+ std::cout << "Adjusting verbosity_level property to value: "
114+ << std::dec << vl << " -> ";
115+ location_service->verbosity_level() = vl;
116+ if (location_service->verbosity_level() != vl)
117+ {
118+ std::cout << "failed" << std::endl;
119+ return EXIT_FAILURE;
120+ }
121+ std::cout << "succeeded" << std::endl;
122+ break;
123+ }
124+ default:
125+ case Command::unknown: break;
126+ }
127+ break;
128+ }
129 case Property::unknown:
130 std::cout << "Unknown property, aborting now." << std::endl;
131 location::service::Daemon::Cli::print_help(std::cout);
132@@ -503,7 +535,8 @@
133 {"is_online", location::service::Daemon::Cli::Property::is_online},
134 {"does_satellite_based_positioning", location::service::Daemon::Cli::Property::does_satellite_based_positioning},
135 {"does_report_wifi_and_cell_ids", location::service::Daemon::Cli::Property::does_report_wifi_and_cell_ids},
136- {"visible_space_vehicles", location::service::Daemon::Cli::Property::visible_space_vehicles}
137+ {"visible_space_vehicles", location::service::Daemon::Cli::Property::visible_space_vehicles},
138+ {"verbosity_level", location::service::Daemon::Cli::Property::verbosity_level}
139 };
140
141 std::string value; in >> value;
142@@ -532,6 +565,8 @@
143 out << "does_report_wifi_and_cell_ids"; break;
144 case location::service::Daemon::Cli::Property::visible_space_vehicles:
145 out << "visible_space_vehicles"; break;
146+ case location::service::Daemon::Cli::Property::verbosity_level:
147+ out << "verbosity_level"; break;
148 case location::service::Daemon::Cli::Property::unknown:
149 out << "unknown"; break;
150 }
151
152=== modified file 'src/location_service/com/ubuntu/location/service/daemon.h'
153--- src/location_service/com/ubuntu/location/service/daemon.h 2015-01-25 12:45:30 +0000
154+++ src/location_service/com/ubuntu/location/service/daemon.h 2015-10-23 13:57:58 +0000
155@@ -69,7 +69,9 @@
156 /** @brief Indicates whether the positioning engine leverages wifi and cell ids for positioning. */
157 does_report_wifi_and_cell_ids,
158 /** @brief The list of currently visible space-vehicles. */
159- visible_space_vehicles
160+ visible_space_vehicles,
161+ /** @brief The logging level for the daemon. */
162+ verbosity_level,
163 };
164
165 /** @brief Parameters for an invocation of the CLI. */
166
167=== modified file 'src/location_service/com/ubuntu/location/service/implementation.cpp'
168--- src/location_service/com/ubuntu/location/service/implementation.cpp 2014-08-13 13:08:22 +0000
169+++ src/location_service/com/ubuntu/location/service/implementation.cpp 2015-10-23 13:57:58 +0000
170@@ -95,6 +95,15 @@
171 cul::SatelliteBasedPositioningState::on :
172 cul::SatelliteBasedPositioningState::off;
173 }),
174+ verbosity_level().changed().connect(
175+ [this](int value)
176+ {
177+ FLAGS_v = value;
178+ if (value >= 0)
179+ FLAGS_logtostderr = 1;
180+ else
181+ FLAGS_logtostderr = 0;
182+ }),
183 configuration.engine->configuration.engine_state.changed().connect(
184 [this](Engine::Status status)
185 {
186
187=== modified file 'src/location_service/com/ubuntu/location/service/implementation.h'
188--- src/location_service/com/ubuntu/location/service/implementation.h 2014-08-01 12:51:25 +0000
189+++ src/location_service/com/ubuntu/location/service/implementation.h 2015-10-23 13:57:58 +0000
190@@ -73,6 +73,7 @@
191 core::ScopedConnection is_online;
192 core::ScopedConnection does_report_cell_and_wifi_ids;
193 core::ScopedConnection does_satellite_based_positioning;
194+ core::ScopedConnection verbosity_level;
195 core::ScopedConnection engine_state;
196 core::ScopedConnection satellite_based_positioning_state;
197 core::ScopedConnection visible_space_vehicles;
198
199=== modified file 'src/location_service/com/ubuntu/location/service/skeleton.cpp'
200--- src/location_service/com/ubuntu/location/service/skeleton.cpp 2015-02-13 13:19:18 +0000
201+++ src/location_service/com/ubuntu/location/service/skeleton.cpp 2015-10-23 13:57:58 +0000
202@@ -76,7 +76,8 @@
203 object->get_property<culs::Interface::Properties::DoesSatelliteBasedPositioning>(),
204 object->get_property<culs::Interface::Properties::DoesReportCellAndWifiIds>(),
205 object->get_property<culs::Interface::Properties::IsOnline>(),
206- object->get_property<culs::Interface::Properties::VisibleSpaceVehicles>()
207+ object->get_property<culs::Interface::Properties::VisibleSpaceVehicles>(),
208+ object->get_property<culs::Interface::Properties::VerbosityLevel>(),
209 },
210 connections
211 {
212@@ -91,7 +92,11 @@
213 properties.is_online->changed().connect([this](bool value)
214 {
215 on_is_online_changed(value);
216- })
217+ }),
218+ properties.verbosity_level->changed().connect([this](int value)
219+ {
220+ on_verbosity_level_changed(value);
221+ }),
222 }
223 {
224 object->install_method_handler<culs::Interface::CreateSessionForCriteria>([this](const dbus::Message::Ptr& msg)
225@@ -258,6 +263,22 @@
226 the_empty_array_of_invalidated_properties()));
227 }
228
229+void culs::Skeleton::on_verbosity_level_changed(int value)
230+{
231+ std::map<std::string, core::dbus::types::Variant> dict
232+ {
233+ {
234+ culs::Interface::Properties::VerbosityLevel::name(),
235+ core::dbus::types::Variant::encode(value)
236+ }
237+ };
238+ properties_changed->emit(
239+ std::tie(
240+ core::dbus::traits::Service<culs::Interface>::interface_name(),
241+ dict,
242+ the_empty_array_of_invalidated_properties()));
243+}
244+
245 core::Property<bool>& culs::Skeleton::does_satellite_based_positioning()
246 {
247 return *properties.does_satellite_based_positioning;
248@@ -277,3 +298,8 @@
249 {
250 return *properties.visible_space_vehicles;
251 }
252+
253+core::Property<int>& culs::Skeleton::verbosity_level()
254+{
255+ return *properties.verbosity_level;
256+}
257
258=== modified file 'src/location_service/com/ubuntu/location/service/stub.cpp'
259--- src/location_service/com/ubuntu/location/service/stub.cpp 2014-07-17 14:03:42 +0000
260+++ src/location_service/com/ubuntu/location/service/stub.cpp 2015-10-23 13:57:58 +0000
261@@ -37,7 +37,8 @@
262 does_satellite_based_positioning(object->get_property<culs::Interface::Properties::DoesSatelliteBasedPositioning>()),
263 does_report_cell_and_wifi_ids(object->get_property<culs::Interface::Properties::DoesReportCellAndWifiIds>()),
264 is_online(object->get_property<culs::Interface::Properties::IsOnline>()),
265- visible_space_vehicles(object->get_property<culs::Interface::Properties::VisibleSpaceVehicles>())
266+ visible_space_vehicles(object->get_property<culs::Interface::Properties::VisibleSpaceVehicles>()),
267+ verbosity_level(object->get_property<culs::Interface::Properties::VerbosityLevel>())
268 {
269 }
270
271@@ -47,6 +48,7 @@
272 std::shared_ptr<dbus::Property<culs::Interface::Properties::DoesReportCellAndWifiIds>> does_report_cell_and_wifi_ids;
273 std::shared_ptr<dbus::Property<culs::Interface::Properties::IsOnline>> is_online;
274 std::shared_ptr<dbus::Property<culs::Interface::Properties::VisibleSpaceVehicles>> visible_space_vehicles;
275+ std::shared_ptr<dbus::Property<culs::Interface::Properties::VerbosityLevel>> verbosity_level;
276 };
277
278 culs::Stub::Stub(const dbus::Bus::Ptr& connection) : dbus::Stub<culs::Interface>(connection),
279@@ -93,3 +95,8 @@
280 {
281 return *d->visible_space_vehicles;
282 }
283+
284+core::Property<int>& culs::Stub::verbosity_level()
285+{
286+ return *d->verbosity_level;
287+}
288
289=== modified file 'tests/daemon_and_cli_tests.cpp'
290--- tests/daemon_and_cli_tests.cpp 2014-12-17 09:26:11 +0000
291+++ tests/daemon_and_cli_tests.cpp 2015-10-23 13:57:58 +0000
292@@ -189,6 +189,25 @@
293 *this)));
294 }
295
296+TEST_F(DaemonAndCli, QueryingVerbosityLevelPropertyWorks)
297+{
298+ EXPECT_EQ(core::testing::ForkAndRunResult::empty,
299+ core::testing::fork_and_run(
300+ testing_daemon(*this),
301+ querying_cli_for_property(
302+ location::service::Daemon::Cli::Property::verbosity_level,
303+ *this)));
304+}
305+
306+TEST_F(DaemonAndCli, AdjustingVerbosityLevelPropertyWorks)
307+{
308+ EXPECT_EQ(core::testing::ForkAndRunResult::empty,
309+ core::testing::fork_and_run(
310+ testing_daemon(*this),
311+ adjusting_cli_for_property(
312+ location::service::Daemon::Cli::Property::verbosity_level, 100, *this)));
313+}
314+
315 namespace
316 {
317 auto null_dbus_connection_factory = [](core::dbus::WellKnownBus)

Subscribers

People subscribed via source and target branches