Merge lp:~sforshee/powerd/clean-up-cli-output into lp:powerd

Proposed by Seth Forshee
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
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

To post a comment you must log in.
Revision history for this message
Matt Fischer (mfisch) 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.

review: Approve
Revision history for this message
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.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'cli/powerd-cli.c'
--- cli/powerd-cli.c 2013-07-02 14:50:36 +0000
+++ cli/powerd-cli.c 2013-07-17 18:59:33 +0000
@@ -32,15 +32,21 @@
32#define do_test(test) \32#define do_test(test) \
33 ({ \33 ({ \
34 gboolean result; \34 gboolean result; \
35 g_message("Test: " #test); \35 printf("Test: " #test "\n"); \
36 result = (test); \36 result = (test); \
37 g_message(" result: %s", result ? "PASSED" : "FAILED"); \37 printf(" result: %s\n", result ? "PASSED" : "FAILED"); \
38 result; \38 result; \
39 })39 })
4040
41#define TEST_NUM_SYS_REQUESTS 541#define TEST_NUM_SYS_REQUESTS 5
42#define TEST_NUM_DISP_REQUESTS POWERD_NUM_DISPLAY_STATES * POWERD_NUM_DISPLAY_BRIGHTNESS_STATES42#define TEST_NUM_DISP_REQUESTS POWERD_NUM_DISPLAY_STATES * POWERD_NUM_DISPLAY_BRIGHTNESS_STATES
4343
44/* Set to TRUE during tests to silence expected errors */
45static gboolean silent_errors = FALSE;
46
47#define cli_warn(f, a...) do { if (!silent_errors) g_warning(f, ##a); } while (0)
48#define cli_debug(f, a...) g_debug(f, ##a)
49
44GDBusProxy *powerd_proxy = NULL;50GDBusProxy *powerd_proxy = NULL;
45char test_dbusname[128] = "";51char test_dbusname[128] = "";
4652
@@ -67,6 +73,12 @@
67static void sig_handler(int signum);73static void sig_handler(int signum);
6874
69static void75static void
76silence_errors(gboolean silent)
77{
78 silent_errors = silent;
79}
80
81static void
70on_powerd_signal (GDBusProxy *proxy,82on_powerd_signal (GDBusProxy *proxy,
71 gchar *sender_name,83 gchar *sender_name,
72 gchar *signal_name,84 gchar *signal_name,
@@ -78,20 +90,18 @@
78 int display_brightness;90 int display_brightness;
79 guint32 display_flags;91 guint32 display_flags;
8092
81 g_warning("we get signal from %s: %s", sender_name, signal_name);
82
83 if (!strcmp(signal_name,"SysPowerStateChange")) {93 if (!strcmp(signal_name,"SysPowerStateChange")) {
84 g_variant_get(parameters, "(i)", &system_state);94 g_variant_get(parameters, "(i)", &system_state);
85 g_warning("System State is now: %d", system_state);95 printf("Received %s: state=%d\n", signal_name, system_state);
86 }96 }
87 else if (!strcmp(signal_name,"DisplayPowerStateChange")) {97 else if (!strcmp(signal_name,"DisplayPowerStateChange")) {
88 g_variant_get(parameters, "(iiu)", &display_state,98 g_variant_get(parameters, "(iiu)", &display_state,
89 &display_brightness, &display_flags);99 &display_brightness, &display_flags);
90 g_warning("Display State is now: %d, Brightness: %d, Flags: %u",100 printf("Received %s: state=%d brightness=%d flags=%#08x\n",
91 display_state, display_brightness, display_flags);101 signal_name, display_state, display_brightness, display_flags);
92 }102 }
93 else {103 else {
94 g_warning("Unknown signal from powerd");104 cli_debug("Unknown signal from %s: %s", sender_name, signal_name);
95 }105 }
96}106}
97107
@@ -105,7 +115,7 @@
105 gboolean success = TRUE;115 gboolean success = TRUE;
106116
107 if (cookie == NULL) {117 if (cookie == NULL) {
108 g_warning("requires a valid pointer for cookie");118 cli_warn("NULL cookie passed to %s", __func__);
109 return FALSE;119 return FALSE;
110 }120 }
111121
@@ -117,18 +127,18 @@
117 NULL,127 NULL,
118 &error);128 &error);
119 if (ret == NULL) {129 if (ret == NULL) {
120 g_warning("Error when calling requestSysState: %s", error->message);130 cli_warn("requestSysState failed: %s", error->message);
121 g_error_free(error);131 g_error_free(error);
122 return FALSE;132 return FALSE;
123 }133 }
124134
125 g_variant_get(ret, "(&s)", &cookie_ptr);135 g_variant_get(ret, "(&s)", &cookie_ptr);
126 if (strlen(cookie_ptr) != sizeof(powerd_cookie_t) - 1) {136 if (strlen(cookie_ptr) != sizeof(powerd_cookie_t) - 1) {
127 g_warning("Returned cookie has incorrect size");137 cli_warn("Returned cookie has incorrect size");
128 success = FALSE;138 success = FALSE;
129 } else {139 } else {
130 strncpy(*cookie, cookie_ptr, sizeof(powerd_cookie_t));140 strncpy(*cookie, cookie_ptr, sizeof(powerd_cookie_t));
131 g_message("Got cookie: %s", *cookie);141 cli_debug("Got cookie: %s", *cookie);
132 }142 }
133143
134 g_variant_unref(ret);144 g_variant_unref(ret);
@@ -145,7 +155,7 @@
145 gboolean success = TRUE;155 gboolean success = TRUE;
146156
147 if (cookie == NULL) {157 if (cookie == NULL) {
148 g_warning("requires a valid pointer for cookie");158 cli_warn("NULL cookie passed to %s", __func__);
149 return FALSE;159 return FALSE;
150 }160 }
151161
@@ -157,18 +167,18 @@
157 NULL,167 NULL,
158 &error);168 &error);
159 if (ret == NULL) {169 if (ret == NULL) {
160 g_warning("Error when calling requestDisplayState: %s", error->message);170 cli_warn("requestDisplayState failed: %s", error->message);
161 g_error_free(error);171 g_error_free(error);
162 return FALSE;172 return FALSE;
163 }173 }
164174
165 g_variant_get(ret, "(&s)", &cookie_ptr);175 g_variant_get(ret, "(&s)", &cookie_ptr);
166 if (strlen(cookie_ptr) != sizeof(powerd_cookie_t) - 1) {176 if (strlen(cookie_ptr) != sizeof(powerd_cookie_t) - 1) {
167 g_warning("Returned cookie has incorrect size");177 cli_warn("Returned cookie has incorrect size");
168 success = FALSE;178 success = FALSE;
169 } else {179 } else {
170 strncpy(*cookie, cookie_ptr, sizeof(powerd_cookie_t));180 strncpy(*cookie, cookie_ptr, sizeof(powerd_cookie_t));
171 g_message("Got cookie: %s", *cookie);181 cli_debug("Got cookie: %s", *cookie);
172 }182 }
173183
174 g_variant_unref(ret);184 g_variant_unref(ret);
@@ -184,7 +194,7 @@
184 gboolean success = TRUE;194 gboolean success = TRUE;
185195
186 if (cookie == NULL) {196 if (cookie == NULL) {
187 g_warning("requires a valid pointer to a cookie");197 cli_warn("NULL cookie passed to %s", __func__);
188 return FALSE;198 return FALSE;
189 }199 }
190200
@@ -197,7 +207,7 @@
197 NULL,207 NULL,
198 &error);208 &error);
199 if (!ret) {209 if (!ret) {
200 g_warning("Error when calling requestDisplayState: %s", error->message);210 cli_warn("requestDisplayState failed: %s", error->message);
201 g_error_free(error);211 g_error_free(error);
202 return FALSE;212 return FALSE;
203 }213 }
@@ -223,27 +233,38 @@
223 NULL,233 NULL,
224 &error);234 &error);
225 if (ret == NULL) {235 if (ret == NULL) {
226 g_warning("Error when calling listSysRequests: %s", error->message);236 cli_warn("listSysRequests failed: %s", error->message);
227 g_error_free(error);237 g_error_free(error);
228 }238 }
229 else {239 else {
230 g_variant_get(ret, "(a(si))", &iter);240 g_variant_get(ret, "(a(si))", &iter);
231 g_message("Current Sys Requests:");
232 while ((item = g_variant_iter_next_value (iter))) {241 while ((item = g_variant_iter_next_value (iter))) {
233 g_variant_get_child (item, 0, "s", &psr.owner);242 g_variant_get_child (item, 0, "s", &psr.owner);
234 g_variant_get_child (item, 1, "i", &psr.state);243 g_variant_get_child (item, 1, "i", &psr.state);
235 g_message(" Owner: %s, State: %d", psr.owner, psr.state);
236 g_array_append_val(retarray, psr);244 g_array_append_val(retarray, psr);
237 g_variant_unref(item);245 g_variant_unref(item);
238 }246 }
239 if (retarray->len == 0) {
240 g_message(" None");
241 }
242 g_variant_unref(ret);247 g_variant_unref(ret);
243 }248 }
244 return retarray;249 return retarray;
245}250}
246251
252static void
253printSysRequests(GArray *requests)
254{
255 int i;
256 struct PublicSysRequest *psr;
257 printf("System State Requests:\n");
258 if (requests->len == 0) {
259 printf(" None\n");
260 } else {
261 for (i = 0; i < requests->len; i++) {
262 psr = &g_array_index(requests, struct PublicSysRequest, i);
263 printf(" Owner: %s, State: %d\n", psr->owner, psr->state);
264 }
265 }
266}
267
247static GArray*268static GArray*
248listDisplayRequests()269listDisplayRequests()
249{270{
@@ -261,30 +282,41 @@
261 NULL,282 NULL,
262 &error);283 &error);
263 if (ret == NULL) {284 if (ret == NULL) {
264 g_warning("Error when calling listDisplayRequests: %s", error->message);285 cli_warn("listDisplayRequests failed: %s", error->message);
265 g_error_free(error);286 g_error_free(error);
266 }287 }
267 else {288 else {
268 g_variant_get(ret, "(a(siiu))", &iter);289 g_variant_get(ret, "(a(siiu))", &iter);
269 g_message("Current Display Requests:");
270 while ((item = g_variant_iter_next_value (iter))) {290 while ((item = g_variant_iter_next_value (iter))) {
271 g_variant_get_child(item, 0, "s", &pdr.owner);291 g_variant_get_child(item, 0, "s", &pdr.owner);
272 g_variant_get_child(item, 1, "i", &pdr.state);292 g_variant_get_child(item, 1, "i", &pdr.state);
273 g_variant_get_child(item, 2, "i", &pdr.brightness);293 g_variant_get_child(item, 2, "i", &pdr.brightness);
274 g_variant_get_child(item, 3, "u", &pdr.flags);294 g_variant_get_child(item, 3, "u", &pdr.flags);
275 g_message(" Owner: %s, State: %d, Brightness: %d, "\
276 "Flags: %u", pdr.owner, pdr.state, pdr.brightness, pdr.flags);
277 g_array_append_val(retarray, pdr);295 g_array_append_val(retarray, pdr);
278 g_variant_unref(item);296 g_variant_unref(item);
279 }297 }
280 if (retarray->len == 0) {
281 g_message(" None");
282 }
283 g_variant_unref(ret);298 g_variant_unref(ret);
284 }299 }
285 return retarray;300 return retarray;
286}301}
287302
303static void
304printDisplayRequests(GArray *requests)
305{
306 int i;
307 struct PublicDispRequest *pdr;
308 printf("Display State Requests:\n");
309 if (requests->len == 0) {
310 printf(" None\n");
311 } else {
312 for (i = 0; i < requests->len; i++) {
313 pdr = &g_array_index(requests, struct PublicDispRequest, i);
314 printf(" Owner: %s, State: %d, Brightness: %d, Flags: %#08x\n",
315 pdr->owner, pdr->state, pdr->brightness, pdr->flags);
316 }
317 }
318}
319
288static gboolean320static gboolean
289clearSysState(powerd_cookie_t cookie)321clearSysState(powerd_cookie_t cookie)
290{322{
@@ -299,7 +331,7 @@
299 NULL,331 NULL,
300 &error);332 &error);
301 if (ret == NULL) {333 if (ret == NULL) {
302 g_warning("Error when calling clearSysState: %s", error->message);334 cli_warn("clearSysState failed: %s", error->message);
303 g_error_free(error);335 g_error_free(error);
304 return FALSE;336 return FALSE;
305 }337 }
@@ -321,7 +353,7 @@
321 NULL,353 NULL,
322 &error);354 &error);
323 if (ret == NULL) {355 if (ret == NULL) {
324 g_warning("Error when calling clearDisplayState: %s", error->message);356 cli_warn("clearDisplayState failed: %s", error->message);
325 g_error_free(error);357 g_error_free(error);
326 return FALSE;358 return FALSE;
327 }359 }
@@ -338,7 +370,7 @@
338370
339 g_signal_connect(proxy, "g-signal", G_CALLBACK (on_powerd_signal), NULL);371 g_signal_connect(proxy, "g-signal", G_CALLBACK (on_powerd_signal), NULL);
340372
341 g_message("Waiting for events");373 printf("Waiting for events, press ctrl-c to quit\n");
342 g_main_loop_run(main_loop);374 g_main_loop_run(main_loop);
343 g_main_loop_unref(main_loop);375 g_main_loop_unref(main_loop);
344}376}
@@ -360,8 +392,8 @@
360 g_array_free(requests, TRUE);392 g_array_free(requests, TRUE);
361 }393 }
362 else {394 else {
363 g_warning("Did not find child's dbusname");395 printf("Did not find child's dbus name\n");
364 g_message("result: FAILED");396 printf(" result: FAILED\n");
365 }397 }
366398
367 // Make sure clean-up didn't remove our request, note we don't pass399 // Make sure clean-up didn't remove our request, note we don't pass
@@ -399,7 +431,7 @@
399 status = g_io_channel_read_line(channel, &string, &size, NULL, NULL);431 status = g_io_channel_read_line(channel, &string, &size, NULL, NULL);
400 if (status == G_IO_STATUS_NORMAL) {432 if (status == G_IO_STATUS_NORMAL) {
401 if (sscanf(string, "DBUSNAME: %s\n", test_dbusname) == 1) {433 if (sscanf(string, "DBUSNAME: %s\n", test_dbusname) == 1) {
402 printf("Parent found child's dbusname as: %s\n", test_dbusname);434 cli_debug("Parent found child's dbusname as: %s", test_dbusname);
403 }435 }
404 g_free(string);436 g_free(string);
405 }437 }
@@ -426,7 +458,7 @@
426 NULL, NULL, &pid, NULL, &out, NULL, NULL);458 NULL, NULL, &pid, NULL, &out, NULL, NULL);
427459
428 if (!ret) {460 if (!ret) {
429 printf("Failed to spawn test app\n");461 cli_warn("Failed to spawn test app");
430 return;462 return;
431 }463 }
432464
@@ -446,6 +478,8 @@
446 powerd_cookie_t cookie, cookies[TEST_NUM_SYS_REQUESTS];478 powerd_cookie_t cookie, cookies[TEST_NUM_SYS_REQUESTS];
447 GArray *requests = NULL;479 GArray *requests = NULL;
448480
481 silence_errors(TRUE);
482
449 // Hold active state request as long we're running tests483 // Hold active state request as long we're running tests
450 requestSysState(POWERD_SYS_STATE_ACTIVE, &main_cookie);484 requestSysState(POWERD_SYS_STATE_ACTIVE, &main_cookie);
451485
@@ -491,6 +525,8 @@
491 //cleanup525 //cleanup
492 do_test(clearSysState(main_cookie) == TRUE);526 do_test(clearSysState(main_cookie) == TRUE);
493 do_test(checkForDbusName(powerd_cli_bus_name, 0, requests, TRUE));527 do_test(checkForDbusName(powerd_cli_bus_name, 0, requests, TRUE));
528
529 silence_errors(FALSE);
494}530}
495531
496static void532static void
@@ -502,6 +538,8 @@
502 GArray *requests = NULL;538 GArray *requests = NULL;
503 struct PublicDispRequest pdr = {0,};539 struct PublicDispRequest pdr = {0,};
504540
541 silence_errors(TRUE);
542
505 // Hold active state request as long we're running tests543 // Hold active state request as long we're running tests
506 requestSysState(POWERD_SYS_STATE_ACTIVE, &main_cookie);544 requestSysState(POWERD_SYS_STATE_ACTIVE, &main_cookie);
507545
@@ -588,6 +626,8 @@
588 //cleanup626 //cleanup
589 do_test(clearSysState(main_cookie) == TRUE);627 do_test(clearSysState(main_cookie) == TRUE);
590 do_test(checkForDbusName(powerd_cli_bus_name, 0, requests, TRUE));628 do_test(checkForDbusName(powerd_cli_bus_name, 0, requests, TRUE));
629
630 silence_errors(FALSE);
591}631}
592632
593// Check that dbus owner appears count times in a list of sys/disp requests633// Check that dbus owner appears count times in a list of sys/disp requests
@@ -603,7 +643,7 @@
603 struct PublicDispRequest *pdr;643 struct PublicDispRequest *pdr;
604644
605 if (requests == NULL) {645 if (requests == NULL) {
606 g_warning("requests is invalid");646 cli_warn("NULL requests passed to %s", __func__);
607 return FALSE;647 return FALSE;
608 }648 }
609649
@@ -624,7 +664,7 @@
624 }664 }
625665
626 if (found != count) {666 if (found != count) {
627 g_warning("Expected %d requests from DbusName (%s), found %d",667 cli_debug("Expected %d requests from DbusName (%s), found %d",
628 count, dbusname, found);668 count, dbusname, found);
629 return FALSE;669 return FALSE;
630 }670 }
@@ -647,11 +687,11 @@
647687
648 if (!strcasecmp(argv[2],"on")) {688 if (!strcasecmp(argv[2],"on")) {
649 pdr->state = POWERD_DISPLAY_STATE_ON;689 pdr->state = POWERD_DISPLAY_STATE_ON;
650 printf("Requesting Display On\n");690 cli_debug("Requesting Display On");
651 }691 }
652 else if (!strcasecmp(argv[2],"dc")) {692 else if (!strcasecmp(argv[2],"dc")) {
653 pdr->state = POWERD_DISPLAY_STATE_DONT_CARE;693 pdr->state = POWERD_DISPLAY_STATE_DONT_CARE;
654 printf("Requesting Display Don't Care\n");694 cli_debug("Requesting Display Don't Care");
655 }695 }
656 else {696 else {
657 fprintf(stderr,"invalid state %s, must be either on or dc\n",697 fprintf(stderr,"invalid state %s, must be either on or dc\n",
@@ -661,14 +701,14 @@
661701
662 if (!strcasecmp(argv[3],"dc")) {702 if (!strcasecmp(argv[3],"dc")) {
663 pdr->brightness = POWERD_DISPLAY_BRIGHTNESS_DONT_CARE;703 pdr->brightness = POWERD_DISPLAY_BRIGHTNESS_DONT_CARE;
664 printf("Requesting Brightness Don't Care\n");704 cli_debug("Requesting Brightness Don't Care");
665 }705 }
666 else if (!strcasecmp(argv[3],"dim")) {706 else if (!strcasecmp(argv[3],"dim")) {
667 printf("Requesting Brightness Dim\n");707 cli_debug("Requesting Brightness Dim");
668 pdr->brightness = POWERD_DISPLAY_BRIGHTNESS_DIM;708 pdr->brightness = POWERD_DISPLAY_BRIGHTNESS_DIM;
669 }709 }
670 else if (!strcasecmp(argv[3],"bright")) {710 else if (!strcasecmp(argv[3],"bright")) {
671 printf("Requesting Brightness Bright\n");711 cli_debug("Requesting Brightness Bright");
672 pdr->brightness = POWERD_DISPLAY_BRIGHTNESS_BRIGHT;712 pdr->brightness = POWERD_DISPLAY_BRIGHTNESS_BRIGHT;
673 }713 }
674 else {714 else {
@@ -682,11 +722,11 @@
682 for (i=4; i<argc; i++) {722 for (i=4; i<argc; i++) {
683 if (!strcmp(argv[i],"proximity")) {723 if (!strcmp(argv[i],"proximity")) {
684 pdr->flags |= POWERD_DISPLAY_FLAG_USE_PROXIMITY;724 pdr->flags |= POWERD_DISPLAY_FLAG_USE_PROXIMITY;
685 printf("Requesting Proximity Sensor Enabled\n");725 cli_debug("Requesting Proximity Sensor Enabled");
686 }726 }
687 else if (!strcmp(argv[i],"disableab")) {727 else if (!strcmp(argv[i],"disableab")) {
688 pdr->flags |= POWERD_DISPLAY_FLAG_DISABLE_AUTOBRIGHTNESS;728 pdr->flags |= POWERD_DISPLAY_FLAG_DISABLE_AUTOBRIGHTNESS;
689 printf("Requesting Proximity Disable AutoBrightness\n");729 cli_debug("Requesting Proximity Disable AutoBrightness");
690 }730 }
691 }731 }
692732
@@ -779,16 +819,17 @@
779 &error);819 &error);
780820
781 if (error != NULL) {821 if (error != NULL) {
782 g_error("error, could not acquire system bus proxy for powerd: %s",822 cli_warn("could not connect to powerd: %s", error->message);
783 error->message);
784 g_error_free(error);823 g_error_free(error);
785 return -1;824 return -1;
786 }825 }
787826
788 if (!strcmp(argv[1],"list")) {827 if (!strcmp(argv[1],"list")) {
789 requests = listSysRequests();828 requests = listSysRequests();
829 printSysRequests(requests);
790 g_array_free(requests, TRUE);830 g_array_free(requests, TRUE);
791 requests = listDisplayRequests();831 requests = listDisplayRequests();
832 printDisplayRequests(requests);
792 g_array_free(requests, TRUE);833 g_array_free(requests, TRUE);
793 }834 }
794 else if (!strcmp(argv[1],"active-nc")) {835 else if (!strcmp(argv[1],"active-nc")) {
@@ -875,7 +916,7 @@
875 else if (!strcmp(argv[1],"dbusnametest")) {916 else if (!strcmp(argv[1],"dbusnametest")) {
876 bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);917 bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
877 bus_name = g_dbus_connection_get_unique_name(bus);918 bus_name = g_dbus_connection_get_unique_name(bus);
878 g_message("Child dbus name is %s", bus_name);919 cli_debug("Child dbus name is %s", bus_name);
879 // This printf is read by the parent920 // This printf is read by the parent
880 printf("DBUSNAME: %s\n", bus_name);921 printf("DBUSNAME: %s\n", bus_name);
881 // Grab some requests so we can see that they get cleared later922 // Grab some requests so we can see that they get cleared later

Subscribers

People subscribed via source and target branches