cec: only send unhandled and selected commands to the command buffer
[deb_libcec.git] / src / lib / CECProcessor.cpp
index 19984f0312c3b33b68eb04a6fc6a79e092001afd..8b8532d7c1d6d2c30df9673d8369fab56fe43e9b 100644 (file)
@@ -216,7 +216,7 @@ bool CCECProcessor::GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu
   if (m_busDevices[iAddress])
   {
     *language = m_busDevices[iAddress]->GetMenuLanguage();
-    return (strcmp(language->language, "???") == 0);
+    return (strcmp(language->language, "???") != 0);
   }
   return false;
 }
@@ -259,16 +259,13 @@ bool CCECProcessor::Transmit(const cec_command &data)
       }
     }
 
-    if (data.ack_timeout > 0)
+    if (data.transmit_timeout > 0)
     {
-      bool bError(false);
-      if ((bReturn = WaitForAck(&bError, output->size(), data.ack_timeout)) == false)
+      if ((bReturn = WaitForTransmitSucceeded(output->size(), data.transmit_timeout)) == false)
         m_controller->AddLog(CEC_LOG_ERROR, "did not receive ack");
     }
     else
-    {
       bReturn = true;
-    }
   }
 
   return bReturn;
@@ -286,16 +283,16 @@ void CCECProcessor::TransmitAbort(cec_logical_address address, cec_opcode opcode
   Transmit(command);
 }
 
-bool CCECProcessor::WaitForAck(bool *bError, uint8_t iLength, uint32_t iTimeout /* = 1000 */)
+bool CCECProcessor::WaitForTransmitSucceeded(uint8_t iLength, uint32_t iTimeout /* = 1000 */)
 {
-  bool bTransmitSucceeded = false;
+  bool bError(false);
+  bool bTransmitSucceeded(false);
   uint8_t iPacketsLeft(iLength / 4);
-  *bError = false;
 
   int64_t iNow = GetTimeMs();
   int64_t iTargetTime = iNow + (uint64_t) iTimeout;
 
-  while (!bTransmitSucceeded && !*bError && (iTimeout == 0 || iNow < iTargetTime))
+  while (!bTransmitSucceeded && !bError && (iTimeout == 0 || iNow < iTargetTime))
   {
     CCECAdapterMessage msg;
 
@@ -305,7 +302,7 @@ bool CCECProcessor::WaitForAck(bool *bError, uint8_t iLength, uint32_t iTimeout
       continue;
     }
 
-    *bError = msg.is_error();
+    bError = msg.is_error();
     m_controller->AddLog(msg.is_error() ? CEC_LOG_WARNING : CEC_LOG_DEBUG, msg.ToString());
 
     switch(msg.message())
@@ -315,20 +312,20 @@ bool CCECProcessor::WaitForAck(bool *bError, uint8_t iLength, uint32_t iTimeout
       break;
     case MSGCODE_TRANSMIT_SUCCEEDED:
       bTransmitSucceeded = (iPacketsLeft == 0);
-      *bError = !bTransmitSucceeded;
+      bError = !bTransmitSucceeded;
       break;
     default:
       CStdString strLog;
-      strLog.Format("received unexpected reply '%1x' instead of ack", msg.message());
+      strLog.Format("received unexpected reply '%s' instead of ack", msg.MessageCodeAsString().c_str());
       m_controller->AddLog(CEC_LOG_WARNING, strLog);
-      *bError = true;
+      bError = true;
       break;
     }
 
     iNow = GetTimeMs();
   }
 
-  return bTransmitSucceeded && !*bError;
+  return bTransmitSucceeded && !bError;
 }
 
 bool CCECProcessor::ParseMessage(const CCECAdapterMessage &msg)
@@ -397,7 +394,7 @@ void CCECProcessor::SetCurrentButton(cec_user_control_code iButtonCode)
 
 void CCECProcessor::AddCommand(const cec_command &command)
 {
-  m_controller->AddCommand(command);
+//  m_controller->AddCommand(command);
 }
 
 void CCECProcessor::AddKey(void)