X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2Fimplementations%2FCECCommandHandler.cpp;h=6db30a4cdde4330949051600440f77be8eca7ea9;hb=9a54dc825e7730a1f2cb8edb201256dbd88da614;hp=2bab840623c473d1b66a6f5f102a99b59bf8d70c;hpb=36cc67e083b00ccd6c74be13f5dbf61601dc2795;p=deb_libcec.git diff --git a/src/lib/implementations/CECCommandHandler.cpp b/src/lib/implementations/CECCommandHandler.cpp index 2bab840..6db30a4 100644 --- a/src/lib/implementations/CECCommandHandler.cpp +++ b/src/lib/implementations/CECCommandHandler.cpp @@ -71,7 +71,7 @@ bool CCECCommandHandler::HandleCommand(const cec_command &command) if (command.opcode_set == 0) return HandlePoll(command); - bool bHandled(true); + int iHandled(CEC_ABORT_REASON_UNRECOGNIZED_OPCODE); CCECClient *client = m_busDevice->GetClient(); if (client) @@ -80,313 +80,314 @@ bool CCECCommandHandler::HandleCommand(const cec_command &command) switch(command.opcode) { case CEC_OPCODE_REPORT_POWER_STATUS: - HandleReportPowerStatus(command); + iHandled = HandleReportPowerStatus(command); break; case CEC_OPCODE_CEC_VERSION: - HandleDeviceCecVersion(command); + iHandled = HandleDeviceCecVersion(command); break; case CEC_OPCODE_SET_MENU_LANGUAGE: - HandleSetMenuLanguage(command); + iHandled = HandleSetMenuLanguage(command); break; case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS: - if (m_processor->CECInitialised()) - HandleGivePhysicalAddress(command); + iHandled = HandleGivePhysicalAddress(command); break; case CEC_OPCODE_GET_MENU_LANGUAGE: - if (m_processor->CECInitialised()) - HandleGiveMenuLanguage(command); + iHandled = HandleGiveMenuLanguage(command); break; case CEC_OPCODE_GIVE_OSD_NAME: - if (m_processor->CECInitialised()) - HandleGiveOSDName(command); + iHandled = HandleGiveOSDName(command); break; case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID: - if (m_processor->CECInitialised()) - HandleGiveDeviceVendorId(command); + iHandled = HandleGiveDeviceVendorId(command); break; case CEC_OPCODE_DEVICE_VENDOR_ID: - HandleDeviceVendorId(command); + iHandled = HandleDeviceVendorId(command); break; case CEC_OPCODE_VENDOR_COMMAND_WITH_ID: - HandleDeviceVendorCommandWithId(command); + iHandled = HandleDeviceVendorCommandWithId(command); break; case CEC_OPCODE_GIVE_DECK_STATUS: - if (m_processor->CECInitialised()) - HandleGiveDeckStatus(command); + iHandled = HandleGiveDeckStatus(command); break; case CEC_OPCODE_DECK_CONTROL: - HandleDeckControl(command); + iHandled = HandleDeckControl(command); break; case CEC_OPCODE_MENU_REQUEST: - if (m_processor->CECInitialised()) - HandleMenuRequest(command); + iHandled = HandleMenuRequest(command); break; case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS: - if (m_processor->CECInitialised()) - HandleGiveDevicePowerStatus(command); + iHandled = HandleGiveDevicePowerStatus(command); break; case CEC_OPCODE_GET_CEC_VERSION: - if (m_processor->CECInitialised()) - HandleGetCecVersion(command); + iHandled = HandleGetCecVersion(command); break; case CEC_OPCODE_USER_CONTROL_PRESSED: - if (m_processor->CECInitialised()) - HandleUserControlPressed(command); + iHandled = HandleUserControlPressed(command); break; case CEC_OPCODE_USER_CONTROL_RELEASE: - if (m_processor->CECInitialised()) - HandleUserControlRelease(command); + iHandled = HandleUserControlRelease(command); break; case CEC_OPCODE_GIVE_AUDIO_STATUS: - if (m_processor->CECInitialised()) - HandleGiveAudioStatus(command); + iHandled = HandleGiveAudioStatus(command); break; case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS: - if (m_processor->CECInitialised()) - HandleGiveSystemAudioModeStatus(command); + iHandled = HandleGiveSystemAudioModeStatus(command); break; case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST: - if (m_processor->CECInitialised()) - HandleSystemAudioModeRequest(command); + iHandled = HandleSystemAudioModeRequest(command); break; case CEC_OPCODE_REPORT_AUDIO_STATUS: - HandleReportAudioStatus(command); + iHandled = HandleReportAudioStatus(command); break; case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS: - HandleSystemAudioModeStatus(command); + iHandled = HandleSystemAudioModeStatus(command); break; case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE: - HandleSetSystemAudioMode(command); + iHandled = HandleSetSystemAudioMode(command); break; case CEC_OPCODE_REQUEST_ACTIVE_SOURCE: - if (m_processor->CECInitialised()) - HandleRequestActiveSource(command); + iHandled = HandleRequestActiveSource(command); break; case CEC_OPCODE_SET_STREAM_PATH: - HandleSetStreamPath(command); + iHandled = HandleSetStreamPath(command); break; case CEC_OPCODE_ROUTING_CHANGE: - HandleRoutingChange(command); + iHandled = HandleRoutingChange(command); break; case CEC_OPCODE_ROUTING_INFORMATION: - HandleRoutingInformation(command); + iHandled = HandleRoutingInformation(command); break; case CEC_OPCODE_STANDBY: - if (m_processor->CECInitialised()) - HandleStandby(command); + iHandled = HandleStandby(command); break; case CEC_OPCODE_ACTIVE_SOURCE: - HandleActiveSource(command); + iHandled = HandleActiveSource(command); break; case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS: - HandleReportPhysicalAddress(command); + iHandled = HandleReportPhysicalAddress(command); break; case CEC_OPCODE_SET_OSD_NAME: - HandleSetOSDName(command); + iHandled = HandleSetOSDName(command); break; case CEC_OPCODE_IMAGE_VIEW_ON: - HandleImageViewOn(command); + iHandled = HandleImageViewOn(command); break; case CEC_OPCODE_TEXT_VIEW_ON: - HandleTextViewOn(command); + iHandled = HandleTextViewOn(command); break; case CEC_OPCODE_FEATURE_ABORT: - HandleFeatureAbort(command); + iHandled = HandleFeatureAbort(command); break; case CEC_OPCODE_VENDOR_COMMAND: - HandleVendorCommand(command); + iHandled = HandleVendorCommand(command); + break; + case CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN: + iHandled = HandleVendorRemoteButtonDown(command); + break; + case CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP: + iHandled = HandleVendorRemoteButtonUp(command); break; case CEC_OPCODE_PLAY: // libCEC (currently) doesn't need to do anything with this, since player applications handle it // but it should not respond with a feature abort + iHandled = COMMAND_HANDLED; break; default: - bHandled = false; break; } - if (bHandled) + if (iHandled == COMMAND_HANDLED) m_waitForResponse->Received((command.opcode == CEC_OPCODE_FEATURE_ABORT && command.parameters.size > 0) ? (cec_opcode)command.parameters[0] : command.opcode); else - UnhandledCommand(command); + UnhandledCommand(command, (cec_abort_reason)iHandled); - return bHandled; + return iHandled == COMMAND_HANDLED; } -bool CCECCommandHandler::HandleActiveSource(const cec_command &command) +int CCECCommandHandler::HandleActiveSource(const cec_command &command) { if (command.parameters.size == 2) { uint16_t iAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); CCECBusDevice *device = m_processor->GetDeviceByPhysicalAddress(iAddress); if (device) + { device->MarkAsActiveSource(); + return COMMAND_HANDLED; + } } - return true; + return CEC_ABORT_REASON_INVALID_OPERAND; } -bool CCECCommandHandler::HandleDeckControl(const cec_command &command) +int CCECCommandHandler::HandleDeckControl(const cec_command &command) { CCECPlaybackDevice *device = CCECBusDevice::AsPlaybackDevice(GetDevice(command.destination)); if (device && command.parameters.size > 0) { device->SetDeckControlMode((cec_deck_control_mode) command.parameters[0]); - return true; + return COMMAND_HANDLED; } - return false; + return CEC_ABORT_REASON_INVALID_OPERAND; } -bool CCECCommandHandler::HandleDeviceCecVersion(const cec_command &command) +int CCECCommandHandler::HandleDeviceCecVersion(const cec_command &command) { if (command.parameters.size == 1) { CCECBusDevice *device = GetDevice(command.initiator); if (device) device->SetCecVersion((cec_version) command.parameters[0]); + + return COMMAND_HANDLED; } - return true; + return CEC_ABORT_REASON_INVALID_OPERAND; } -bool CCECCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &command) +int CCECCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &command) { - if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) - m_processor->TransmitAbort(command.destination, command.initiator, command.opcode, CEC_ABORT_REASON_REFUSED); - - return true; + return CEC_ABORT_REASON_REFUSED; } -bool CCECCommandHandler::HandleDeviceVendorId(const cec_command &command) +int CCECCommandHandler::HandleDeviceVendorId(const cec_command &command) { - return SetVendorId(command); + SetVendorId(command); + return COMMAND_HANDLED; } -bool CCECCommandHandler::HandleFeatureAbort(const cec_command &command) +int CCECCommandHandler::HandleFeatureAbort(const cec_command &command) { if (command.parameters.size == 2 && (command.parameters[1] == CEC_ABORT_REASON_UNRECOGNIZED_OPCODE || command.parameters[1] == CEC_ABORT_REASON_REFUSED)) m_processor->GetDevice(command.initiator)->SetUnsupportedFeature((cec_opcode)command.parameters[0]); - return true; + return COMMAND_HANDLED; } -bool CCECCommandHandler::HandleGetCecVersion(const cec_command &command) +int CCECCommandHandler::HandleGetCecVersion(const cec_command &command) { if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) { CCECBusDevice *device = GetDevice(command.destination); - if (device) - return device->TransmitCECVersion(command.initiator); + if (device && device->TransmitCECVersion(command.initiator)) + return COMMAND_HANDLED; + return CEC_ABORT_REASON_INVALID_OPERAND; } - return false; + return CEC_ABORT_REASON_NOT_IN_CORRECT_MODE_TO_RESPOND; } -bool CCECCommandHandler::HandleGiveAudioStatus(const cec_command &command) +int CCECCommandHandler::HandleGiveAudioStatus(const cec_command &command) { if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) { CCECAudioSystem *device = CCECBusDevice::AsAudioSystem(GetDevice(command.destination)); - if (device) - return device->TransmitAudioStatus(command.initiator); + if (device && device->TransmitAudioStatus(command.initiator)) + return COMMAND_HANDLED; + return CEC_ABORT_REASON_INVALID_OPERAND; } - return false; + return CEC_ABORT_REASON_NOT_IN_CORRECT_MODE_TO_RESPOND; } -bool CCECCommandHandler::HandleGiveDeckStatus(const cec_command &command) +int CCECCommandHandler::HandleGiveDeckStatus(const cec_command &command) { if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) { CCECPlaybackDevice *device = CCECBusDevice::AsPlaybackDevice(GetDevice(command.destination)); - if (device) - return device->TransmitDeckStatus(command.initiator); + if (device && device->TransmitDeckStatus(command.initiator)) + return COMMAND_HANDLED; + return CEC_ABORT_REASON_INVALID_OPERAND; } - return false; + return CEC_ABORT_REASON_NOT_IN_CORRECT_MODE_TO_RESPOND; } -bool CCECCommandHandler::HandleGiveDevicePowerStatus(const cec_command &command) +int CCECCommandHandler::HandleGiveDevicePowerStatus(const cec_command &command) { if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) { CCECBusDevice *device = GetDevice(command.destination); - if (device) - return device->TransmitPowerState(command.initiator); + if (device && device->TransmitPowerState(command.initiator)) + return COMMAND_HANDLED; + return CEC_ABORT_REASON_INVALID_OPERAND; } - return false; + return CEC_ABORT_REASON_INVALID_OPERAND; } -bool CCECCommandHandler::HandleGiveDeviceVendorId(const cec_command &command) +int CCECCommandHandler::HandleGiveDeviceVendorId(const cec_command &command) { if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) { CCECBusDevice *device = GetDevice(command.destination); - if (device) - return device->TransmitVendorID(command.initiator); + if (device && device->TransmitVendorID(command.initiator)) + return COMMAND_HANDLED; } - return false; + return CEC_ABORT_REASON_INVALID_OPERAND; } -bool CCECCommandHandler::HandleGiveOSDName(const cec_command &command) +int CCECCommandHandler::HandleGiveOSDName(const cec_command &command) { if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) { CCECBusDevice *device = GetDevice(command.destination); - if (device) - return device->TransmitOSDName(command.initiator); + if (device && device->TransmitOSDName(command.initiator)) + return COMMAND_HANDLED; } - return false; + return CEC_ABORT_REASON_INVALID_OPERAND; } -bool CCECCommandHandler::HandleGivePhysicalAddress(const cec_command &command) +int CCECCommandHandler::HandleGivePhysicalAddress(const cec_command &command) { if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) { CCECBusDevice *device = GetDevice(command.destination); - if (device) - return device->TransmitPhysicalAddress(); + if (device && device->TransmitPhysicalAddress()) + return COMMAND_HANDLED; + return CEC_ABORT_REASON_INVALID_OPERAND; } - return false; + return CEC_ABORT_REASON_NOT_IN_CORRECT_MODE_TO_RESPOND; } -bool CCECCommandHandler::HandleGiveMenuLanguage(const cec_command &command) +int CCECCommandHandler::HandleGiveMenuLanguage(const cec_command &command) { if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) { CCECBusDevice *device = GetDevice(command.destination); - if (device) - return device->TransmitSetMenuLanguage(command.initiator); + if (device && device->TransmitSetMenuLanguage(command.initiator)) + return COMMAND_HANDLED; + return CEC_ABORT_REASON_INVALID_OPERAND; } - return false; + return CEC_ABORT_REASON_NOT_IN_CORRECT_MODE_TO_RESPOND; } -bool CCECCommandHandler::HandleGiveSystemAudioModeStatus(const cec_command &command) +int CCECCommandHandler::HandleGiveSystemAudioModeStatus(const cec_command &command) { if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) { CCECAudioSystem *device = CCECBusDevice::AsAudioSystem(GetDevice(command.destination)); - if (device) - return device->TransmitSystemAudioModeStatus(command.initiator); + if (device && device->TransmitSystemAudioModeStatus(command.initiator)) + return COMMAND_HANDLED; + return CEC_ABORT_REASON_INVALID_OPERAND; } - return false; + return CEC_ABORT_REASON_NOT_IN_CORRECT_MODE_TO_RESPOND; } -bool CCECCommandHandler::HandleImageViewOn(const cec_command &command) +int CCECCommandHandler::HandleImageViewOn(const cec_command &command) { m_processor->GetDevice(command.initiator)->MarkAsActiveSource(); - return true; + return COMMAND_HANDLED; } -bool CCECCommandHandler::HandleMenuRequest(const cec_command &command) +int CCECCommandHandler::HandleMenuRequest(const cec_command &command) { if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) { @@ -407,11 +408,13 @@ bool CCECCommandHandler::HandleMenuRequest(const cec_command &command) device->SetMenuState(CEC_MENU_STATE_DEACTIVATED); } } - return device->TransmitMenuState(command.initiator); + if (device->TransmitMenuState(command.initiator)) + return COMMAND_HANDLED; } + return CEC_ABORT_REASON_INVALID_OPERAND; } - return false; + return CEC_ABORT_REASON_NOT_IN_CORRECT_MODE_TO_RESPOND; } bool CCECCommandHandler::HandlePoll(const cec_command &command) @@ -420,7 +423,7 @@ bool CCECCommandHandler::HandlePoll(const cec_command &command) return true; } -bool CCECCommandHandler::HandleReportAudioStatus(const cec_command &command) +int CCECCommandHandler::HandleReportAudioStatus(const cec_command &command) { if (command.parameters.size == 1) { @@ -428,34 +431,38 @@ bool CCECCommandHandler::HandleReportAudioStatus(const cec_command &command) if (device) { device->SetAudioStatus(command.parameters[0]); - return true; + return COMMAND_HANDLED; } } - return false; + return CEC_ABORT_REASON_INVALID_OPERAND; } -bool CCECCommandHandler::HandleReportPhysicalAddress(const cec_command &command) +int CCECCommandHandler::HandleReportPhysicalAddress(const cec_command &command) { if (command.parameters.size == 3) { uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); SetPhysicalAddress(command.initiator, iNewAddress); + return COMMAND_HANDLED; } - return true; + return CEC_ABORT_REASON_INVALID_OPERAND; } -bool CCECCommandHandler::HandleReportPowerStatus(const cec_command &command) +int CCECCommandHandler::HandleReportPowerStatus(const cec_command &command) { if (command.parameters.size == 1) { CCECBusDevice *device = GetDevice(command.initiator); if (device) + { device->SetPowerStatus((cec_power_status) command.parameters[0]); + return COMMAND_HANDLED; + } } - return true; + return CEC_ABORT_REASON_INVALID_OPERAND; } -bool CCECCommandHandler::HandleRequestActiveSource(const cec_command &command) +int CCECCommandHandler::HandleRequestActiveSource(const cec_command &command) { if (m_processor->CECInitialised()) { @@ -465,13 +472,12 @@ bool CCECCommandHandler::HandleRequestActiveSource(const cec_command &command) vector devices; for (size_t iDevicePtr = 0; iDevicePtr < GetMyDevices(devices); iDevicePtr++) devices[iDevicePtr]->TransmitActiveSource(); - - return true; } - return false; + + return COMMAND_HANDLED; } -bool CCECCommandHandler::HandleRoutingChange(const cec_command &command) +int CCECCommandHandler::HandleRoutingChange(const cec_command &command) { if (command.parameters.size == 4) { @@ -480,25 +486,32 @@ bool CCECCommandHandler::HandleRoutingChange(const cec_command &command) CCECBusDevice *device = GetDevice(command.initiator); if (device) + { device->SetStreamPath(iNewAddress, iOldAddress); + return COMMAND_HANDLED; + } } - return true; + + return CEC_ABORT_REASON_INVALID_OPERAND; } -bool CCECCommandHandler::HandleRoutingInformation(const cec_command &command) +int CCECCommandHandler::HandleRoutingInformation(const cec_command &command) { if (command.parameters.size == 2) { uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); CCECBusDevice *device = m_processor->GetDeviceByPhysicalAddress(iNewAddress); if (device) + { device->MarkAsActiveSource(); + return COMMAND_HANDLED; + } } - return false; + return CEC_ABORT_REASON_INVALID_OPERAND; } -bool CCECCommandHandler::HandleSetMenuLanguage(const cec_command &command) +int CCECCommandHandler::HandleSetMenuLanguage(const cec_command &command) { if (command.parameters.size == 3) { @@ -511,13 +524,14 @@ bool CCECCommandHandler::HandleSetMenuLanguage(const cec_command &command) language.language[iPtr] = command.parameters[iPtr]; language.language[3] = 0; device->SetMenuLanguage(language); - return true; + return COMMAND_HANDLED; } } - return false; + + return CEC_ABORT_REASON_INVALID_OPERAND; } -bool CCECCommandHandler::HandleSetOSDName(const cec_command &command) +int CCECCommandHandler::HandleSetOSDName(const cec_command &command) { if (command.parameters.size > 0) { @@ -532,15 +546,19 @@ bool CCECCommandHandler::HandleSetOSDName(const cec_command &command) CStdString strName(buf); device->SetOSDName(strName); - return true; + return COMMAND_HANDLED; } } - return false; + + return CEC_ABORT_REASON_INVALID_OPERAND; } -bool CCECCommandHandler::HandleSetStreamPath(const cec_command &command) +int CCECCommandHandler::HandleSetStreamPath(const cec_command &command) { - if (m_processor->CECInitialised() && command.parameters.size >= 2) + if (!m_processor->CECInitialised()) + return CEC_ABORT_REASON_NOT_IN_CORRECT_MODE_TO_RESPOND; + + if (command.parameters.size >= 2) { uint16_t iStreamAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); LIB_CEC->AddLog(CEC_LOG_DEBUG, ">> %i sets stream path to physical address %04x", command.initiator, iStreamAddress); @@ -548,12 +566,16 @@ bool CCECCommandHandler::HandleSetStreamPath(const cec_command &command) /* one of the device handled by libCEC has been made active */ CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamAddress); if (device && device->IsHandledByLibCEC()) + { device->ActivateSource(); + return COMMAND_HANDLED; + } } - return false; + + return CEC_ABORT_REASON_INVALID_OPERAND; } -bool CCECCommandHandler::HandleSystemAudioModeRequest(const cec_command &command) +int CCECCommandHandler::HandleSystemAudioModeRequest(const cec_command &command) { if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) { @@ -568,28 +590,31 @@ bool CCECCommandHandler::HandleSystemAudioModeRequest(const cec_command &command CCECBusDevice *newActiveDevice = GetDeviceByPhysicalAddress(iNewAddress); if (newActiveDevice) newActiveDevice->MarkAsActiveSource(); - return device->TransmitSetSystemAudioMode(command.initiator); + if (device->TransmitSetSystemAudioMode(command.initiator)) + return COMMAND_HANDLED; } else { device->SetSystemAudioModeStatus(CEC_SYSTEM_AUDIO_STATUS_OFF); - return device->TransmitSetSystemAudioMode(command.initiator); + if (device->TransmitSetSystemAudioMode(command.initiator)) + return COMMAND_HANDLED; } } } - return false; + + return CEC_ABORT_REASON_NOT_IN_CORRECT_MODE_TO_RESPOND; } -bool CCECCommandHandler::HandleStandby(const cec_command &command) +int CCECCommandHandler::HandleStandby(const cec_command &command) { CCECBusDevice *device = GetDevice(command.initiator); if (device) device->SetPowerStatus(CEC_POWER_STATUS_STANDBY); - return true; + return COMMAND_HANDLED; } -bool CCECCommandHandler::HandleSystemAudioModeStatus(const cec_command &command) +int CCECCommandHandler::HandleSystemAudioModeStatus(const cec_command &command) { if (command.parameters.size == 1) { @@ -597,14 +622,14 @@ bool CCECCommandHandler::HandleSystemAudioModeStatus(const cec_command &command) if (device) { device->SetSystemAudioModeStatus((cec_system_audio_status)command.parameters[0]); - return true; + return COMMAND_HANDLED; } } - return false; + return CEC_ABORT_REASON_INVALID_OPERAND; } -bool CCECCommandHandler::HandleSetSystemAudioMode(const cec_command &command) +int CCECCommandHandler::HandleSetSystemAudioMode(const cec_command &command) { if (command.parameters.size == 1) { @@ -612,89 +637,92 @@ bool CCECCommandHandler::HandleSetSystemAudioMode(const cec_command &command) if (device) { device->SetSystemAudioModeStatus((cec_system_audio_status)command.parameters[0]); - return true; + return COMMAND_HANDLED; } } - return false; + return CEC_ABORT_REASON_INVALID_OPERAND; } -bool CCECCommandHandler::HandleTextViewOn(const cec_command &command) +int CCECCommandHandler::HandleTextViewOn(const cec_command &command) { m_processor->GetDevice(command.initiator)->MarkAsActiveSource(); - return true; + return COMMAND_HANDLED; } -bool CCECCommandHandler::HandleUserControlPressed(const cec_command &command) +int CCECCommandHandler::HandleUserControlPressed(const cec_command &command) { - if (m_processor->CECInitialised() && - m_processor->IsHandledByLibCEC(command.destination) && - command.parameters.size > 0) - { - CCECBusDevice *device = GetDevice(command.destination); - if (!device) - return true; + if (!m_processor->CECInitialised() || + !m_processor->IsHandledByLibCEC(command.destination)) + return CEC_ABORT_REASON_NOT_IN_CORRECT_MODE_TO_RESPOND; - CCECClient *client = device->GetClient(); - if (client) - client->AddKey(); + if (command.parameters.size == 0) + return CEC_ABORT_REASON_INVALID_OPERAND; - if (command.parameters[0] <= CEC_USER_CONTROL_CODE_MAX) - client->SetCurrentButton((cec_user_control_code) command.parameters[0]); + CCECBusDevice *device = GetDevice(command.destination); + if (!device) + return CEC_ABORT_REASON_INVALID_OPERAND; - if (command.parameters[0] == CEC_USER_CONTROL_CODE_POWER || - command.parameters[0] == CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION) - { - bool bPowerOn(true); - if (!device) - return true; + CCECClient *client = device->GetClient(); + if (client) + client->AddKey(); - // CEC_USER_CONTROL_CODE_POWER operates as a toggle - // assume CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION does not - if (command.parameters[0] == CEC_USER_CONTROL_CODE_POWER) - { - cec_power_status status = device->GetCurrentPowerStatus(); - bPowerOn = !(status == CEC_POWER_STATUS_ON || status == CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON); - } + if (command.parameters[0] <= CEC_USER_CONTROL_CODE_MAX) + client->SetCurrentButton((cec_user_control_code) command.parameters[0]); - if (bPowerOn) - { - device->ActivateSource(); - } - else - { - device->MarkAsInactiveSource(); - device->TransmitInactiveSource(); - device->SetMenuState(CEC_MENU_STATE_DEACTIVATED); - } + if (command.parameters[0] == CEC_USER_CONTROL_CODE_POWER || + command.parameters[0] == CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION) + { + bool bPowerOn(true); + + // CEC_USER_CONTROL_CODE_POWER operates as a toggle + // assume CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION does not + if (command.parameters[0] == CEC_USER_CONTROL_CODE_POWER) + { + cec_power_status status = device->GetCurrentPowerStatus(); + bPowerOn = !(status == CEC_POWER_STATUS_ON || status == CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON); } - return true; + if (bPowerOn) + { + device->ActivateSource(); + } + else + { + device->MarkAsInactiveSource(); + device->TransmitInactiveSource(); + device->SetMenuState(CEC_MENU_STATE_DEACTIVATED); + } } - return false; + + return COMMAND_HANDLED; } -bool CCECCommandHandler::HandleUserControlRelease(const cec_command &command) +int CCECCommandHandler::HandleUserControlRelease(const cec_command &command) { + if (!m_processor->CECInitialised() || + !m_processor->IsHandledByLibCEC(command.destination)) + return CEC_ABORT_REASON_NOT_IN_CORRECT_MODE_TO_RESPOND; + CCECClient *client = m_processor->GetClient(command.destination); if (client) client->AddKey(); - return true; + + return COMMAND_HANDLED; } -bool CCECCommandHandler::HandleVendorCommand(const cec_command &command) +int CCECCommandHandler::HandleVendorCommand(const cec_command &command) { - if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) - m_processor->TransmitAbort(command.destination, command.initiator, command.opcode, CEC_ABORT_REASON_REFUSED); - return true; + return CEC_ABORT_REASON_REFUSED; } -void CCECCommandHandler::UnhandledCommand(const cec_command &command) +void CCECCommandHandler::UnhandledCommand(const cec_command &command, const cec_abort_reason reason) { - LIB_CEC->AddLog(CEC_LOG_DEBUG, "unhandled command with opcode %02x from address %d", command.opcode, command.initiator); - - if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) - m_processor->TransmitAbort(m_busDevice->GetLogicalAddress(), command.initiator, command.opcode, CEC_ABORT_REASON_UNRECOGNIZED_OPCODE); + if (m_processor->IsHandledByLibCEC(command.destination)) + { + LIB_CEC->AddLog(CEC_LOG_DEBUG, "sending abort with opcode %02x and reason '%s' to %s", command.opcode, ToString(reason), ToString(command.initiator)); + m_processor->TransmitAbort(command.destination, command.initiator, command.opcode, reason); + } } size_t CCECCommandHandler::GetMyDevices(vector &devices) const