using namespace PLATFORM;
CCECProcessor::CCECProcessor(CLibCEC *controller, const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS*/) :
- m_bStarted(false),
m_bInitialised(false),
m_iHDMIPort(CEC_DEFAULT_HDMI_PORT),
m_iBaseDevice((cec_logical_address)CEC_DEFAULT_BASE_DEVICE),
}
CCECProcessor::CCECProcessor(CLibCEC *controller, const char *strDeviceName, const cec_device_type_list &types) :
- m_bStarted(false),
m_bInitialised(false),
m_iHDMIPort(CEC_DEFAULT_HDMI_PORT),
m_iBaseDevice((cec_logical_address)CEC_DEFAULT_BASE_DEVICE),
CCECProcessor::~CCECProcessor(void)
{
- m_bStarted = false;
- m_startCondition.Broadcast();
StopThread();
delete m_communication;
return bReturn;
/* create the processor thread */
- if (!CreateThread() || !m_startCondition.Wait(m_mutex) || !m_bStarted)
+ if (!CreateThread())
{
CLibCEC::AddLog(CEC_LOG_ERROR, "could not create a processor thread");
return bReturn;
void *CCECProcessor::Process(void)
{
- bool bParseFrame(false);
- cec_command command;
- CCECAdapterMessage msg;
-
- {
- CLockObject lock(m_mutex);
- m_bStarted = true;
- CLibCEC::AddLog(CEC_LOG_DEBUG, "processor thread started");
- m_startCondition.Signal();
- }
+ bool bParseCommand(false);
+ cec_command command;
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "processor thread started");
while (!IsStopped())
{
{
CLockObject lock(m_mutex);
if (m_commandBuffer.Pop(command))
- bParseFrame = true;
+ bParseCommand = true;
else if (m_communication->IsOpen() && m_communication->Read(command, 50))
- bParseFrame = true;
+ bParseCommand = true;
}
- if (bParseFrame)
+ if (bParseCommand)
ParseCommand(command);
- bParseFrame = false;
+ bParseCommand = false;
Sleep(5);
m_iBaseDevice = iBaseDevice;
m_iHDMIPort = iPort;
- if (!m_bStarted && !bForce)
+ if (!IsRunning() && !bForce)
return true;
CLibCEC::AddLog(CEC_LOG_DEBUG, "setting HDMI port to %d on device %s (%d)", iPort, ToString(iBaseDevice), (int)iBaseDevice);
virtual bool IsPresentDeviceType(cec_device_type type);
virtual uint16_t GetPhysicalAddress(void) const;
virtual uint64_t GetLastTransmission(void) const { return m_iLastTransmission; }
- virtual bool IsStarted(void) const { return m_bStarted; }
virtual cec_logical_address GetActiveSource(void);
virtual bool IsActiveSource(cec_logical_address iAddress);
virtual bool IsInitialised(void) const { return m_bInitialised; }
void LogOutput(const cec_command &data);
void ParseCommand(cec_command &command);
- bool m_bStarted;
bool m_bInitialised;
uint8_t m_iHDMIPort;
cec_logical_address m_iBaseDevice;
std::string m_strDeviceName;
cec_device_type_list m_types;
PLATFORM::CMutex m_mutex;
- PLATFORM::CCondition m_startCondition;
IAdapterCommunication * m_communication;
CLibCEC* m_controller;
bool m_bMonitor;
bool CCECCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &command)
{
- if (m_processor->IsStarted() && m_busDevice->MyLogicalAddressContains(command.destination))
+ if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination))
m_processor->TransmitAbort(command.initiator, command.opcode, CEC_ABORT_REASON_REFUSED);
return true;
bool CCECCommandHandler::HandleGetCecVersion(const cec_command &command)
{
- if (m_processor->IsStarted() && m_busDevice->MyLogicalAddressContains(command.destination))
+ if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination))
{
CCECBusDevice *device = GetDevice(command.destination);
if (device)
bool CCECCommandHandler::HandleGiveAudioStatus(const cec_command &command)
{
- if (m_processor->IsStarted() && m_busDevice->MyLogicalAddressContains(command.destination))
+ if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination))
{
CCECBusDevice *device = GetDevice(command.destination);
if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
bool CCECCommandHandler::HandleGiveDeckStatus(const cec_command &command)
{
- if (m_processor->IsStarted() && m_busDevice->MyLogicalAddressContains(command.destination))
+ if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination))
{
CCECBusDevice *device = GetDevice(command.destination);
if (device && (device->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || device->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE))
bool CCECCommandHandler::HandleGiveDevicePowerStatus(const cec_command &command)
{
- if (m_processor->IsStarted() && m_busDevice->MyLogicalAddressContains(command.destination))
+ if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination))
{
CCECBusDevice *device = GetDevice(command.destination);
if (device)
bool CCECCommandHandler::HandleGiveDeviceVendorId(const cec_command &command)
{
- if (m_processor->IsStarted() && m_busDevice->MyLogicalAddressContains(command.destination))
+ if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination))
{
CCECBusDevice *device = GetDevice(command.destination);
if (device)
bool CCECCommandHandler::HandleGiveOSDName(const cec_command &command)
{
- if (m_processor->IsStarted() && m_busDevice->MyLogicalAddressContains(command.destination))
+ if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination))
{
CCECBusDevice *device = GetDevice(command.destination);
if (device)
bool CCECCommandHandler::HandleGivePhysicalAddress(const cec_command &command)
{
- if (m_processor->IsStarted() && m_busDevice->MyLogicalAddressContains(command.destination))
+ if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination))
{
CCECBusDevice *device = GetDevice(command.destination);
if (device)
bool CCECCommandHandler::HandleGiveSystemAudioModeStatus(const cec_command &command)
{
- if (m_processor->IsStarted() && m_busDevice->MyLogicalAddressContains(command.destination))
+ if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination))
{
CCECBusDevice *device = GetDevice(command.destination);
if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
bool CCECCommandHandler::HandleMenuRequest(const cec_command &command)
{
- if (m_processor->IsStarted() && m_busDevice->MyLogicalAddressContains(command.destination))
+ if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination))
{
if (command.parameters[0] == CEC_MENU_REQUEST_TYPE_QUERY)
{
bool CCECCommandHandler::HandleRequestActiveSource(const cec_command &command)
{
- if (m_processor->IsStarted())
+ if (m_processor->IsRunning())
{
CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %i requests active source", (uint8_t) command.initiator);
bool CCECCommandHandler::HandleSetStreamPath(const cec_command &command)
{
- if (m_processor->IsStarted() && command.parameters.size >= 2)
+ if (m_processor->IsRunning() && command.parameters.size >= 2)
{
uint16_t iStreamAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
CLibCEC::AddLog(CEC_LOG_DEBUG, ">> %i sets stream path to physical address %04x", command.initiator, iStreamAddress);
bool CCECCommandHandler::HandleSystemAudioModeRequest(const cec_command &command)
{
- if (m_processor->IsStarted() && m_busDevice->MyLogicalAddressContains(command.destination))
+ if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination))
{
CCECBusDevice *device = GetDevice(command.destination);
if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
bool CCECCommandHandler::HandleUserControlPressed(const cec_command &command)
{
- if (m_processor->IsStarted() && m_busDevice->MyLogicalAddressContains(command.destination) && command.parameters.size > 0)
+ if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination) && command.parameters.size > 0)
{
CLibCEC::AddKey();
bool CCECCommandHandler::HandleUserControlRelease(const cec_command &command)
{
- if (m_processor->IsStarted() && m_busDevice->MyLogicalAddressContains(command.destination))
+ if (m_processor->IsRunning() && m_busDevice->MyLogicalAddressContains(command.destination))
CLibCEC::AddKey();
return true;