Skip to content

Commit

Permalink
fixed: don't probe all devices in CCECClient::IsActiveDeviceType(). c…
Browse files Browse the repository at this point in the history
…loses #492
  • Loading branch information
opdenkamp committed Mar 27, 2020
1 parent d208d0e commit 5e5788d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
6 changes: 1 addition & 5 deletions src/libcec/CECClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1457,11 +1457,7 @@ bool CCECClient::IsActiveDevice(const cec_logical_address 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();
return m_processor->GetDevices()->IsActiveType(type);
}

cec_logical_address CCECClient::GetActiveSource(void)
Expand Down
7 changes: 7 additions & 0 deletions src/libcec/devices/CECBusDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,13 @@ bool CCECBusDevice::IsHandledByLibCEC(void)
return m_deviceStatus == CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC;
}

bool CCECBusDevice::IsActive(void)
{
CLockObject lock(m_mutex);
return (m_deviceStatus == CEC_DEVICE_STATUS_PRESENT) ||
(m_deviceStatus == CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC);
}

void CCECBusDevice::SetUnsupportedFeature(cec_opcode opcode)
{
// some commands should never be marked as unsupported
Expand Down
1 change: 1 addition & 0 deletions src/libcec/devices/CECBusDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ namespace CEC
virtual const char* GetLogicalAddressName(void) const;
virtual bool IsPresent(void);
virtual bool IsHandledByLibCEC(void);
virtual bool IsActive(void);

virtual bool HandleCommand(const cec_command &command);
virtual bool IsUnsupportedFeature(cec_opcode opcode);
Expand Down
24 changes: 19 additions & 5 deletions src/libcec/devices/CECDeviceMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,27 @@ void CCECDeviceMap::GetLibCECControlled(CECDEVICEVEC &devices) const

void CCECDeviceMap::GetActive(CECDEVICEVEC &devices) const
{
for (CECDEVICEMAP::const_iterator it = m_busDevices.begin(); it != m_busDevices.end(); it++)
for (auto it = m_busDevices.begin(); it != m_busDevices.end(); ++it)
{
cec_bus_device_status status = it->second->GetStatus();
if (status == CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC ||
status == CEC_DEVICE_STATUS_PRESENT)
devices.push_back(it->second);
auto dev = it->second;
if (!!dev && dev->IsActive()) {
devices.push_back(it->second);
}
}
}

bool CCECDeviceMap::IsActiveType(const cec_device_type type) const
{
for (auto it = m_busDevices.begin(); it != m_busDevices.end(); ++it)
{
auto dev = it->second;
if (!!dev &&
(dev->GetType() == type) &&
(dev->IsActive())) {
return true;
}
}
return false;
}

void CCECDeviceMap::GetPowerOffDevices(const libcec_configuration &configuration, CECDEVICEVEC &devices) const
Expand Down
1 change: 1 addition & 0 deletions src/libcec/devices/CECDeviceMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ namespace CEC
void GetLibCECControlled(CECDEVICEVEC &devices) const;
void GetByLogicalAddresses(CECDEVICEVEC &devices, const cec_logical_addresses &addresses);
void GetActive(CECDEVICEVEC &devices) const;
bool IsActiveType(const cec_device_type type) const;
void GetByType(const cec_device_type type, CECDEVICEVEC &devices) const;
void GetChildrenOf(CECDEVICEVEC& devices, CCECBusDevice* device) const;
void SignalAll(cec_opcode opcode);
Expand Down

0 comments on commit 5e5788d

Please sign in to comment.