X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2FCECProcessor.cpp;h=3fb3bc299a3a5782fb2699293a4b982b12ad5e60;hb=cd505625984870e36f98323209d3c2d7273e3266;hp=1bc4c597854ad6475dc6557a67429445fa5a1813;hpb=0e31a62c1ff3854f1c4dad3fb0917683c9528e5b;p=deb_libcec.git diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 1bc4c59..3fb3bc2 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -42,7 +42,7 @@ using namespace CEC; using namespace std; CCECProcessor::CCECProcessor(CLibCEC *controller, CAdapterCommunication *serComm, const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS*/) : - m_iLogicalAddress(iLogicalAddress), + m_iLogicalAddress(CECDEVICE_UNKNOWN), m_strDeviceName(strDeviceName), m_communication(serComm), m_controller(controller), @@ -54,6 +54,7 @@ CCECProcessor::CCECProcessor(CLibCEC *controller, CAdapterCommunication *serComm CCECProcessor::~CCECProcessor(void) { + m_startCondition.Broadcast(); StopThread(); m_communication = NULL; m_controller = NULL; @@ -63,6 +64,7 @@ CCECProcessor::~CCECProcessor(void) bool CCECProcessor::Start(void) { + CLockObject lock(&m_mutex); if (!m_communication || !m_communication->IsOpen()) { m_controller->AddLog(CEC_LOG_ERROR, "connection is closed"); @@ -76,7 +78,14 @@ bool CCECProcessor::Start(void) } if (CreateThread()) + { + if (!m_startCondition.Wait(&m_mutex)) + { + m_controller->AddLog(CEC_LOG_ERROR, "could not create a processor thread"); + return false; + } return true; + } else m_controller->AddLog(CEC_LOG_ERROR, "could not create a processor thread"); @@ -85,12 +94,18 @@ bool CCECProcessor::Start(void) void *CCECProcessor::Process(void) { - m_controller->AddLog(CEC_LOG_DEBUG, "processor thread started"); + { + CLockObject lock(&m_mutex); + m_controller->AddLog(CEC_LOG_DEBUG, "processor thread started"); + m_startCondition.Signal(); + } cec_command command; CCECAdapterMessage msg; CCECAdapterMessagePtr msgPtr; + m_communication->SetAckMask(0x1 << (uint8_t)m_iLogicalAddress); + while (!IsStopped()) { bool bParseFrame(false); @@ -187,7 +202,7 @@ bool CCECProcessor::SwitchMonitoring(bool bEnable) return m_communication && m_communication->SetAckMask(0x1 << (uint8_t)m_iLogicalAddress); } -bool CCECProcessor::Transmit(const cec_command &data, bool bWaitForAck /* = true */) +bool CCECProcessor::Transmit(const cec_command &data) { bool bReturn(false); LogOutput(data); @@ -208,17 +223,17 @@ bool CCECProcessor::Transmit(const cec_command &data, bool bWaitForAck /* = true return bReturn; } } - } - if (bWaitForAck) - { - bool bError(false); - if ((bReturn = WaitForAck(&bError, output->size(), 1000)) == false) - m_controller->AddLog(CEC_LOG_ERROR, "did not receive ack"); - } - else - { - bReturn = true; + if (data.ack_timeout > 0) + { + bool bError(false); + if ((bReturn = WaitForAck(&bError, output->size(), data.ack_timeout)) == false) + m_controller->AddLog(CEC_LOG_ERROR, "did not receive ack"); + } + else + { + bReturn = true; + } } return bReturn;