p8: fixed - updated the cached device type setting properly when persisting new setti...
authorLars Op den Kamp <lars@opdenkamp.eu>
Wed, 25 Jul 2012 09:32:15 +0000 (11:32 +0200)
committerLars Op den Kamp <lars@opdenkamp.eu>
Wed, 25 Jul 2012 10:31:08 +0000 (12:31 +0200)
src/lib/adapter/Pulse-Eight/USBCECAdapterCommands.cpp
src/lib/adapter/Pulse-Eight/USBCECAdapterCommands.h

index bbd15d4b0b230edf42b76e0042396f35489f6ffe..af4d6a0bdb9bcc182f75de8cbb33a0231414a64c 100644 (file)
@@ -230,10 +230,13 @@ bool CUSBCECAdapterCommands::SetSettingAutoEnabled(bool enabled)
   bool bReturn(false);
 
   /* check whether this value was changed */
-  if (m_bSettingAutoEnabled == enabled)
-    return bReturn;
+  {
+    CLockObject lock(m_mutex);
+    if (m_bSettingAutoEnabled == enabled)
+      return bReturn;
+    m_bNeedsWrite = true;
+  }
 
-  m_bNeedsWrite = true;
   LIB_CEC->AddLog(CEC_LOG_DEBUG, "turning autonomous mode %s", enabled ? "on" : "off");
 
   CCECAdapterMessage params;
@@ -243,7 +246,10 @@ bool CUSBCECAdapterCommands::SetSettingAutoEnabled(bool enabled)
   delete message;
 
   if (bReturn)
+  {
+    CLockObject lock(m_mutex);
     m_bSettingAutoEnabled = enabled;
+  }
 
   return bReturn;
 }
@@ -253,10 +259,13 @@ bool CUSBCECAdapterCommands::SetSettingDeviceType(cec_device_type type)
   bool bReturn(false);
 
   /* check whether this value was changed */
-  if (m_persistedConfiguration.deviceTypes.types[0] == type)
-    return bReturn;
+  {
+    CLockObject lock(m_mutex);
+    if (m_persistedConfiguration.deviceTypes.types[0] == type)
+      return bReturn;
+    m_bNeedsWrite = true;
+  }
 
-  m_bNeedsWrite = true;
   LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the device type to %X (previous: %X)", (uint8_t)type, (uint8_t)m_persistedConfiguration.deviceTypes.types[0]);
 
   CCECAdapterMessage params;
@@ -265,6 +274,12 @@ bool CUSBCECAdapterCommands::SetSettingDeviceType(cec_device_type type)
   bReturn = message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED;
   delete message;
 
+  if (bReturn)
+  {
+    CLockObject lock(m_mutex);
+    m_persistedConfiguration.deviceTypes.types[0] = type;
+  }
+
   return bReturn;
 }
 
@@ -273,10 +288,13 @@ bool CUSBCECAdapterCommands::SetSettingDefaultLogicalAddress(cec_logical_address
   bool bReturn(false);
 
   /* check whether this value was changed */
-  if (m_persistedConfiguration.logicalAddresses.primary == address)
-    return bReturn;
+  {
+    CLockObject lock(m_mutex);
+    if (m_persistedConfiguration.logicalAddresses.primary == address)
+      return bReturn;
+    m_bNeedsWrite = true;
+  }
 
-  m_bNeedsWrite = true;
   LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the default logical address to %X (previous: %X)", (uint8_t)address, (uint8_t)m_persistedConfiguration.logicalAddresses.primary);
 
   CCECAdapterMessage params;
@@ -286,7 +304,10 @@ bool CUSBCECAdapterCommands::SetSettingDefaultLogicalAddress(cec_logical_address
   delete message;
 
   if (bReturn)
+  {
+    CLockObject lock(m_mutex);
     m_persistedConfiguration.logicalAddresses.primary = address;
+  }
 
   return bReturn;
 }
@@ -296,10 +317,13 @@ bool CUSBCECAdapterCommands::SetSettingLogicalAddressMask(uint16_t iMask)
   bool bReturn(false);
 
   /* check whether this value was changed */
-  if (m_iSettingLAMask == iMask)
-    return bReturn;
+  {
+    CLockObject lock(m_mutex);
+    if (m_iSettingLAMask == iMask)
+      return bReturn;
+    m_bNeedsWrite = true;
+  }
 
-  m_bNeedsWrite = true;
   LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the logical address mask to %2X (previous: %2X)", iMask, m_iSettingLAMask);
 
   CCECAdapterMessage params;
@@ -310,7 +334,10 @@ bool CUSBCECAdapterCommands::SetSettingLogicalAddressMask(uint16_t iMask)
   delete message;
 
   if (bReturn)
+  {
+    CLockObject lock(m_mutex);
     m_iSettingLAMask = iMask;
+  }
 
   return bReturn;
 }
@@ -320,10 +347,13 @@ bool CUSBCECAdapterCommands::SetSettingPhysicalAddress(uint16_t iPhysicalAddress
   bool bReturn(false);
 
   /* check whether this value was changed */
-  if (m_persistedConfiguration.iPhysicalAddress == iPhysicalAddress)
-    return bReturn;
+  {
+    CLockObject lock(m_mutex);
+    if (m_persistedConfiguration.iPhysicalAddress == iPhysicalAddress)
+      return bReturn;
+    m_bNeedsWrite = true;
+  }
 
-  m_bNeedsWrite = true;
   LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the physical address to %04X (previous: %04X)", iPhysicalAddress, m_persistedConfiguration.iPhysicalAddress);
 
   CCECAdapterMessage params;
@@ -334,7 +364,10 @@ bool CUSBCECAdapterCommands::SetSettingPhysicalAddress(uint16_t iPhysicalAddress
   delete message;
 
   if (bReturn)
+  {
+    CLockObject lock(m_mutex);
     m_persistedConfiguration.iPhysicalAddress = iPhysicalAddress;
+  }
 
   return bReturn;
 }
@@ -344,10 +377,13 @@ bool CUSBCECAdapterCommands::SetSettingCECVersion(cec_version version)
   bool bReturn(false);
 
   /* check whether this value was changed */
-  if (m_settingCecVersion == version)
-    return bReturn;
+  {
+    CLockObject lock(m_mutex);
+    if (m_settingCecVersion == version)
+      return bReturn;
+    m_bNeedsWrite = true;
+  }
 
-  m_bNeedsWrite = true;
   LIB_CEC->AddLog(CEC_LOG_DEBUG, "setting the CEC version to %s (previous: %s)", ToString(version), ToString(m_settingCecVersion));
 
   CCECAdapterMessage params;
@@ -357,7 +393,10 @@ bool CUSBCECAdapterCommands::SetSettingCECVersion(cec_version version)
   delete message;
 
   if (bReturn)
+  {
+    CLockObject lock(m_mutex);
     m_settingCecVersion = version;
+  }
 
   return bReturn;
 }
@@ -387,16 +426,26 @@ bool CUSBCECAdapterCommands::SetSettingOSDName(const char *strOSDName)
 
 bool CUSBCECAdapterCommands::WriteEEPROM(void)
 {
-  if (!m_bNeedsWrite)
-    return true;
+  {
+    CLockObject lock(m_mutex);
+    if (!m_bNeedsWrite)
+      return true;
+  }
 
   LIB_CEC->AddLog(CEC_LOG_DEBUG, "writing settings in the EEPROM");
 
   CCECAdapterMessage params;
   CCECAdapterMessage *message = m_comm->SendCommand(MSGCODE_WRITE_EEPROM, params);
-  m_bNeedsWrite = !(message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED);
+  bool bReturn = message->state == ADAPTER_MESSAGE_STATE_SENT_ACKED;
   delete message;
-  return m_bNeedsWrite;
+
+  if (bReturn)
+  {
+    CLockObject lock(m_mutex);
+    m_bNeedsWrite = false;
+  }
+
+  return bReturn;
 }
 
 bool CUSBCECAdapterCommands::PersistConfiguration(const libcec_configuration &configuration)
index ff0c187e89fc9e7e76544e68d69f37730238fda3..df376f3c4b80539ce74f5c88004c0d283913da4a 100644 (file)
@@ -31,6 +31,8 @@
  *     http://www.pulse-eight.net/
  */
 
+#include "lib/platform/threads/mutex.h"
+
 namespace CEC
 {
   class CUSBCECAdapterCommunication;
@@ -230,5 +232,6 @@ 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 */
+    PLATFORM::CMutex             m_mutex;
   };
 }