Merge lp:~sforshee/powerd/clean-up-cli-output into lp:powerd
- clean-up-cli-output
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Matt Fischer |
Approved revision: | 75 |
Merged at revision: | 69 |
Proposed branch: | lp:~sforshee/powerd/clean-up-cli-output |
Merge into: | lp:powerd |
Diff against target: |
424 lines (+91/-50) 1 file modified
cli/powerd-cli.c (+91/-50) |
To merge this branch: | bzr merge lp:~sforshee/powerd/clean-up-cli-output |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot | continuous-integration | Approve | |
Matt Fischer (community) | Approve | ||
Review via email: mp+175376@code.launchpad.net |
Commit message
Clean up powerd-cli output
Description of the change
Clean up powerd-cli output
Seth Forshee (sforshee) wrote : | # |
> Looks cleaner, to reiterate what I said on IRC, I had someone look for "We Get
> Signal" when a MMS was sent, he didn't see it. When MMS does work, we may need
> to bring that back because it might be a different signal. tl;dr: We need to
> test screen on with MMS once it works.
If you look down to the else block for the if statement which follows, you'll see that as long as you enable debug output you will get the same information for any unknown signal.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:75
http://
Executed test runs:
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
Preview Diff
1 | === modified file 'cli/powerd-cli.c' |
2 | --- cli/powerd-cli.c 2013-07-02 14:50:36 +0000 |
3 | +++ cli/powerd-cli.c 2013-07-17 18:59:33 +0000 |
4 | @@ -32,15 +32,21 @@ |
5 | #define do_test(test) \ |
6 | ({ \ |
7 | gboolean result; \ |
8 | - g_message("Test: " #test); \ |
9 | + printf("Test: " #test "\n"); \ |
10 | result = (test); \ |
11 | - g_message(" result: %s", result ? "PASSED" : "FAILED"); \ |
12 | + printf(" result: %s\n", result ? "PASSED" : "FAILED"); \ |
13 | result; \ |
14 | }) |
15 | |
16 | #define TEST_NUM_SYS_REQUESTS 5 |
17 | #define TEST_NUM_DISP_REQUESTS POWERD_NUM_DISPLAY_STATES * POWERD_NUM_DISPLAY_BRIGHTNESS_STATES |
18 | |
19 | +/* Set to TRUE during tests to silence expected errors */ |
20 | +static gboolean silent_errors = FALSE; |
21 | + |
22 | +#define cli_warn(f, a...) do { if (!silent_errors) g_warning(f, ##a); } while (0) |
23 | +#define cli_debug(f, a...) g_debug(f, ##a) |
24 | + |
25 | GDBusProxy *powerd_proxy = NULL; |
26 | char test_dbusname[128] = ""; |
27 | |
28 | @@ -67,6 +73,12 @@ |
29 | static void sig_handler(int signum); |
30 | |
31 | static void |
32 | +silence_errors(gboolean silent) |
33 | +{ |
34 | + silent_errors = silent; |
35 | +} |
36 | + |
37 | +static void |
38 | on_powerd_signal (GDBusProxy *proxy, |
39 | gchar *sender_name, |
40 | gchar *signal_name, |
41 | @@ -78,20 +90,18 @@ |
42 | int display_brightness; |
43 | guint32 display_flags; |
44 | |
45 | - g_warning("we get signal from %s: %s", sender_name, signal_name); |
46 | - |
47 | if (!strcmp(signal_name,"SysPowerStateChange")) { |
48 | g_variant_get(parameters, "(i)", &system_state); |
49 | - g_warning("System State is now: %d", system_state); |
50 | + printf("Received %s: state=%d\n", signal_name, system_state); |
51 | } |
52 | else if (!strcmp(signal_name,"DisplayPowerStateChange")) { |
53 | g_variant_get(parameters, "(iiu)", &display_state, |
54 | &display_brightness, &display_flags); |
55 | - g_warning("Display State is now: %d, Brightness: %d, Flags: %u", |
56 | - display_state, display_brightness, display_flags); |
57 | + printf("Received %s: state=%d brightness=%d flags=%#08x\n", |
58 | + signal_name, display_state, display_brightness, display_flags); |
59 | } |
60 | else { |
61 | - g_warning("Unknown signal from powerd"); |
62 | + cli_debug("Unknown signal from %s: %s", sender_name, signal_name); |
63 | } |
64 | } |
65 | |
66 | @@ -105,7 +115,7 @@ |
67 | gboolean success = TRUE; |
68 | |
69 | if (cookie == NULL) { |
70 | - g_warning("requires a valid pointer for cookie"); |
71 | + cli_warn("NULL cookie passed to %s", __func__); |
72 | return FALSE; |
73 | } |
74 | |
75 | @@ -117,18 +127,18 @@ |
76 | NULL, |
77 | &error); |
78 | if (ret == NULL) { |
79 | - g_warning("Error when calling requestSysState: %s", error->message); |
80 | + cli_warn("requestSysState failed: %s", error->message); |
81 | g_error_free(error); |
82 | return FALSE; |
83 | } |
84 | |
85 | g_variant_get(ret, "(&s)", &cookie_ptr); |
86 | if (strlen(cookie_ptr) != sizeof(powerd_cookie_t) - 1) { |
87 | - g_warning("Returned cookie has incorrect size"); |
88 | + cli_warn("Returned cookie has incorrect size"); |
89 | success = FALSE; |
90 | } else { |
91 | strncpy(*cookie, cookie_ptr, sizeof(powerd_cookie_t)); |
92 | - g_message("Got cookie: %s", *cookie); |
93 | + cli_debug("Got cookie: %s", *cookie); |
94 | } |
95 | |
96 | g_variant_unref(ret); |
97 | @@ -145,7 +155,7 @@ |
98 | gboolean success = TRUE; |
99 | |
100 | if (cookie == NULL) { |
101 | - g_warning("requires a valid pointer for cookie"); |
102 | + cli_warn("NULL cookie passed to %s", __func__); |
103 | return FALSE; |
104 | } |
105 | |
106 | @@ -157,18 +167,18 @@ |
107 | NULL, |
108 | &error); |
109 | if (ret == NULL) { |
110 | - g_warning("Error when calling requestDisplayState: %s", error->message); |
111 | + cli_warn("requestDisplayState failed: %s", error->message); |
112 | g_error_free(error); |
113 | return FALSE; |
114 | } |
115 | |
116 | g_variant_get(ret, "(&s)", &cookie_ptr); |
117 | if (strlen(cookie_ptr) != sizeof(powerd_cookie_t) - 1) { |
118 | - g_warning("Returned cookie has incorrect size"); |
119 | + cli_warn("Returned cookie has incorrect size"); |
120 | success = FALSE; |
121 | } else { |
122 | strncpy(*cookie, cookie_ptr, sizeof(powerd_cookie_t)); |
123 | - g_message("Got cookie: %s", *cookie); |
124 | + cli_debug("Got cookie: %s", *cookie); |
125 | } |
126 | |
127 | g_variant_unref(ret); |
128 | @@ -184,7 +194,7 @@ |
129 | gboolean success = TRUE; |
130 | |
131 | if (cookie == NULL) { |
132 | - g_warning("requires a valid pointer to a cookie"); |
133 | + cli_warn("NULL cookie passed to %s", __func__); |
134 | return FALSE; |
135 | } |
136 | |
137 | @@ -197,7 +207,7 @@ |
138 | NULL, |
139 | &error); |
140 | if (!ret) { |
141 | - g_warning("Error when calling requestDisplayState: %s", error->message); |
142 | + cli_warn("requestDisplayState failed: %s", error->message); |
143 | g_error_free(error); |
144 | return FALSE; |
145 | } |
146 | @@ -223,27 +233,38 @@ |
147 | NULL, |
148 | &error); |
149 | if (ret == NULL) { |
150 | - g_warning("Error when calling listSysRequests: %s", error->message); |
151 | + cli_warn("listSysRequests failed: %s", error->message); |
152 | g_error_free(error); |
153 | } |
154 | else { |
155 | g_variant_get(ret, "(a(si))", &iter); |
156 | - g_message("Current Sys Requests:"); |
157 | while ((item = g_variant_iter_next_value (iter))) { |
158 | g_variant_get_child (item, 0, "s", &psr.owner); |
159 | g_variant_get_child (item, 1, "i", &psr.state); |
160 | - g_message(" Owner: %s, State: %d", psr.owner, psr.state); |
161 | g_array_append_val(retarray, psr); |
162 | g_variant_unref(item); |
163 | } |
164 | - if (retarray->len == 0) { |
165 | - g_message(" None"); |
166 | - } |
167 | g_variant_unref(ret); |
168 | } |
169 | return retarray; |
170 | } |
171 | |
172 | +static void |
173 | +printSysRequests(GArray *requests) |
174 | +{ |
175 | + int i; |
176 | + struct PublicSysRequest *psr; |
177 | + printf("System State Requests:\n"); |
178 | + if (requests->len == 0) { |
179 | + printf(" None\n"); |
180 | + } else { |
181 | + for (i = 0; i < requests->len; i++) { |
182 | + psr = &g_array_index(requests, struct PublicSysRequest, i); |
183 | + printf(" Owner: %s, State: %d\n", psr->owner, psr->state); |
184 | + } |
185 | + } |
186 | +} |
187 | + |
188 | static GArray* |
189 | listDisplayRequests() |
190 | { |
191 | @@ -261,30 +282,41 @@ |
192 | NULL, |
193 | &error); |
194 | if (ret == NULL) { |
195 | - g_warning("Error when calling listDisplayRequests: %s", error->message); |
196 | + cli_warn("listDisplayRequests failed: %s", error->message); |
197 | g_error_free(error); |
198 | } |
199 | else { |
200 | g_variant_get(ret, "(a(siiu))", &iter); |
201 | - g_message("Current Display Requests:"); |
202 | while ((item = g_variant_iter_next_value (iter))) { |
203 | g_variant_get_child(item, 0, "s", &pdr.owner); |
204 | g_variant_get_child(item, 1, "i", &pdr.state); |
205 | g_variant_get_child(item, 2, "i", &pdr.brightness); |
206 | g_variant_get_child(item, 3, "u", &pdr.flags); |
207 | - g_message(" Owner: %s, State: %d, Brightness: %d, "\ |
208 | - "Flags: %u", pdr.owner, pdr.state, pdr.brightness, pdr.flags); |
209 | g_array_append_val(retarray, pdr); |
210 | g_variant_unref(item); |
211 | } |
212 | - if (retarray->len == 0) { |
213 | - g_message(" None"); |
214 | - } |
215 | g_variant_unref(ret); |
216 | } |
217 | return retarray; |
218 | } |
219 | |
220 | +static void |
221 | +printDisplayRequests(GArray *requests) |
222 | +{ |
223 | + int i; |
224 | + struct PublicDispRequest *pdr; |
225 | + printf("Display State Requests:\n"); |
226 | + if (requests->len == 0) { |
227 | + printf(" None\n"); |
228 | + } else { |
229 | + for (i = 0; i < requests->len; i++) { |
230 | + pdr = &g_array_index(requests, struct PublicDispRequest, i); |
231 | + printf(" Owner: %s, State: %d, Brightness: %d, Flags: %#08x\n", |
232 | + pdr->owner, pdr->state, pdr->brightness, pdr->flags); |
233 | + } |
234 | + } |
235 | +} |
236 | + |
237 | static gboolean |
238 | clearSysState(powerd_cookie_t cookie) |
239 | { |
240 | @@ -299,7 +331,7 @@ |
241 | NULL, |
242 | &error); |
243 | if (ret == NULL) { |
244 | - g_warning("Error when calling clearSysState: %s", error->message); |
245 | + cli_warn("clearSysState failed: %s", error->message); |
246 | g_error_free(error); |
247 | return FALSE; |
248 | } |
249 | @@ -321,7 +353,7 @@ |
250 | NULL, |
251 | &error); |
252 | if (ret == NULL) { |
253 | - g_warning("Error when calling clearDisplayState: %s", error->message); |
254 | + cli_warn("clearDisplayState failed: %s", error->message); |
255 | g_error_free(error); |
256 | return FALSE; |
257 | } |
258 | @@ -338,7 +370,7 @@ |
259 | |
260 | g_signal_connect(proxy, "g-signal", G_CALLBACK (on_powerd_signal), NULL); |
261 | |
262 | - g_message("Waiting for events"); |
263 | + printf("Waiting for events, press ctrl-c to quit\n"); |
264 | g_main_loop_run(main_loop); |
265 | g_main_loop_unref(main_loop); |
266 | } |
267 | @@ -360,8 +392,8 @@ |
268 | g_array_free(requests, TRUE); |
269 | } |
270 | else { |
271 | - g_warning("Did not find child's dbusname"); |
272 | - g_message("result: FAILED"); |
273 | + printf("Did not find child's dbus name\n"); |
274 | + printf(" result: FAILED\n"); |
275 | } |
276 | |
277 | // Make sure clean-up didn't remove our request, note we don't pass |
278 | @@ -399,7 +431,7 @@ |
279 | status = g_io_channel_read_line(channel, &string, &size, NULL, NULL); |
280 | if (status == G_IO_STATUS_NORMAL) { |
281 | if (sscanf(string, "DBUSNAME: %s\n", test_dbusname) == 1) { |
282 | - printf("Parent found child's dbusname as: %s\n", test_dbusname); |
283 | + cli_debug("Parent found child's dbusname as: %s", test_dbusname); |
284 | } |
285 | g_free(string); |
286 | } |
287 | @@ -426,7 +458,7 @@ |
288 | NULL, NULL, &pid, NULL, &out, NULL, NULL); |
289 | |
290 | if (!ret) { |
291 | - printf("Failed to spawn test app\n"); |
292 | + cli_warn("Failed to spawn test app"); |
293 | return; |
294 | } |
295 | |
296 | @@ -446,6 +478,8 @@ |
297 | powerd_cookie_t cookie, cookies[TEST_NUM_SYS_REQUESTS]; |
298 | GArray *requests = NULL; |
299 | |
300 | + silence_errors(TRUE); |
301 | + |
302 | // Hold active state request as long we're running tests |
303 | requestSysState(POWERD_SYS_STATE_ACTIVE, &main_cookie); |
304 | |
305 | @@ -491,6 +525,8 @@ |
306 | //cleanup |
307 | do_test(clearSysState(main_cookie) == TRUE); |
308 | do_test(checkForDbusName(powerd_cli_bus_name, 0, requests, TRUE)); |
309 | + |
310 | + silence_errors(FALSE); |
311 | } |
312 | |
313 | static void |
314 | @@ -502,6 +538,8 @@ |
315 | GArray *requests = NULL; |
316 | struct PublicDispRequest pdr = {0,}; |
317 | |
318 | + silence_errors(TRUE); |
319 | + |
320 | // Hold active state request as long we're running tests |
321 | requestSysState(POWERD_SYS_STATE_ACTIVE, &main_cookie); |
322 | |
323 | @@ -588,6 +626,8 @@ |
324 | //cleanup |
325 | do_test(clearSysState(main_cookie) == TRUE); |
326 | do_test(checkForDbusName(powerd_cli_bus_name, 0, requests, TRUE)); |
327 | + |
328 | + silence_errors(FALSE); |
329 | } |
330 | |
331 | // Check that dbus owner appears count times in a list of sys/disp requests |
332 | @@ -603,7 +643,7 @@ |
333 | struct PublicDispRequest *pdr; |
334 | |
335 | if (requests == NULL) { |
336 | - g_warning("requests is invalid"); |
337 | + cli_warn("NULL requests passed to %s", __func__); |
338 | return FALSE; |
339 | } |
340 | |
341 | @@ -624,7 +664,7 @@ |
342 | } |
343 | |
344 | if (found != count) { |
345 | - g_warning("Expected %d requests from DbusName (%s), found %d", |
346 | + cli_debug("Expected %d requests from DbusName (%s), found %d", |
347 | count, dbusname, found); |
348 | return FALSE; |
349 | } |
350 | @@ -647,11 +687,11 @@ |
351 | |
352 | if (!strcasecmp(argv[2],"on")) { |
353 | pdr->state = POWERD_DISPLAY_STATE_ON; |
354 | - printf("Requesting Display On\n"); |
355 | + cli_debug("Requesting Display On"); |
356 | } |
357 | else if (!strcasecmp(argv[2],"dc")) { |
358 | pdr->state = POWERD_DISPLAY_STATE_DONT_CARE; |
359 | - printf("Requesting Display Don't Care\n"); |
360 | + cli_debug("Requesting Display Don't Care"); |
361 | } |
362 | else { |
363 | fprintf(stderr,"invalid state %s, must be either on or dc\n", |
364 | @@ -661,14 +701,14 @@ |
365 | |
366 | if (!strcasecmp(argv[3],"dc")) { |
367 | pdr->brightness = POWERD_DISPLAY_BRIGHTNESS_DONT_CARE; |
368 | - printf("Requesting Brightness Don't Care\n"); |
369 | + cli_debug("Requesting Brightness Don't Care"); |
370 | } |
371 | else if (!strcasecmp(argv[3],"dim")) { |
372 | - printf("Requesting Brightness Dim\n"); |
373 | + cli_debug("Requesting Brightness Dim"); |
374 | pdr->brightness = POWERD_DISPLAY_BRIGHTNESS_DIM; |
375 | } |
376 | else if (!strcasecmp(argv[3],"bright")) { |
377 | - printf("Requesting Brightness Bright\n"); |
378 | + cli_debug("Requesting Brightness Bright"); |
379 | pdr->brightness = POWERD_DISPLAY_BRIGHTNESS_BRIGHT; |
380 | } |
381 | else { |
382 | @@ -682,11 +722,11 @@ |
383 | for (i=4; i<argc; i++) { |
384 | if (!strcmp(argv[i],"proximity")) { |
385 | pdr->flags |= POWERD_DISPLAY_FLAG_USE_PROXIMITY; |
386 | - printf("Requesting Proximity Sensor Enabled\n"); |
387 | + cli_debug("Requesting Proximity Sensor Enabled"); |
388 | } |
389 | else if (!strcmp(argv[i],"disableab")) { |
390 | pdr->flags |= POWERD_DISPLAY_FLAG_DISABLE_AUTOBRIGHTNESS; |
391 | - printf("Requesting Proximity Disable AutoBrightness\n"); |
392 | + cli_debug("Requesting Proximity Disable AutoBrightness"); |
393 | } |
394 | } |
395 | |
396 | @@ -779,16 +819,17 @@ |
397 | &error); |
398 | |
399 | if (error != NULL) { |
400 | - g_error("error, could not acquire system bus proxy for powerd: %s", |
401 | - error->message); |
402 | + cli_warn("could not connect to powerd: %s", error->message); |
403 | g_error_free(error); |
404 | return -1; |
405 | } |
406 | |
407 | if (!strcmp(argv[1],"list")) { |
408 | requests = listSysRequests(); |
409 | + printSysRequests(requests); |
410 | g_array_free(requests, TRUE); |
411 | requests = listDisplayRequests(); |
412 | + printDisplayRequests(requests); |
413 | g_array_free(requests, TRUE); |
414 | } |
415 | else if (!strcmp(argv[1],"active-nc")) { |
416 | @@ -875,7 +916,7 @@ |
417 | else if (!strcmp(argv[1],"dbusnametest")) { |
418 | bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL); |
419 | bus_name = g_dbus_connection_get_unique_name(bus); |
420 | - g_message("Child dbus name is %s", bus_name); |
421 | + cli_debug("Child dbus name is %s", bus_name); |
422 | // This printf is read by the parent |
423 | printf("DBUSNAME: %s\n", bus_name); |
424 | // Grab some requests so we can see that they get cleared later |
Looks cleaner, to reiterate what I said on IRC, I had someone look for "We Get Signal" when a MMS was sent, he didn't see it. When MMS does work, we may need to bring that back because it might be a different signal. tl;dr: We need to test screen on with MMS once it works.