repositories
/
deb_libcec.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
ad24cba
)
cec: use boost::shared_ptr for messages
author
Lars Op den Kamp
<lars@opdenkamp.eu>
Sat, 29 Oct 2011 23:18:35 +0000
(
01:18
+0200)
committer
Lars Op den Kamp
<lars@opdenkamp.eu>
Sat, 29 Oct 2011 23:54:39 +0000
(
01:54
+0200)
configure.ac
patch
|
blob
|
blame
|
history
src/lib/AdapterCommunication.cpp
patch
|
blob
|
blame
|
history
src/lib/AdapterCommunication.h
patch
|
blob
|
blame
|
history
src/lib/CECProcessor.cpp
patch
|
blob
|
blame
|
history
src/lib/platform/linux/serialport.cpp
patch
|
blob
|
blame
|
history
src/lib/platform/serialport.h
patch
|
blob
|
blame
|
history
diff --git
a/configure.ac
b/configure.ac
index b350c827cd30ad64b6b2d8483de40d5301788a87..124c013c0ee7cf69a752d9ad508fb0982da108ef 100644
(file)
--- a/
configure.ac
+++ b/
configure.ac
@@
-23,6
+23,11
@@
libs_pre_dl=$LIBS
AC_SUBST([LIBS_DL])
LIBS=$libs_pre_dl
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)
CXXFLAGS="-fPIC -Wall -Wextra $CXXFLAGS"
AC_SUBST(REQUIRES)
diff --git
a/src/lib/AdapterCommunication.cpp
b/src/lib/AdapterCommunication.cpp
index ba027234d78253b9798ef73cf90cb3b6d66c207f..743f00d66e6caefe6bf0d079248a641e7d691bd3 100644
(file)
--- a/
src/lib/AdapterCommunication.cpp
+++ b/
src/lib/AdapterCommunication.cpp
@@
-210,10
+210,10
@@
void CAdapterCommunication::AddData(uint8_t *data, uint8_t iLen)
void CAdapterCommunication::WriteNextCommand(void)
{
void CAdapterCommunication::WriteNextCommand(void)
{
- CCECAdapterMessage msg;
+ CCECAdapterMessage
Ptr
msg;
if (m_outBuffer.Pop(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());
{
CStdString strError;
strError.Format("error writing to serial port: %s", m_port->GetError().c_str());
@@
-222,12
+222,12
@@
void CAdapterCommunication::WriteNextCommand(void)
else
{
m_controller->AddLog(CEC_LOG_DEBUG, "command sent");
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;
{
m_outBuffer.Push(data);
return true;
@@
-295,11
+295,11
@@
bool CAdapterCommunication::StartBootloader(void)
return false;
m_controller->AddLog(CEC_LOG_DEBUG, "starting the bootloader");
return false;
m_controller->AddLog(CEC_LOG_DEBUG, "starting the bootloader");
- CCECAdapterMessage
output
;
+ CCECAdapterMessage
Ptr 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))
{
if (!Write(output))
{
@@
-319,13
+319,13
@@
bool CAdapterCommunication::SetAckMask(uint16_t iMask)
strLog.Format("setting ackmask to %2x", iMask);
m_controller->AddLog(CEC_LOG_DEBUG, strLog.c_str());
strLog.Format("setting ackmask to %2x", iMask);
m_controller->AddLog(CEC_LOG_DEBUG, strLog.c_str());
- CCECAdapterMessage
output
;
+ CCECAdapterMessage
Ptr 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))
{
if (!Write(output))
{
@@
-342,11
+342,11
@@
bool CAdapterCommunication::PingAdapter(void)
return false;
m_controller->AddLog(CEC_LOG_DEBUG, "sending ping");
return false;
m_controller->AddLog(CEC_LOG_DEBUG, "sending ping");
- CCECAdapterMessage
output
;
+ CCECAdapterMessage
Ptr 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))
{
if (!Write(output))
{
diff --git
a/src/lib/AdapterCommunication.h
b/src/lib/AdapterCommunication.h
index 9aab611632a54bdda7a403aad54480f660d961af..71688301351c89d84428d63b31d319d90fc76706 100644
(file)
--- a/
src/lib/AdapterCommunication.h
+++ b/
src/lib/AdapterCommunication.h
@@
-35,10
+35,12
@@
#include "platform/threads.h"
#include "util/buffer.h"
#include <string>
#include "platform/threads.h"
#include "util/buffer.h"
#include <string>
+#include <boost/enable_shared_from_this.hpp>
+#include <boost/shared_ptr.hpp>
namespace CEC
{
namespace CEC
{
- class CCECAdapterMessage
+ class CCECAdapterMessage
: public boost::enable_shared_from_this<CCECAdapterMessage>
{
public:
CCECAdapterMessage(void) {}
{
public:
CCECAdapterMessage(void) {}
@@
-61,6
+63,7
@@
namespace CEC
cec_datapacket packet;
};
cec_datapacket packet;
};
+ typedef boost::shared_ptr<CCECAdapterMessage> CCECAdapterMessagePtr;
class CSerialPort;
class CLibCEC;
class CSerialPort;
class CLibCEC;
@@
-73,7
+76,7
@@
namespace CEC
bool Open(const char *strPort, uint16_t iBaudRate = 38400, uint32_t iTimeoutMs = 10000);
bool Read(CCECAdapterMessage &msg, uint32_t iTimeout = 1000);
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;
bool PingAdapter(void);
void Close(void);
bool IsOpen(void) const;
@@
-89,11
+92,11
@@
namespace CEC
void AddData(uint8_t *data, uint8_t iLen);
bool ReadFromDevice(uint32_t iTimeout);
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<CCECAdapterMessage
Ptr
> m_outBuffer;
+ CMutex
m_bufferMutex;
+ CCondition
m_rcvCondition;
};
};
};
};
diff --git
a/src/lib/CECProcessor.cpp
b/src/lib/CECProcessor.cpp
index 7e8af29c0a88abce63037bb29e2e614f5e5133f5..73cae64b04ca0ba139b4b89a5ec40711a0f663a3 100644
(file)
--- a/
src/lib/CECProcessor.cpp
+++ b/
src/lib/CECProcessor.cpp
@@
-186,7
+186,7
@@
bool CCECProcessor::Transmit(const cec_command &data, bool bWaitForAck /* = true
bool bReturn(false);
LogOutput(data);
bool bReturn(false);
LogOutput(data);
- CCECAdapterMessage
output(data
);
+ CCECAdapterMessage
Ptr output(new CCECAdapterMessage(data)
);
CLockObject lock(&m_mutex);
if (!m_communication || !m_communication->Write(output))
CLockObject lock(&m_mutex);
if (!m_communication || !m_communication->Write(output))
@@
-195,7
+195,7
@@
bool CCECProcessor::Transmit(const cec_command &data, bool bWaitForAck /* = true
if (bWaitForAck)
{
bool bError(false);
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
m_controller->AddLog(CEC_LOG_ERROR, "did not receive ack");
}
else
diff --git
a/src/lib/platform/linux/serialport.cpp
b/src/lib/platform/linux/serialport.cpp
index 32f76757584c5558a02f0bd5d4ec19a527542c4d..e362396e6cd471d41d4d562658fbc8adc5c54ec0 100644
(file)
--- a/
src/lib/platform/linux/serialport.cpp
+++ b/
src/lib/platform/linux/serialport.cpp
@@
-46,7
+46,7
@@
CSerialPort::~CSerialPort()
Close();
}
Close();
}
-int8_t CSerialPort::Write(
const CCECAdapterMessage &
data)
+int8_t CSerialPort::Write(
CCECAdapterMessagePtr
data)
{
fd_set port;
{
fd_set port;
@@
-59,7
+59,7
@@
int8_t CSerialPort::Write(const CCECAdapterMessage &data)
int32_t byteswritten = 0;
int32_t byteswritten = 0;
- while (byteswritten < (int32_t) data
.
size())
+ while (byteswritten < (int32_t) data
->
size())
{
FD_ZERO(&port);
FD_SET(m_fd, &port);
{
FD_ZERO(&port);
FD_SET(m_fd, &port);
@@
-70,7
+70,7
@@
int8_t CSerialPort::Write(const CCECAdapterMessage &data)
return -1;
}
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);
if (returnv == -1)
{
m_error = strerror(errno);
diff --git
a/src/lib/platform/serialport.h
b/src/lib/platform/serialport.h
index ae465435851766b4c17f6df92543b1f37ff15e63..4fb29541008441c8255207615dc9b02e0f07e6f0 100644
(file)
--- a/
src/lib/platform/serialport.h
+++ b/
src/lib/platform/serialport.h
@@
-47,7
+47,7
@@
namespace CEC
bool IsOpen();
void Close();
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; }
int32_t Read(uint8_t* data, uint32_t len, uint64_t iTimeoutMs = 0);
std::string GetError() { return m_error; }