+
+CStdString CCECClient::GetConnectionInfo(void)
+{
+ CStdString strLog;
+ strLog.Format("libCEC version = %s, client version = %s, firmware version = %d", ToString((cec_server_version)m_configuration.serverVersion), ToString((cec_client_version)m_configuration.clientVersion), m_configuration.iFirmwareVersion);
+ if (m_configuration.iFirmwareBuildDate != CEC_FW_BUILD_UNKNOWN)
+ {
+ time_t buildTime = (time_t)m_configuration.iFirmwareBuildDate;
+ strLog.AppendFormat(", firmware build date: %s", asctime(gmtime(&buildTime)));
+ strLog = strLog.Left((int)strLog.length() - 1); // strip \n added by asctime
+ strLog.append(" +0000");
+ }
+
+ // log the addresses that are being used
+ if (!m_configuration.logicalAddresses.IsEmpty())
+ {
+ strLog.append(", logical address(es) = ");
+ CECDEVICEVEC devices;
+ m_processor->GetDevices()->GetByLogicalAddresses(devices, m_configuration.logicalAddresses);
+ for (CECDEVICEVEC::iterator it = devices.begin(); it != devices.end(); it++)
+ strLog.AppendFormat("%s (%X) ", (*it)->GetLogicalAddressName(), (*it)->GetLogicalAddress());
+ }
+
+ if (!CLibCEC::IsValidPhysicalAddress(m_configuration.iPhysicalAddress))
+ strLog.AppendFormat(", base device: %s (%X), HDMI port number: %d", ToString(m_configuration.baseDevice), m_configuration.baseDevice, m_configuration.iHDMIPort);
+ else
+ strLog.AppendFormat(", physical address: %04x", m_configuration.iPhysicalAddress);
+
+ return strLog;
+}
+
+void CCECClient::SetTVVendorOverride(const cec_vendor_id id)
+{
+ {
+ CLockObject lock(m_mutex);
+ m_configuration.tvVendor = id;
+ }
+
+ if (id != CEC_VENDOR_UNKNOWN)
+ {
+ LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s - vendor id '%s'", __FUNCTION__, ToString(id));
+
+ CCECBusDevice *tv = m_processor ? m_processor->GetTV() : NULL;
+ if (tv)
+ tv->SetVendorId((uint64_t)id);
+ }
+}
+
+cec_vendor_id CCECClient::GetTVVendorOverride(void)
+{
+ CLockObject lock(m_mutex);
+ return (cec_vendor_id)m_configuration.tvVendor;
+}
+
+void CCECClient::SetOSDName(const CStdString &strDeviceName)
+{
+ {
+ CLockObject lock(m_mutex);
+ snprintf(m_configuration.strDeviceName, 13, "%s", strDeviceName.c_str());
+ }
+
+ LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s - using OSD name '%s'", __FUNCTION__, strDeviceName.c_str());
+
+ CCECBusDevice *primary = GetPrimaryDevice();
+ if (primary && !primary->GetCurrentOSDName().Equals(strDeviceName))
+ {
+ primary->SetOSDName(strDeviceName);
+ if (m_processor && m_processor->IsRunning())
+ primary->TransmitOSDName(CECDEVICE_TV);
+ }
+}
+
+CStdString CCECClient::GetOSDName(void)
+{
+ CLockObject lock(m_mutex);
+ CStdString strOSDName(m_configuration.strDeviceName);
+ return strOSDName;
+}
+
+void CCECClient::SetWakeDevices(const cec_logical_addresses &addresses)
+{
+ CLockObject lock(m_mutex);
+ m_configuration.wakeDevices = addresses;
+}
+
+cec_logical_addresses CCECClient::GetWakeDevices(void)
+{
+ CLockObject lock(m_mutex);
+ return m_configuration.wakeDevices;
+}
+
+bool CCECClient::AutodetectPhysicalAddress(void)
+{
+ bool bPhysicalAutodetected(false);
+ uint16_t iPhysicalAddress = m_processor ? m_processor->GetDetectedPhysicalAddress() : CEC_INVALID_PHYSICAL_ADDRESS;
+
+ if (CLibCEC::IsValidPhysicalAddress(iPhysicalAddress))
+ {
+ LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s - autodetected physical address '%04X'", __FUNCTION__, iPhysicalAddress);
+
+ CLockObject lock(m_mutex);
+ m_configuration.iPhysicalAddress = iPhysicalAddress;
+ m_configuration.iHDMIPort = CEC_HDMI_PORTNUMBER_NONE;
+ m_configuration.baseDevice = CECDEVICE_UNKNOWN;
+ bPhysicalAutodetected = true;
+ }
+
+ SetDevicePhysicalAddress(iPhysicalAddress);
+
+ return bPhysicalAutodetected;
+}
+
+void CCECClient::SetClientVersion(const cec_client_version version)
+{
+ LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s - using client version '%s'", __FUNCTION__, ToString(version));
+
+ CLockObject lock(m_mutex);
+ m_configuration.clientVersion = (uint32_t)version;
+}
+
+cec_client_version CCECClient::GetClientVersion(void)
+{
+ CLockObject lock(m_mutex);
+ return (cec_client_version)m_configuration.clientVersion;
+}
+
+bool CCECClient::SetDeviceTypes(const cec_device_type_list &deviceTypes)
+{
+ bool bNeedReinit(false);
+
+ {
+ CLockObject lock(m_mutex);
+ bNeedReinit = m_processor && m_processor->IsRunning() &&
+ (m_configuration.deviceTypes != deviceTypes);
+ m_configuration.deviceTypes = deviceTypes;
+ }
+
+ if (bNeedReinit)
+ LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s - using primary device type '%s'", __FUNCTION__, ToString(deviceTypes[0]));
+
+ return bNeedReinit;
+}
+
+cec_device_type_list CCECClient::GetDeviceTypes(void)
+{
+ cec_device_type_list retVal;
+ CLockObject lock(m_mutex);
+ retVal = m_configuration.deviceTypes;
+ return retVal;
+}
+
+bool CCECClient::SetDevicePhysicalAddress(const uint16_t iPhysicalAddress)
+{
+ if (!CLibCEC::IsValidPhysicalAddress(iPhysicalAddress))
+ return false;
+
+ // reconfigure all devices
+ cec_logical_address reactivateSource(CECDEVICE_UNKNOWN);
+ CECDEVICEVEC devices;
+ m_processor->GetDevices()->GetByLogicalAddresses(devices, m_configuration.logicalAddresses);
+ for (CECDEVICEVEC::iterator it = devices.begin(); it != devices.end(); it++)
+ {
+ // if this device was the active source, reactivate it afterwards
+ if ((*it)->IsActiveSource())
+ reactivateSource = (*it)->GetLogicalAddress();
+
+ // mark the device as inactive source
+ if (IsInitialised())
+ (*it)->MarkAsInactiveSource();
+
+ // set the new physical address
+ (*it)->SetPhysicalAddress(iPhysicalAddress);
+
+ // and transmit it
+ if (IsInitialised())
+ (*it)->TransmitPhysicalAddress();
+ }
+
+ // reactivate the previous active source
+ if (reactivateSource != CECDEVICE_UNKNOWN &&
+ m_processor->IsRunning() &&
+ IsInitialised())
+ {
+ CCECBusDevice *device = m_processor->GetDevice(reactivateSource);
+ if (device)
+ device->ActivateSource();
+ }
+
+ return true;
+}
+
+bool CCECClient::SwitchMonitoring(bool bEnable)
+{
+ return m_processor ? m_processor->SwitchMonitoring(bEnable) : false;
+}
+
+bool CCECClient::PollDevice(const cec_logical_address iAddress)
+{
+ // try to find the primary device
+ CCECBusDevice *primary = GetPrimaryDevice();
+ // poll the destination, with the primary as source
+ if (primary)
+ return primary->TransmitPoll(iAddress);
+
+ return m_processor ? m_processor->PollDevice(iAddress) : false;
+}
+
+cec_logical_addresses CCECClient::GetActiveDevices(void)
+{
+ CECDEVICEVEC activeDevices;
+ if (m_processor)
+ m_processor->GetDevices()->GetActive(activeDevices);
+ return CCECDeviceMap::ToLogicalAddresses(activeDevices);
+}
+
+bool CCECClient::IsActiveDevice(const cec_logical_address iAddress)
+{
+ cec_logical_addresses activeDevices = GetActiveDevices();
+ return activeDevices.IsSet(iAddress);
+}
+
+bool CCECClient::IsActiveDeviceType(const cec_device_type type)
+{
+ CECDEVICEVEC activeDevices;
+ if (m_processor)
+ m_processor->GetDevices()->GetActive(activeDevices);
+ CCECDeviceMap::FilterType(type, activeDevices);
+ return !activeDevices.empty();
+}
+
+cec_logical_address CCECClient::GetActiveSource(void)
+{
+ return m_processor ? m_processor->GetActiveSource() : CECDEVICE_UNKNOWN;
+}
+
+bool CCECClient::IsActiveSource(const cec_logical_address iAddress)
+{
+ return m_processor ? m_processor->IsActiveSource(iAddress) : false;
+}
+
+bool CCECClient::SetStreamPath(const cec_logical_address iAddress)
+{
+ uint16_t iPhysicalAddress = GetDevicePhysicalAddress(iAddress);
+ if (iPhysicalAddress != CEC_INVALID_PHYSICAL_ADDRESS)
+ return SetStreamPath(iPhysicalAddress);
+ return false;
+}
+
+bool CCECClient::SetStreamPath(const uint16_t iPhysicalAddress)
+{
+ return m_processor ? m_processor->SetStreamPath(iPhysicalAddress) : false;
+}
+
+cec_logical_addresses CCECClient::GetLogicalAddresses(void)
+{
+ cec_logical_addresses addresses;
+ CLockObject lock(m_mutex);
+ addresses = m_configuration.logicalAddresses;
+ return addresses;
+}
+
+bool CCECClient::CanPersistConfiguration(void)
+{
+ return m_processor ? m_processor->CanPersistConfiguration() : false;
+}
+
+bool CCECClient::PersistConfiguration(const libcec_configuration &configuration)
+{
+ return m_processor ? m_processor->PersistConfiguration(configuration) : false;
+}
+
+void CCECClient::RescanActiveDevices(void)
+{
+ if (m_processor)
+ m_processor->RescanActiveDevices();
+}
+
+bool CCECClient::IsLibCECActiveSource(void)
+{
+ bool bReturn(false);
+ if (m_processor)
+ {
+ cec_logical_address activeSource = m_processor->GetActiveSource();
+ CCECBusDevice *device = m_processor->GetDevice(activeSource);
+ if (device)
+ bReturn = device->IsHandledByLibCEC();
+ }
+ return bReturn;
+}