cec: extracted a Close() method in CCECProcessor
[deb_libcec.git] / src / lib / CECProcessor.cpp
index 78d24360b6da344ed7471379b9e7b96ee097c118..06f847754f621711c4f7225439ccbd4943f76f1d 100644 (file)
@@ -115,15 +115,25 @@ CCECProcessor::CCECProcessor(CLibCEC *controller, const char *strDeviceName, con
 
 CCECProcessor::~CCECProcessor(void)
 {
-  StopThread();
+  Close();
 
-  delete m_communication;
-  m_communication = NULL;
-  m_controller = NULL;
   for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
     delete m_busDevices[iPtr];
 }
 
+void CCECProcessor::Close(void)
+{
+  StopThread();
+
+  CLockObject lock(m_mutex);
+  if (m_communication)
+  {
+    m_communication->Close();
+    delete m_communication;
+    m_communication = NULL;
+  }
+}
+
 bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint32_t iTimeoutMs)
 {
   bool bReturn(false);
@@ -411,13 +421,6 @@ void *CCECProcessor::Process(void)
     Sleep(5);
   }
 
-  if (m_communication)
-  {
-    m_communication->Close();
-    delete m_communication;
-    m_communication = NULL;
-  }
-
   return NULL;
 }