no need to cache the physical address of the active source in the device map; the...
authorLars Op den Kamp <lars@opdenkamp.eu>
Wed, 14 Nov 2012 01:26:52 +0000 (02:26 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Wed, 14 Nov 2012 01:26:52 +0000 (02:26 +0100)
src/lib/CECProcessor.cpp
src/lib/devices/CECBusDevice.cpp
src/lib/devices/CECDeviceMap.cpp
src/lib/devices/CECDeviceMap.h
src/lib/implementations/CECCommandHandler.cpp

index 399e065daa81f9872e4d95d3efb54e2773c49d05..e432033961ab0a487cbeb4d4768d44455ac48824 100644 (file)
@@ -351,7 +351,7 @@ cec_logical_address CCECProcessor::GetActiveSource(bool bRequestActiveSource /*
   if (activeSource)
     return activeSource->GetLogicalAddress();
 
-  if (bRequestActiveSource && m_busDevices->GetActiveSourceAddress() == CEC_INVALID_PHYSICAL_ADDRESS)
+  if (bRequestActiveSource)
   {
     // request the active source from the bus
     CCECBusDevice *primary = GetPrimaryDevice();
index d50045af89eebe2ad5e3aaefbd5d29755d8a95ea..fd2a348a64a7bc6d87064fa2a298db9c1df59457 100644 (file)
@@ -537,9 +537,6 @@ bool CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress)
   {
     LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s (%X): physical address changed from %04x to %04x", GetLogicalAddressName(), m_iLogicalAddress, m_iPhysicalAddress, iNewAddress);
     m_iPhysicalAddress = iNewAddress;
-
-    if (m_processor->GetDevices()->GetActiveSourceAddress() == iNewAddress)
-      MarkAsActiveSource();
   }
   return true;
 }
index b614e1a9175a1c322e28578fcee55ca2390ebb65..b7f3ab2026b4143b88b1096358b04d513b5caa3c 100644 (file)
@@ -45,8 +45,7 @@ using namespace std;
 using namespace CEC;
 
 CCECDeviceMap::CCECDeviceMap(CCECProcessor *processor) :
-    m_processor(processor),
-    m_iActiveSource(CEC_INVALID_PHYSICAL_ADDRESS)
+    m_processor(processor)
 {
   for (uint8_t iPtr = CECDEVICE_TV; iPtr <= CECDEVICE_BROADCAST; iPtr++)
   {
@@ -207,10 +206,6 @@ 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;
   }
@@ -289,16 +284,6 @@ void CCECDeviceMap::GetChildrenOf(CECDEVICEVEC& devices, CCECBusDevice* device)
   }
 }
 
-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++)
index 50271dc04d61576f8827b3cd3f7390dc11a7112c..6037fa3d548140523b587b2df8d34c28eb2c441c 100644 (file)
@@ -63,8 +63,6 @@ namespace CEC
     void GetActive(CECDEVICEVEC &devices) const;
     void GetByType(const cec_device_type type, CECDEVICEVEC &devices) const;
     void GetChildrenOf(CECDEVICEVEC& devices, CCECBusDevice* device) const;
-    void SetActiveSource(uint16_t iPhysicalAddress);
-    uint16_t GetActiveSourceAddress(void) const;
     void SignalAll(cec_opcode opcode);
 
     void GetPowerOffDevices(const libcec_configuration &configuration, CECDEVICEVEC &devices) const;
@@ -82,6 +80,5 @@ namespace CEC
 
     CECDEVICEMAP   m_busDevices;
     CCECProcessor *m_processor;
-    uint16_t       m_iActiveSource;
   };
 }
index 3423c283b1960195a2ffb5f9bb3988ef2fe2b353..0e00e4c2ef0107e654538aa4d2555321b1a6ed20 100644 (file)
@@ -209,10 +209,12 @@ int CCECCommandHandler::HandleActiveSource(const cec_command &command)
   if (command.parameters.size == 2)
   {
     uint16_t iAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
-    m_processor->GetDevices()->SetActiveSource(iAddress);
-    CCECBusDevice *device = m_processor->GetDeviceByPhysicalAddress(iAddress);
+    CCECBusDevice *device = m_processor->GetDevice(command.initiator);
     if (device)
+    {
+      device->SetPhysicalAddress(iAddress);
       device->MarkAsActiveSource();
+    }
 
     m_processor->GetDevices()->SignalAll(command.opcode);
     return COMMAND_HANDLED;