cec: changed the name of the new menu state callback to match the formatting of the...
[deb_libcec.git] / src / lib / adapter / USBCECAdapterCommunication.cpp
index a74194369029665969f01de31ab8783b70b997d5..ef80ed049731abe60fe886f67dcd91018a40ac89 100644 (file)
@@ -64,6 +64,7 @@ CUSBCECAdapterCommunication::~CUSBCECAdapterCommunication(void)
   Close();
   delete m_commands;
   delete m_adapterMessageQueue;
+  delete m_port;
 }
 
 bool CUSBCECAdapterCommunication::Open(uint32_t iTimeoutMs /* = 10000 */, bool bSkipChecks /* = false */, bool bStartListening /* = true */)
@@ -145,11 +146,6 @@ bool CUSBCECAdapterCommunication::Open(uint32_t iTimeoutMs /* = 10000 */, bool b
 
   if (!bConnectionOpened || !bStartListening)
     StopThread(0);
-  if (!bConnectionOpened)
-  {
-    delete m_port;
-    m_port = NULL;
-  }
 
   return bConnectionOpened;
 }
@@ -174,8 +170,8 @@ void CUSBCECAdapterCommunication::Close(void)
   StopThread(0);
 
   /* close and delete the com port connection */
-  delete m_port;
-  m_port = NULL;
+  if (m_port)
+    m_port->Close();
 }
 
 cec_adapter_message_state CUSBCECAdapterCommunication::Write(const cec_command &data, uint8_t iMaxTries, uint8_t iLineTimeout /* = 3 */, uint8_t iRetryLineTimeout /* = 3 */)
@@ -268,10 +264,11 @@ void CUSBCECAdapterCommunication::ClearInputBytes(uint32_t iTimeout /* = 1000 */
   CTimeout timeout(iTimeout);
   uint8_t buff[1024];
   ssize_t iBytesRead(0);
-  bool bGotMsgEnd(false);
+  bool bGotMsgEnd(true);
 
   while (timeout.TimeLeft() > 0 && ((iBytesRead = m_port->Read(buff, 1024, 5)) > 0 || !bGotMsgEnd))
   {
+    bGotMsgEnd = false;
     /* if something was received, wait for MSGEND */
     for (ssize_t iPtr = 0; iPtr < iBytesRead; iPtr++)
       bGotMsgEnd = buff[iPtr] == MSGEND;