X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2Fdevices%2FCECBusDevice.cpp;h=c9699d8f96f6f46dcf3ce1d54cce543e646ae2af;hb=2ee922ad2f1812c74f2aa6e61305fdcc5c27de53;hp=f2bd59f7b495345b7cad0fd6fbd25c03ae43a046;hpb=d9de2aae6b2f47b8e1faacc69adba7406b9d85f0;p=deb_libcec.git diff --git a/src/lib/devices/CECBusDevice.cpp b/src/lib/devices/CECBusDevice.cpp index f2bd59f..c9699d8 100644 --- a/src/lib/devices/CECBusDevice.cpp +++ b/src/lib/devices/CECBusDevice.cpp @@ -61,6 +61,75 @@ using namespace PLATFORM; #define LIB_CEC m_processor->GetLib() #define ToString(p) CCECTypeUtils::ToString(p) +CResponse::CResponse(cec_opcode opcode) : + m_opcode(opcode) +{ +} + +CResponse::~CResponse(void) +{ + Broadcast(); +} + +bool CResponse::Wait(uint32_t iTimeout) +{ + return m_event.Wait(iTimeout); +} + +void CResponse::Broadcast(void) +{ + m_event.Broadcast(); +} + +CWaitForResponse::CWaitForResponse(void) +{ +} + +CWaitForResponse::~CWaitForResponse(void) +{ + Clear(); +} + +void CWaitForResponse::Clear() +{ + PLATFORM::CLockObject lock(m_mutex); + for (std::map::iterator it = m_waitingFor.begin(); it != m_waitingFor.end(); it++) + it->second->Broadcast(); + m_waitingFor.clear(); +} + +bool CWaitForResponse::Wait(cec_opcode opcode, uint32_t iTimeout) +{ + CResponse *response = GetEvent(opcode); + return response ? response->Wait(iTimeout) : false; +} + +void CWaitForResponse::Received(cec_opcode opcode) +{ + CResponse *response = GetEvent(opcode); + if (response) + response->Broadcast(); +} + +CResponse* CWaitForResponse::GetEvent(cec_opcode opcode) +{ + CResponse *retVal(NULL); + { + PLATFORM::CLockObject lock(m_mutex); + std::map::iterator it = m_waitingFor.find(opcode); + if (it != m_waitingFor.end()) + { + retVal = it->second; + } + else + { + retVal = new CResponse(opcode); + m_waitingFor[opcode] = retVal; + } + return retVal; + } +} + CCECBusDevice::CCECBusDevice(CCECProcessor *processor, cec_logical_address iLogicalAddress, uint16_t iPhysicalAddress /* = CEC_INVALID_PHYSICAL_ADDRESS */) : m_type (CEC_DEVICE_TYPE_RESERVED), m_iPhysicalAddress (iPhysicalAddress), @@ -1147,14 +1216,10 @@ void CCECBusDevice::SetActiveRoute(uint16_t iRoute) return; CCECBusDevice* newRoute = m_processor->GetDeviceByPhysicalAddress(iRoute, true); - if (newRoute) + if (newRoute && newRoute->IsHandledByLibCEC()) { // we were made the active source, send notification - if (newRoute->IsHandledByLibCEC()) - newRoute->ActivateSource(); - // another device was made active - else - newRoute->MarkAsActiveSource(); + newRoute->ActivateSource(); } }