rpi: don't try to re-register a logical address when the logical address isn't regist...
authorLars Op den Kamp <lars@opdenkamp.eu>
Tue, 22 Jan 2013 00:47:18 +0000 (01:47 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Tue, 22 Jan 2013 00:47:18 +0000 (01:47 +0100)
src/lib/adapter/RPi/RPiCECAdapterCommunication.cpp
src/lib/adapter/RPi/RPiCECAdapterCommunication.h

index e1fcae6af7cd5caf561afe94e918ca6b78f23b06..8084b780a15bf8c62756f74d217662995aaad95e 100644 (file)
@@ -62,7 +62,8 @@ CRPiCECAdapterCommunication::CRPiCECAdapterCommunication(IAdapterCommunicationCa
     IAdapterCommunication(callback),
     m_logicalAddress(CECDEVICE_UNKNOWN),
     m_bLogicalAddressChanged(false),
-    m_previousLogicalAddress(CECDEVICE_FREEUSE)
+    m_previousLogicalAddress(CECDEVICE_FREEUSE),
+    m_bLogicalAddressRegistered(false)
 {
   m_queue = new CRPiCECAdapterMessageQueue(this);
 }
@@ -199,7 +200,12 @@ void CRPiCECAdapterCommunication::OnDataReceived(uint32_t header, uint32_t p0, u
       m_logicalAddress = CECDEVICE_UNKNOWN;
 
       // notify libCEC that we lost our LA when the connection was initialised
-      if (m_bInitialised)
+      bool bNotify(false);
+      {
+        CLockObject lock(m_mutex);
+        bNotify = m_bInitialised && m_bLogicalAddressRegistered;
+      }
+      if (bNotify)
         m_callback->HandleLogicalAddressLost(previousAddress);
     }
     break;
@@ -379,7 +385,11 @@ bool CRPiCECAdapterCommunication::UnregisterLogicalAddress(void)
     return true;
 
   LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s - releasing previous logical address", __FUNCTION__);
-  m_bLogicalAddressChanged = false;
+  {
+    CLockObject lock(m_mutex);
+    m_bLogicalAddressRegistered = false;
+    m_bLogicalAddressChanged    = false;
+  }
 
   vc_cec_release_logical_address();
 
@@ -411,7 +421,12 @@ bool CRPiCECAdapterCommunication::RegisterLogicalAddress(const cec_logical_addre
     return false;
   }
 
-  return m_logicalAddressCondition.Wait(m_mutex, m_bLogicalAddressChanged);
+  if (m_logicalAddressCondition.Wait(m_mutex, m_bLogicalAddressChanged))
+  {
+    m_bLogicalAddressRegistered = true;
+    return true;
+  }
+  return false;
 }
 
 cec_logical_addresses CRPiCECAdapterCommunication::GetLogicalAddresses(void)
index 92b7157be3360d0e00e1af181cbce4968ec45a60..9a0a9fd62f4e7a22966130893dd1f0716a5d0594 100644 (file)
@@ -110,6 +110,7 @@ namespace CEC
     VCHI_INSTANCE_T             m_vchi_instance;
     VCHI_CONNECTION_T *         m_vchi_connection;
     cec_logical_address         m_previousLogicalAddress;
+    bool                        m_bLogicalAddressRegistered;
   };
 };