cec: changed all Handle...() commands to return a cec_abort_reason and send the corre...
[deb_libcec.git] / src / lib / implementations / ANCommandHandler.cpp
index 7c2d05906d7b4a33550edb0eb55cbfcdd129268f..554b637f783a7c56f89d5b1baeec23bcffb66ecf 100644 (file)
@@ -48,61 +48,45 @@ CANCommandHandler::CANCommandHandler(CCECBusDevice *busDevice) :
   m_bOPTSendDeckStatusUpdateOnActiveSource = false;
 }
 
-bool CANCommandHandler::HandleVendorRemoteButtonDown(const cec_command &command)
+int CANCommandHandler::HandleVendorRemoteButtonDown(const cec_command &command)
 {
-  if (m_processor->CECInitialised() && command.parameters.size > 0)
-  {
-    CCECClient *client = m_processor->GetClient(command.destination);
-
-    cec_keypress key;
-    key.duration = CEC_BUTTON_TIMEOUT;
-    key.keycode = CEC_USER_CONTROL_CODE_UNKNOWN;
+  if (command.parameters.size == 0)
+    return CEC_ABORT_REASON_INVALID_OPERAND;
 
-    switch (command.parameters[0])
-    {
-    case CEC_USER_CONTROL_CODE_AN_RETURN:
-      key.keycode = client && client->GetClientVersion() >= CEC_CLIENT_VERSION_1_5_0 ?
-        CEC_USER_CONTROL_CODE_AN_RETURN :
-        CEC_USER_CONTROL_CODE_EXIT;
-      break;
-    case CEC_USER_CONTROL_CODE_AN_CHANNELS_LIST:
-      key.keycode = CEC_USER_CONTROL_CODE_AN_CHANNELS_LIST;
-      break;
-    default:
-      break;
-    }
+  if (!m_processor->CECInitialised())
+    return CEC_ABORT_REASON_NOT_IN_CORRECT_MODE_TO_RESPOND;
 
-    if (key.keycode != CEC_USER_CONTROL_CODE_UNKNOWN && client)
-      client->AddKey(key);
-  }
+  CCECClient *client = m_processor->GetClient(command.destination);
+  if (!client)
+    return CEC_ABORT_REASON_NOT_IN_CORRECT_MODE_TO_RESPOND;
 
-  return true;
-}
+  cec_keypress key;
+  key.duration = CEC_BUTTON_TIMEOUT;
+  key.keycode = CEC_USER_CONTROL_CODE_UNKNOWN;
 
-bool CANCommandHandler::HandleCommand(const cec_command &command)
-{
-  bool bHandled(false);
-  if (m_processor->IsHandledByLibCEC(command.destination))
+  switch (command.parameters[0])
   {
-    switch(command.opcode)
-    {
-    case CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN:
-      bHandled = true;
-      HandleVendorRemoteButtonDown(command);
-      break;
-    case CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP:
-      bHandled = true;
-      HandleUserControlRelease(command);
-      break;
-    default:
-      break;
-    }
+  case CEC_USER_CONTROL_CODE_AN_RETURN:
+    key.keycode = client && client->GetClientVersion() >= CEC_CLIENT_VERSION_1_5_0 ?
+      CEC_USER_CONTROL_CODE_AN_RETURN :
+      CEC_USER_CONTROL_CODE_EXIT;
+    break;
+  case CEC_USER_CONTROL_CODE_AN_CHANNELS_LIST:
+    key.keycode = CEC_USER_CONTROL_CODE_AN_CHANNELS_LIST;
+    break;
+  default:
+    break;
   }
 
-  if (!bHandled)
-    bHandled = CCECCommandHandler::HandleCommand(command);
+  if (key.keycode != CEC_USER_CONTROL_CODE_UNKNOWN && client)
+    client->AddKey(key);
+
+  return COMMAND_HANDLED;
+}
 
-  return bHandled;
+int CANCommandHandler::HandleVendorRemoteButtonUp(const cec_command &command)
+{
+  return HandleUserControlRelease(command);
 }
 
 bool CANCommandHandler::PowerOn(const cec_logical_address iInitiator, const cec_logical_address iDestination)