From 828682d35c298ff062422521689258c363ea3579 Mon Sep 17 00:00:00 2001 From: Lars Op den Kamp Date: Mon, 3 Oct 2011 21:54:29 +0200 Subject: [PATCH] cec: renamed CCommunication -> CAdapterCommunication --- ...unication.cpp => AdapterCommunication.cpp} | 37 +++++++------------ ...Communication.h => AdapterCommunication.h} | 11 +++--- src/lib/CECParser.cpp | 4 +- src/lib/CECParser.h | 4 +- src/lib/Makefile.am | 4 +- 5 files changed, 25 insertions(+), 35 deletions(-) rename src/lib/{Communication.cpp => AdapterCommunication.cpp} (86%) rename src/lib/{Communication.h => AdapterCommunication.h} (91%) diff --git a/src/lib/Communication.cpp b/src/lib/AdapterCommunication.cpp similarity index 86% rename from src/lib/Communication.cpp rename to src/lib/AdapterCommunication.cpp index fd86b53..1ee7f88 100644 --- a/src/lib/Communication.cpp +++ b/src/lib/AdapterCommunication.cpp @@ -30,7 +30,7 @@ * http://www.pulse-eight.net/ */ -#include "Communication.h" +#include "AdapterCommunication.h" #include "CECParser.h" #include "libPlatform/serialport.h" #include "util/StdString.h" @@ -38,7 +38,7 @@ using namespace std; using namespace CEC; -CCommunication::CCommunication(CCECParser *parser) : +CAdapterCommunication::CAdapterCommunication(CCECParser *parser) : m_parser(parser), m_inbuf(NULL), m_iInbufSize(0), @@ -49,13 +49,13 @@ CCommunication::CCommunication(CCECParser *parser) : m_port = new CSerialPort; } -CCommunication::~CCommunication(void) +CAdapterCommunication::~CAdapterCommunication(void) { m_port->Close(); m_port = NULL; } -bool CCommunication::Open(const char *strPort, int iBaudRate /* = 38400 */, int iTimeoutMs /* = 10000 */) +bool CAdapterCommunication::Open(const char *strPort, int iBaudRate /* = 38400 */, int iTimeoutMs /* = 10000 */) { CLockObject lock(&m_commMutex); if (m_bStarted) @@ -79,10 +79,10 @@ bool CCommunication::Open(const char *strPort, int iBaudRate /* = 38400 */, int m_bStop = false; m_bStarted = true; - if (pthread_create(&m_thread, NULL, (void *(*) (void *))&CCommunication::ReaderThreadHandler, (void *)this) == 0) + + if (CreateThread()) { m_parser->AddLog(CEC_LOG_DEBUG, "reader thread created"); - pthread_detach(m_thread); return true; } else @@ -93,22 +93,13 @@ bool CCommunication::Open(const char *strPort, int iBaudRate /* = 38400 */, int return false; } -void *CCommunication::ReaderThreadHandler(CCommunication *comm) -{ - if (comm) - comm->ReaderProcess(); - - return NULL; -} - -void CCommunication::Close(void) +void CAdapterCommunication::Close(void) { - m_bStop = true; - pthread_join(m_thread, NULL); + StopThread(); m_port->Close(); } -void *CCommunication::ReaderProcess(void) +void *CAdapterCommunication::Process(void) { while (!m_bStop) { @@ -128,7 +119,7 @@ void *CCommunication::ReaderProcess(void) return NULL; } -bool CCommunication::ReadFromDevice(int iTimeout) +bool CAdapterCommunication::ReadFromDevice(int iTimeout) { uint8_t buff[1024]; CLockObject lock(&m_commMutex); @@ -147,7 +138,7 @@ bool CCommunication::ReadFromDevice(int iTimeout) return true; } -void CCommunication::AddData(uint8_t *data, int iLen) +void CAdapterCommunication::AddData(uint8_t *data, int iLen) { CLockObject lock(&m_bufferMutex); if (iLen + m_iInbufUsed > m_iInbufSize) @@ -162,7 +153,7 @@ void CCommunication::AddData(uint8_t *data, int iLen) m_condition.Signal(); } -bool CCommunication::Write(const cec_frame &data) +bool CAdapterCommunication::Write(const cec_frame &data) { CLockObject lock(&m_commMutex); @@ -178,7 +169,7 @@ bool CCommunication::Write(const cec_frame &data) return true; } -bool CCommunication::Read(cec_frame &msg, int iTimeout) +bool CAdapterCommunication::Read(cec_frame &msg, int iTimeout) { CLockObject lock(&m_bufferMutex); @@ -269,7 +260,7 @@ bool CCommunication::Read(cec_frame &msg, int iTimeout) return false; } -std::string CCommunication::GetError(void) const +std::string CAdapterCommunication::GetError(void) const { return m_port->GetError(); } diff --git a/src/lib/Communication.h b/src/lib/AdapterCommunication.h similarity index 91% rename from src/lib/Communication.h rename to src/lib/AdapterCommunication.h index 82afbb6..270d96b 100644 --- a/src/lib/Communication.h +++ b/src/lib/AdapterCommunication.h @@ -36,6 +36,7 @@ #include "../../include/CECExports.h" #include "../../include/CECTypes.h" #include "util/buffer.h" +#include "util/threads.h" class CSerialPort; @@ -43,11 +44,11 @@ namespace CEC { class CCECParser; - class CCommunication + class CAdapterCommunication : CThread { public: - CCommunication(CCECParser *parser); - virtual ~CCommunication(); + CAdapterCommunication(CCECParser *parser); + virtual ~CAdapterCommunication(); bool Open(const char *strPort, int iBaudRate = 38400, int iTimeoutMs = 10000); bool Read(cec_frame &msg, int iTimeout = 1000); @@ -56,8 +57,7 @@ namespace CEC bool IsOpen(void) const { return !m_bStop && m_bStarted; } std::string GetError(void) const; - static void *ReaderThreadHandler(CCommunication *reader); - void *ReaderProcess(void); + void *Process(void); private: void AddData(uint8_t *data, int iLen); bool ReadFromDevice(int iTimeout); @@ -69,7 +69,6 @@ namespace CEC int m_iInbufUsed; bool m_bStarted; bool m_bStop; - pthread_t m_thread; CMutex m_commMutex; CMutex m_bufferMutex; CCondition m_condition; diff --git a/src/lib/CECParser.cpp b/src/lib/CECParser.cpp index 5f24286..a86da1a 100644 --- a/src/lib/CECParser.cpp +++ b/src/lib/CECParser.cpp @@ -42,7 +42,7 @@ #include "util/threads.h" #include "util/timeutils.h" #include "CECDetect.h" -#include "Communication.h" +#include "AdapterCommunication.h" using namespace CEC; using namespace std; @@ -60,7 +60,7 @@ CCECParser::CCECParser(const char *strDeviceName, cec_logical_address iLogicalAd m_iLogicalAddress(iLogicalAddress), m_strDeviceName(strDeviceName) { - m_communication = new CCommunication(this); + m_communication = new CAdapterCommunication(this); } CCECParser::~CCECParser(void) diff --git a/src/lib/CECParser.h b/src/lib/CECParser.h index c70cc48..27187c7 100644 --- a/src/lib/CECParser.h +++ b/src/lib/CECParser.h @@ -42,7 +42,7 @@ class CSerialPort; namespace CEC { - class CCommunication; + class CAdapterCommunication; class CCECParser : public ICECDevice, public CThread { @@ -114,6 +114,6 @@ namespace CEC CecBuffer m_commandBuffer; std::string m_strDeviceName; CMutex m_mutex; - CCommunication *m_communication; + CAdapterCommunication *m_communication; }; }; diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 586e1b1..0d015ad 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -13,8 +13,8 @@ libcec_la_SOURCES = CECParser.cpp \ CECParserC.cpp \ CECDetect.cpp \ CECDetect.h \ - Communication.cpp \ - Communication.h \ + AdapterCommunication.cpp \ + AdapterCommunication.h \ ../../include/CECExports.h \ ../../include/CECExportsCpp.h \ ../../include/CECExportsC.h \ -- 2.34.1