only mark a device as active source from cache if it's powered on
[deb_libcec.git] / src / lib / devices / CECDeviceMap.cpp
index 3c70603a541092ce56eadde795b899fbf3d84e75..b614e1a9175a1c322e28578fcee55ca2390ebb65 100644 (file)
  *     http://www.pulse-eight.net/
  */
 
+#include "env.h"
 #include "CECDeviceMap.h"
+
 #include "CECAudioSystem.h"
 #include "CECPlaybackDevice.h"
 #include "CECRecordingDevice.h"
 #include "CECTuner.h"
 #include "CECTV.h"
-#include "../CECProcessor.h"
+#include "lib/CECProcessor.h"
+#include "lib/CECTypeUtils.h"
 
 using namespace std;
 using namespace CEC;
 
 CCECDeviceMap::CCECDeviceMap(CCECProcessor *processor) :
-    m_processor(processor)
+    m_processor(processor),
+    m_iActiveSource(CEC_INVALID_PHYSICAL_ADDRESS)
 {
   for (uint8_t iPtr = CECDEVICE_TV; iPtr <= CECDEVICE_BROADCAST; iPtr++)
   {
@@ -203,6 +207,10 @@ CCECBusDevice *CCECDeviceMap::GetActiveSource(void) const
 {
   for (CECDEVICEMAP::const_iterator it = m_busDevices.begin(); it != m_busDevices.end(); it++)
   {
+    if (m_iActiveSource != CEC_INVALID_PHYSICAL_ADDRESS && !it->second->IsActiveSource() &&
+        it->second->GetCurrentPowerStatus() == CEC_POWER_STATUS_ON &&
+        m_iActiveSource == it->second->GetCurrentPhysicalAddress())
+      it->second->MarkAsActiveSource();
     if (it->second->IsActiveSource())
       return it->second;
   }
@@ -264,3 +272,35 @@ cec_logical_addresses CCECDeviceMap::ToLogicalAddresses(const CECDEVICEVEC &devi
     addresses.Set((*it)->GetLogicalAddress());
   return addresses;
 }
+
+void CCECDeviceMap::GetChildrenOf(CECDEVICEVEC& devices, CCECBusDevice* device) const
+{
+  devices.clear();
+  if (!device)
+    return;
+
+  uint16_t iPA = device->GetCurrentPhysicalAddress();
+
+  for (CECDEVICEMAP::const_iterator it = m_busDevices.begin(); it != m_busDevices.end(); it++)
+  {
+    uint16_t iCurrentPA = it->second->GetCurrentPhysicalAddress();
+    if (CCECTypeUtils::PhysicalAddressIsIncluded(iPA, iCurrentPA))
+      devices.push_back(it->second);
+  }
+}
+
+void CCECDeviceMap::SetActiveSource(uint16_t iPhysicalAddress)
+{
+  m_iActiveSource = iPhysicalAddress;
+}
+
+uint16_t CCECDeviceMap::GetActiveSourceAddress(void) const
+{
+  return m_iActiveSource;
+}
+
+void CCECDeviceMap::SignalAll(cec_opcode opcode)
+{
+  for (CECDEVICEMAP::iterator it = m_busDevices.begin(); it != m_busDevices.end(); it++)
+    it->second->SignalOpcode(opcode);
+}