cec: fix background polling and libcec exit
[deb_libcec.git] / src / lib / implementations / CECCommandHandler.cpp
index 9f8dc9d30c0b9f970e72546309bd650500b97dc6..2fe03080c7911fb3acb4bd062fb8b9e6f203a045 100644 (file)
@@ -210,7 +210,7 @@ bool CCECCommandHandler::HandleDeviceCecVersion(const cec_command &command)
 
 bool CCECCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &command)
 {
-  if (m_busDevice->MyLogicalAddressContains(command.destination))
+  if (m_processor->IsStarted() && m_busDevice->MyLogicalAddressContains(command.destination))
     m_processor->TransmitAbort(command.initiator, command.opcode, CEC_ABORT_REASON_REFUSED);
 
   return true;
@@ -223,7 +223,7 @@ bool CCECCommandHandler::HandleDeviceVendorId(const cec_command &command)
 
 bool CCECCommandHandler::HandleGetCecVersion(const cec_command &command)
 {
-  if (m_busDevice->MyLogicalAddressContains(command.destination))
+  if (m_processor->IsStarted() && m_busDevice->MyLogicalAddressContains(command.destination))
   {
     CCECBusDevice *device = GetDevice(command.destination);
     if (device)
@@ -235,7 +235,7 @@ bool CCECCommandHandler::HandleGetCecVersion(const cec_command &command)
 
 bool CCECCommandHandler::HandleGiveAudioStatus(const cec_command &command)
 {
-  if (m_busDevice->MyLogicalAddressContains(command.destination))
+  if (m_processor->IsStarted() && m_busDevice->MyLogicalAddressContains(command.destination))
   {
     CCECBusDevice *device = GetDevice(command.destination);
     if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
@@ -247,7 +247,7 @@ bool CCECCommandHandler::HandleGiveAudioStatus(const cec_command &command)
 
 bool CCECCommandHandler::HandleGiveDeckStatus(const cec_command &command)
 {
-  if (m_busDevice->MyLogicalAddressContains(command.destination))
+  if (m_processor->IsStarted() && m_busDevice->MyLogicalAddressContains(command.destination))
   {
     CCECBusDevice *device = GetDevice(command.destination);
     if (device && (device->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || device->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE))
@@ -259,7 +259,7 @@ bool CCECCommandHandler::HandleGiveDeckStatus(const cec_command &command)
 
 bool CCECCommandHandler::HandleGiveDevicePowerStatus(const cec_command &command)
 {
-  if (m_busDevice->MyLogicalAddressContains(command.destination))
+  if (m_processor->IsStarted() && m_busDevice->MyLogicalAddressContains(command.destination))
   {
     CCECBusDevice *device = GetDevice(command.destination);
     if (device)
@@ -271,7 +271,7 @@ bool CCECCommandHandler::HandleGiveDevicePowerStatus(const cec_command &command)
 
 bool CCECCommandHandler::HandleGiveDeviceVendorId(const cec_command &command)
 {
-  if (m_busDevice->MyLogicalAddressContains(command.destination))
+  if (m_processor->IsStarted() && m_busDevice->MyLogicalAddressContains(command.destination))
   {
     CCECBusDevice *device = GetDevice(command.destination);
     if (device)
@@ -283,7 +283,7 @@ bool CCECCommandHandler::HandleGiveDeviceVendorId(const cec_command &command)
 
 bool CCECCommandHandler::HandleGiveOSDName(const cec_command &command)
 {
-  if (m_busDevice->MyLogicalAddressContains(command.destination))
+  if (m_processor->IsStarted() && m_busDevice->MyLogicalAddressContains(command.destination))
   {
     CCECBusDevice *device = GetDevice(command.destination);
     if (device)
@@ -295,7 +295,7 @@ bool CCECCommandHandler::HandleGiveOSDName(const cec_command &command)
 
 bool CCECCommandHandler::HandleGivePhysicalAddress(const cec_command &command)
 {
-  if (m_busDevice->MyLogicalAddressContains(command.destination))
+  if (m_processor->IsStarted() && m_busDevice->MyLogicalAddressContains(command.destination))
   {
     CCECBusDevice *device = GetDevice(command.destination);
     if (device)
@@ -307,7 +307,7 @@ bool CCECCommandHandler::HandleGivePhysicalAddress(const cec_command &command)
 
 bool CCECCommandHandler::HandleGiveSystemAudioModeStatus(const cec_command &command)
 {
-  if (m_busDevice->MyLogicalAddressContains(command.destination))
+  if (m_processor->IsStarted() && m_busDevice->MyLogicalAddressContains(command.destination))
   {
     CCECBusDevice *device = GetDevice(command.destination);
     if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
@@ -325,7 +325,7 @@ bool CCECCommandHandler::HandleImageViewOn(const cec_command &command)
 
 bool CCECCommandHandler::HandleMenuRequest(const cec_command &command)
 {
-  if (m_busDevice->MyLogicalAddressContains(command.destination))
+  if (m_processor->IsStarted() && m_busDevice->MyLogicalAddressContains(command.destination))
   {
     if (command.parameters[0] == CEC_MENU_REQUEST_TYPE_QUERY)
     {
@@ -375,15 +375,19 @@ bool CCECCommandHandler::HandleReportPowerStatus(const cec_command &command)
 
 bool CCECCommandHandler::HandleRequestActiveSource(const cec_command &command)
 {
-  CStdString strLog;
-  strLog.Format(">> %i requests active source", (uint8_t) command.initiator);
-  m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str());
+  if (m_processor->IsStarted())
+  {
+    CStdString strLog;
+    strLog.Format(">> %i requests active source", (uint8_t) command.initiator);
+    m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str());
 
-  vector<CCECBusDevice *> devices;
-  for (int iDevicePtr = (int)GetMyDevices(devices)-1; iDevicePtr >=0; iDevicePtr--)
-    devices[iDevicePtr]->TransmitActiveSource();
+    vector<CCECBusDevice *> devices;
+    for (int iDevicePtr = (int)GetMyDevices(devices)-1; iDevicePtr >=0; iDevicePtr--)
+      devices[iDevicePtr]->TransmitActiveSource();
 
-  return true;
+    return true;
+  }
+  return false;
 }
 
 bool CCECCommandHandler::HandleRoutingChange(const cec_command &command)
@@ -453,7 +457,7 @@ bool CCECCommandHandler::HandleSetOSDName(const cec_command &command)
 
 bool CCECCommandHandler::HandleSetStreamPath(const cec_command &command)
 {
-  if (command.parameters.size >= 2)
+  if (m_processor->IsStarted() && command.parameters.size >= 2)
   {
     uint16_t iStreamAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
     CStdString strLog;
@@ -475,7 +479,7 @@ bool CCECCommandHandler::HandleSetStreamPath(const cec_command &command)
 
 bool CCECCommandHandler::HandleSystemAudioModeRequest(const cec_command &command)
 {
-  if (m_busDevice->MyLogicalAddressContains(command.destination))
+  if (m_processor->IsStarted() && m_busDevice->MyLogicalAddressContains(command.destination))
   {
     CCECBusDevice *device = GetDevice(command.destination);
     if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
@@ -547,7 +551,7 @@ bool CCECCommandHandler::HandleTextViewOn(const cec_command &command)
 
 bool CCECCommandHandler::HandleUserControlPressed(const cec_command &command)
 {
-  if (m_busDevice->MyLogicalAddressContains(command.destination) && command.parameters.size > 0)
+  if (m_processor->IsStarted() && m_busDevice->MyLogicalAddressContains(command.destination) && command.parameters.size > 0)
   {
     m_processor->AddKey();
 
@@ -574,7 +578,7 @@ bool CCECCommandHandler::HandleUserControlPressed(const cec_command &command)
 
 bool CCECCommandHandler::HandleUserControlRelease(const cec_command &command)
 {
-  if (m_busDevice->MyLogicalAddressContains(command.destination))
+  if (m_processor->IsStarted() && m_busDevice->MyLogicalAddressContains(command.destination))
     m_processor->AddKey();
 
   return true;