cec: drop shared_ptr and use a normal pointer. removed boost dependency
authorLars Op den Kamp <lars@opdenkamp.eu>
Wed, 2 Nov 2011 23:13:09 +0000 (00:13 +0100)
committerLars Op den Kamp <lars@opdenkamp.eu>
Wed, 2 Nov 2011 23:13:09 +0000 (00:13 +0100)
configure.ac
src/lib/AdapterCommunication.cpp
src/lib/AdapterCommunication.h
src/lib/CECProcessor.cpp
src/lib/CECProcessor.h
src/lib/platform/linux/serialport.cpp
src/lib/platform/serialport.h
src/lib/platform/windows/serialport.cpp

index 3285c89a3856a6580683509657070d065cf89595..b350c827cd30ad64b6b2d8483de40d5301788a87 100644 (file)
@@ -23,13 +23,6 @@ libs_pre_dl=$LIBS
   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_CHECK_HEADERS([boost/enable_shared_from_this.hpp], [],
-    [AC_MSG_ERROR(You need the Boost libraries.)])
-AC_LANG_POP([C++])
-
 CXXFLAGS="-fPIC -Wall -Wextra $CXXFLAGS"
 
 AC_SUBST(REQUIRES)
index 2286a01e57080e8c12663e7b6c5a48d0d628f1c0..00fa87e408615828cf0615dd045d1e1df74f5bc8 100644 (file)
@@ -353,7 +353,7 @@ void CAdapterCommunication::AddData(uint8_t *data, uint8_t iLen)
 
 void CAdapterCommunication::WriteNextCommand(void)
 {
-  CCECAdapterMessagePtr msg;
+  CCECAdapterMessage *msg;
   if (m_outBuffer.Pop(msg))
   {
     CLockObject lock(&msg->mutex);
@@ -374,7 +374,7 @@ void CAdapterCommunication::WriteNextCommand(void)
   }
 }
 
-bool CAdapterCommunication::Write(CCECAdapterMessagePtr data)
+bool CAdapterCommunication::Write(CCECAdapterMessage *data)
 {
   data->state = ADAPTER_MESSAGE_STATE_WAITING;
   m_outBuffer.Push(data);
@@ -442,47 +442,45 @@ std::string CAdapterCommunication::GetError(void) const
 
 bool CAdapterCommunication::StartBootloader(void)
 {
+  bool bReturn(false);
   if (!IsRunning())
-    return false;
+    return bReturn;
 
   m_controller->AddLog(CEC_LOG_DEBUG, "starting the bootloader");
-  CCECAdapterMessagePtr output(new CCECAdapterMessage);
+  CCECAdapterMessage *output = new CCECAdapterMessage;
 
   output->push_back(MSGSTART);
   output->push_escaped(MSGCODE_START_BOOTLOADER);
   output->push_back(MSGEND);
 
-  if (!Write(output))
-  {
+  if ((bReturn = Write(output)) == false)
     m_controller->AddLog(CEC_LOG_ERROR, "could not start the bootloader");
-    return false;
-  }
-  m_controller->AddLog(CEC_LOG_DEBUG, "bootloader start command transmitted");
-  return true;
+
+  delete output;
+
+  return bReturn;
 }
 
 bool CAdapterCommunication::PingAdapter(void)
 {
+  bool bReturn(false);
   if (!IsRunning())
-    return false;
+    return bReturn;
 
   m_controller->AddLog(CEC_LOG_DEBUG, "sending ping");
-  CCECAdapterMessagePtr output(new CCECAdapterMessage);
+  CCECAdapterMessage *output = new CCECAdapterMessage;
 
   output->push_back(MSGSTART);
   output->push_escaped(MSGCODE_PING);
   output->push_back(MSGEND);
 
-  if (!Write(output))
-  {
+  if ((bReturn = Write(output)) == false)
     m_controller->AddLog(CEC_LOG_ERROR, "could not send ping command");
-    return false;
-  }
-
-  m_controller->AddLog(CEC_LOG_DEBUG, "ping tranmitted");
 
   // TODO check for pong
-  return true;
+  delete output;
+
+  return bReturn;
 }
 
 bool CAdapterCommunication::IsOpen(void) const
index ef5e0aa7c2934c55649dcef5915b65130da3a52f..31de379e1350ac131529590e095ae2dd7bac2ee6 100644 (file)
@@ -36,8 +36,6 @@
 #include "util/buffer.h"
 #include "util/StdString.h"
 #include <string>
-#include <boost/enable_shared_from_this.hpp>
-#include <boost/shared_ptr.hpp>
 
 namespace CEC
 {
@@ -51,7 +49,7 @@ namespace CEC
   } cec_adapter_message_state;
 
 
-  class CCECAdapterMessage : public boost::enable_shared_from_this<CCECAdapterMessage>
+  class CCECAdapterMessage
   {
   public:
     CCECAdapterMessage(void) { clear(); }
@@ -81,7 +79,6 @@ namespace CEC
     CMutex                    mutex;
     CCondition                condition;
   };
-  typedef boost::shared_ptr<CCECAdapterMessage> CCECAdapterMessagePtr;
 
   class CSerialPort;
   class CLibCEC;
@@ -94,7 +91,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 Write(CCECAdapterMessagePtr data);
+    bool Write(CCECAdapterMessage *data);
     bool PingAdapter(void);
     void Close(void);
     bool IsOpen(void) const;
@@ -112,7 +109,7 @@ namespace CEC
     CSerialPort *                    m_port;
     CLibCEC *                        m_controller;
     CecBuffer<uint8_t>               m_inBuffer;
-    CecBuffer<CCECAdapterMessagePtr> m_outBuffer;
+    CecBuffer<CCECAdapterMessage *>  m_outBuffer;
     CMutex                           m_mutex;
     CCondition                       m_rcvCondition;
     CCondition                       m_startCondition;
index 0749e5375f00c0362d1dc9a93127f49b8cfe4976..563f2aa13a1c4cba31bf74155219e3d5fe5721c3 100644 (file)
@@ -231,13 +231,17 @@ cec_power_status CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddres
 
 bool CCECProcessor::Transmit(const cec_command &data)
 {
+  bool bReturn(false);
   LogOutput(data);
 
-  CCECAdapterMessagePtr output(new CCECAdapterMessage(data));
-  return Transmit(output);
+  CCECAdapterMessage *output = new CCECAdapterMessage(data);
+  bReturn = Transmit(output);
+  delete output;
+
+  return bReturn;
 }
 
-bool CCECProcessor::Transmit(CCECAdapterMessagePtr output)
+bool CCECProcessor::Transmit(CCECAdapterMessage *output)
 {
   bool bReturn(false);
   CLockObject lock(&m_mutex);
@@ -402,11 +406,12 @@ void CCECProcessor::AddLog(cec_log_level level, const CStdString &strMessage)
 
 bool CCECProcessor::SetAckMask(uint16_t iMask)
 {
+  bool bReturn(false);
   CStdString strLog;
   strLog.Format("setting ackmask to %2x", iMask);
   m_controller->AddLog(CEC_LOG_DEBUG, strLog.c_str());
 
-  CCECAdapterMessagePtr output(new CCECAdapterMessage);
+  CCECAdapterMessage *output = new CCECAdapterMessage;
 
   output->push_back(MSGSTART);
   output->push_escaped(MSGCODE_SET_ACK_MASK);
@@ -414,11 +419,10 @@ bool CCECProcessor::SetAckMask(uint16_t iMask)
   output->push_escaped((uint8_t)iMask);
   output->push_back(MSGEND);
 
-  if (!Transmit(output))
-  {
+  if ((bReturn = Transmit(output)) == false)
     m_controller->AddLog(CEC_LOG_ERROR, "could not set the ackmask");
-    return false;
-  }
 
-  return true;
+  delete output;
+
+  return bReturn;
 }
index e2793a3bbcb75621d9b5af0516e61b28038f257f..895445ff14ee0e1aa3056ea17f5dc793a25a2359 100644 (file)
@@ -70,7 +70,7 @@ namespace CEC
       virtual bool SwitchMonitoring(bool bEnable);
 
       virtual bool Transmit(const cec_command &data);
-      virtual bool Transmit(CCECAdapterMessagePtr output);
+      virtual bool Transmit(CCECAdapterMessage *output);
       virtual void TransmitAbort(cec_logical_address address, cec_opcode opcode, ECecAbortReason reason = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE);
 
       virtual void SetCurrentButton(cec_user_control_code iButtonCode);
index e362396e6cd471d41d4d562658fbc8adc5c54ec0..56bdc3070fc8fa6603a0f85317d35ca03c611f19 100644 (file)
@@ -46,7 +46,7 @@ CSerialPort::~CSerialPort()
   Close();
 }
 
-int8_t CSerialPort::Write(CCECAdapterMessagePtr data)
+int8_t CSerialPort::Write(CCECAdapterMessage *data)
 {
   fd_set port;
 
index 4fb29541008441c8255207615dc9b02e0f07e6f0..a88ebecb1738da26d6cb6dc106e366c2ba6f0270 100644 (file)
@@ -47,7 +47,7 @@ namespace CEC
       bool IsOpen();
       void Close();
 
-      int8_t Write(CCECAdapterMessagePtr data);
+      int8_t Write(CCECAdapterMessage *data);
       int32_t Read(uint8_t* data, uint32_t len, uint64_t iTimeoutMs = 0);
 
       std::string GetError() { return m_error; }
index b028ff32e5e8810f5bb01bcb70cf8aa2810722db..df619ef048c31ac03c5f90588a443edf42e5d141 100644 (file)
@@ -166,7 +166,7 @@ void CSerialPort::Close(void)
   }
 }
 
-int8_t CSerialPort::Write(CCECAdapterMessagePtr data)
+int8_t CSerialPort::Write(CCECAdapterMessage *data)
 {
   CLockObject lock(&m_mutex);
   DWORD iBytesWritten = 0;