cec: signal waiting threads when receiving a feature abort too
[deb_libcec.git] / src / lib / implementations / CECCommandHandler.cpp
index eb7d58ea9bac3b83c7631578b54621ec5a296186..2d3fbe0af29376e5ad5500b09f29d87583f9bbac 100644 (file)
@@ -334,12 +334,7 @@ bool CCECCommandHandler::HandleGivePhysicalAddress(const cec_command &command)
   {
     CCECBusDevice *device = GetDevice(command.destination);
     if (device)
-    {
-      device->SetActiveSource();
-      return device->TransmitPhysicalAddress() &&
-          device->TransmitImageViewOn() &&
-          device->TransmitActiveSource();
-    }
+      return device->TransmitPhysicalAddress();
   }
 
   return false;
@@ -379,11 +374,20 @@ bool CCECCommandHandler::HandleMenuRequest(const cec_command &command)
 {
   if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination))
   {
-    if (command.parameters[0] == CEC_MENU_REQUEST_TYPE_QUERY)
+    CCECBusDevice *device = GetDevice(command.destination);
+    if (device)
     {
-      CCECBusDevice *device = GetDevice(command.destination);
-      if (device)
-        return device->TransmitMenuState(command.initiator);
+      if (command.parameters[0] == CEC_MENU_REQUEST_TYPE_ACTIVATE)
+      {
+        if (CLibCEC::MenuStateChanged(CEC_MENU_STATE_ACTIVATED) == 1)
+          device->SetMenuState(CEC_MENU_STATE_ACTIVATED);
+      }
+      else if (command.parameters[0] == CEC_MENU_REQUEST_TYPE_DEACTIVATE)
+      {
+        if (CLibCEC::MenuStateChanged(CEC_MENU_STATE_DEACTIVATED) == 1)
+          device->SetMenuState(CEC_MENU_STATE_DEACTIVATED);
+      }
+      return device->TransmitMenuState(command.initiator);
     }
   }
 
@@ -392,7 +396,7 @@ bool CCECCommandHandler::HandleMenuRequest(const cec_command &command)
 
 bool CCECCommandHandler::HandlePoll(const cec_command &command)
 {
-  m_busDevice->HandlePoll(command.initiator);
+  m_busDevice->HandlePoll(command.destination);
   return true;
 }
 
@@ -769,52 +773,52 @@ bool CCECCommandHandler::TransmitStandby(const cec_logical_address iInitiator, c
   return Transmit(command, false);
 }
 
-bool CCECCommandHandler::TransmitRequestCecVersion(const cec_logical_address iInitiator, const cec_logical_address iDestination)
+bool CCECCommandHandler::TransmitRequestCecVersion(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */)
 {
   cec_command command;
   cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GET_CEC_VERSION);
 
-  return Transmit(command, true, CEC_OPCODE_CEC_VERSION);
+  return Transmit(command, bWaitForResponse, CEC_OPCODE_CEC_VERSION);
 }
 
-bool CCECCommandHandler::TransmitRequestMenuLanguage(const cec_logical_address iInitiator, const cec_logical_address iDestination)
+bool CCECCommandHandler::TransmitRequestMenuLanguage(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */)
 {
   cec_command command;
   cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GET_MENU_LANGUAGE);
 
-  return Transmit(command, true, CEC_OPCODE_SET_MENU_LANGUAGE);
+  return Transmit(command, bWaitForResponse, CEC_OPCODE_SET_MENU_LANGUAGE);
 }
 
-bool CCECCommandHandler::TransmitRequestOSDName(const cec_logical_address iInitiator, const cec_logical_address iDestination)
+bool CCECCommandHandler::TransmitRequestOSDName(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */)
 {
   cec_command command;
   cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GIVE_OSD_NAME);
 
-  return Transmit(command, true, CEC_OPCODE_SET_OSD_NAME);
+  return Transmit(command, bWaitForResponse, CEC_OPCODE_SET_OSD_NAME);
 }
 
-bool CCECCommandHandler::TransmitRequestPhysicalAddress(const cec_logical_address iInitiator, const cec_logical_address iDestination)
+bool CCECCommandHandler::TransmitRequestPhysicalAddress(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */)
 {
   cec_command command;
   cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GIVE_PHYSICAL_ADDRESS);
 
-  return Transmit(command, true, CEC_OPCODE_REPORT_PHYSICAL_ADDRESS);
+  return Transmit(command, bWaitForResponse, CEC_OPCODE_REPORT_PHYSICAL_ADDRESS);
 }
 
-bool CCECCommandHandler::TransmitRequestPowerStatus(const cec_logical_address iInitiator, const cec_logical_address iDestination)
+bool CCECCommandHandler::TransmitRequestPowerStatus(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */)
 {
   cec_command command;
   cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GIVE_DEVICE_POWER_STATUS);
 
-  return Transmit(command, true, CEC_OPCODE_REPORT_POWER_STATUS);
+  return Transmit(command, bWaitForResponse, CEC_OPCODE_REPORT_POWER_STATUS);
 }
 
-bool CCECCommandHandler::TransmitRequestVendorId(const cec_logical_address iInitiator, const cec_logical_address iDestination)
+bool CCECCommandHandler::TransmitRequestVendorId(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */)
 {
   cec_command command;
   cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID);
 
-  return Transmit(command, true, CEC_OPCODE_DEVICE_VENDOR_ID);
+  return Transmit(command, bWaitForResponse, CEC_OPCODE_DEVICE_VENDOR_ID);
 }
 
 bool CCECCommandHandler::TransmitActiveSource(const cec_logical_address iInitiator, uint16_t iPhysicalAddress)
@@ -1006,8 +1010,8 @@ bool CCECCommandHandler::Transmit(cec_command &command, bool bExpectResponse /*
   }
 
   {
-    uint8_t iTries(0), iMaxTries(command.opcode == CEC_OPCODE_NONE ? 1 : m_iTransmitRetries + 1);
-    while (!bReturn && ++iTries <= iMaxTries)
+    uint8_t iTries(0), iMaxTries(!command.opcode_set ? 1 : m_iTransmitRetries + 1);
+    while (!bReturn && ++iTries <= iMaxTries && !m_busDevice->IsUnsupportedFeature(command.opcode))
     {
       if ((bReturn = m_processor->Transmit(command)) == true)
       {
@@ -1043,3 +1047,8 @@ bool CCECCommandHandler::ActivateSource(void)
   }
   return true;
 }
+
+void CCECCommandHandler::SignalOpcode(cec_opcode opcode)
+{
+  m_waitForResponse->Received(opcode);
+}