From: Lars Op den Kamp Date: Thu, 10 Nov 2011 17:30:00 +0000 (+0100) Subject: cec: show the power status as string instead of int X-Git-Tag: upstream/2.2.0~1^2~70 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=66c16b6967cb0272afbdcce34156a754f00e5311;p=deb_libcec.git cec: show the power status as string instead of int --- diff --git a/src/lib/devices/CECBusDevice.cpp b/src/lib/devices/CECBusDevice.cpp index 49ca7db..00a6bcd 100644 --- a/src/lib/devices/CECBusDevice.cpp +++ b/src/lib/devices/CECBusDevice.cpp @@ -315,7 +315,7 @@ void CCECBusDevice::SetPowerStatus(const cec_power_status powerStatus) if (m_powerStatus != powerStatus) { CStdString strLog; - strLog.Format(">> %s (%X): power status changed from %2x to %2x", GetLogicalAddressName(), m_iLogicalAddress, m_powerStatus, powerStatus); + strLog.Format(">> %s (%X): power status changed from '%s' to '%s'", GetLogicalAddressName(), m_iLogicalAddress, CCECCommandHandler::ToString(m_powerStatus), CCECCommandHandler::ToString(powerStatus)); m_processor->AddLog(CEC_LOG_DEBUG, strLog); m_powerStatus = powerStatus; } @@ -524,31 +524,9 @@ bool CCECBusDevice::TransmitPoll(cec_logical_address dest) bool CCECBusDevice::TransmitPowerState(cec_logical_address dest) { CStdString strLog; - strLog.Format("<< %s (%X) -> %s (%X): ", GetLogicalAddressName(), m_iLogicalAddress, CCECCommandHandler::ToString(dest), dest); - - switch (m_powerStatus) - { - case CEC_POWER_STATUS_ON: - strLog.append("powered on"); - break; - case CEC_POWER_STATUS_STANDBY: - strLog.append("in standby mode"); - break; - case CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY: - strLog.append("in transition from on to standby"); - break; - case CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON: - strLog.append("in transition from standby to on"); - break; - default: - strLog.append("power state unknown"); - break; - } + strLog.Format("<< %s (%X) -> %s (%X): %s", GetLogicalAddressName(), m_iLogicalAddress, CCECCommandHandler::ToString(dest), dest, CCECCommandHandler::ToString(m_powerStatus)); AddLog(CEC_LOG_NOTICE, strLog.c_str()); - strLog.Format("<< reporting power status '%d'", m_powerStatus); - AddLog(CEC_LOG_NOTICE, strLog); - cec_command command; cec_command::format(command, m_iLogicalAddress, dest, CEC_OPCODE_REPORT_POWER_STATUS); command.parameters.push_back((uint8_t) m_powerStatus); diff --git a/src/lib/implementations/CECCommandHandler.cpp b/src/lib/implementations/CECCommandHandler.cpp index c37f7a2..94aaeaa 100644 --- a/src/lib/implementations/CECCommandHandler.cpp +++ b/src/lib/implementations/CECCommandHandler.cpp @@ -465,6 +465,23 @@ void CCECCommandHandler::SetVendorId(const cec_command &command) device->SetVendorId(iVendorId, command.parameters.size > 3 ? command.parameters[3] : 0); } +const char *CCECCommandHandler::ToString(const cec_power_status status) +{ + switch (status) + { + case CEC_POWER_STATUS_ON: + return "on"; + case CEC_POWER_STATUS_STANDBY: + return "standby"; + case CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY: + return "in transition from on to standby"; + case CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON: + return "in transition from standby to on"; + default: + return "unknown"; + } +} + const char *CCECCommandHandler::ToString(const cec_logical_address address) { switch(address) diff --git a/src/lib/implementations/CECCommandHandler.h b/src/lib/implementations/CECCommandHandler.h index 843aa63..a290764 100644 --- a/src/lib/implementations/CECCommandHandler.h +++ b/src/lib/implementations/CECCommandHandler.h @@ -47,6 +47,7 @@ namespace CEC virtual bool HandleCommand(const cec_command &command); virtual cec_vendor_id GetVendorId(void) { return CEC_VENDOR_UNKNOWN; }; + static const char *ToString(const cec_power_status status); static const char *ToString(const cec_deck_info status); static const char* ToString(const cec_logical_address address); static const char* ToString(const cec_opcode opcode);