p8: fixed - always set controlled mode to false when unregistering the last client...
authorLars Op den Kamp <lars@opdenkamp.eu>
Wed, 25 Jul 2012 09:45:15 +0000 (11:45 +0200)
committerLars Op den Kamp <lars@opdenkamp.eu>
Wed, 25 Jul 2012 10:31:09 +0000 (12:31 +0200)
src/lib/CECProcessor.cpp
src/lib/adapter/Pulse-Eight/USBCECAdapterCommands.cpp
src/lib/adapter/Pulse-Eight/USBCECAdapterCommands.h

index 71e5c6960ac8d643f5ba98de374843685dcafacf..76c2465fb2dd74419822d63cf5991e4c4814af95 100644 (file)
@@ -660,6 +660,9 @@ bool CCECProcessor::RegisterClient(CCECClient *client)
   if (client->IsRegistered())
     UnregisterClient(client);
 
+  // ensure that controlled mode is enabled
+  m_communication->SetControlledMode(true);
+
   // ensure that we know the vendor id of the TV
   CCECBusDevice *tv = GetTV();
   if (m_communication->SupportsSourceLogicalAddress(CECDEVICE_UNREGISTERED))
@@ -784,7 +787,17 @@ bool CCECProcessor::UnregisterClient(CCECClient *client)
   }
 
   // set the new ackmask
-  return SetLogicalAddresses(GetLogicalAddresses());;
+  cec_logical_addresses addresses = GetLogicalAddresses();
+  if (SetLogicalAddresses(addresses))
+  {
+    // no more clients left, disable controlled mode
+    if (addresses.IsEmpty())
+      m_communication->SetControlledMode(false);
+
+    return true;
+  }
+
+  return false;
 }
 
 void CCECProcessor::UnregisterClients(void)
index af4d6a0bdb9bcc182f75de8cbb33a0231414a64c..457889cf3b555d9baffba9ed786ad2e813880ed0 100644 (file)
@@ -53,7 +53,8 @@ CUSBCECAdapterCommands::CUSBCECAdapterCommands(CUSBCECAdapterCommunication *comm
     m_settingCecVersion(CEC_VERSION_UNKNOWN),
     m_iSettingLAMask(0),
     m_bNeedsWrite(false),
-    m_iBuildDate(CEC_FW_BUILD_UNKNOWN)
+    m_iBuildDate(CEC_FW_BUILD_UNKNOWN),
+    m_bControlledMode(false)
 {
   m_persistedConfiguration.Clear();
 }
@@ -575,6 +576,12 @@ bool CUSBCECAdapterCommands::SetLineTimeout(uint8_t iTimeout)
 
 bool CUSBCECAdapterCommands::SetControlledMode(bool controlled)
 {
+  {
+    CLockObject lock(m_mutex);
+    if (m_bControlledMode == controlled)
+      return true;
+  }
+
   LIB_CEC->AddLog(CEC_LOG_DEBUG, "turning controlled mode %s", controlled ? "on" : "off");
 
   CCECAdapterMessage params;
@@ -582,5 +589,12 @@ bool CUSBCECAdapterCommands::SetControlledMode(bool controlled)
   CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_SET_CONTROLLED, params);
   bool bReturn = message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED;
   delete message;
+
+  if (bReturn)
+  {
+    CLockObject lock(m_mutex);
+    m_bControlledMode = controlled;
+  }
+
   return bReturn;
 }
index df376f3c4b80539ce74f5c88004c0d283913da4a..897ed1cb417239784cd78e7914f9ef5c06357023 100644 (file)
@@ -232,6 +232,7 @@ namespace CEC
     bool                         m_bNeedsWrite;            /**< true when we sent changed settings to the adapter that have not been persisted */
     libcec_configuration         m_persistedConfiguration; /**< the configuration that is persisted in the eeprom */
     uint32_t                     m_iBuildDate;             /**< the build date of the firmware */
+    bool                         m_bControlledMode;        /**< current value of the controlled mode feature */
     PLATFORM::CMutex             m_mutex;
   };
 }