cec: fixed - delayed source switch time was reset, resulting in an attempt every...
[deb_libcec.git] / src / lib / CECClient.h
CommitLineData
004b8382
LOK
1#pragma once
2/*
3 * This file is part of the libCEC(R) library.
4 *
5 * libCEC(R) is Copyright (C) 2011-2012 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
2b44051c 34#include <string>
004b8382
LOK
35#include "platform/threads/mutex.h"
36#include "platform/util/buffer.h"
37
004b8382
LOK
38namespace CEC
39{
40 class CCECProcessor;
2b44051c
LOK
41 class CCECBusDevice;
42 class CCECPlaybackDevice;
004b8382
LOK
43
44 class CCECClient
45 {
679dfa07
LOK
46 friend class CCECProcessor;
47
004b8382 48 public:
c0152c09 49 CCECClient(CCECProcessor *processor, const libcec_configuration &configuration);
004b8382
LOK
50 virtual ~CCECClient(void);
51
679dfa07
LOK
52 /*!
53 * @return True when initialised and registered, false otherwise.
54 */
55 virtual bool IsInitialised(void);
56
57 /*!
58 * @return True when registered in the processor, false otherwise.
59 */
60 virtual bool IsRegistered(void);
61
62 /*!
63 * @return The primary logical address that this client is controlling.
64 */
65 virtual cec_logical_address GetPrimaryLogicalAdddress(void);
66
67 /*!
68 * @return The primary device that this client is controlling, or NULL if none.
69 */
70 virtual CCECBusDevice *GetPrimaryDevice(void);
71
72 /*!
73 * @return Get the playback device or recording device that this client is controlling, or NULL if none.
74 */
75 virtual CCECPlaybackDevice *GetPlaybackDevice(void);
76
77 /*!
78 * @brief Change one of the device types that this client is controlling into another.
79 * @param from The type to change.
80 * @param to The new value.
81 * @return True when changed, false otherwise.
82 */
83 virtual bool ChangeDeviceType(const cec_device_type from, const cec_device_type to);
84
85 /*!
86 * @brief Get a device that this client is controlling, given it's type.
87 * @param type The type of the device to get.
88 * @return The requested device, or NULL if not found.
89 */
90 virtual CCECBusDevice *GetDeviceByType(const cec_device_type type) const;
91
92 /*!
93 * @brief Reset the physical address from the configuration.
94 */
95 virtual void ResetPhysicalAddress(void);
96
97 /*!
98 * @return A string that describes this client.
99 */
2b44051c 100 virtual std::string GetConnectionInfo(void);
679dfa07
LOK
101
102 /*!
103 * @return The current value of the TV vendor override setting.
104 */
105 virtual cec_vendor_id GetTVVendorOverride(void);
106
107 /*!
108 * @return The current value of the OSD name setting.
109 */
2b44051c 110 virtual std::string GetOSDName(void);
679dfa07
LOK
111
112 /*!
113 * @return Get the current value of the wake device setting.
114 */
115 virtual cec_logical_addresses GetWakeDevices(void);
116
117 /*!
118 * @return The version of this client.
119 */
120 virtual cec_client_version GetClientVersion(void);
121
122 /*!
123 * @return The device types that this client is controlling.
124 */
125 virtual cec_device_type_list GetDeviceTypes(void);
004b8382
LOK
126
127 // client-specific part of ICECAdapter
679dfa07
LOK
128 virtual bool EnableCallbacks(void *cbParam, ICECCallbacks *callbacks);
129 virtual bool PingAdapter(void);
130 virtual bool GetNextLogMessage(cec_log_message *message); /**< @deprecated will be removed in v2.0 */
131 virtual bool GetNextKeypress(cec_keypress *key); /**< @deprecated will be removed in v2.0 */
132 virtual bool GetNextCommand(cec_command *command); /**< @deprecated will be removed in v2.0 */
2b44051c 133 virtual bool Transmit(const cec_command &data, bool bIsReply);
679dfa07
LOK
134 virtual bool SetLogicalAddress(const cec_logical_address iLogicalAddress);
135 virtual bool SetPhysicalAddress(const uint16_t iPhysicalAddress);
136 virtual bool SetHDMIPort(const cec_logical_address iBaseDevice, const uint8_t iPort, bool bForce = false);
137 virtual bool SendPowerOnDevices(const cec_logical_address address = CECDEVICE_TV);
138 virtual bool SendStandbyDevices(const cec_logical_address address = CECDEVICE_BROADCAST);
139 virtual bool SendSetActiveSource(const cec_device_type type = CEC_DEVICE_TYPE_RESERVED);
140 virtual bool SendSetDeckControlMode(const cec_deck_control_mode mode, bool bSendUpdate = true);
141 virtual bool SendSetDeckInfo(const cec_deck_info info, bool bSendUpdate = true);
142 virtual bool SendSetInactiveView(void);
143 virtual bool SendSetMenuState(const cec_menu_state state, bool bSendUpdate = true);
144 virtual bool SendSetOSDString(const cec_logical_address iLogicalAddress, const cec_display_control duration, const char *strMessage);
145 virtual bool SwitchMonitoring(bool bEnable);
146 virtual cec_version GetDeviceCecVersion(const cec_logical_address iAddress);
147 virtual bool GetDeviceMenuLanguage(const cec_logical_address iAddress, cec_menu_language &language);
148 virtual uint64_t GetDeviceVendorId(const cec_logical_address iAddress);
149 virtual cec_power_status GetDevicePowerStatus(const cec_logical_address iAddress);
150 virtual uint16_t GetDevicePhysicalAddress(const cec_logical_address iAddress);
151 virtual bool PollDevice(const cec_logical_address iAddress);
152 virtual cec_logical_addresses GetActiveDevices(void);
153 virtual bool IsActiveDevice(const cec_logical_address iAddress);
154 virtual bool IsActiveDeviceType(const cec_device_type type);
155 virtual uint8_t SendVolumeUp(bool bSendRelease = true);
156 virtual uint8_t SendVolumeDown(bool bSendRelease = true);
157 virtual uint8_t SendMuteAudio(void);
158 virtual bool SendKeypress(const cec_logical_address iDestination, const cec_user_control_code key, bool bWait = true);
159 virtual bool SendKeyRelease(const cec_logical_address iDestination, bool bWait = true);
160 virtual cec_osd_name GetDeviceOSDName(const cec_logical_address iAddress);
161 virtual cec_logical_address GetActiveSource(void);
162 virtual bool IsActiveSource(const cec_logical_address iAddress);
163 virtual bool SetStreamPath(const cec_logical_address iAddress);
164 virtual bool SetStreamPath(const uint16_t iPhysicalAddress);
165 virtual cec_logical_addresses GetLogicalAddresses(void);
166 virtual void RescanActiveDevices(void);
167 virtual bool IsLibCECActiveSource(void);
004b8382
LOK
168
169 // configuration
679dfa07
LOK
170 virtual bool GetCurrentConfiguration(libcec_configuration &configuration);
171 virtual bool SetConfiguration(const libcec_configuration &configuration);
172 virtual bool CanPersistConfiguration(void);
173 virtual bool PersistConfiguration(const libcec_configuration &configuration);
174 virtual void SetPhysicalAddress(const libcec_configuration &configuration);
004b8382
LOK
175
176 // callbacks
679dfa07
LOK
177 virtual void AddCommand(const cec_command &command);
178 virtual int MenuStateChanged(const cec_menu_state newState);
2b44051c
LOK
179 virtual void Alert(const libcec_alert type, const libcec_parameter &param) { CallbackAlert(type, param); }
180 virtual void AddLog(const cec_log_message &message) { CallbackAddLog(message); }
679dfa07
LOK
181 virtual void AddKey(void);
182 virtual void AddKey(const cec_keypress &key);
183 virtual void SetCurrentButton(const cec_user_control_code iButtonCode);
184 virtual void CheckKeypressTimeout(void);
29d5198c
LOK
185 virtual void SourceActivated(const cec_logical_address logicalAddress);
186 virtual void SourceDeactivated(const cec_logical_address logicalAddress);
004b8382
LOK
187
188 protected:
679dfa07
LOK
189 /*!
190 * @brief Register this client in the processor
191 * @return True when registered, false otherwise.
192 */
193 virtual bool OnRegister(void);
194
195 /*!
196 * @brief Called by the processor when this client is unregistered
197 */
198 virtual void OnUnregister(void) { SetRegistered(false); SetInitialised(false); }
199
200 /*!
201 * @brief Set the registered state of this client.
202 * @param bSetTo The new value.
203 */
204 virtual void SetRegistered(bool bSetTo);
205
206 /*!
207 * @brief Set the initialised state of this client.
208 * @param bSetTo The new value
209 */
210 virtual void SetInitialised(bool bSetTo);
211
212 /*!
213 * @brief Change the TV vendor id override setting.
214 * @param id The new value.
215 */
216 virtual void SetTVVendorOverride(const cec_vendor_id id);
217
218 /*!
219 * @brief Change the OSD name of the primary device that this client is controlling.
220 * @param strDeviceName The new value.
221 */
2b44051c 222 virtual void SetOSDName(const std::string &strDeviceName);
679dfa07
LOK
223
224 /*!
225 * @brief Change the value of the devices to wake.
226 * @param addresses The new value.
227 */
228 virtual void SetWakeDevices(const cec_logical_addresses &addresses);
229
230 /*!
231 * @brief Change the value of the client version setting.
232 * @param version The new version setting.
233 */
234 virtual void SetClientVersion(const cec_client_version version);
235
236 /*!
237 * @brief Change the device types that this client is controlling.
238 * @param deviceTypes The new types.
239 * @return True when the client needs to be re-registered to pick up the new setting, false otherwise.
240 */
241 virtual bool SetDeviceTypes(const cec_device_type_list &deviceTypes);
242
243 /*!
244 * @return A pointer to the current configuration of this client.
245 */
246 virtual libcec_configuration *GetConfiguration(void) { return &m_configuration; }
247
248 /*!
249 * @brief Called by the processor when registering this client to allocate the logical addresses.
250 * @return True when the addresses for all types were allocated, false otherwise.
251 */
252 virtual bool AllocateLogicalAddresses(void);
253
254 /*!
255 * @brief Try to allocate a logical address for a recording device controlled by this client.
256 * @return The logical address that was allocated, or CECDEVICE_UNKNOWN if none could be allocated.
257 */
258 virtual cec_logical_address AllocateLogicalAddressRecordingDevice(void);
259
260 /*!
261 * @brief Try to allocate a logical address for a tuner controlled by this client.
262 * @return The logical address that was allocated, or CECDEVICE_UNKNOWN if none could be allocated.
263 */
264 virtual cec_logical_address AllocateLogicalAddressTuner(void);
265
266 /*!
267 * @brief Try to allocate a logical address for a playback device controlled by this client.
268 * @return The logical address that was allocated, or CECDEVICE_UNKNOWN if none could be allocated.
269 */
270 virtual cec_logical_address AllocateLogicalAddressPlaybackDevice(void);
271
272 /*!
273 * @brief Try to allocate a logical address for an audiosystem controlled by this client.
274 * @return The logical address that was allocated, or CECDEVICE_UNKNOWN if none could be allocated.
275 */
276 virtual cec_logical_address AllocateLogicalAddressAudioSystem(void);
277
278 /*!
279 * @brief Change the physical address of the devices controlled by this client.
280 * @param iPhysicalAddress The new physical address.
281 * @return True when changed, false otherwise.
282 */
283 virtual bool SetDevicePhysicalAddress(const uint16_t iPhysicalAddress);
284
679dfa07
LOK
285 /*!
286 * @brief Try to autodetect the physical address.
287 * @return True when autodetected (and set in m_configuration), false otherwise.
288 */
289 virtual bool AutodetectPhysicalAddress(void);
290
42d28d15
LOK
291 /*!
292 * @brief Replaces all device types in m_configuration by types that are supported by the command handler of the TV
293 */
294 virtual void SetSupportedDeviceTypes(void);
295
2b44051c
LOK
296 virtual void CallbackAddCommand(const cec_command &command);
297 virtual void CallbackAddKey(const cec_keypress &key);
298 virtual void CallbackAddLog(const cec_log_message &message);
299 virtual void CallbackAlert(const libcec_alert type, const libcec_parameter &param);
300 virtual void CallbackConfigurationChanged(const libcec_configuration &config);
301 virtual int CallbackMenuStateChanged(const cec_menu_state newState);
302 virtual void CallbackSourceActivated(bool bActivated, const cec_logical_address logicalAddress);
303
679dfa07
LOK
304 CCECProcessor * m_processor; /**< a pointer to the processor */
305 libcec_configuration m_configuration; /**< the configuration of this client */
306 bool m_bInitialised; /**< true when initialised, false otherwise */
307 bool m_bRegistered; /**< true when registered in the processor, false otherwise */
308 PLATFORM::CMutex m_mutex; /**< mutex for changes to this instance */
2b44051c 309 PLATFORM::CMutex m_cbMutex; /**< mutex that is held when doing anything with callbacks */
679dfa07
LOK
310 cec_user_control_code m_iCurrentButton; /**< the control code of the button that's currently held down (if any) */
311 int64_t m_buttontime; /**< the timestamp when the button was pressed (in seconds since epoch), or 0 if none was pressed. */
55c18d43 312 int64_t m_iPreventForwardingPowerOffCommand; /**< prevent forwarding standby commands until this time */
679dfa07
LOK
313 PLATFORM::SyncedBuffer<cec_log_message> m_logBuffer; /**< @deprecated will be removed in v2.0. buffer for log messages */
314 PLATFORM::SyncedBuffer<cec_keypress> m_keyBuffer; /**< @deprecated will be removed in v2.0. buffer for keypresses */
315 PLATFORM::SyncedBuffer<cec_command> m_commandBuffer; /**< @deprecated will be removed in v2.0. buffer for commands */
004b8382
LOK
316 };
317}