Commit | Line | Data |
---|---|---|
e9de9629 LOK |
1 | #pragma once |
2 | /* | |
3 | * This file is part of the libCEC(R) library. | |
4 | * | |
16f47961 | 5 | * libCEC(R) is Copyright (C) 2011-2013 Pulse-Eight Limited. All rights reserved. |
e9de9629 LOK |
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 | ||
4d738fe3 | 34 | #include <set> |
060a7b5e | 35 | #include <map> |
2b44051c LOK |
36 | #include "lib/platform/threads/mutex.h" |
37 | #include "lib/platform/util/StdString.h" | |
e9de9629 LOK |
38 | |
39 | namespace CEC | |
40 | { | |
004b8382 | 41 | class CCECClient; |
e9de9629 | 42 | class CCECProcessor; |
1b5cc4a2 | 43 | class CCECCommandHandler; |
004b8382 LOK |
44 | class CCECAudioSystem; |
45 | class CCECPlaybackDevice; | |
46 | class CCECRecordingDevice; | |
47 | class CCECTuner; | |
48 | class CCECTV; | |
e9de9629 | 49 | |
060a7b5e LOK |
50 | class CResponse |
51 | { | |
52 | public: | |
2ee922ad LOK |
53 | CResponse(cec_opcode opcode); |
54 | ~CResponse(void); | |
060a7b5e | 55 | |
2ee922ad LOK |
56 | bool Wait(uint32_t iTimeout); |
57 | void Broadcast(void); | |
060a7b5e LOK |
58 | |
59 | private: | |
60 | cec_opcode m_opcode; | |
61 | PLATFORM::CEvent m_event; | |
62 | }; | |
63 | ||
64 | class CWaitForResponse | |
65 | { | |
66 | public: | |
2ee922ad LOK |
67 | CWaitForResponse(void); |
68 | ~CWaitForResponse(void); | |
060a7b5e | 69 | |
2ee922ad LOK |
70 | void Clear(); |
71 | bool Wait(cec_opcode opcode, uint32_t iTimeout = CEC_DEFAULT_TRANSMIT_WAIT); | |
72 | void Received(cec_opcode opcode); | |
060a7b5e LOK |
73 | |
74 | private: | |
2ee922ad | 75 | CResponse *GetEvent(cec_opcode opcode); |
060a7b5e LOK |
76 | |
77 | PLATFORM::CMutex m_mutex; | |
78 | std::map<cec_opcode, CResponse*> m_waitingFor; | |
79 | }; | |
80 | ||
e9de9629 LOK |
81 | class CCECBusDevice |
82 | { | |
787a3cb8 LOK |
83 | friend class CCECProcessor; |
84 | ||
e9de9629 | 85 | public: |
d2d1660c | 86 | CCECBusDevice(CCECProcessor *processor, cec_logical_address address, uint16_t iPhysicalAddress = CEC_INVALID_PHYSICAL_ADDRESS); |
e9de9629 LOK |
87 | virtual ~CCECBusDevice(void); |
88 | ||
004b8382 | 89 | virtual bool ReplaceHandler(bool bActivateSource = true); |
91ef4e2d LOK |
90 | |
91 | // TODO use something smarter than this | |
92 | /*! | |
93 | * @brief Get the command handler for this device. Call MarkHandlerReady() when done with it. | |
94 | * @return The current handler. | |
95 | */ | |
96 | virtual CCECCommandHandler * GetHandler(void); | |
97 | ||
98 | /*! | |
99 | * @brief To be called after GetHandler(), when no longer using it. | |
100 | */ | |
101 | virtual void MarkHandlerReady(void) { MarkReady(); } | |
102 | ||
004b8382 LOK |
103 | virtual CCECProcessor * GetProcessor(void) const { return m_processor; } |
104 | virtual uint64_t GetLastActive(void) const { return m_iLastActive; } | |
105 | virtual cec_device_type GetType(void) const { return m_type; } | |
f8ae3295 LOK |
106 | virtual cec_logical_address GetLogicalAddress(void) const { return m_iLogicalAddress; } |
107 | virtual const char* GetLogicalAddressName(void) const; | |
004b8382 LOK |
108 | virtual bool IsPresent(void); |
109 | virtual bool IsHandledByLibCEC(void); | |
110 | ||
111 | virtual bool HandleCommand(const cec_command &command); | |
33dd87a9 | 112 | virtual bool IsUnsupportedFeature(cec_opcode opcode); |
4d738fe3 | 113 | virtual void SetUnsupportedFeature(cec_opcode opcode); |
004b8382 LOK |
114 | |
115 | virtual bool TransmitKeypress(const cec_logical_address initiator, cec_user_control_code key, bool bWait = true); | |
116 | virtual bool TransmitKeyRelease(const cec_logical_address initiator, bool bWait = true); | |
117 | ||
118 | virtual cec_version GetCecVersion(const cec_logical_address initiator, bool bUpdate = false); | |
119 | virtual void SetCecVersion(const cec_version newVersion); | |
120 | virtual bool RequestCecVersion(const cec_logical_address initiator, bool bWaitForResponse = true); | |
2b44051c | 121 | virtual bool TransmitCECVersion(const cec_logical_address destination, bool bIsReply); |
004b8382 LOK |
122 | |
123 | virtual cec_menu_language & GetMenuLanguage(const cec_logical_address initiator, bool bUpdate = false); | |
124 | virtual void SetMenuLanguage(const char *strLanguage); | |
125 | virtual void SetMenuLanguage(const cec_menu_language &menuLanguage); | |
126 | virtual bool RequestMenuLanguage(const cec_logical_address initiator, bool bWaitForResponse = true); | |
2b44051c | 127 | virtual bool TransmitSetMenuLanguage(const cec_logical_address destination, bool bIsReply); |
004b8382 | 128 | |
2b44051c | 129 | virtual bool TransmitOSDString(const cec_logical_address destination, cec_display_control duration, const char *strMessage, bool bIsReply); |
004b8382 | 130 | |
c0152c09 | 131 | virtual CStdString GetCurrentOSDName(void); |
004b8382 LOK |
132 | virtual CStdString GetOSDName(const cec_logical_address initiator, bool bUpdate = false); |
133 | virtual void SetOSDName(CStdString strName); | |
134 | virtual bool RequestOSDName(const cec_logical_address source, bool bWaitForResponse = true); | |
2b44051c | 135 | virtual bool TransmitOSDName(const cec_logical_address destination, bool bIsReply); |
004b8382 LOK |
136 | |
137 | virtual uint16_t GetCurrentPhysicalAddress(void); | |
138 | virtual bool HasValidPhysicalAddress(void); | |
139 | virtual uint16_t GetPhysicalAddress(const cec_logical_address initiator, bool bSuppressUpdate = false); | |
140 | virtual bool SetPhysicalAddress(uint16_t iNewAddress); | |
141 | virtual bool RequestPhysicalAddress(const cec_logical_address initiator, bool bWaitForResponse = true); | |
2b44051c | 142 | virtual bool TransmitPhysicalAddress(bool bIsReply); |
004b8382 LOK |
143 | |
144 | virtual cec_power_status GetCurrentPowerStatus(void); | |
145 | virtual cec_power_status GetPowerStatus(const cec_logical_address initiator, bool bUpdate = false); | |
146 | virtual void SetPowerStatus(const cec_power_status powerStatus); | |
14f56268 LOK |
147 | virtual void OnImageViewOnSent(bool bSentByLibCEC); |
148 | virtual bool ImageViewOnSent(void); | |
d9de2aae | 149 | virtual bool RequestPowerStatus(const cec_logical_address initiator, bool bUpdate, bool bWaitForResponse = true); |
2b44051c | 150 | virtual bool TransmitPowerState(const cec_logical_address destination, bool bIsReply); |
004b8382 LOK |
151 | |
152 | virtual cec_vendor_id GetCurrentVendorId(void); | |
153 | virtual cec_vendor_id GetVendorId(const cec_logical_address initiator, bool bUpdate = false); | |
154 | virtual const char * GetVendorName(const cec_logical_address initiator, bool bUpdate = false); | |
155 | virtual bool SetVendorId(uint64_t iVendorId); | |
156 | virtual bool RequestVendorId(const cec_logical_address initiator, bool bWaitForResponse = true); | |
2b44051c | 157 | virtual bool TransmitVendorID(const cec_logical_address destination, bool bSendAbort, bool bIsReply); |
004b8382 LOK |
158 | |
159 | virtual cec_bus_device_status GetCurrentStatus(void) { return GetStatus(false, true); } | |
160 | virtual cec_bus_device_status GetStatus(bool bForcePoll = false, bool bSuppressPoll = false); | |
2b44051c | 161 | virtual void SetDeviceStatus(const cec_bus_device_status newStatus, cec_version libCECSpecVersion = CEC_VERSION_1_4); |
a582c2bb | 162 | virtual void ResetDeviceStatus(bool bClientUnregistered = false); |
be3b6983 | 163 | virtual bool TransmitPoll(const cec_logical_address destination, bool bUpdateDeviceStatus); |
004b8382 LOK |
164 | virtual void HandlePoll(const cec_logical_address destination); |
165 | virtual void HandlePollFrom(const cec_logical_address initiator); | |
0cfdeb5a | 166 | virtual bool HandleReceiveFailed(void); |
e9de9629 | 167 | |
004b8382 LOK |
168 | virtual cec_menu_state GetMenuState(const cec_logical_address initiator); |
169 | virtual void SetMenuState(const cec_menu_state state); | |
2b44051c | 170 | virtual bool TransmitMenuState(const cec_logical_address destination, bool bIsReply); |
004b8382 | 171 | |
060a7b5e | 172 | virtual bool ActivateSource(uint64_t iDelay = 0); |
004b8382 LOK |
173 | virtual bool IsActiveSource(void) const { return m_bActiveSource; } |
174 | virtual bool RequestActiveSource(bool bWaitForResponse = true); | |
175 | virtual void MarkAsActiveSource(void); | |
a582c2bb | 176 | virtual void MarkAsInactiveSource(bool bClientUnregistered = false); |
2b44051c | 177 | virtual bool TransmitActiveSource(bool bIsReply); |
004b8382 LOK |
178 | virtual bool TransmitImageViewOn(void); |
179 | virtual bool TransmitInactiveSource(void); | |
180 | virtual bool TransmitPendingActiveSourceCommands(void); | |
844eab4e | 181 | virtual void SetActiveRoute(uint16_t iRoute); |
004b8382 LOK |
182 | virtual void SetStreamPath(uint16_t iNewAddress, uint16_t iOldAddress = CEC_INVALID_PHYSICAL_ADDRESS); |
183 | ||
184 | virtual bool PowerOn(const cec_logical_address initiator); | |
185 | virtual bool Standby(const cec_logical_address initiator); | |
186 | ||
2b44051c | 187 | virtual bool TryLogicalAddress(cec_version libCECSpecVersion = CEC_VERSION_1_4); |
004b8382 LOK |
188 | |
189 | CCECClient * GetClient(void); | |
060a7b5e LOK |
190 | void SignalOpcode(cec_opcode opcode); |
191 | bool WaitForOpcode(cec_opcode opcode); | |
004b8382 LOK |
192 | |
193 | CCECAudioSystem * AsAudioSystem(void); | |
194 | static CCECAudioSystem * AsAudioSystem(CCECBusDevice *device); | |
195 | CCECPlaybackDevice * AsPlaybackDevice(void); | |
196 | static CCECPlaybackDevice * AsPlaybackDevice(CCECBusDevice *device); | |
197 | CCECRecordingDevice * AsRecordingDevice(void); | |
198 | static CCECRecordingDevice * AsRecordingDevice(CCECBusDevice *device); | |
199 | CCECTuner * AsTuner(void); | |
200 | static CCECTuner * AsTuner(CCECBusDevice *device); | |
201 | CCECTV * AsTV(void); | |
202 | static CCECTV * AsTV(CCECBusDevice *device); | |
5734016c | 203 | |
e9de9629 | 204 | protected: |
004b8382 | 205 | void CheckVendorIdRequested(const cec_logical_address source); |
1344fd1a LOK |
206 | void MarkBusy(void); |
207 | void MarkReady(void); | |
b64db02e | 208 | |
9fd73dd4 LOK |
209 | bool NeedsPoll(void); |
210 | ||
f8ae3295 LOK |
211 | cec_device_type m_type; |
212 | CStdString m_strDeviceName; | |
213 | uint16_t m_iPhysicalAddress; | |
214 | uint16_t m_iStreamPath; | |
215 | cec_logical_address m_iLogicalAddress; | |
216 | cec_power_status m_powerStatus; | |
217 | cec_menu_language m_menuLanguage; | |
218 | CCECProcessor * m_processor; | |
219 | CCECCommandHandler * m_handler; | |
220 | cec_vendor_id m_vendor; | |
b64db02e | 221 | bool m_bReplaceHandler; |
f8ae3295 LOK |
222 | cec_menu_state m_menuState; |
223 | bool m_bActiveSource; | |
045b2e29 LOK |
224 | int64_t m_iLastActive; |
225 | int64_t m_iLastPowerStateUpdate; | |
f8ae3295 LOK |
226 | cec_version m_cecVersion; |
227 | cec_bus_device_status m_deviceStatus; | |
4d738fe3 | 228 | std::set<cec_opcode> m_unsupportedFeatures; |
f00ff009 LOK |
229 | PLATFORM::CMutex m_mutex; |
230 | PLATFORM::CMutex m_handlerMutex; | |
67b9d205 | 231 | PLATFORM::CEvent m_replacing; |
1344fd1a | 232 | unsigned m_iHandlerUseCount; |
ef583662 | 233 | bool m_bAwaitingReceiveFailed; |
ebb6ddb3 | 234 | bool m_bVendorIdRequested; |
060a7b5e | 235 | CWaitForResponse *m_waitForResponse; |
14f56268 | 236 | bool m_bImageViewOnSent; |
e9de9629 LOK |
237 | }; |
238 | }; |