cec: more consistent log messages + cosmetics
[deb_libcec.git] / src / lib / implementations / CECCommandHandler.cpp
index 2a5b375f6050875709d01f848fc31a3f267b6923..c92908c8c3459436f930e093bdbe45cc79e03706 100644 (file)
@@ -36,6 +36,7 @@
 #include "../CECProcessor.h"
 
 using namespace CEC;
+using namespace std;
 
 CCECCommandHandler::CCECCommandHandler(CCECBusDevice *busDevice)
 {
@@ -47,7 +48,7 @@ bool CCECCommandHandler::HandleCommand(const cec_command &command)
   bool bHandled(true);
 
   CStdString strLog;
-  strLog.Format(">> %x -> %x: %s (%2x)", command.initiator, command.destination, ToString(command.opcode), command.opcode);
+  strLog.Format(">> %s (%X) -> %s (%X): %s (%2X)", ToString(command.initiator), command.initiator, ToString(command.destination), command.destination, ToString(command.opcode), command.opcode);
   m_busDevice->AddLog(CEC_LOG_NOTICE, strLog);
 
   if (m_busDevice->MyLogicalAddressContains(command.destination))
@@ -271,10 +272,11 @@ 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());
-  CCECBusDevice *device = m_busDevice->GetProcessor()->m_busDevices[m_busDevice->GetMyLogicalAddress()];
-  if (device)
-    return device->TransmitActiveSource();
-  return false;
+
+  vector<CCECBusDevice *> devices;
+  for (int iDevicePtr = (int)GetMyDevices(devices)-1; iDevicePtr >=0; iDevicePtr--)
+    devices[iDevicePtr]->TransmitActiveSource();
+  return true;
 }
 
 bool CCECCommandHandler::HandleRoutingChange(const cec_command &command)
@@ -375,6 +377,23 @@ void CCECCommandHandler::UnhandledCommand(const cec_command &command)
   m_busDevice->AddLog(CEC_LOG_DEBUG, strLog);
 }
 
+unsigned int CCECCommandHandler::GetMyDevices(vector<CCECBusDevice *> &devices) const
+{
+  unsigned int iReturn(0);
+
+  cec_logical_addresses addresses = m_busDevice->GetProcessor()->GetLogicalAddresses();
+  for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
+  {
+    if (addresses[iPtr])
+    {
+      devices.push_back(GetDevice((cec_logical_address) iPtr));
+      ++iReturn;
+    }
+  }
+
+  return iReturn;
+}
+
 CCECBusDevice *CCECCommandHandler::GetDevice(cec_logical_address iLogicalAddress) const
 {
   CCECBusDevice *device = NULL;
@@ -418,6 +437,47 @@ void CCECCommandHandler::SetVendorId(const cec_command &command)
     device->SetVendorId(iVendorId, command.parameters.size > 3 ? command.parameters[3] : 0);
 }
 
+const char *CCECCommandHandler::ToString(const cec_logical_address address)
+{
+  switch(address)
+  {
+  case CECDEVICE_AUDIOSYSTEM:
+    return "Audio";
+  case CECDEVICE_BROADCAST:
+    return "Broadcast";
+  case CECDEVICE_FREEUSE:
+    return "Free use";
+  case CECDEVICE_PLAYBACKDEVICE1:
+    return "Playback 1";
+  case CECDEVICE_PLAYBACKDEVICE2:
+    return "Playback 2";
+  case CECDEVICE_PLAYBACKDEVICE3:
+    return "Playback 3";
+  case CECDEVICE_RECORDINGDEVICE1:
+    return "Recorder 1";
+  case CECDEVICE_RECORDINGDEVICE2:
+    return "Recorder 2";
+  case CECDEVICE_RECORDINGDEVICE3:
+    return "Recorder 3";
+  case CECDEVICE_RESERVED1:
+    return "Reserved 1";
+  case CECDEVICE_RESERVED2:
+    return "Reserved 2";
+  case CECDEVICE_TUNER1:
+    return "Tuner 1";
+  case CECDEVICE_TUNER2:
+    return "Tuner 2";
+  case CECDEVICE_TUNER3:
+    return "Tuner 3";
+  case CECDEVICE_TUNER4:
+    return "Tuner 4";
+  case CECDEVICE_TV:
+    return "TV";
+  default:
+    return "unknown";
+  }
+}
+
 const char *CCECCommandHandler::ToString(const cec_opcode opcode)
 {
   switch (opcode)