From: Lars Op den Kamp Date: Wed, 8 Feb 2012 22:29:16 +0000 (+0100) Subject: cec: extracted a Close() method in CCECProcessor X-Git-Tag: upstream/2.2.0~1^2~35^2~136 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=eca71746decee108194af2c47d6073133a1e8207;p=deb_libcec.git cec: extracted a Close() method in CCECProcessor --- diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 78d2436..06f8477 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -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; } diff --git a/src/lib/CECProcessor.h b/src/lib/CECProcessor.h index f0dbda4..24c02bb 100644 --- a/src/lib/CECProcessor.h +++ b/src/lib/CECProcessor.h @@ -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); diff --git a/src/lib/LibCEC.cpp b/src/lib/LibCEC.cpp index 9c169cc..30a3221 100644 --- a/src/lib/LibCEC.cpp +++ b/src/lib/LibCEC.cpp @@ -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)