}
bool isset(cec_logical_address address) const { return addresses[(int) address] == 1; }
+ bool operator[](uint8_t pos) const { return pos < 16 ? isset((cec_logical_address) pos) : false; }
#endif
} cec_logical_addresses;
strLog.Format("using logical address '%s'", strLabel);
AddLog(CEC_LOG_NOTICE, strLog);
- /* only set our OSD name for the primary device */
+ /* only set our OSD name and active source for the primary device */
if (m_logicalAddresses.empty())
+ {
m_busDevices[address]->m_strDeviceName = m_strDeviceName;
+ m_busDevices[address]->m_bActiveSource = true;
+ }
m_busDevices[address]->m_powerStatus = (m_types[0] == m_busDevices[address]->m_type) ? CEC_POWER_STATUS_ON : CEC_POWER_STATUS_STANDBY;
m_busDevices[address]->m_cecVersion = CEC_VERSION_1_3A;
m_logicalAddresses.set(address);
void *CCECProcessor::Process(void)
{
+ bool bParseFrame(false);
cec_command command;
CCECAdapterMessage msg;
while (!IsStopped())
{
- bool bParseFrame(false);
command.clear();
msg.clear();
{
CLockObject lock(&m_mutex);
- if (m_communication->IsOpen() && m_communication->Read(msg, 50))
+ if (m_commandBuffer.Pop(command))
+ {
+ bParseFrame = true;
+ }
+ else if (m_communication->IsOpen() && m_communication->Read(msg, 50))
{
m_controller->AddLog(msg.is_error() ? CEC_LOG_WARNING : CEC_LOG_DEBUG, msg.ToString());
- bParseFrame = ParseMessage(msg) && !IsStopped();
+ if ((bParseFrame = (ParseMessage(msg) && !IsStopped())))
+ command = m_currentframe;
}
-
- if (bParseFrame)
- command = m_currentframe;
}
if (bParseFrame)
ParseCommand(command);
+ bParseFrame = false;
Sleep(5);
bError = !bTransmitSucceeded;
break;
default:
- ParseMessage(msg);
+ if (ParseMessage(msg))
+ m_commandBuffer.Push(m_currentframe);
}
iNow = GetTimeMs();
virtual bool Start(void);
virtual void *Process(void);
- virtual bool IsMonitoring(void) const { return m_bMonitor; }
- virtual cec_version GetDeviceCecVersion(cec_logical_address iAddress);
- virtual bool GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language);
- virtual const std::string & GetDeviceName(void) { return m_strDeviceName; }
- virtual uint64_t GetDeviceVendorId(cec_logical_address iAddress);
- virtual cec_power_status GetDevicePowerStatus(cec_logical_address iAddress);
- virtual cec_logical_address GetLogicalAddress(void) const { return m_logicalAddresses.primary; }
- virtual bool HasLogicalAddress(cec_logical_address address) const { return m_logicalAddresses.isset(address); }
- virtual uint16_t GetPhysicalAddress(void) const;
+ virtual bool IsMonitoring(void) const { return m_bMonitor; }
+ virtual cec_version GetDeviceCecVersion(cec_logical_address iAddress);
+ virtual bool GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language);
+ virtual const std::string & GetDeviceName(void) { return m_strDeviceName; }
+ virtual uint64_t GetDeviceVendorId(cec_logical_address iAddress);
+ virtual cec_power_status GetDevicePowerStatus(cec_logical_address iAddress);
+ virtual cec_logical_address GetLogicalAddress(void) const { return m_logicalAddresses.primary; }
+ virtual cec_logical_addresses GetLogicalAddresses(void) const { return m_logicalAddresses; }
+ virtual bool HasLogicalAddress(cec_logical_address address) const { return m_logicalAddresses.isset(address); }
+ virtual uint16_t GetPhysicalAddress(void) const;
virtual bool SetActiveView(void);
virtual bool SetInactiveView(void);
CAdapterCommunication* m_communication;
CLibCEC* m_controller;
bool m_bMonitor;
+ CecBuffer<cec_command> m_commandBuffer;
};
};
m_powerStatus(CEC_POWER_STATUS_UNKNOWN),
m_processor(processor),
m_bMenuActive(true),
+ m_bActiveSource(false),
m_iVendorClass(CEC_VENDOR_UNKNOWN),
m_iLastActive(0),
m_cecVersion(CEC_VERSION_UNKNOWN)
//@{
bool CCECBusDevice::TransmitActiveSource(void)
{
- CStdString strLog;
- strLog.Format("<< %x -> broadcast: active source (%4x)", m_iLogicalAddress, m_iPhysicalAddress);
- AddLog(CEC_LOG_NOTICE, strLog);
+ if (m_bActiveSource)
+ {
+ CStdString strLog;
+ strLog.Format("<< %x -> broadcast: active source (%4x)", m_iLogicalAddress, m_iPhysicalAddress);
+ AddLog(CEC_LOG_NOTICE, strLog);
- cec_command command;
- cec_command::format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_ACTIVE_SOURCE);
- command.parameters.push_back((uint8_t) ((m_iPhysicalAddress >> 8) & 0xFF));
- command.parameters.push_back((uint8_t) (m_iPhysicalAddress & 0xFF));
+ cec_command command;
+ cec_command::format(command, m_iLogicalAddress, CECDEVICE_BROADCAST, CEC_OPCODE_ACTIVE_SOURCE);
+ command.parameters.push_back((uint8_t) ((m_iPhysicalAddress >> 8) & 0xFF));
+ command.parameters.push_back((uint8_t) (m_iPhysicalAddress & 0xFF));
- return m_processor->Transmit(command);
+ return m_processor->Transmit(command);
+ }
+ else
+ {
+ CStdString strLog;
+ strLog.Format("<< %x is not the active source", m_iLogicalAddress);
+ AddLog(CEC_LOG_DEBUG, strLog);
+ }
+
+ return false;
}
bool CCECBusDevice::TransmitActiveView(void)
CCECCommandHandler *m_handler;
cec_vendor m_vendor;
bool m_bMenuActive;
+ bool m_bActiveSource;
uint8_t m_iVendorClass;
uint64_t m_iLastActive;
cec_version m_cecVersion;
#include "../CECProcessor.h"
using namespace CEC;
+using namespace std;
CCECCommandHandler::CCECCommandHandler(CCECBusDevice *busDevice)
{
CStdString strLog;
strLog.Format(">> %i requests active source", (uint8_t) command.initiator);
m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str());
- CCECBusDevice *device = m_busDevice->GetProcessor()->m_busDevices[m_busDevice->GetMyLogicalAddress()];
- if (device)
- return device->TransmitActiveSource();
- return false;
+
+ vector<CCECBusDevice *> devices;
+ for (int iDevicePtr = (int)GetMyDevices(devices)-1; iDevicePtr >=0; iDevicePtr--)
+ devices[iDevicePtr]->TransmitActiveSource();
+ return true;
}
bool CCECCommandHandler::HandleRoutingChange(const cec_command &command)
m_busDevice->AddLog(CEC_LOG_DEBUG, strLog);
}
+unsigned int CCECCommandHandler::GetMyDevices(vector<CCECBusDevice *> &devices) const
+{
+ unsigned int iReturn(0);
+
+ cec_logical_addresses addresses = m_busDevice->GetProcessor()->GetLogicalAddresses();
+ for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
+ {
+ if (addresses[iPtr])
+ {
+ devices.push_back(GetDevice((cec_logical_address) iPtr));
+ ++iReturn;
+ }
+ }
+
+ return iReturn;
+}
+
CCECBusDevice *CCECCommandHandler::GetDevice(cec_logical_address iLogicalAddress) const
{
CCECBusDevice *device = NULL;
*/
#include <cectypes.h>
+#include <vector>
namespace CEC
{
virtual bool HandleCommand(const cec_command &command);
virtual cec_vendor_id GetVendorId(void) { return CEC_VENDOR_UNKNOWN; };
+ static const char* ToString(const cec_opcode opcode);
+
protected:
virtual bool HandleDeviceCecVersion(const cec_command &command);
virtual bool HandleDeviceVendorCommandWithId(const cec_command &command);
virtual bool HandleUserControlRelease(const cec_command &command);
virtual void UnhandledCommand(const cec_command &command);
+ virtual unsigned int GetMyDevices(std::vector<CCECBusDevice *> &devices) const;
virtual CCECBusDevice *GetDevice(cec_logical_address iLogicalAddress) const;
virtual CCECBusDevice *GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress) const;
- static const char* ToString(const cec_opcode opcode);
-
virtual void SetVendorId(const cec_command &command);
CCECBusDevice *m_busDevice;
};