aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Fjeldtvedt <jaffe1@gmail.com>2016-07-21 17:45:12 +0200
committerHans Verkuil <hans.verkuil@cisco.com>2016-07-21 18:33:44 +0200
commit4c3f1492e308c7f75b6fe9c85754a68e3000aa35 (patch)
treea84867f939184edde01341f94694b2d7cb3bf258
parent3ba08fd00d4343b49788772bf324b09ce7badbea (diff)
cec-compliance: extract common power status check code
The common code for interactively asking the user to change power state and checking for the correct state is extracted into a new function. The logic is altered slightly: - The question is printed once, before the loop - It is checked for whether the device supports power status reporting at all. If it is, we will have to assume that the user did what was asked. TODO: return error code instead of bool to make the calling test know about this? - Not being able to retrieve the power status is accepted, and the user can try again instead of the test failing. Signed-off-by: Johan Fjeldtvedt <jaffe1@gmail.com> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
-rw-r--r--utils/cec-compliance/cec-power.cpp83
1 files changed, 41 insertions, 42 deletions
diff --git a/utils/cec-compliance/cec-power.cpp b/utils/cec-compliance/cec-power.cpp
index 635cdfaa..c7aa725e 100644
--- a/utils/cec-compliance/cec-power.cpp
+++ b/utils/cec-compliance/cec-power.cpp
@@ -30,6 +30,44 @@
#include "cec-compliance.h"
+
+static bool get_power_status(struct node *node, unsigned me, unsigned la, __u8 &power_status)
+{
+ struct cec_msg msg = {};
+
+ cec_msg_init(&msg, me, la);
+ cec_msg_give_device_power_status(&msg, true);
+ if (!transmit_timeout(node, &msg) || timed_out_or_abort(&msg))
+ return false;
+ cec_ops_report_power_status(&msg, &power_status);
+ return true;
+}
+
+static bool util_interactive_ensure_power_state(struct node *node, unsigned me, unsigned la, bool interactive,
+ __u8 target_pwr)
+{
+ interactive_info(true, "Please ensure that the device is in state %s.",
+ power_status2s(target_pwr));
+
+ if (!node->remote[la].has_power_status)
+ return true;
+
+ while (interactive) {
+ __u8 pwr;
+
+ if (!get_power_status(node, me, la, pwr))
+ announce("Failed to retrieve power status.");
+ else if (pwr == target_pwr)
+ return true;
+ else
+ announce("The device reported power status %s.", power_status2s(pwr));
+ fail_on_test(!question("Retry?"));
+ }
+
+ return true;
+}
+
+
/* Device Power Status */
static int power_status_probe(struct node *node, unsigned me, unsigned la, bool interactive)
@@ -57,18 +95,6 @@ struct remote_subtest power_status_subtests[] = {
const unsigned power_status_subtests_size = ARRAY_SIZE(power_status_subtests);
-static bool get_power_status(struct node *node, unsigned me, unsigned la, __u8 &power_status)
-{
- struct cec_msg msg = {};
-
- cec_msg_init(&msg, me, la);
- cec_msg_give_device_power_status(&msg, true);
- if (!transmit_timeout(node, &msg) || timed_out_or_abort(&msg))
- return false;
- cec_ops_report_power_status(&msg, &power_status);
- return true;
-}
-
/* One Touch Play */
@@ -76,16 +102,7 @@ static int one_touch_play_image_view_on(struct node *node, unsigned me, unsigned
{
struct cec_msg msg = {};
- while (interactive) {
- __u8 pwr;
-
- interactive_info(true, "Please ensure that the TV is in standby.");
- fail_on_test(!get_power_status(node, me, la, pwr));
- if (pwr == CEC_OP_POWER_STATUS_STANDBY)
- break;
- announce("The device reported power status %s.", power_status2s(pwr));
- fail_on_test(!question("Retry?"));
- }
+ fail_on_test(!util_interactive_ensure_power_state(node, me, la, interactive, CEC_OP_POWER_STATUS_STANDBY));
cec_msg_init(&msg, me, la);
cec_msg_image_view_on(&msg);
@@ -104,16 +121,7 @@ static int one_touch_play_text_view_on(struct node *node, unsigned me, unsigned
{
struct cec_msg msg = {};
- while (interactive) {
- __u8 pwr;
-
- interactive_info(true, "Please ensure that the TV is in standby.");
- fail_on_test(!get_power_status(node, me, la, pwr));
- if (pwr == CEC_OP_POWER_STATUS_STANDBY)
- break;
- announce("The device reported power status %s.", power_status2s(pwr));
- fail_on_test(!question("Retry?"));
- }
+ fail_on_test(!util_interactive_ensure_power_state(node, me, la, interactive, CEC_OP_POWER_STATUS_STANDBY));
cec_msg_init(&msg, me, la);
cec_msg_text_view_on(&msg);
@@ -250,16 +258,7 @@ static int standby_resume_standby(struct node *node, unsigned me, unsigned la, b
struct cec_msg msg = {};
unsigned unresponsive_time = 0;
- while (interactive) {
- __u8 pwr;
-
- interactive_info(true, "Please ensure that the device is in powered on state.");
- fail_on_test(!get_power_status(node, me, la, pwr));
- if (pwr == CEC_OP_POWER_STATUS_ON)
- break;
- announce("The device reported power status %s.", power_status2s(pwr));
- fail_on_test(!question("Retry?"));
- }
+ fail_on_test(!util_interactive_ensure_power_state(node, me, la, interactive, CEC_OP_POWER_STATUS_ON));
announce("Sending Standby message.");
cec_msg_init(&msg, me, la);

Privacy Policy