X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2Fimplementations%2FSLCommandHandler.cpp;h=8ddac56c7fc372ead8136bbd296ba71a47e9f57f;hb=d78e4e6f492d94f613dd4577b9fedc53c5a53a0d;hp=e1632ee5d7e68faff2753fa5640658587570fc50;hpb=004b83822a351e1fb6e982a9183a12a430b0b769;p=deb_libcec.git diff --git a/src/lib/implementations/SLCommandHandler.cpp b/src/lib/implementations/SLCommandHandler.cpp index e1632ee..8ddac56 100644 --- a/src/lib/implementations/SLCommandHandler.cpp +++ b/src/lib/implementations/SLCommandHandler.cpp @@ -62,14 +62,6 @@ CSLCommandHandler::CSLCommandHandler(CCECBusDevice *busDevice) : m_bActiveSourceSent(false) { m_vendorId = CEC_VENDOR_LG; - CCECBusDevice *primary = m_processor->GetPrimaryDevice(); - - /* imitate LG devices */ - if (primary && m_busDevice->GetLogicalAddress() != primary->GetLogicalAddress()) - { - primary->SetVendorId(CEC_VENDOR_LG); - primary->ReplaceHandler(false); - } /* LG devices don't always reply to CEC version requests, so just set it to 1.3a */ m_busDevice->SetCecVersion(CEC_VERSION_1_3A); @@ -87,22 +79,31 @@ bool CSLCommandHandler::InitHandler(void) return true; m_bHandlerInited = true; - if (m_busDevice->GetLogicalAddress() == CECDEVICE_TV) + CCECBusDevice *primary = m_processor->GetPrimaryDevice(); + if (primary && primary->GetLogicalAddress() != CECDEVICE_UNREGISTERED) { - CCECBusDevice *primary = m_processor->GetPrimaryDevice(); + /* imitate LG devices */ + if (m_busDevice->GetLogicalAddress() != primary->GetLogicalAddress()) + { + primary->SetVendorId(CEC_VENDOR_LG); + primary->ReplaceHandler(false); + } - /* start as 'in transition standby->on' */ - primary->SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON); - primary->TransmitPowerState(CECDEVICE_TV); + if (m_busDevice->GetLogicalAddress() == CECDEVICE_TV) + { + /* start as 'in transition standby->on' */ + primary->SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON); + primary->TransmitPowerState(CECDEVICE_TV); - /* send the vendor id */ - primary->TransmitVendorID(CECDEVICE_BROADCAST); + /* send the vendor id */ + primary->TransmitVendorID(CECDEVICE_BROADCAST); + } } return true; } -bool CSLCommandHandler::HandleActiveSource(const cec_command &command) +int CSLCommandHandler::HandleActiveSource(const cec_command &command) { if (command.parameters.size == 2) { @@ -121,26 +122,38 @@ bool CSLCommandHandler::HandleActiveSource(const cec_command &command) } primary->TransmitPowerState(CECDEVICE_TV); } + + return COMMAND_HANDLED; } - return true; + return CEC_ABORT_REASON_INVALID_OPERAND; } -bool CSLCommandHandler::HandleDeviceVendorId(const cec_command &command) +int CSLCommandHandler::HandleDeviceVendorId(const cec_command &command) { SetVendorId(command); if (!SLInitialised() && command.initiator == CECDEVICE_TV) { - cec_command response; - cec_command::Format(response, command.destination, command.initiator, CEC_OPCODE_FEATURE_ABORT); - return Transmit(response); + CCECBusDevice *destination = m_processor->GetDevice(command.destination); + if (destination && (destination->GetLogicalAddress() == CECDEVICE_BROADCAST || destination->IsHandledByLibCEC())) + { + cec_logical_address initiator = destination->GetLogicalAddress(); + if (initiator == CECDEVICE_BROADCAST) + initiator = m_processor->GetPrimaryDevice()->GetLogicalAddress(); + + cec_command response; + cec_command::Format(response, initiator, command.initiator, CEC_OPCODE_FEATURE_ABORT); + Transmit(response); + return COMMAND_HANDLED; + } } - return true; + + return CCECCommandHandler::HandleDeviceVendorId(command); } -bool CSLCommandHandler::HandleVendorCommand(const cec_command &command) +int CSLCommandHandler::HandleVendorCommand(const cec_command &command) { if (!m_processor->IsHandledByLibCEC(command.destination)) return true; @@ -149,28 +162,28 @@ bool CSLCommandHandler::HandleVendorCommand(const cec_command &command) command.parameters[0] == SL_COMMAND_UNKNOWN_01) { HandleVendorCommand01(command); - return true; + return COMMAND_HANDLED; } else if (command.parameters.size == 2 && command.parameters[0] == SL_COMMAND_POWER_ON) { HandleVendorCommandPowerOn(command); - return true; + return COMMAND_HANDLED; } else if (command.parameters.size == 2 && command.parameters[0] == SL_COMMAND_CONNECT_REQUEST) { HandleVendorCommandSLConnect(command); - return true; + return COMMAND_HANDLED; } else if (command.parameters.size == 1 && command.parameters[0] == SL_COMMAND_REQUEST_POWER_STATUS) { HandleVendorCommandPowerOnStatus(command); - return true; + return COMMAND_HANDLED; } - return false; + return CCECCommandHandler::HandleVendorCommand(command); } void CSLCommandHandler::HandleVendorCommand01(const cec_command &command) @@ -243,44 +256,41 @@ void CSLCommandHandler::TransmitVendorCommandSetDeviceMode(const cec_logical_add Transmit(response); } -bool CSLCommandHandler::HandleGiveDeckStatus(const cec_command &command) +int CSLCommandHandler::HandleGiveDeckStatus(const cec_command &command) { - if (m_processor->IsRunning() && m_processor->IsHandledByLibCEC(command.destination)) + if (!m_processor->CECInitialised() || + !m_processor->IsHandledByLibCEC(command.destination)) + return CEC_ABORT_REASON_NOT_IN_CORRECT_MODE_TO_RESPOND; + + CCECPlaybackDevice *device = CCECBusDevice::AsPlaybackDevice(GetDevice(command.destination)); + if (!device || command.parameters.size == 0) + return CEC_ABORT_REASON_INVALID_OPERAND; + + device->SetDeckStatus(!device->IsActiveSource() ? CEC_DECK_INFO_OTHER_STATUS : CEC_DECK_INFO_OTHER_STATUS_LG); + if (command.parameters[0] == CEC_STATUS_REQUEST_ON) { - CCECBusDevice *device = GetDevice(command.destination); - if (device && (device->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || device->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE)) - { - if (command.parameters.size > 0) - { - ((CCECPlaybackDevice *) device)->SetDeckStatus(!device->IsActiveSource() ? CEC_DECK_INFO_OTHER_STATUS : CEC_DECK_INFO_OTHER_STATUS_LG); - if (command.parameters[0] == CEC_STATUS_REQUEST_ON) - { - bool bReturn = ((CCECPlaybackDevice *) device)->TransmitDeckStatus(command.initiator); - if (!ActiveSourceSent()) - ActivateSource(); - return bReturn; - } - else if (command.parameters[0] == CEC_STATUS_REQUEST_ONCE) - { - return ((CCECPlaybackDevice *) device)->TransmitDeckStatus(command.initiator); - } - } - } - return CCECCommandHandler::HandleGiveDeckStatus(command); + device->TransmitDeckStatus(command.initiator); + if (!ActiveSourceSent()) + ActivateSource(); + return COMMAND_HANDLED; + } + else if (command.parameters[0] == CEC_STATUS_REQUEST_ONCE) + { + device->TransmitDeckStatus(command.initiator); + return COMMAND_HANDLED; } - return false; + return CCECCommandHandler::HandleGiveDeckStatus(command); } -bool CSLCommandHandler::HandleGiveDevicePowerStatus(const cec_command &command) +int CSLCommandHandler::HandleGiveDevicePowerStatus(const cec_command &command) { - bool bReturn(false); - if (m_processor->IsRunning() && m_processor->IsHandledByLibCEC(command.destination) && command.initiator == CECDEVICE_TV) + if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination) && command.initiator == CECDEVICE_TV) { CCECBusDevice *device = GetDevice(command.destination); if (device && device->GetCurrentPowerStatus() != CEC_POWER_STATUS_ON) { - bReturn = device->TransmitPowerState(command.initiator); + device->TransmitPowerState(command.initiator); device->SetPowerStatus(CEC_POWER_STATUS_ON); } else @@ -288,7 +298,7 @@ bool CSLCommandHandler::HandleGiveDevicePowerStatus(const cec_command &command) if (!ActiveSourceSent()) { device->SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON); - bReturn = device->TransmitPowerState(command.initiator); + device->TransmitPowerState(command.initiator); ActivateSource(); } else if (m_resetPowerState.IsSet() && m_resetPowerState.TimeLeft() > 0) @@ -300,35 +310,37 @@ bool CSLCommandHandler::HandleGiveDevicePowerStatus(const cec_command &command) m_bActiveSourceSent = false; } device->SetPowerStatus(CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON); - bReturn = device->TransmitPowerState(command.initiator); + device->TransmitPowerState(command.initiator); device->SetPowerStatus(CEC_POWER_STATUS_ON); m_resetPowerState.Init(5000); } else { - bReturn = device->TransmitPowerState(command.initiator); + device->TransmitPowerState(command.initiator); m_resetPowerState.Init(5000); } } + + return COMMAND_HANDLED; } - return bReturn; + return CEC_ABORT_REASON_NOT_IN_CORRECT_MODE_TO_RESPOND; } -bool CSLCommandHandler::HandleRequestActiveSource(const cec_command &command) +int CSLCommandHandler::HandleRequestActiveSource(const cec_command &command) { - if (m_processor->IsRunning()) + if (m_processor->CECInitialised()) { if (ActiveSourceSent()) LIB_CEC->AddLog(CEC_LOG_DEBUG, ">> %i requests active source, ignored", (uint8_t) command.initiator); else ActivateSource(); - return true; + return COMMAND_HANDLED; } - return false; + return CEC_ABORT_REASON_NOT_IN_CORRECT_MODE_TO_RESPOND; } -bool CSLCommandHandler::HandleFeatureAbort(const cec_command &command) +int CSLCommandHandler::HandleFeatureAbort(const cec_command &command) { if (command.parameters.size == 0 && m_processor->GetPrimaryDevice()->GetCurrentPowerStatus() == CEC_POWER_STATUS_ON && !SLInitialised() && command.initiator == CECDEVICE_TV) @@ -340,7 +352,7 @@ bool CSLCommandHandler::HandleFeatureAbort(const cec_command &command) return CCECCommandHandler::HandleFeatureAbort(command); } -bool CSLCommandHandler::HandleStandby(const cec_command &command) +int CSLCommandHandler::HandleStandby(const cec_command &command) { if (command.initiator == CECDEVICE_TV) {