cec-client: fixed entering bootloader mode
authorLars Op den Kamp <lars@opdenkamp.eu>
Fri, 27 Apr 2012 13:01:27 +0000 (15:01 +0200)
committerLars Op den Kamp <lars@opdenkamp.eu>
Fri, 27 Apr 2012 13:01:27 +0000 (15:01 +0200)
src/lib/CECProcessor.cpp
src/lib/adapter/USBCECAdapterCommunication.cpp
src/lib/adapter/USBCECAdapterMessageQueue.cpp

index 5ea6bd5de62d9501daded2a4b64db06d491781fb..be14a0b837b22bd0dbdcaae8351b35f3ac66dd4c 100644 (file)
@@ -1509,9 +1509,9 @@ const char *CCECProcessor::ToString(const cec_server_version version)
 
 bool CCECProcessor::StartBootloader(const char *strPort /* = NULL */)
 {
+  bool bReturn(false);
   if (!m_communication && strPort)
   {
-    bool bReturn(false);
     IAdapterCommunication *comm = new CUSBCECAdapterCommunication(this, strPort);
     CTimeout timeout(CEC_DEFAULT_CONNECT_TIMEOUT);
     int iConnectTry(0);
@@ -1530,8 +1530,12 @@ bool CCECProcessor::StartBootloader(const char *strPort /* = NULL */)
   }
   else
   {
-    return m_communication->StartBootloader();
+    m_communication->StartBootloader();
+    Close();
+    bReturn = true;
   }
+
+  return bReturn;
 }
 
 bool CCECProcessor::PingAdapter(void)
index 1d3df13c907541d4863a902644f395bec06cfae1..3b8d2a39275c4f847f7da6cfe7f03dfc6ca18be1 100644 (file)
@@ -458,7 +458,12 @@ bool CUSBCECAdapterCommunication::IsInitialised(void)
 
 bool CUSBCECAdapterCommunication::StartBootloader(void)
 {
-  return m_port->IsOpen() ? m_commands->StartBootloader() : false;
+  if (m_port->IsOpen() && m_commands->StartBootloader())
+  {
+    Close();
+    return true;
+  }
+  return false;
 }
 
 bool CUSBCECAdapterCommunication::SetAckMask(uint16_t iMask)
index 71289ce52687d7c5248a4aff0707dc219aa4682f..a270a78235792a39a81a6fd746088c7155cea175 100644 (file)
@@ -232,11 +232,15 @@ void *CCECAdapterMessageQueue::Process(void)
   while (!IsStopped())
   {
     /* wait for a new message */
-    if (m_writeQueue.Pop(message, MESSAGE_QUEUE_SIGNAL_WAIT_TIME))
+    if (m_writeQueue.Pop(message, MESSAGE_QUEUE_SIGNAL_WAIT_TIME) && message)
     {
       /* write this message */
-      m_com->WriteToDevice(message->m_message);
-      if (message->m_message->state == ADAPTER_MESSAGE_STATE_ERROR)
+      {
+        CLockObject lock(m_mutex);
+        m_com->WriteToDevice(message->m_message);
+      }
+      if (message->m_message->state == ADAPTER_MESSAGE_STATE_ERROR ||
+          message->m_message->Message() == MSGCODE_START_BOOTLOADER)
       {
         message->Signal();
         Clear();
@@ -308,13 +312,12 @@ bool CCECAdapterMessageQueue::Write(CCECAdapterMessage *msg)
     m_com->SetLineTimeout(msg->lineTimeout);
   }
 
-  CCECAdapterMessageQueueEntry *entry(NULL);
+  CCECAdapterMessageQueueEntry *entry = new CCECAdapterMessageQueueEntry(msg);
   uint64_t iEntryId(0);
   /* add to the wait for ack queue */
   if (msg->Message() != MSGCODE_START_BOOTLOADER)
   {
     CLockObject lock(m_mutex);
-    entry = new CCECAdapterMessageQueueEntry(msg);
     iEntryId = m_iNextMessage++;
     m_messages.insert(make_pair(iEntryId, entry));
   }
@@ -332,8 +335,11 @@ bool CCECAdapterMessageQueue::Write(CCECAdapterMessage *msg)
       bReturn = false;
     }
 
-    CLockObject lock(m_mutex);
-    m_messages.erase(iEntryId);
+    if (msg->Message() != MSGCODE_START_BOOTLOADER)
+    {
+      CLockObject lock(m_mutex);
+      m_messages.erase(iEntryId);
+    }
     delete entry;
   }