cec: fixed - only the key release events were sent, not keypresses, which appeared...
authorLars Op den Kamp <lars@opdenkamp.eu>
Wed, 25 Jan 2012 18:31:33 +0000 (19:31 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Wed, 25 Jan 2012 18:31:33 +0000 (19:31 +0100)
src/lib/CECProcessor.cpp
src/lib/CECProcessor.h
src/lib/LibCEC.cpp
src/lib/LibCEC.h
src/lib/implementations/ANCommandHandler.cpp
src/lib/implementations/CECCommandHandler.cpp

index 7a4e019d0b7fdfb2a48968f9ff185c54c82ce2f0..a8c4a5daf20b0135af081e60c0fca66637120a28 100644 (file)
@@ -988,26 +988,6 @@ uint16_t CCECProcessor::GetPhysicalAddress(void) const
   return false;
 }
 
-void CCECProcessor::SetCurrentButton(cec_user_control_code iButtonCode)
-{
-  m_controller->SetCurrentButton(iButtonCode);
-}
-
-void CCECProcessor::AddCommand(const cec_command &command)
-{
-  m_controller->AddCommand(command);
-}
-
-void CCECProcessor::AddKey(cec_keypress &key)
-{
-  m_controller->AddKey(key);
-}
-
-void CCECProcessor::AddKey(void)
-{
-  m_controller->AddKey();
-}
-
 bool CCECProcessor::SetAckMask(uint16_t iMask)
 {
   return m_communication->SetAckMask(iMask);
index 39c36710e1f630cecd0a363630901bbecab84a2e..140911a7022a828628171e67574febac6703706d 100644 (file)
@@ -117,11 +117,6 @@ namespace CEC
       virtual bool Transmit(CCECAdapterMessage *output);
       virtual void TransmitAbort(cec_logical_address address, cec_opcode opcode, cec_abort_reason reason = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE);
 
-      virtual void SetCurrentButton(cec_user_control_code iButtonCode);
-      virtual void AddCommand(const cec_command &command);
-      virtual void AddKey(cec_keypress &key);
-      virtual void AddKey(void);
-
       virtual bool ChangeDeviceType(cec_device_type from, cec_device_type to);
       virtual bool FindLogicalAddresses(void);
       virtual bool SetAckMask(uint16_t iMask);
index 69830fdf040b5367b062ffccc9cbb767f36affb1..1dd336621ded1c6af8abc99ba8896feb8e87c2e6 100644 (file)
@@ -366,51 +366,64 @@ void CLibCEC::AddLog(cec_log_level level, const char *strFormat, ...)
 
 void CLibCEC::AddKey(cec_keypress &key)
 {
-  CLockObject lock(m_mutex);
-  if (m_callbacks)
-    m_callbacks->CBCecKeyPress(m_cbParam, key);
+  CLibCEC *instance = CLibCEC::GetInstance();
+  CLockObject lock(instance->m_mutex);
+
+  AddLog(CEC_LOG_DEBUG, "key pressed: %1x", key.keycode);
+
+  if (instance->m_callbacks)
+    instance->m_callbacks->CBCecKeyPress(instance->m_cbParam, key);
   else
-    m_keyBuffer.Push(key);
-  m_iCurrentButton = CEC_USER_CONTROL_CODE_UNKNOWN;
-  m_buttontime = 0;
+    instance->m_keyBuffer.Push(key);
+
+  instance->m_iCurrentButton = key.duration > 0 ? CEC_USER_CONTROL_CODE_UNKNOWN : key.keycode;
+  instance->m_buttontime = key.duration > 0 ? 0 : GetTimeMs();
+}
+
+void CLibCEC::SetCurrentButton(cec_user_control_code iButtonCode)
+{
+  /* push keypress to the keybuffer with 0 duration.
+     push another press to the keybuffer with the duration set when the button is released */
+  cec_keypress key;
+  key.duration = 0;
+  key.keycode = iButtonCode;
+
+  AddKey(key);
 }
 
 void CLibCEC::AddKey(void)
 {
-  CLockObject lock(m_mutex);
-  if (m_iCurrentButton != CEC_USER_CONTROL_CODE_UNKNOWN)
+  CLibCEC *instance = CLibCEC::GetInstance();
+  CLockObject lock(instance->m_mutex);
+
+  if (instance->m_iCurrentButton != CEC_USER_CONTROL_CODE_UNKNOWN)
   {
     cec_keypress key;
 
-    key.duration = (unsigned int) (GetTimeMs() - m_buttontime);
-    key.keycode = m_iCurrentButton;
+    key.duration = (unsigned int) (GetTimeMs() - instance->m_buttontime);
+    key.keycode = instance->m_iCurrentButton;
+    AddLog(CEC_LOG_DEBUG, "key released: %1x", key.keycode);
 
-    if (m_callbacks)
-      m_callbacks->CBCecKeyPress(m_cbParam, key);
+    if (instance->m_callbacks)
+      instance->m_callbacks->CBCecKeyPress(instance->m_cbParam, key);
     else
-      m_keyBuffer.Push(key);
-    m_iCurrentButton = CEC_USER_CONTROL_CODE_UNKNOWN;
+      instance->m_keyBuffer.Push(key);
+    instance->m_iCurrentButton = CEC_USER_CONTROL_CODE_UNKNOWN;
   }
-  m_buttontime = 0;
+  instance->m_buttontime = 0;
 }
 
 void CLibCEC::AddCommand(const cec_command &command)
 {
-  CLockObject lock(m_mutex);
-  if (m_callbacks)
-  {
-    m_callbacks->CBCecCommand(m_cbParam, command);
-  }
-  else if (m_commandBuffer.Push(command))
-  {
-    CStdString strDebug;
-    strDebug.Format("stored command '%2x' in the command buffer. buffer size = %d", command.opcode, m_commandBuffer.Size());
-    AddLog(CEC_LOG_DEBUG, strDebug);
-  }
-  else
-  {
+  CLibCEC *instance = CLibCEC::GetInstance();
+  CLockObject lock(instance->m_mutex);
+
+  AddLog(CEC_LOG_NOTICE, ">> %s (%X) -> %s (%X): %s (%2X)", instance->m_cec->ToString(command.initiator), command.initiator, instance->m_cec->ToString(command.destination), command.destination, instance->m_cec->ToString(command.opcode), command.opcode);
+
+  if (instance->m_callbacks)
+    instance->m_callbacks->CBCecCommand(instance->m_cbParam, command);
+  else if (!instance->m_commandBuffer.Push(command))
     AddLog(CEC_LOG_WARNING, "command buffer is full");
-  }
 }
 
 void CLibCEC::CheckKeypressTimeout(void)
@@ -422,19 +435,6 @@ void CLibCEC::CheckKeypressTimeout(void)
   }
 }
 
-void CLibCEC::SetCurrentButton(cec_user_control_code iButtonCode)
-{
-  m_iCurrentButton = iButtonCode;
-  m_buttontime = GetTimeMs();
-
-  /* push keypress to the keybuffer with 0 duration.
-     push another press to the keybuffer with the duration set when the button is released */
-  cec_keypress key;
-  key.duration = 0;
-  key.keycode = m_iCurrentButton;
-  m_keyBuffer.Push(key);
-}
-
 static CLibCEC *g_libCEC_instance(NULL);
 CLibCEC *CLibCEC::GetInstance(void)
 {
index 9ca006e066ea5468d199c16ae4832f024392d3f1..752bae6933f919957ceb2df060d3d0a02ede24ab 100644 (file)
@@ -113,11 +113,11 @@ namespace CEC
     //@}
 
       static void AddLog(cec_log_level level, const char *strFormat, ...);
-      virtual void AddKey(void);
-      virtual void AddKey(cec_keypress &key);
-      virtual void AddCommand(const cec_command &command);
+      static void AddKey(void);
+      static void AddKey(cec_keypress &key);
+      static void AddCommand(const cec_command &command);
+      static void SetCurrentButton(cec_user_control_code iButtonCode);
       virtual void CheckKeypressTimeout(void);
-      virtual void SetCurrentButton(cec_user_control_code iButtonCode);
 
       static CLibCEC *GetInstance(void);
       static void SetInstance(CLibCEC *instance);
index 1df94fa061c1a194936737bf1c7310d5a14b04fd..75d0a8c23c89f12c29134d48f25d7779a6fbe868 100644 (file)
@@ -62,10 +62,7 @@ bool CANCommandHandler::HandleVendorRemoteButtonDown(const cec_command &command)
     }
 
     if (key.keycode != CEC_USER_CONTROL_CODE_UNKNOWN)
-    {
-      CLibCEC::AddLog(CEC_LOG_DEBUG, "key pressed: %1x", key.keycode);
-      m_busDevice->GetProcessor()->AddKey(key);
-    }
+      CLibCEC::AddKey(key);
   }
 
   return true;
index 0178ae069fedcef2123231dc5fadd80f408f4521..ebd2ec24a829e008dfa55a6aa2c1fc02d9f787f6 100644 (file)
@@ -67,9 +67,7 @@ bool CCECCommandHandler::HandleCommand(const cec_command &command)
   bool bHandled(true);
 
   MarkBusy();
-  CLibCEC::AddLog(CEC_LOG_NOTICE, ">> %s (%X) -> %s (%X): %s (%2X)", m_processor->ToString(command.initiator), command.initiator, m_processor->ToString(command.destination), command.destination, m_processor->ToString(command.opcode), command.opcode);
-
-  m_processor->AddCommand(command);
+  CLibCEC::AddCommand(command);
 
   switch(command.opcode)
   {
@@ -591,12 +589,10 @@ bool CCECCommandHandler::HandleUserControlPressed(const cec_command &command)
 {
   if (m_processor->IsStarted() && m_busDevice->MyLogicalAddressContains(command.destination) && command.parameters.size > 0)
   {
-    m_processor->AddKey();
+    CLibCEC::AddKey();
 
     if (command.parameters[0] <= CEC_USER_CONTROL_CODE_MAX)
     {
-      CLibCEC::AddLog(CEC_LOG_DEBUG, "key pressed: %x", command.parameters[0]);
-
       if (command.parameters[0] == CEC_USER_CONTROL_CODE_POWER ||
           command.parameters[0] == CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION)
       {
@@ -617,7 +613,7 @@ bool CCECCommandHandler::HandleUserControlPressed(const cec_command &command)
       }
       else
       {
-        m_processor->SetCurrentButton((cec_user_control_code) command.parameters[0]);
+        CLibCEC::SetCurrentButton((cec_user_control_code) command.parameters[0]);
       }
       return true;
     }
@@ -628,7 +624,7 @@ bool CCECCommandHandler::HandleUserControlPressed(const cec_command &command)
 bool CCECCommandHandler::HandleUserControlRelease(const cec_command &command)
 {
   if (m_processor->IsStarted() && m_busDevice->MyLogicalAddressContains(command.destination))
-    m_processor->AddKey();
+    CLibCEC::AddKey();
 
   return true;
 }