cec: close and delete the connection when the processor thread ends. fixes reconnect...
authorLars Op den Kamp <lars@opdenkamp.eu>
Thu, 2 Feb 2012 00:02:56 +0000 (01:02 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Thu, 2 Feb 2012 00:05:19 +0000 (01:05 +0100)
src/lib/CECProcessor.cpp
src/lib/adapter/USBCECAdapterCommunication.cpp

index 7041b78f79acf82075b29d0eff9155e24448c556..38c9b76f8e52e3592802ea4d158a31eea5ea8601 100644 (file)
@@ -134,8 +134,9 @@ bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint
   CLockObject lock(m_mutex);
   if (m_communication)
   {
-    CLibCEC::AddLog(CEC_LOG_ERROR, "existing connection handler found");
-    return bReturn;
+    CLibCEC::AddLog(CEC_LOG_WARNING, "existing connection handler found, deleting it");
+    m_communication->Close();
+    delete m_communication;
   }
 
   m_communication = new CUSBCECAdapterCommunication(this, strPort, iBaudRate);
@@ -449,7 +450,11 @@ void *CCECProcessor::Process(void)
   }
 
   if (m_communication)
+  {
     m_communication->Close();
+    delete m_communication;
+    m_communication = NULL;
+  }
 
   return NULL;
 }
index e2b03862d437cf75da03dda403a94e3da4e8f600..a3b7c459837e017ce75aca543b0190a6a30d3d6c 100644 (file)
@@ -55,12 +55,6 @@ CUSBCECAdapterCommunication::CUSBCECAdapterCommunication(CCECProcessor *processo
 CUSBCECAdapterCommunication::~CUSBCECAdapterCommunication(void)
 {
   Close();
-
-  if (m_port)
-  {
-    delete m_port;
-    m_port = NULL;
-  }
 }
 
 bool CUSBCECAdapterCommunication::Open(uint32_t iTimeoutMs /* = 10000 */)
@@ -143,6 +137,12 @@ void *CUSBCECAdapterCommunication::Process(void)
   if (m_outBuffer.Pop(msg))
     msg->condition.Broadcast();
 
+  if (m_port)
+  {
+    delete m_port;
+    m_port = NULL;
+  }
+
   return NULL;
 }