cec: fixed some int conversions that made the win32 build because it's configured...
[deb_libcec.git] / src / lib / CECProcessor.cpp
index 53a1da3405e7e3a1c4b5a41a39444fda83c58d75..3aef595c50f7e5e8bd77db95763d0926d8515813 100644 (file)
@@ -156,12 +156,12 @@ bool CCECProcessor::TryLogicalAddress(cec_logical_address address, unsigned int
       m_busDevices[address]->m_strDeviceName = m_strDeviceName;
       m_busDevices[address]->m_bActiveSource = true;
     }
-    m_busDevices[address]->m_powerStatus = (m_types[0] == m_busDevices[address]->m_type) ? CEC_POWER_STATUS_ON : CEC_POWER_STATUS_STANDBY;
+    m_busDevices[address]->m_powerStatus = CEC_POWER_STATUS_STANDBY;
     m_busDevices[address]->m_cecVersion = CEC_VERSION_1_3A;
     m_logicalAddresses.set(address);
 
     // TODO
-    m_busDevices[address]->SetPhysicalAddress(CEC_DEFAULT_PHYSICAL_ADDRESS + (iIndex * 0x100));
+    m_busDevices[address]->SetPhysicalAddress((uint16_t)CEC_DEFAULT_PHYSICAL_ADDRESS + ((uint16_t)iIndex * 0x100));
 
     return true;
   }
@@ -268,7 +268,7 @@ void *CCECProcessor::Process(void)
       else if (m_communication->IsOpen() && m_communication->Read(msg, 50))
       {
         m_controller->AddLog(msg.is_error() ? CEC_LOG_WARNING : CEC_LOG_DEBUG, msg.ToString());
-        if ((bParseFrame = (ParseMessage(msg) && !IsStopped())))
+        if ((bParseFrame = (ParseMessage(msg) && !IsStopped())) == true)
           command = m_currentframe;
       }
     }
@@ -290,23 +290,39 @@ void *CCECProcessor::Process(void)
   return NULL;
 }
 
-bool CCECProcessor::SetActiveView(void)
+bool CCECProcessor::SetActiveSource(cec_device_type type /* = CEC_DEVICE_TYPE_RESERVED */)
 {
   bool bReturn(false);
 
   if (!IsRunning())
     return bReturn;
 
-  if (!m_logicalAddresses.empty() && m_busDevices[m_logicalAddresses.primary])
+  cec_logical_address addr = m_logicalAddresses.primary;
+
+  if (type != CEC_DEVICE_TYPE_RESERVED)
   {
-    SetStreamPath(m_busDevices[m_logicalAddresses.primary]->GetPhysicalAddress());
-    bReturn = m_busDevices[m_logicalAddresses.primary]->TransmitActiveSource();
+    for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
+    {
+      if (m_logicalAddresses[iPtr] && m_busDevices[iPtr]->m_type == type)
+      {
+        addr = (cec_logical_address) iPtr;
+        break;
+      }
+    }
   }
-  return false;
+
+  return SetStreamPath(m_busDevices[addr]->GetPhysicalAddress());
+}
+
+bool CCECProcessor::SetActiveView(void)
+{
+  return SetActiveSource();
 }
 
 bool CCECProcessor::SetStreamPath(uint16_t iStreamPath)
 {
+  bool bReturn(false);
+
   CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamPath);
   if (device)
   {
@@ -314,10 +330,15 @@ bool CCECProcessor::SetStreamPath(uint16_t iStreamPath)
       m_busDevices[iPtr]->m_bActiveSource = false;
 
     device->m_bActiveSource = true;
-    return true;
+    device->m_powerStatus   = CEC_POWER_STATUS_ON;
+
+    if (m_logicalAddresses.isset(device->m_iLogicalAddress))
+      bReturn = device->TransmitActiveSource();
+    else
+      bReturn = true;
   }
 
-  return false;
+  return bReturn;
 }
 
 bool CCECProcessor::SetInactiveView(void)