From: Lars Op den Kamp Date: Fri, 27 Apr 2012 13:01:27 +0000 (+0200) Subject: cec-client: fixed entering bootloader mode X-Git-Tag: upstream/2.2.0~1^2~29^2^2~7 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=55c75e6e4bd3d1c44907b59768b891227bd8ab5a;p=deb_libcec.git cec-client: fixed entering bootloader mode --- diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 5ea6bd5..be14a0b 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -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) diff --git a/src/lib/adapter/USBCECAdapterCommunication.cpp b/src/lib/adapter/USBCECAdapterCommunication.cpp index 1d3df13..3b8d2a3 100644 --- a/src/lib/adapter/USBCECAdapterCommunication.cpp +++ b/src/lib/adapter/USBCECAdapterCommunication.cpp @@ -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) diff --git a/src/lib/adapter/USBCECAdapterMessageQueue.cpp b/src/lib/adapter/USBCECAdapterMessageQueue.cpp index 71289ce..a270a78 100644 --- a/src/lib/adapter/USBCECAdapterMessageQueue.cpp +++ b/src/lib/adapter/USBCECAdapterMessageQueue.cpp @@ -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; }