AC_SUBST([LIBS_DL])
LIBS=$libs_pre_dl
+AC_LANG_PUSH([C++])
+AC_CHECK_HEADERS([boost/shared_ptr.hpp], [],
+ [AC_MSG_ERROR(You need the Boost libraries.)])
+AC_LANG_POP([C++])
+
CXXFLAGS="-fPIC -Wall -Wextra $CXXFLAGS"
AC_SUBST(REQUIRES)
void CAdapterCommunication::WriteNextCommand(void)
{
- CCECAdapterMessage msg;
+ CCECAdapterMessagePtr msg;
if (m_outBuffer.Pop(msg))
{
- if (m_port->Write(msg) != (int32_t) msg.size())
+ if (m_port->Write(msg) != (int32_t) msg.get()->size())
{
CStdString strError;
strError.Format("error writing to serial port: %s", m_port->GetError().c_str());
else
{
m_controller->AddLog(CEC_LOG_DEBUG, "command sent");
- CCondition::Sleep((uint32_t) msg.size() * (uint32_t)24 /*data*/ + (uint32_t)5 /*start bit (4.5 ms)*/);
+ CCondition::Sleep((uint32_t) msg.get()->size() * (uint32_t)24 /*data*/ + (uint32_t)5 /*start bit (4.5 ms)*/);
}
}
}
-bool CAdapterCommunication::Write(const CCECAdapterMessage &data)
+bool CAdapterCommunication::Write(CCECAdapterMessagePtr data)
{
m_outBuffer.Push(data);
return true;
return false;
m_controller->AddLog(CEC_LOG_DEBUG, "starting the bootloader");
- CCECAdapterMessage output;
+ CCECAdapterMessagePtr output(new CCECAdapterMessage);
- output.push_back(MSGSTART);
- output.push_escaped(MSGCODE_START_BOOTLOADER);
- output.push_back(MSGEND);
+ output->push_back(MSGSTART);
+ output->push_escaped(MSGCODE_START_BOOTLOADER);
+ output->push_back(MSGEND);
if (!Write(output))
{
strLog.Format("setting ackmask to %2x", iMask);
m_controller->AddLog(CEC_LOG_DEBUG, strLog.c_str());
- CCECAdapterMessage output;
+ CCECAdapterMessagePtr output(new CCECAdapterMessage);
- output.push_back(MSGSTART);
- output.push_escaped(MSGCODE_SET_ACK_MASK);
- output.push_escaped(iMask >> 8);
- output.push_escaped((uint8_t)iMask);
- output.push_back(MSGEND);
+ output->push_back(MSGSTART);
+ output->push_escaped(MSGCODE_SET_ACK_MASK);
+ output->push_escaped(iMask >> 8);
+ output->push_escaped((uint8_t)iMask);
+ output->push_back(MSGEND);
if (!Write(output))
{
return false;
m_controller->AddLog(CEC_LOG_DEBUG, "sending ping");
- CCECAdapterMessage output;
+ CCECAdapterMessagePtr output(new CCECAdapterMessage);
- output.push_back(MSGSTART);
- output.push_escaped(MSGCODE_PING);
- output.push_back(MSGEND);
+ output->push_back(MSGSTART);
+ output->push_escaped(MSGCODE_PING);
+ output->push_back(MSGEND);
if (!Write(output))
{
#include "platform/threads.h"
#include "util/buffer.h"
#include <string>
+#include <boost/enable_shared_from_this.hpp>
+#include <boost/shared_ptr.hpp>
namespace CEC
{
- class CCECAdapterMessage
+ class CCECAdapterMessage : public boost::enable_shared_from_this<CCECAdapterMessage>
{
public:
CCECAdapterMessage(void) {}
cec_datapacket packet;
};
+ typedef boost::shared_ptr<CCECAdapterMessage> CCECAdapterMessagePtr;
class CSerialPort;
class CLibCEC;
bool Open(const char *strPort, uint16_t iBaudRate = 38400, uint32_t iTimeoutMs = 10000);
bool Read(CCECAdapterMessage &msg, uint32_t iTimeout = 1000);
- bool Write(const CCECAdapterMessage &frame);
+ bool Write(CCECAdapterMessagePtr data);
bool PingAdapter(void);
void Close(void);
bool IsOpen(void) const;
void AddData(uint8_t *data, uint8_t iLen);
bool ReadFromDevice(uint32_t iTimeout);
- CSerialPort * m_port;
- CLibCEC * m_controller;
- CecBuffer<uint8_t> m_inBuffer;
- CecBuffer<CCECAdapterMessage> m_outBuffer;
- CMutex m_bufferMutex;
- CCondition m_rcvCondition;
+ CSerialPort * m_port;
+ CLibCEC * m_controller;
+ CecBuffer<uint8_t> m_inBuffer;
+ CecBuffer<CCECAdapterMessagePtr> m_outBuffer;
+ CMutex m_bufferMutex;
+ CCondition m_rcvCondition;
};
};
bool bReturn(false);
LogOutput(data);
- CCECAdapterMessage output(data);
+ CCECAdapterMessagePtr output(new CCECAdapterMessage(data));
CLockObject lock(&m_mutex);
if (!m_communication || !m_communication->Write(output))
if (bWaitForAck)
{
bool bError(false);
- if ((bReturn = WaitForAck(&bError, output.size(), 1000)) == false)
+ if ((bReturn = WaitForAck(&bError, output->size(), 1000)) == false)
m_controller->AddLog(CEC_LOG_ERROR, "did not receive ack");
}
else
Close();
}
-int8_t CSerialPort::Write(const CCECAdapterMessage &data)
+int8_t CSerialPort::Write(CCECAdapterMessagePtr data)
{
fd_set port;
int32_t byteswritten = 0;
- while (byteswritten < (int32_t) data.size())
+ while (byteswritten < (int32_t) data->size())
{
FD_ZERO(&port);
FD_SET(m_fd, &port);
return -1;
}
- returnv = write(m_fd, data.packet.data + byteswritten, data.size() - byteswritten);
+ returnv = write(m_fd, data->packet.data + byteswritten, data->size() - byteswritten);
if (returnv == -1)
{
m_error = strerror(errno);
bool IsOpen();
void Close();
- int8_t Write(const CCECAdapterMessage &data);
+ int8_t Write(CCECAdapterMessagePtr data);
int32_t Read(uint8_t* data, uint32_t len, uint64_t iTimeoutMs = 0);
std::string GetError() { return m_error; }