* http://www.pulse-eight.net/
*/
-#include "Communication.h"
+#include "AdapterCommunication.h"
#include "CECParser.h"
#include "libPlatform/serialport.h"
#include "util/StdString.h"
using namespace std;
using namespace CEC;
-CCommunication::CCommunication(CCECParser *parser) :
+CAdapterCommunication::CAdapterCommunication(CCECParser *parser) :
m_parser(parser),
m_inbuf(NULL),
m_iInbufSize(0),
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)
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
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)
{
return NULL;
}
-bool CCommunication::ReadFromDevice(int iTimeout)
+bool CAdapterCommunication::ReadFromDevice(int iTimeout)
{
uint8_t buff[1024];
CLockObject lock(&m_commMutex);
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)
m_condition.Signal();
}
-bool CCommunication::Write(const cec_frame &data)
+bool CAdapterCommunication::Write(const cec_frame &data)
{
CLockObject lock(&m_commMutex);
return true;
}
-bool CCommunication::Read(cec_frame &msg, int iTimeout)
+bool CAdapterCommunication::Read(cec_frame &msg, int iTimeout)
{
CLockObject lock(&m_bufferMutex);
return false;
}
-std::string CCommunication::GetError(void) const
+std::string CAdapterCommunication::GetError(void) const
{
return m_port->GetError();
}
#include "../../include/CECExports.h"
#include "../../include/CECTypes.h"
#include "util/buffer.h"
+#include "util/threads.h"
class CSerialPort;
{
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);
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);
int m_iInbufUsed;
bool m_bStarted;
bool m_bStop;
- pthread_t m_thread;
CMutex m_commMutex;
CMutex m_bufferMutex;
CCondition m_condition;
#include "util/threads.h"
#include "util/timeutils.h"
#include "CECDetect.h"
-#include "Communication.h"
+#include "AdapterCommunication.h"
using namespace CEC;
using namespace std;
m_iLogicalAddress(iLogicalAddress),
m_strDeviceName(strDeviceName)
{
- m_communication = new CCommunication(this);
+ m_communication = new CAdapterCommunication(this);
}
CCECParser::~CCECParser(void)