3 * This file is part of the libCEC(R) library.
5 * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved.
6 * libCEC(R) is an original work, containing original code.
8 * libCEC(R) is a trademark of Pulse-Eight Limited.
10 * This program is dual-licensed; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 * Alternatively, you can license this library under a commercial license,
26 * please contact Pulse-Eight Licensing for more information.
28 * For more information contact:
29 * Pulse-Eight Licensing <license@pulse-eight.com>
30 * http://www.pulse-eight.com/
31 * http://www.pulse-eight.net/
36 #include "platform/threads/threads.h"
37 #include "platform/util/buffer.h"
39 #include "adapter/AdapterCommunication.h"
40 #include "devices/CECDeviceMap.h"
41 #include "CECInputBuffer.h"
46 class IAdapterCommunication
;
48 class CCECAudioSystem
;
49 class CCECPlaybackDevice
;
50 class CCECRecordingDevice
;
55 class CCECProcessor
: public PLATFORM::CThread
, public IAdapterCommunicationCallback
58 CCECProcessor(CLibCEC
*libcec
);
59 virtual ~CCECProcessor(void);
61 bool Start(const char *strPort
, uint16_t iBaudRate
= CEC_SERIAL_DEFAULT_BAUDRATE
, uint32_t iTimeoutMs
= CEC_DEFAULT_CONNECT_TIMEOUT
);
65 bool RegisterClient(CCECClient
*client
);
66 bool UnregisterClient(CCECClient
*client
);
67 void UnregisterClients(void);
68 CCECClient
*GetPrimaryClient(void);
69 CCECClient
*GetClient(const cec_logical_address address
);
71 bool OnCommandReceived(const cec_command
&command
);
73 CCECBusDevice
* GetDevice(cec_logical_address address
) const;
74 CCECAudioSystem
* GetAudioSystem(void) const;
75 CCECPlaybackDevice
* GetPlaybackDevice(cec_logical_address address
) const;
76 CCECRecordingDevice
* GetRecordingDevice(cec_logical_address address
) const;
77 CCECTuner
* GetTuner(cec_logical_address address
) const;
78 CCECTV
* GetTV(void) const;
80 CCECBusDevice
* GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress
, bool bSuppressUpdate
= true);
81 CCECBusDevice
* GetPrimaryDevice(void);
82 cec_logical_address
GetLogicalAddress(void);
83 cec_logical_addresses
GetLogicalAddresses(void);
84 bool IsPresentDevice(cec_logical_address address
);
85 bool IsPresentDeviceType(cec_device_type type
);
86 uint16_t GetDetectedPhysicalAddress(void) const;
87 uint64_t GetLastTransmission(void) const { return m_iLastTransmission
; }
88 cec_logical_address
GetActiveSource(bool bRequestActiveSource
= true);
89 bool IsActiveSource(cec_logical_address iAddress
);
90 bool CECInitialised(void);
92 bool StandbyDevices(const cec_logical_address initiator
, const CECDEVICEVEC
&devices
);
93 bool StandbyDevice(const cec_logical_address initiator
, cec_logical_address address
);
94 bool PowerOnDevices(const cec_logical_address initiator
, const CECDEVICEVEC
&devices
);
95 bool PowerOnDevice(const cec_logical_address initiator
, cec_logical_address address
);
97 bool SetDeckInfo(cec_deck_info info
, bool bSendUpdate
= true);
98 bool ActivateSource(uint16_t iStreamPath
);
99 bool PollDevice(cec_logical_address iAddress
);
100 void SetStandardLineTimeout(uint8_t iTimeout
);
101 uint8_t GetStandardLineTimeout(void);
102 void SetRetryLineTimeout(uint8_t iTimeout
);
103 uint8_t GetRetryLineTimeout(void);
104 bool CanPersistConfiguration(void);
105 bool PersistConfiguration(const libcec_configuration
&configuration
);
106 void RescanActiveDevices(void);
108 bool SetLineTimeout(uint8_t iTimeout
);
110 bool Transmit(const cec_command
&data
, bool bIsReply
);
111 void TransmitAbort(cec_logical_address source
, cec_logical_address destination
, cec_opcode opcode
, cec_abort_reason reason
= CEC_ABORT_REASON_UNRECOGNIZED_OPCODE
);
113 bool StartBootloader(const char *strPort
= NULL
);
114 bool PingAdapter(void);
115 void HandlePoll(cec_logical_address initiator
, cec_logical_address destination
);
116 bool HandleReceiveFailed(cec_logical_address initiator
);
118 bool GetDeviceInformation(const char *strPort
, libcec_configuration
*config
, uint32_t iTimeoutMs
= CEC_DEFAULT_CONNECT_TIMEOUT
);
120 bool TransmitPendingActiveSourceCommands(void);
122 CCECDeviceMap
*GetDevices(void) const { return m_busDevices
; }
123 CLibCEC
*GetLib(void) const { return m_libcec
; }
125 bool IsHandledByLibCEC(const cec_logical_address address
) const;
127 bool TryLogicalAddress(cec_logical_address address
, cec_version libCECSpecVersion
= CEC_VERSION_1_4
);
129 bool IsRunningLatestFirmware(void);
130 void SwitchMonitoring(bool bSwitchTo
);
133 bool OpenConnection(const char *strPort
, uint16_t iBaudRate
, uint32_t iTimeoutMs
, bool bStartListening
= true);
134 void SetCECInitialised(bool bSetTo
= true);
136 void ReplaceHandlers(void);
137 bool PhysicalAddressInUse(uint16_t iPhysicalAddress
);
139 bool ClearLogicalAddresses(void);
140 bool SetLogicalAddresses(const cec_logical_addresses
&addresses
);
142 void LogOutput(const cec_command
&data
);
143 void ProcessCommand(const cec_command
&command
);
145 void ResetMembers(void);
148 PLATFORM::CMutex m_mutex
;
149 IAdapterCommunication
* m_communication
;
151 uint8_t m_iStandardLineTimeout
;
152 uint8_t m_iRetryLineTimeout
;
153 uint64_t m_iLastTransmission
;
154 CCECInputBuffer m_inBuffer
;
155 CCECDeviceMap
* m_busDevices
;
156 std::map
<cec_logical_address
, CCECClient
*> m_clients
;