cec: extracted a Close() method in CCECProcessor
authorLars Op den Kamp <lars@opdenkamp.eu>
Wed, 8 Feb 2012 22:29:16 +0000 (23:29 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Wed, 8 Feb 2012 22:29:16 +0000 (23:29 +0100)
src/lib/CECProcessor.cpp
src/lib/CECProcessor.h
src/lib/LibCEC.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;
 }
 
index f0dbda41cb1f57df0c75604cf7f5a16330d500cc..24c02bbfa9691d7afb66993ddad98002a9ae8f00 100644 (file)
@@ -52,6 +52,7 @@ namespace CEC
 
       virtual bool Start(const char *strPort, uint16_t iBaudRate = 38400, uint32_t iTimeoutMs = 10000);
       virtual void *Process(void);
+      virtual void Close(void);
 
       virtual bool                  OnCommandReceived(const cec_command &command);
 
index 9c169cc4854602e5d9ad550b913206ed401c3ee2..30a3221cfb46fe86f5000a1f1107b7e2270c6313 100644 (file)
@@ -88,7 +88,7 @@ bool CLibCEC::Open(const char *strPort, uint32_t iTimeoutMs /* = 10000 */)
 void CLibCEC::Close(void)
 {
   if (m_cec)
-    m_cec->StopThread();
+    m_cec->Close();
 }
 
 bool CLibCEC::EnableCallbacks(void *cbParam, ICECCallbacks *callbacks)