Commit | Line | Data |
---|---|---|
cbbe90dd JB |
1 | #pragma once |
2 | /* | |
3 | * This file is part of the libCEC(R) library. | |
4 | * | |
5 | * libCEC(R) is Copyright (C) 2011-2013 Pulse-Eight Limited. All rights reserved. | |
6 | * libCEC(R) is an original work, containing original code. | |
7 | * | |
8 | * libCEC(R) is a trademark of Pulse-Eight Limited. | |
9 | * | |
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. | |
14 | * | |
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. | |
19 | * | |
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. | |
23 | * | |
24 | * | |
25 | * Alternatively, you can license this library under a commercial license, | |
26 | * please contact Pulse-Eight Licensing for more information. | |
27 | * | |
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/ | |
32 | */ | |
33 | ||
34 | #include <string> | |
35 | ||
36 | #include "platform/threads/threads.h" | |
37 | #include "platform/util/buffer.h" | |
38 | ||
39 | #include "adapter/AdapterCommunication.h" | |
40 | #include "devices/CECDeviceMap.h" | |
41 | #include "CECInputBuffer.h" | |
42 | ||
43 | namespace CEC | |
44 | { | |
45 | class CLibCEC; | |
46 | class IAdapterCommunication; | |
47 | class CCECBusDevice; | |
48 | class CCECAudioSystem; | |
49 | class CCECPlaybackDevice; | |
50 | class CCECRecordingDevice; | |
51 | class CCECTuner; | |
52 | class CCECTV; | |
53 | class CCECClient; | |
54 | class CCECProcessor; | |
55 | class CCECStandbyProtection; | |
56 | ||
57 | class CCECAllocateLogicalAddress : public PLATFORM::CThread | |
58 | { | |
59 | public: | |
60 | CCECAllocateLogicalAddress(CCECProcessor* processor, CCECClient* client); | |
61 | void* Process(void); | |
62 | ||
63 | private: | |
64 | CCECProcessor* m_processor; | |
65 | CCECClient* m_client; | |
66 | }; | |
67 | ||
68 | class CCECProcessor : public PLATFORM::CThread, public IAdapterCommunicationCallback | |
69 | { | |
70 | public: | |
71 | CCECProcessor(CLibCEC *libcec); | |
72 | virtual ~CCECProcessor(void); | |
73 | ||
74 | bool Start(const char *strPort, uint16_t iBaudRate = CEC_SERIAL_DEFAULT_BAUDRATE, uint32_t iTimeoutMs = CEC_DEFAULT_CONNECT_TIMEOUT); | |
75 | void *Process(void); | |
76 | void Close(void); | |
77 | ||
78 | bool RegisterClient(CCECClient *client); | |
79 | bool UnregisterClient(CCECClient *client); | |
80 | void UnregisterClients(void); | |
81 | uint16_t GetPhysicalAddressFromEeprom(void); | |
82 | CCECClient *GetPrimaryClient(void); | |
83 | CCECClient *GetClient(const cec_logical_address address); | |
84 | ||
85 | bool OnCommandReceived(const cec_command &command); | |
86 | void HandleLogicalAddressLost(cec_logical_address oldAddress); | |
87 | void HandlePhysicalAddressChanged(uint16_t iNewAddress); | |
88 | ||
89 | CCECBusDevice * GetDevice(cec_logical_address address) const; | |
90 | CCECAudioSystem * GetAudioSystem(void) const; | |
91 | CCECPlaybackDevice * GetPlaybackDevice(cec_logical_address address) const; | |
92 | CCECRecordingDevice * GetRecordingDevice(cec_logical_address address) const; | |
93 | CCECTuner * GetTuner(cec_logical_address address) const; | |
94 | CCECTV * GetTV(void) const; | |
95 | ||
96 | CCECBusDevice * GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress, bool bSuppressUpdate = true); | |
97 | CCECBusDevice * GetPrimaryDevice(void); | |
98 | cec_logical_address GetLogicalAddress(void); | |
99 | cec_logical_addresses GetLogicalAddresses(void); | |
100 | bool IsPresentDevice(cec_logical_address address); | |
101 | bool IsPresentDeviceType(cec_device_type type); | |
102 | uint16_t GetDetectedPhysicalAddress(void) const; | |
103 | uint64_t GetLastTransmission(void) const { return m_iLastTransmission; } | |
104 | cec_logical_address GetActiveSource(bool bRequestActiveSource = true); | |
105 | bool IsActiveSource(cec_logical_address iAddress); | |
106 | bool CECInitialised(void); | |
107 | ||
108 | bool StandbyDevices(const cec_logical_address initiator, const CECDEVICEVEC &devices); | |
109 | bool StandbyDevice(const cec_logical_address initiator, cec_logical_address address); | |
110 | bool PowerOnDevices(const cec_logical_address initiator, const CECDEVICEVEC &devices); | |
111 | bool PowerOnDevice(const cec_logical_address initiator, cec_logical_address address); | |
112 | ||
113 | bool SetDeckInfo(cec_deck_info info, bool bSendUpdate = true); | |
114 | bool ActivateSource(uint16_t iStreamPath); | |
115 | void SetActiveSource(bool bSetTo, bool bClientUnregistered); | |
116 | bool PollDevice(cec_logical_address iAddress); | |
117 | void SetStandardLineTimeout(uint8_t iTimeout); | |
118 | uint8_t GetStandardLineTimeout(void); | |
119 | void SetRetryLineTimeout(uint8_t iTimeout); | |
120 | uint8_t GetRetryLineTimeout(void); | |
121 | bool CanPersistConfiguration(void); | |
122 | bool PersistConfiguration(const libcec_configuration &configuration); | |
123 | void RescanActiveDevices(void); | |
124 | ||
125 | bool SetLineTimeout(uint8_t iTimeout); | |
126 | ||
127 | bool Transmit(const cec_command &data, bool bIsReply); | |
128 | void TransmitAbort(cec_logical_address source, cec_logical_address destination, cec_opcode opcode, cec_abort_reason reason = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE); | |
129 | ||
130 | bool StartBootloader(const char *strPort = NULL); | |
131 | bool PingAdapter(void); | |
132 | void HandlePoll(cec_logical_address initiator, cec_logical_address destination); | |
133 | bool HandleReceiveFailed(cec_logical_address initiator); | |
134 | ||
135 | bool GetDeviceInformation(const char *strPort, libcec_configuration *config, uint32_t iTimeoutMs = CEC_DEFAULT_CONNECT_TIMEOUT); | |
136 | ||
137 | bool TransmitPendingActiveSourceCommands(void); | |
138 | ||
139 | CCECDeviceMap *GetDevices(void) const { return m_busDevices; } | |
140 | CLibCEC *GetLib(void) const { return m_libcec; } | |
141 | ||
142 | bool IsHandledByLibCEC(const cec_logical_address address) const; | |
143 | ||
144 | bool TryLogicalAddress(cec_logical_address address, cec_version libCECSpecVersion = CEC_VERSION_1_4); | |
145 | ||
146 | bool IsRunningLatestFirmware(void); | |
147 | void SwitchMonitoring(bool bSwitchTo); | |
148 | ||
149 | bool AllocateLogicalAddresses(CCECClient* client); | |
150 | ||
151 | uint16_t GetAdapterVendorId(void) const; | |
152 | uint16_t GetAdapterProductId(void) const; | |
153 | private: | |
154 | bool OpenConnection(const char *strPort, uint16_t iBaudRate, uint32_t iTimeoutMs, bool bStartListening = true); | |
155 | void SetCECInitialised(bool bSetTo = true); | |
156 | ||
157 | void ReplaceHandlers(void); | |
158 | bool PhysicalAddressInUse(uint16_t iPhysicalAddress); | |
159 | ||
160 | bool ClearLogicalAddresses(void); | |
161 | bool SetLogicalAddresses(const cec_logical_addresses &addresses); | |
162 | ||
163 | void LogOutput(const cec_command &data); | |
164 | void ProcessCommand(const cec_command &command); | |
165 | ||
166 | void ResetMembers(void); | |
167 | ||
168 | bool m_bInitialised; | |
169 | PLATFORM::CMutex m_mutex; | |
170 | IAdapterCommunication * m_communication; | |
171 | CLibCEC* m_libcec; | |
172 | uint8_t m_iStandardLineTimeout; | |
173 | uint8_t m_iRetryLineTimeout; | |
174 | uint64_t m_iLastTransmission; | |
175 | CCECInputBuffer m_inBuffer; | |
176 | CCECDeviceMap * m_busDevices; | |
177 | std::map<cec_logical_address, CCECClient *> m_clients; | |
178 | bool m_bMonitor; | |
179 | CCECAllocateLogicalAddress* m_addrAllocator; | |
180 | bool m_bStallCommunication; | |
181 | CCECStandbyProtection* m_connCheck; | |
182 | }; | |
183 | ||
184 | class CCECStandbyProtection : public PLATFORM::CThread | |
185 | { | |
186 | public: | |
187 | CCECStandbyProtection(CCECProcessor* processor); | |
188 | virtual ~CCECStandbyProtection(void); | |
189 | void* Process(void); | |
190 | ||
191 | private: | |
192 | CCECProcessor* m_processor; | |
193 | }; | |
194 | }; |