cec: fixed - ensure that the correct libCEC version is set after initialising the...
authorLars Op den Kamp <lars@opdenkamp.eu>
Thu, 10 May 2012 22:30:16 +0000 (00:30 +0200)
committerLars Op den Kamp <lars@opdenkamp.eu>
Thu, 10 May 2012 23:26:24 +0000 (01:26 +0200)
src/lib/CECClient.cpp
src/lib/CECProcessor.cpp
src/lib/LibCEC.cpp
src/lib/devices/CECBusDevice.cpp
src/lib/platform/threads/threads.h

index 4cccb60e65ec6bec0f6396516c4cdbb6c23cbeac..30723fe6dfb5bd71365454e27b9b6a51b0062537 100644 (file)
@@ -733,8 +733,7 @@ bool CCECClient::SetConfiguration(const libcec_configuration *configuration)
   CCECBusDevice *primary = bIsRunning ? GetPrimaryDevice() : NULL;
   cec_device_type oldPrimaryType = primary ? primary->GetType() : CEC_DEVICE_TYPE_RECORDING_DEVICE;
 
-  m_configuration.serverVersion  = LIBCEC_VERSION_CURRENT;
-  m_configuration.clientVersion  = configuration->clientVersion;
+  m_configuration.clientVersion = configuration->clientVersion;
   LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s - using client version '%s'", __FUNCTION__, ToString((cec_client_version)configuration->clientVersion));
 
   // client version 1.5.0
index 435177b6e3bceaeb18119fac58e9d6794c2840b4..0add41b67ca42cb3763ee54fffff890a151b528c 100644 (file)
@@ -104,6 +104,13 @@ void CCECProcessor::Close(void)
     delete m_communication;
     m_communication = NULL;
   }
+
+  m_bMonitor = false;
+  m_iPreviousAckMask = 0;
+  m_iStandardLineTimeout = 3;
+  m_iRetryLineTimeout = 3;
+  m_iLastTransmission = 0;
+  m_busDevices->ResetDeviceStatus();
 }
 
 bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint32_t iTimeoutMs, bool bStartListening /* = true */)
@@ -617,7 +624,8 @@ bool CCECProcessor::RegisterClient(CCECClient *client)
       client->Initialise();
 
   // set the firmware version and build date
-  configuration.iFirmwareVersion = m_communication->GetFirmwareVersion();
+  configuration.serverVersion      = LIBCEC_VERSION_CURRENT;
+  configuration.iFirmwareVersion   = m_communication->GetFirmwareVersion();
   configuration.iFirmwareBuildDate = m_communication->GetFirmwareBuildDate();
 
   CStdString strLog;
@@ -670,9 +678,8 @@ bool CCECProcessor::RegisterClient(CCECClient *client)
 void CCECProcessor::UnregisterClient(CCECClient *client)
 {
   CLockObject lock(m_mutex);
-  libcec_configuration &configuration = *client->GetConfiguration();
   CECDEVICEVEC devices;
-  m_busDevices->GetByLogicalAddresses(devices, configuration.logicalAddresses);
+  m_busDevices->GetByLogicalAddresses(devices, client->GetConfiguration()->logicalAddresses);
   for (CECDEVICEVEC::const_iterator it = devices.begin(); it != devices.end(); it++)
   {
     map<cec_logical_address, CCECClient *>::iterator entry = m_clients.find((*it)->GetLogicalAddress());
index f8607004e50c257ed01a3ebc50c485ab2c89d2fb..daa0b551d4749f1f5bfdffd2d50139662e2066ed 100644 (file)
@@ -65,6 +65,9 @@ CLibCEC::~CLibCEC(void)
 
 bool CLibCEC::Open(const char *strPort, uint32_t iTimeoutMs /* = CEC_DEFAULT_CONNECT_TIMEOUT */)
 {
+  if (!m_cec)
+    return false;
+
   if (m_cec->IsRunning())
   {
     AddLog(CEC_LOG_ERROR, "connection already open");
@@ -91,17 +94,13 @@ bool CLibCEC::Open(const char *strPort, uint32_t iTimeoutMs /* = CEC_DEFAULT_CON
 
 void CLibCEC::Close(void)
 {
-  m_clients.clear();
-
-  if (m_client)
-  {
-    delete m_client;
-    m_client = NULL;
-  }
   if (m_cec)
+    m_cec->Close();
+
+  for (vector<CCECClient *>::iterator it = m_clients.begin(); it != m_clients.end(); it++)
   {
-    delete m_cec;
-    m_cec = NULL;
+    (*it)->SetRegistered(false);
+    (*it)->SetInitialised(false);
   }
 }
 
@@ -923,7 +922,7 @@ CCECClient *CLibCEC::RegisterClient(libcec_configuration *configuration)
   if (m_cec->IsRunning())
     m_cec->RegisterClient(newClient);
 
-  return m_client;
+  return newClient;
 }
 
 void CLibCEC::UnregisterClients(void)
@@ -939,8 +938,15 @@ void * CECInitialise(libcec_configuration *configuration)
     return NULL;
 
   CLibCEC *lib = new CLibCEC;
+  CCECClient *client(NULL);
   if (lib)
-    lib->RegisterClient(configuration);
+    client = lib->RegisterClient(configuration);
+
+  if (client)
+    client->GetCurrentConfiguration(configuration);
+
+  // ensure that the correct server version is set
+  configuration->serverVersion = LIBCEC_VERSION_CURRENT;
 
   return static_cast< void* > (lib);
 }
@@ -948,7 +954,6 @@ void * CECInitialise(libcec_configuration *configuration)
 void * CECInit(const char *strDeviceName, CEC::cec_device_type_list types, uint16_t iPhysicalAddress /* = 0 */)
 {
   libcec_configuration configuration;
-  configuration.serverVersion = LIBCEC_VERSION_CURRENT;
 
   // client version < 1.5.0
   snprintf(configuration.strDeviceName, 13, "%s", strDeviceName);
index ca66a464e1d2c7da17a2cf5b045420cae2dabfda..a0d20a8a43d5ebfab551715993734b9e9e033438 100644 (file)
@@ -998,6 +998,9 @@ void CCECBusDevice::SetStreamPath(uint16_t iNewAddress, uint16_t iOldAddress /*
     m_iStreamPath = iNewAddress;
   }
 
+  if (!LIB_CEC->IsValidPhysicalAddress(iNewAddress))
+    return;
+
   CCECBusDevice *device = m_processor->GetDeviceByPhysicalAddress(iNewAddress);
   if (device)
   {
index e29578c728a1b5b0abf5288b5898615433fb6498..ead0ebdcb18c5e53525f60bb1882cdf9f12fabe6 100644 (file)
@@ -41,13 +41,15 @@ namespace PLATFORM
     CThread(void) :
         m_bStop(false),
         m_bRunning(false),
-        m_bStopped(false) {}
+        m_bStopped(false),
+        m_thread(NULL) {}
 
     virtual ~CThread(void)
     {
       StopThread(0);
       void *retVal;
-      ThreadsWait(m_thread, &retVal);
+      if (m_thread)
+        ThreadsWait(m_thread, &retVal);
       #if defined(__WINDOWS__)
       (void *)retVal; //"unreferenced local variable" warning
       #endif