+ {
+ switch(iPtr)
+ {
+ case CECDEVICE_AUDIOSYSTEM:
+ m_busDevices[iPtr] = new CCECAudioSystem(this, (cec_logical_address) iPtr, 0xFFFF);
+ break;
+ case CECDEVICE_PLAYBACKDEVICE1:
+ case CECDEVICE_PLAYBACKDEVICE2:
+ case CECDEVICE_PLAYBACKDEVICE3:
+ m_busDevices[iPtr] = new CCECPlaybackDevice(this, (cec_logical_address) iPtr, 0xFFFF);
+ break;
+ case CECDEVICE_RECORDINGDEVICE1:
+ case CECDEVICE_RECORDINGDEVICE2:
+ case CECDEVICE_RECORDINGDEVICE3:
+ m_busDevices[iPtr] = new CCECRecordingDevice(this, (cec_logical_address) iPtr, 0xFFFF);
+ break;
+ case CECDEVICE_TUNER1:
+ case CECDEVICE_TUNER2:
+ case CECDEVICE_TUNER3:
+ case CECDEVICE_TUNER4:
+ m_busDevices[iPtr] = new CCECTuner(this, (cec_logical_address) iPtr, 0xFFFF);
+ break;
+ case CECDEVICE_TV:
+ m_busDevices[iPtr] = new CCECTV(this, (cec_logical_address) iPtr, 0);
+ break;
+ default:
+ m_busDevices[iPtr] = new CCECBusDevice(this, (cec_logical_address) iPtr, 0xFFFF);
+ break;
+ }
+ }
+}
+
+CCECProcessor::~CCECProcessor(void)
+{
+ Close();
+
+ for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
+ {
+ delete m_busDevices[iPtr];
+ m_busDevices[iPtr] = NULL;
+ }
+}
+
+void CCECProcessor::Close(void)
+{
+ StopThread(false);
+ SetInitialised(false);
+ StopThread();
+
+ bool bClose(false);
+ {
+ CLockObject lock(m_mutex);
+ bClose = m_bConnectionOpened;
+ m_bConnectionOpened = false;
+ }
+
+ if (bClose && m_communication)
+ {
+ m_communication->PersistConfiguration(&m_configuration);
+ m_communication->Close();
+ delete m_communication;
+ m_communication = NULL;
+ }
+}
+
+bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint32_t iTimeoutMs, bool bStartListening /* = true */)
+{
+ bool bReturn(false);
+ Close();
+
+ {
+ CLockObject lock(m_mutex);
+ if (m_bConnectionOpened)
+ {
+ CLibCEC::AddLog(CEC_LOG_ERROR, "connection already opened");
+ return false;
+ }
+ m_communication = new CUSBCECAdapterCommunication(this, strPort, iBaudRate);
+ m_bConnectionOpened = (m_communication != NULL);
+ }
+
+ /* check for an already opened connection */
+ if (m_communication->IsOpen())
+ {
+ CLibCEC::AddLog(CEC_LOG_ERROR, "connection already opened");
+ return bReturn;
+ }
+
+ CTimeout timeout(iTimeoutMs > 0 ? iTimeoutMs : CEC_DEFAULT_TRANSMIT_WAIT);
+
+ /* open a new connection */
+ unsigned iConnectTry(0);
+ while (timeout.TimeLeft() > 0 && (bReturn = m_communication->Open(this, (timeout.TimeLeft() / CEC_CONNECT_TRIES), false, bStartListening)) == false)
+ {
+ CLibCEC::AddLog(CEC_LOG_ERROR, "could not open a connection (try %d)", ++iConnectTry);
+ m_communication->Close();
+ CEvent::Sleep(1000);
+ }
+
+ if (bReturn)
+ {
+ m_configuration.iFirmwareVersion = m_communication->GetFirmwareVersion();
+ CLibCEC::AddLog(CEC_LOG_NOTICE, "connected to the CEC adapter. firmware version = %d, client version = %s", m_configuration.iFirmwareVersion, ToString((cec_client_version)m_configuration.clientVersion));
+ }
+
+ if (m_configuration.bGetSettingsFromROM == 1)
+ m_communication->GetConfiguration(&m_configuration);
+
+ return bReturn;
+}
+
+bool CCECProcessor::IsInitialised(void)
+{
+ CLockObject lock(m_mutex);
+ return m_bInitialised;
+}
+
+void CCECProcessor::SetInitialised(bool bSetTo /* = true */)
+{
+ CLockObject lock(m_mutex);
+ m_bInitialised = bSetTo;
+}
+
+bool CCECProcessor::Initialise(void)
+{
+ bool bReturn(false);
+ {
+ CLockObject lock(m_mutex);
+ if (!m_configuration.logicalAddresses.IsEmpty())
+ m_configuration.logicalAddresses.Clear();
+
+ if (!FindLogicalAddresses())
+ {
+ CLibCEC::AddLog(CEC_LOG_ERROR, "could not detect our logical addresses");
+ return bReturn;
+ }
+
+ /* only set our OSD name for the primary device */
+ m_busDevices[m_configuration.logicalAddresses.primary]->m_strDeviceName = m_configuration.strDeviceName;
+
+ /* make the primary device the active source if the option is set */
+ if (m_configuration.bActivateSource == 1)
+ m_busDevices[m_configuration.logicalAddresses.primary]->m_bActiveSource = true;
+ }
+
+ /* get the vendor id from the TV, so we are using the correct handler */
+ m_busDevices[CECDEVICE_TV]->GetVendorId();
+
+ if (m_configuration.iPhysicalAddress != 0)
+ {
+ CLibCEC::AddLog(CEC_LOG_NOTICE, "setting the physical address to %4x", m_configuration.iPhysicalAddress);
+ m_busDevices[m_configuration.logicalAddresses.primary]->m_iPhysicalAddress = m_configuration.iPhysicalAddress;
+ if ((bReturn = m_busDevices[m_configuration.logicalAddresses.primary]->TransmitPhysicalAddress()) == false)
+ CLibCEC::AddLog(CEC_LOG_ERROR, "unable to set the physical address to %4x", m_configuration.iPhysicalAddress);
+ }
+ else if (m_configuration.iPhysicalAddress == 0 && (bReturn = SetHDMIPort(m_configuration.baseDevice, m_configuration.iHDMIPort, true)) == false)
+ CLibCEC::AddLog(CEC_LOG_ERROR, "unable to set HDMI port %d on %s (%x)", m_configuration.iHDMIPort, ToString(m_configuration.baseDevice), (uint8_t)m_configuration.baseDevice);
+
+ if (m_configuration.bActivateSource == 1)
+ m_busDevices[m_configuration.logicalAddresses.primary]->ActivateSource();
+
+ SetInitialised(bReturn);
+ if (bReturn)
+ CLibCEC::ConfigurationChanged(m_configuration);
+
+ return bReturn;
+}
+
+bool CCECProcessor::Start(const char *strPort, uint16_t iBaudRate /* = 38400 */, uint32_t iTimeoutMs /* = 10000 */)
+{
+ bool bReturn(false);
+
+ {
+ CLockObject lock(m_mutex);
+ if (!OpenConnection(strPort, iBaudRate, iTimeoutMs))
+ return bReturn;
+
+ /* create the processor thread */
+ if (!CreateThread())
+ {
+ CLibCEC::AddLog(CEC_LOG_ERROR, "could not create a processor thread");
+ return bReturn;
+ }
+ }
+
+ if ((bReturn = Initialise()) == false)
+ {
+ CLibCEC::AddLog(CEC_LOG_ERROR, "could not create a processor thread");
+ StopThread(true);
+ }
+ else
+ {
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "processor thread started");
+ }
+
+ return bReturn;
+}
+
+bool CCECProcessor::TryLogicalAddress(cec_logical_address address)
+{
+ if (m_busDevices[address]->TryLogicalAddress())
+ {
+ m_configuration.logicalAddresses.Set(address);
+ return true;
+ }
+
+ return false;
+}
+
+bool CCECProcessor::FindLogicalAddressRecordingDevice(void)
+{
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'recording device'");
+ return TryLogicalAddress(CECDEVICE_RECORDINGDEVICE1) ||
+ TryLogicalAddress(CECDEVICE_RECORDINGDEVICE2) ||
+ TryLogicalAddress(CECDEVICE_RECORDINGDEVICE3);
+}
+
+bool CCECProcessor::FindLogicalAddressTuner(void)
+{
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'tuner'");
+ return TryLogicalAddress(CECDEVICE_TUNER1) ||
+ TryLogicalAddress(CECDEVICE_TUNER2) ||
+ TryLogicalAddress(CECDEVICE_TUNER3) ||
+ TryLogicalAddress(CECDEVICE_TUNER4);
+}
+
+bool CCECProcessor::FindLogicalAddressPlaybackDevice(void)
+{
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'playback device'");
+ return TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE1) ||
+ TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE2) ||
+ TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE3);
+}
+
+bool CCECProcessor::FindLogicalAddressAudioSystem(void)
+{
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'audio'");
+ return TryLogicalAddress(CECDEVICE_AUDIOSYSTEM);
+}
+
+bool CCECProcessor::ChangeDeviceType(cec_device_type from, cec_device_type to)
+{
+ bool bChanged(false);
+
+ CLibCEC::AddLog(CEC_LOG_NOTICE, "changing device type '%s' into '%s'", ToString(from), ToString(to));
+
+ CLockObject lock(m_mutex);
+ CCECBusDevice *previousDevice = GetDeviceByType(from);
+ m_configuration.logicalAddresses.primary = CECDEVICE_UNKNOWN;
+
+ for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
+ {
+ if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_RESERVED)
+ continue;
+
+ if (m_configuration.deviceTypes.types[iPtr] == from)
+ {
+ bChanged = true;
+ m_configuration.deviceTypes.types[iPtr] = to;
+ }
+ else if (m_configuration.deviceTypes.types[iPtr] == to && bChanged)
+ {
+ m_configuration.deviceTypes.types[iPtr] = CEC_DEVICE_TYPE_RESERVED;
+ }
+ }
+
+ if (bChanged)
+ {
+ FindLogicalAddresses();
+
+ CCECBusDevice *newDevice = GetDeviceByType(to);
+ if (previousDevice && newDevice)
+ {
+ newDevice->SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC);
+ previousDevice->SetDeviceStatus(CEC_DEVICE_STATUS_NOT_PRESENT);
+
+ newDevice->SetCecVersion(previousDevice->GetCecVersion(false));
+ previousDevice->SetCecVersion(CEC_VERSION_UNKNOWN);
+
+ newDevice->SetMenuLanguage(previousDevice->GetMenuLanguage(false));
+ cec_menu_language lang;
+ lang.device = previousDevice->GetLogicalAddress();
+ for (unsigned int iPtr = 0; iPtr < 4; iPtr++)
+ lang.language[iPtr] = '?';
+ lang.language[3] = 0;
+ previousDevice->SetMenuLanguage(lang);
+
+ newDevice->SetMenuState(previousDevice->GetMenuState());
+ previousDevice->SetMenuState(CEC_MENU_STATE_DEACTIVATED);
+
+ newDevice->SetOSDName(previousDevice->GetOSDName(false));
+ previousDevice->SetOSDName(ToString(previousDevice->GetLogicalAddress()));
+
+ newDevice->SetPhysicalAddress(previousDevice->GetPhysicalAddress(false));
+ previousDevice->SetPhysicalAddress(0xFFFF);
+
+ newDevice->SetPowerStatus(previousDevice->GetPowerStatus(false));
+ previousDevice->SetPowerStatus(CEC_POWER_STATUS_UNKNOWN);
+
+ newDevice->SetVendorId(previousDevice->GetVendorId(false));
+ previousDevice->SetVendorId(CEC_VENDOR_UNKNOWN);
+
+ if ((from == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || from == CEC_DEVICE_TYPE_RECORDING_DEVICE) &&
+ (to == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || to == CEC_DEVICE_TYPE_RECORDING_DEVICE))
+ {
+ ((CCECPlaybackDevice *) newDevice)->SetDeckControlMode(((CCECPlaybackDevice *) previousDevice)->GetDeckControlMode());
+ ((CCECPlaybackDevice *) previousDevice)->SetDeckControlMode(CEC_DECK_CONTROL_MODE_STOP);
+
+ ((CCECPlaybackDevice *) newDevice)->SetDeckStatus(((CCECPlaybackDevice *) previousDevice)->GetDeckStatus());
+ ((CCECPlaybackDevice *) previousDevice)->SetDeckStatus(CEC_DECK_INFO_STOP);
+ }
+ }
+ }
+
+ return true;
+}
+
+bool CCECProcessor::FindLogicalAddresses(void)
+{
+ bool bReturn(true);
+ m_configuration.logicalAddresses.Clear();
+
+ if (m_configuration.deviceTypes.IsEmpty())
+ {
+ CLibCEC::AddLog(CEC_LOG_ERROR, "no device types set");
+ return false;
+ }
+
+ for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
+ {
+ if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_RESERVED)
+ continue;
+
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - device %d: type %d", __FUNCTION__, iPtr, m_configuration.deviceTypes.types[iPtr]);
+
+ if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_RECORDING_DEVICE)
+ bReturn &= FindLogicalAddressRecordingDevice();
+ if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_TUNER)
+ bReturn &= FindLogicalAddressTuner();
+ if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_PLAYBACK_DEVICE)
+ bReturn &= FindLogicalAddressPlaybackDevice();
+ if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
+ bReturn &= FindLogicalAddressAudioSystem();
+ }
+
+ if (bReturn)
+ SetAckMask(m_configuration.logicalAddresses.AckMask());
+
+ return bReturn;
+}
+
+void CCECProcessor::ReplaceHandlers(void)
+{
+ if (!IsInitialised())
+ return;
+ for (uint8_t iPtr = 0; iPtr <= CECDEVICE_PLAYBACKDEVICE3; iPtr++)
+ m_busDevices[iPtr]->ReplaceHandler(m_bInitialised);
+}
+
+bool CCECProcessor::OnCommandReceived(const cec_command &command)
+{
+ ParseCommand(command);
+ return true;
+}
+
+void *CCECProcessor::Process(void)
+{
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "processor thread started");
+
+ while (!IsStopped() && m_communication->IsOpen())
+ {
+ if (IsInitialised())
+ {
+ ReplaceHandlers();
+
+ m_controller->CheckKeypressTimeout();
+ }
+ Sleep(5);
+ }
+
+ return NULL;
+}
+
+bool CCECProcessor::SetActiveSource(cec_device_type type /* = CEC_DEVICE_TYPE_RESERVED */)
+{
+ bool bReturn(false);
+
+ if (!IsRunning())
+ return bReturn;
+
+ cec_logical_address addr = m_configuration.logicalAddresses.primary;
+
+ if (type != CEC_DEVICE_TYPE_RESERVED)
+ {
+ for (uint8_t iPtr = 0; iPtr <= 11; iPtr++)
+ {
+ if (m_configuration.logicalAddresses[iPtr] && m_busDevices[iPtr]->m_type == type)
+ {
+ addr = (cec_logical_address) iPtr;
+ break;
+ }
+ }
+ }
+
+ m_busDevices[addr]->SetActiveSource();
+ if (m_busDevices[addr]->GetPhysicalAddress(false) != 0xFFFF)
+ bReturn = m_busDevices[addr]->ActivateSource();
+
+ return bReturn;
+}
+
+bool CCECProcessor::SetActiveSource(uint16_t iStreamPath)
+{
+ bool bReturn(false);
+
+ CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamPath);
+ if (device)
+ {
+ device->SetActiveSource();
+ bReturn = true;
+ }
+
+ return bReturn;
+}
+
+void CCECProcessor::SetStandardLineTimeout(uint8_t iTimeout)
+{
+ CLockObject lock(m_mutex);
+ m_iStandardLineTimeout = iTimeout;
+}
+
+void CCECProcessor::SetRetryLineTimeout(uint8_t iTimeout)
+{
+ CLockObject lock(m_mutex);
+ m_iRetryLineTimeout = iTimeout;
+}
+
+bool CCECProcessor::SetActiveView(void)
+{
+ CLibCEC::AddLog(CEC_LOG_WARNING, "deprecated method %s called", __FUNCTION__);
+ return SetActiveSource(m_configuration.deviceTypes.IsEmpty() ? CEC_DEVICE_TYPE_RESERVED : m_configuration.deviceTypes[0]);
+}
+
+bool CCECProcessor::SetDeckControlMode(cec_deck_control_mode mode, bool bSendUpdate /* = true */)
+{
+ bool bReturn(false);
+
+ CCECBusDevice *device = GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
+ if (device)
+ {
+ ((CCECPlaybackDevice *) device)->SetDeckControlMode(mode);
+ if (bSendUpdate)
+ ((CCECPlaybackDevice *) device)->TransmitDeckStatus(CECDEVICE_TV);
+ bReturn = true;
+ }
+
+ return bReturn;
+}
+
+bool CCECProcessor::SetDeckInfo(cec_deck_info info, bool bSendUpdate /* = true */)
+{
+ bool bReturn(false);
+
+ CCECBusDevice *device = GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
+ if (device)
+ {
+ ((CCECPlaybackDevice *) device)->SetDeckStatus(info);
+ if (bSendUpdate)
+ ((CCECPlaybackDevice *) device)->TransmitDeckStatus(CECDEVICE_TV);
+ bReturn = true;
+ }
+
+ return bReturn;
+}
+
+bool CCECProcessor::SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort, bool bForce /* = false */)
+{
+ bool bReturn(false);
+
+ {
+ CLockObject lock(m_mutex);
+ m_configuration.baseDevice = iBaseDevice;
+ m_configuration.iHDMIPort = iPort;
+ }
+
+ if (!IsRunning() && !bForce)
+ return true;
+
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "setting HDMI port to %d on device %s (%d)", iPort, ToString(iBaseDevice), (int)iBaseDevice);
+
+ uint16_t iPhysicalAddress(0);
+ if (iBaseDevice > CECDEVICE_TV)
+ {
+ iPhysicalAddress = m_busDevices[iBaseDevice]->GetPhysicalAddress();
+ }
+
+ if (iPhysicalAddress < 0xffff)
+ {
+ if (iPhysicalAddress == 0)
+ iPhysicalAddress += 0x1000 * iPort;
+ else if (iPhysicalAddress % 0x1000 == 0)
+ iPhysicalAddress += 0x100 * iPort;
+ else if (iPhysicalAddress % 0x100 == 0)
+ iPhysicalAddress += 0x10 * iPort;
+ else if (iPhysicalAddress % 0x10 == 0)
+ iPhysicalAddress += iPort;
+
+ bReturn = true;
+ }
+
+ if (!bReturn)
+ CLibCEC::AddLog(CEC_LOG_ERROR, "failed to set the physical address");
+ else
+ SetPhysicalAddress(iPhysicalAddress);
+
+ return bReturn;
+}
+
+bool CCECProcessor::PhysicalAddressInUse(uint16_t iPhysicalAddress)
+{
+ for (unsigned int iPtr = 0; iPtr < 15; iPtr++)
+ {
+ if (m_busDevices[iPtr]->GetPhysicalAddress(false) == iPhysicalAddress)
+ return true;
+ }
+ return false;
+}
+
+bool CCECProcessor::TransmitInactiveSource(void)
+{
+ if (!IsRunning())
+ return false;
+
+ if (!m_configuration.logicalAddresses.IsEmpty() && m_busDevices[m_configuration.logicalAddresses.primary])
+ return m_busDevices[m_configuration.logicalAddresses.primary]->TransmitInactiveSource();
+ return false;
+}
+
+void CCECProcessor::LogOutput(const cec_command &data)
+{
+ CStdString strTx;
+ strTx.Format("<< %02x", ((uint8_t)data.initiator << 4) + (uint8_t)data.destination);
+ if (data.opcode_set)
+ strTx.AppendFormat(":%02x", (uint8_t)data.opcode);
+
+ for (uint8_t iPtr = 0; iPtr < data.parameters.size; iPtr++)
+ strTx.AppendFormat(":%02x", data.parameters[iPtr]);
+ CLibCEC::AddLog(CEC_LOG_TRAFFIC, strTx.c_str());
+}
+
+bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress)
+{
+ CLockObject lock(m_mutex);
+ if (m_configuration.logicalAddresses.primary != iLogicalAddress)
+ {
+ CLibCEC::AddLog(CEC_LOG_NOTICE, "<< setting primary logical address to %1x", iLogicalAddress);
+ m_configuration.logicalAddresses.primary = iLogicalAddress;
+ m_configuration.logicalAddresses.Set(iLogicalAddress);
+ return SetAckMask(m_configuration.logicalAddresses.AckMask());
+ }
+
+ return true;
+}
+
+bool CCECProcessor::SetMenuState(cec_menu_state state, bool bSendUpdate /* = true */)
+{
+ for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
+ {
+ if (m_configuration.logicalAddresses[iPtr])
+ m_busDevices[iPtr]->SetMenuState(state);
+ }
+
+ if (bSendUpdate)
+ m_busDevices[m_configuration.logicalAddresses.primary]->TransmitMenuState(CECDEVICE_TV);
+
+ return true;
+}
+
+bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress, bool bSendUpdate /* = true */)
+{
+ bool bSendActiveView(false);
+ bool bReturn(false);
+ cec_logical_addresses sendUpdatesTo;
+ sendUpdatesTo.Clear();
+
+ {
+ CLockObject lock(m_mutex);
+ m_configuration.iPhysicalAddress = iPhysicalAddress;
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "setting physical address to '%4x'", iPhysicalAddress);
+
+ if (!m_configuration.logicalAddresses.IsEmpty())
+ {
+ bool bWasActiveSource(false);
+ for (uint8_t iPtr = 0; iPtr < 15; iPtr++)
+ if (m_configuration.logicalAddresses[iPtr])
+ {
+ bWasActiveSource |= m_busDevices[iPtr]->IsActiveSource();
+ m_busDevices[iPtr]->SetInactiveSource();
+ m_busDevices[iPtr]->SetPhysicalAddress(iPhysicalAddress);
+ if (bSendUpdate)
+ sendUpdatesTo.Set((cec_logical_address)iPtr);
+ }
+
+ bSendActiveView = bWasActiveSource && bSendUpdate;
+ bReturn = true;
+ }
+ }
+
+ for (uint8_t iPtr = 0; iPtr < 15; iPtr++)
+ if (sendUpdatesTo[iPtr])
+ m_busDevices[iPtr]->TransmitPhysicalAddress();
+
+ if (bSendActiveView)
+ SetActiveView();
+
+ if (bReturn)
+ CLibCEC::ConfigurationChanged(m_configuration);
+
+ return bReturn;
+}
+
+bool CCECProcessor::SwitchMonitoring(bool bEnable)
+{
+ CLibCEC::AddLog(CEC_LOG_NOTICE, "== %s monitoring mode ==", bEnable ? "enabling" : "disabling");
+
+ {
+ CLockObject lock(m_mutex);
+ m_bMonitor = bEnable;
+ }
+
+ if (bEnable)
+ return SetAckMask(0);
+ else
+ return SetAckMask(m_configuration.logicalAddresses.AckMask());
+}
+
+bool CCECProcessor::PollDevice(cec_logical_address iAddress)
+{
+ if (iAddress != CECDEVICE_UNKNOWN && m_busDevices[iAddress])
+ {
+ return m_configuration.logicalAddresses.primary == CECDEVICE_UNKNOWN ?
+ m_busDevices[iAddress]->TransmitPoll(iAddress) :
+ m_busDevices[m_configuration.logicalAddresses.primary]->TransmitPoll(iAddress);
+ }
+ return false;
+}
+
+uint8_t CCECProcessor::VolumeUp(bool bSendRelease /* = true */)
+{
+ uint8_t status = 0;
+ if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM))
+ status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->VolumeUp(bSendRelease);
+
+ return status;
+}
+
+uint8_t CCECProcessor::VolumeDown(bool bSendRelease /* = true */)
+{
+ uint8_t status = 0;
+ if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM))
+ status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->VolumeDown(bSendRelease);
+
+ return status;
+}
+
+uint8_t CCECProcessor::MuteAudio(bool bSendRelease /* = true */)
+{
+ uint8_t status = 0;
+ if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM))
+ status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->MuteAudio(bSendRelease);
+
+ return status;
+}
+
+CCECBusDevice *CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress, bool bRefresh /* = false */) const
+{
+ if (m_busDevices[m_configuration.logicalAddresses.primary]->GetPhysicalAddress(false) == iPhysicalAddress)
+ return m_busDevices[m_configuration.logicalAddresses.primary];
+
+ CCECBusDevice *device = NULL;
+ for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
+ {
+ if (m_busDevices[iPtr]->GetPhysicalAddress(bRefresh) == iPhysicalAddress)
+ {
+ device = m_busDevices[iPtr];
+ break;
+ }
+ }
+
+ return device;
+}
+
+CCECBusDevice *CCECProcessor::GetDeviceByType(cec_device_type type) const
+{
+ CCECBusDevice *device = NULL;
+
+ for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
+ {
+ if (m_busDevices[iPtr]->m_type == type && m_configuration.logicalAddresses[iPtr])
+ {
+ device = m_busDevices[iPtr];
+ break;
+ }
+ }
+
+ return device;
+}
+
+CCECBusDevice *CCECProcessor::GetPrimaryDevice(void) const
+{
+ CCECBusDevice *device(NULL);
+ cec_logical_address primary = m_configuration.logicalAddresses.primary;
+ if (primary != CECDEVICE_UNKNOWN)
+ device = m_busDevices[primary];
+ return device;
+}
+
+cec_version CCECProcessor::GetDeviceCecVersion(cec_logical_address iAddress)
+{
+ return m_busDevices[iAddress]->GetCecVersion();
+}
+
+cec_osd_name CCECProcessor::GetDeviceOSDName(cec_logical_address iAddress)
+{
+ CStdString strOSDName = m_busDevices[iAddress]->GetOSDName();
+ cec_osd_name retVal;
+
+ snprintf(retVal.name, sizeof(retVal.name), "%s", strOSDName.c_str());
+ retVal.device = iAddress;
+
+ return retVal;
+}
+
+bool CCECProcessor::GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language)
+{
+ if (m_busDevices[iAddress])
+ {
+ *language = m_busDevices[iAddress]->GetMenuLanguage();
+ return (strcmp(language->language, "???") != 0);
+ }
+ return false;
+}
+
+uint64_t CCECProcessor::GetDeviceVendorId(cec_logical_address iAddress)
+{
+ if (m_busDevices[iAddress])
+ return m_busDevices[iAddress]->GetVendorId();
+ return false;