#include "USBCECAdapterMessageQueue.h"
#include "../platform/sockets/serialport.h"
#include "../platform/util/timeutils.h"
+#include "../platform/util/util.h"
#include "../LibCEC.h"
#include "../CECProcessor.h"
CUSBCECAdapterCommunication::~CUSBCECAdapterCommunication(void)
{
Close();
- delete m_commands;
- delete m_adapterMessageQueue;
- delete m_port;
+ DELETE_AND_NULL(m_commands);
+ DELETE_AND_NULL(m_adapterMessageQueue);
+ DELETE_AND_NULL(m_port);
}
bool CUSBCECAdapterCommunication::Open(uint32_t iTimeoutMs /* = CEC_DEFAULT_CONNECT_TIMEOUT */, bool bSkipChecks /* = false */, bool bStartListening /* = true */)
m_adapterMessageQueue->Clear();
/* stop and delete the ping thread */
- if (m_pingThread)
- m_pingThread->StopThread(0);
- delete m_pingThread;
- m_pingThread = NULL;
+ DELETE_AND_NULL(m_pingThread);
/* close and delete the com port connection */
if (m_port)
{
LIB_CEC->AddLog(CEC_LOG_DEBUG, "error writing command '%s' to serial port '%s': %s", CCECAdapterMessage::ToString(message->Message()), m_port->GetName().c_str(), m_port->GetError().c_str());
message->state = ADAPTER_MESSAGE_STATE_ERROR;
- Close();
+ // this will trigger an alert in the reader thread
+ m_port->Close();
return false;
}
{
if (m_port->IsOpen() && m_commands->StartBootloader())
{
- Close();
+ m_port->Close();
return true;
}
return false;