cec: don't switch handlers when not needed
authorLars Op den Kamp <lars@opdenkamp.eu>
Tue, 3 Jan 2012 13:00:33 +0000 (14:00 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Tue, 3 Jan 2012 13:00:33 +0000 (14:00 +0100)
src/lib/devices/CECBusDevice.cpp
src/lib/implementations/CECCommandHandler.h

index 044cd9c0b938e341ac58ca0e4512687c106bd5d5..b42967d12613cdbaf48634aed0466b47032cf6e3 100644 (file)
@@ -627,39 +627,42 @@ bool CCECBusDevice::ReplaceHandler(bool bActivateSource /* = true */)
 
   if (m_vendor != m_handler->GetVendorId())
   {
-    CStdString strLog;
-    if (m_handler->InUse())
+    if (CCECCommandHandler::HasSpecificHandler(m_vendor))
     {
-      strLog.Format("handler for device '%s' (%x) is being used. not replacing the command handler", GetLogicalAddressName(), GetLogicalAddress());
-      m_processor->AddLog(CEC_LOG_DEBUG, strLog);
-      return false;
-    }
+      CStdString strLog;
+      if (m_handler->InUse())
+      {
+        strLog.Format("handler for device '%s' (%x) is being used. not replacing the command handler", GetLogicalAddressName(), GetLogicalAddress());
+        m_processor->AddLog(CEC_LOG_DEBUG, strLog);
+        return false;
+      }
 
-    strLog.Format("replacing the command handler for device '%s' (%x)", GetLogicalAddressName(), GetLogicalAddress());
-    m_processor->AddLog(CEC_LOG_DEBUG, strLog);
-    delete m_handler;
+      strLog.Format("replacing the command handler for device '%s' (%x)", GetLogicalAddressName(), GetLogicalAddress());
+      m_processor->AddLog(CEC_LOG_DEBUG, strLog);
+      delete m_handler;
 
-    switch (m_vendor)
-    {
-    case CEC_VENDOR_SAMSUNG:
-      m_handler = new CANCommandHandler(this);
-      break;
-    case CEC_VENDOR_LG:
-      m_handler = new CSLCommandHandler(this);
-      break;
-    case CEC_VENDOR_PANASONIC:
-      m_handler = new CVLCommandHandler(this);
-      break;
-    default:
-      m_handler = new CCECCommandHandler(this);
-      break;
-    }
+      switch (m_vendor)
+      {
+      case CEC_VENDOR_SAMSUNG:
+        m_handler = new CANCommandHandler(this);
+        break;
+      case CEC_VENDOR_LG:
+        m_handler = new CSLCommandHandler(this);
+        break;
+      case CEC_VENDOR_PANASONIC:
+        m_handler = new CVLCommandHandler(this);
+        break;
+      default:
+        m_handler = new CCECCommandHandler(this);
+        break;
+      }
 
-    m_handler->SetVendorId(m_vendor);
-    m_handler->InitHandler();
+      m_handler->SetVendorId(m_vendor);
+      m_handler->InitHandler();
 
-    if (bActivateSource && m_processor->GetLogicalAddresses().IsSet(m_iLogicalAddress) && m_processor->IsInitialised())
-      m_handler->ActivateSource();
+      if (bActivateSource && m_processor->GetLogicalAddresses().IsSet(m_iLogicalAddress) && m_processor->IsInitialised())
+        m_handler->ActivateSource();
+    }
   }
 
   return true;
index afd1315afa02d473a3ed24fe691b99d083cd1079..0e3602d9871a5cecaa929cb21110cacdc472ec9f 100644 (file)
@@ -52,6 +52,7 @@ namespace CEC
     virtual void SetVendorId(cec_vendor_id vendorId) { m_vendorId = vendorId; }
     virtual void HandlePoll(const cec_logical_address iInitiator, const cec_logical_address iDestination);
     virtual bool HandleReceiveFailed(void);
+    static bool HasSpecificHandler(cec_vendor_id vendorId) { return vendorId == CEC_VENDOR_LG || vendorId == CEC_VENDOR_SAMSUNG || vendorId == CEC_VENDOR_PANASONIC;}
 
     virtual bool InitHandler(void) { return true; }
     virtual bool ActivateSource(void);