cec: make SetStreamPath() thread safe. bugzid: 19
authorLars Op den Kamp <lars@opdenkamp.eu>
Tue, 22 Nov 2011 23:50:57 +0000 (00:50 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Tue, 22 Nov 2011 23:51:21 +0000 (00:51 +0100)
src/lib/CECProcessor.cpp
src/lib/devices/CECBusDevice.cpp
src/lib/devices/CECBusDevice.h

index a51abc7917b2fdc48fa4b789e6277027f1f33d1d..a7ff64ca09ea8c42357242b5125c6615b389d14d 100644 (file)
@@ -360,12 +360,7 @@ bool CCECProcessor::SetStreamPath(uint16_t iStreamPath)
   CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamPath);
   if (device)
   {
-    for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
-      m_busDevices[iPtr]->m_bActiveSource = false;
-
-    device->m_bActiveSource = true;
-    device->m_powerStatus   = CEC_POWER_STATUS_ON;
-
+    device->SetActiveDevice();
     bReturn = true;
   }
 
index 1fca4a513f04ce99073210d31c0586e806a8374e..e46e82df9dff67b300eeb9f6b96672563bc781dc 100644 (file)
@@ -216,7 +216,7 @@ cec_power_status CCECBusDevice::GetPowerStatus(void)
   return m_powerStatus;
 }
 
-const cec_vendor_id CCECBusDevice::GetVendorId(void)
+cec_vendor_id CCECBusDevice::GetVendorId(void)
 {
   if (m_vendor == CEC_VENDOR_UNKNOWN)
   {
@@ -283,6 +283,24 @@ void CCECBusDevice::SetMenuState(const cec_menu_state state)
   }
 }
 
+void CCECBusDevice::SetInactiveDevice(void)
+{
+  CLockObject lock(&m_mutex);
+  m_bActiveSource = false;
+}
+
+void CCECBusDevice::SetActiveDevice(void)
+{
+  CLockObject lock(&m_mutex);
+
+  for (int iPtr = 0; iPtr < 16; iPtr++)
+    if (iPtr != m_iLogicalAddress)
+      m_processor->m_busDevices[iPtr]->SetInactiveDevice();
+
+  m_bActiveSource = true;
+  m_powerStatus   = CEC_POWER_STATUS_ON;
+}
+
 void CCECBusDevice::SetPhysicalAddress(uint16_t iNewAddress)
 {
   if (iNewAddress > 0)
index 245f829405ece5fa8cdca9c24caa3309b5b72726..6b0ddb9180b2e35615a3ee55c65787fc8fadd38e 100644 (file)
@@ -67,10 +67,13 @@ namespace CEC
     virtual cec_power_status    GetPowerStatus(void);
     virtual CCECProcessor *     GetProcessor(void) const { return m_processor; }
     virtual cec_device_type     GetType(void) const { return m_type; }
-    virtual const cec_vendor_id GetVendorId(void);
+    virtual cec_vendor_id       GetVendorId(void);
     virtual const char *        GetVendorName(void);
     virtual bool                MyLogicalAddressContains(cec_logical_address address) const;
 
+    virtual void SetInactiveDevice(void);
+    virtual void SetActiveDevice(void);
+
     virtual void SetPhysicalAddress(uint16_t iNewAddress);
     virtual void SetStreamPath(uint16_t iNewAddress, uint16_t iOldAddress = 0);
     virtual void SetCecVersion(const cec_version newVersion);