* 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();
}