stall outgoing messages when the logical address was lost, until we got a new address
authorLars Op den Kamp <lars@opdenkamp.eu>
Wed, 5 Sep 2012 13:05:19 +0000 (15:05 +0200)
committerLars Op den Kamp <lars@opdenkamp.eu>
Wed, 5 Sep 2012 13:07:59 +0000 (15:07 +0200)
src/lib/CECProcessor.cpp
src/lib/CECProcessor.h

index 8df38846002ecb643e31135a0b37f33d26cd66fc..9d496404d30a338b61a9acbb43ef70f3c2b34c06 100644 (file)
@@ -64,13 +64,15 @@ CCECProcessor::CCECProcessor(CLibCEC *libcec) :
     m_iRetryLineTimeout(3),
     m_iLastTransmission(0),
     m_bMonitor(true),
-    m_addrAllocator(NULL)
+    m_addrAllocator(NULL),
+    m_bStallCommunication(false)
 {
   m_busDevices = new CCECDeviceMap(this);
 }
 
 CCECProcessor::~CCECProcessor(void)
 {
+  m_bStallCommunication = false;
   DELETE_AND_NULL(m_addrAllocator);
   Close();
   DELETE_AND_NULL(m_busDevices);
@@ -412,6 +414,9 @@ bool CCECProcessor::Transmit(const cec_command &data, bool bIsReply)
     }
   }
 
+  // wait until we finished allocating a new LA if it got lost
+  while (m_bStallCommunication) Sleep(5);
+
   {
     CLockObject lock(m_mutex);
     m_iLastTransmission = GetTimeMs();
@@ -686,6 +691,9 @@ bool CCECProcessor::AllocateLogicalAddresses(CCECClient* client)
   // set the new ackmask
   SetLogicalAddresses(GetLogicalAddresses());
 
+  // resume outgoing communication
+  m_bStallCommunication = false;
+
   return true;
 }
 
@@ -918,6 +926,9 @@ void CCECProcessor::SwitchMonitoring(bool bSwitchTo)
 
 void CCECProcessor::HandleLogicalAddressLost(cec_logical_address oldAddress)
 {
+  // stall outgoing messages until we know our new LA
+  m_bStallCommunication = true;
+
   m_libcec->AddLog(CEC_LOG_NOTICE, "logical address %x was taken by another device, allocating a new address", oldAddress);
   CCECClient* client = GetClient(oldAddress);
   if (client)
index 6ad60c515a6c7a55137423b62f2602cf59f7b492..e1f6d68517eee2908cc7f1b6906e72db0f29240b 100644 (file)
@@ -170,5 +170,6 @@ namespace CEC
       std::map<cec_logical_address, CCECClient *> m_clients;
       bool                                        m_bMonitor;
       CCECAllocateLogicalAddress*                 m_addrAllocator;
+      bool                                        m_bStallCommunication;
   };
 };