cec: refactored threading/locking - added windows native instead of pthread-win32...
[deb_libcec.git] / src / lib / implementations / CECCommandHandler.cpp
index 4656110bfbdf981c51b3d0cb6953fb4ce1f6f477..d407e40221df6aad75f61c354ee5d8ddca96a455 100644 (file)
@@ -38,6 +38,7 @@
 
 using namespace CEC;
 using namespace std;
+using namespace PLATFORM;
 
 CCECCommandHandler::CCECCommandHandler(CCECBusDevice *busDevice) :
     m_busDevice(busDevice),
@@ -47,14 +48,16 @@ CCECCommandHandler::CCECCommandHandler(CCECBusDevice *busDevice) :
     m_iTransmitRetries(CEC_DEFAULT_TRANSMIT_RETRIES),
     m_bHandlerInited(false),
     m_iUseCounter(0),
-    m_expectedResponse(CEC_OPCODE_NONE)
+    m_expectedResponse(CEC_OPCODE_NONE),
+    m_bOPTSendDeckStatusUpdateOnActiveSource(false),
+    m_vendorId(CEC_VENDOR_UNKNOWN)
 {
 }
 
 CCECCommandHandler::~CCECCommandHandler(void)
 {
-  CLockObject lock(&m_processor->m_transmitMutex);
-  CLockObject receiveLock(&m_receiveMutex);
+  CLockObject lock(m_processor->m_transmitMutex);
+  CLockObject receiveLock(m_receiveMutex);
   m_condition.Broadcast();
 }
 
@@ -192,7 +195,7 @@ bool CCECCommandHandler::HandleCommand(const cec_command &command)
 
   if (bHandled)
   {
-    CLockObject lock(&m_receiveMutex);
+    CLockObject lock(m_receiveMutex);
     if (m_expectedResponse == CEC_OPCODE_NONE ||
         m_expectedResponse == command.opcode)
       m_condition.Signal();
@@ -424,7 +427,7 @@ bool CCECCommandHandler::HandleRequestActiveSource(const cec_command &command)
     m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str());
 
     vector<CCECBusDevice *> devices;
-    for (int iDevicePtr = (int)GetMyDevices(devices)-1; iDevicePtr >=0; iDevicePtr--)
+    for (size_t iDevicePtr = 0; iDevicePtr < GetMyDevices(devices); iDevicePtr++)
       devices[iDevicePtr]->TransmitActiveSource();
 
     return true;
@@ -637,6 +640,11 @@ bool CCECCommandHandler::HandleUserControlRelease(const cec_command &command)
   return true;
 }
 
+bool CCECCommandHandler::HandleVendorCommand(const cec_command & UNUSED(command))
+{
+  return true;
+}
+
 void CCECCommandHandler::UnhandledCommand(const cec_command &command)
 {
   CStdString strLog;
@@ -644,9 +652,9 @@ void CCECCommandHandler::UnhandledCommand(const cec_command &command)
   m_busDevice->AddLog(CEC_LOG_DEBUG, strLog);
 }
 
-unsigned int CCECCommandHandler::GetMyDevices(vector<CCECBusDevice *> &devices) const
+size_t CCECCommandHandler::GetMyDevices(vector<CCECBusDevice *> &devices) const
 {
-  unsigned int iReturn(0);
+  size_t iReturn(0);
 
   cec_logical_addresses addresses = m_processor->GetLogicalAddresses();
   for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
@@ -835,7 +843,7 @@ bool CCECCommandHandler::TransmitOSDName(const cec_logical_address iInitiator, c
 {
   cec_command command;
   cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_SET_OSD_NAME);
-  for (unsigned int iPtr = 0; iPtr < strDeviceName.length(); iPtr++)
+  for (size_t iPtr = 0; iPtr < strDeviceName.length(); iPtr++)
     command.parameters.PushBack(strDeviceName.at(iPtr));
 
   return Transmit(command, false);
@@ -847,10 +855,10 @@ bool CCECCommandHandler::TransmitOSDString(const cec_logical_address iInitiator,
   cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_SET_OSD_STRING);
   command.parameters.PushBack((uint8_t)duration);
 
-  unsigned int iLen = strlen(strMessage);
+  size_t iLen = strlen(strMessage);
   if (iLen > 13) iLen = 13;
 
-  for (unsigned int iPtr = 0; iPtr < iLen; iPtr++)
+  for (size_t iPtr = 0; iPtr < iLen; iPtr++)
     command.parameters.PushBack(strMessage[iPtr]);
 
   return Transmit(command, false);
@@ -957,8 +965,8 @@ bool CCECCommandHandler::Transmit(cec_command &command, bool bExpectResponse /*
 
   {
     uint8_t iTries(0), iMaxTries(command.opcode == CEC_OPCODE_NONE ? 1 : m_iTransmitRetries + 1);
-    CLockObject writeLock(&m_processor->m_transmitMutex);
-    CLockObject receiveLock(&m_receiveMutex);
+    CLockObject writeLock(m_processor->m_transmitMutex);
+    CLockObject receiveLock(m_receiveMutex);
     ++m_iUseCounter;
     while (!bReturn && ++iTries <= iMaxTries)
     {
@@ -967,7 +975,7 @@ bool CCECCommandHandler::Transmit(cec_command &command, bool bExpectResponse /*
       {
         m_processor->AddLog(CEC_LOG_DEBUG, "command transmitted");
         bReturn = bExpectResponse ?
-            m_condition.Wait(&m_receiveMutex, m_iTransmitWait) :
+            m_condition.Wait(m_receiveMutex, m_iTransmitWait) :
             true;
       }
     }
@@ -998,18 +1006,18 @@ bool CCECCommandHandler::ActivateSource(void)
 
 void CCECCommandHandler::MarkBusy(void)
 {
-  CLockObject receiveLock(&m_receiveMutex);
+  CLockObject receiveLock(m_receiveMutex);
   ++m_iUseCounter;
 }
 
 bool CCECCommandHandler::MarkReady(void)
 {
-  CLockObject receiveLock(&m_receiveMutex);
+  CLockObject receiveLock(m_receiveMutex);
   return m_iUseCounter > 0 ? (--m_iUseCounter == 0) : true;
 }
 
 bool CCECCommandHandler::InUse(void)
 {
-  CLockObject receiveLock(&m_receiveMutex);
+  CLockObject receiveLock(m_receiveMutex);
   return m_iUseCounter > 0;
 }