3 * This file is part of the libCEC(R) library.
5 * libCEC(R) is Copyright (C) 2011-2013 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/
35 #include "platform/threads/mutex.h"
36 #include "platform/util/buffer.h"
42 class CCECPlaybackDevice
;
46 friend class CCECProcessor
;
49 CCECClient(CCECProcessor
*processor
, const libcec_configuration
&configuration
);
50 virtual ~CCECClient(void);
53 * @return True when initialised and registered, false otherwise.
55 virtual bool IsInitialised(void);
58 * @return True when registered in the processor, false otherwise.
60 virtual bool IsRegistered(void);
63 * @return The primary logical address that this client is controlling.
65 virtual cec_logical_address
GetPrimaryLogicalAdddress(void);
68 * @return The primary device that this client is controlling, or NULL if none.
70 virtual CCECBusDevice
*GetPrimaryDevice(void);
73 * @return Get the playback device or recording device that this client is controlling, or NULL if none.
75 virtual CCECPlaybackDevice
*GetPlaybackDevice(void);
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.
83 virtual bool ChangeDeviceType(const cec_device_type from
, const cec_device_type to
);
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.
90 virtual CCECBusDevice
*GetDeviceByType(const cec_device_type type
) const;
93 * @brief Reset the physical address from the configuration.
95 virtual void ResetPhysicalAddress(void);
98 * @return A string that describes this client.
100 virtual std::string
GetConnectionInfo(void);
103 * @return The current value of the TV vendor override setting.
105 virtual cec_vendor_id
GetTVVendorOverride(void);
108 * @return The current value of the OSD name setting.
110 virtual std::string
GetOSDName(void);
113 * @return Get the current value of the wake device setting.
115 virtual cec_logical_addresses
GetWakeDevices(void);
118 * @return The version of this client.
120 virtual cec_client_version
GetClientVersion(void);
123 * @return The device types that this client is controlling.
125 virtual cec_device_type_list
GetDeviceTypes(void);
127 // client-specific part of ICECAdapter
128 virtual bool EnableCallbacks(void *cbParam
, ICECCallbacks
*callbacks
);
129 virtual bool PingAdapter(void);
130 virtual bool Transmit(const cec_command
&data
, bool bIsReply
);
131 virtual bool SetLogicalAddress(const cec_logical_address iLogicalAddress
);
132 virtual bool SetPhysicalAddress(const uint16_t iPhysicalAddress
);
133 virtual bool SetHDMIPort(const cec_logical_address iBaseDevice
, const uint8_t iPort
, bool bForce
= false);
134 virtual bool SendPowerOnDevices(const cec_logical_address address
= CECDEVICE_TV
);
135 virtual bool SendStandbyDevices(const cec_logical_address address
= CECDEVICE_BROADCAST
);
136 virtual bool SendSetActiveSource(const cec_device_type type
= CEC_DEVICE_TYPE_RESERVED
);
137 virtual bool SendSetDeckControlMode(const cec_deck_control_mode mode
, bool bSendUpdate
= true);
138 virtual bool SendSetDeckInfo(const cec_deck_info info
, bool bSendUpdate
= true);
139 virtual bool SendSetInactiveView(void);
140 virtual bool SendSetMenuState(const cec_menu_state state
, bool bSendUpdate
= true);
141 virtual bool SendSetOSDString(const cec_logical_address iLogicalAddress
, const cec_display_control duration
, const char *strMessage
);
142 virtual bool SwitchMonitoring(bool bEnable
);
143 virtual cec_version
GetDeviceCecVersion(const cec_logical_address iAddress
);
144 virtual bool GetDeviceMenuLanguage(const cec_logical_address iAddress
, cec_menu_language
&language
);
145 virtual uint64_t GetDeviceVendorId(const cec_logical_address iAddress
);
146 virtual cec_power_status
GetDevicePowerStatus(const cec_logical_address iAddress
);
147 virtual uint16_t GetDevicePhysicalAddress(const cec_logical_address iAddress
);
148 virtual bool PollDevice(const cec_logical_address iAddress
);
149 virtual cec_logical_addresses
GetActiveDevices(void);
150 virtual bool IsActiveDevice(const cec_logical_address iAddress
);
151 virtual bool IsActiveDeviceType(const cec_device_type type
);
152 virtual uint8_t SendVolumeUp(bool bSendRelease
= true);
153 virtual uint8_t SendVolumeDown(bool bSendRelease
= true);
154 virtual uint8_t SendMuteAudio(void);
155 virtual uint8_t AudioToggleMute(void);
156 virtual uint8_t AudioMute(void);
157 virtual uint8_t AudioUnmute(void);
158 virtual uint8_t AudioStatus(void);
159 virtual bool SendKeypress(const cec_logical_address iDestination
, const cec_user_control_code key
, bool bWait
= true);
160 virtual bool SendKeyRelease(const cec_logical_address iDestination
, bool bWait
= true);
161 virtual cec_osd_name
GetDeviceOSDName(const cec_logical_address iAddress
);
162 virtual cec_logical_address
GetActiveSource(void);
163 virtual bool IsActiveSource(const cec_logical_address iAddress
);
164 virtual bool SetStreamPath(const cec_logical_address iAddress
);
165 virtual bool SetStreamPath(const uint16_t iPhysicalAddress
);
166 virtual cec_logical_addresses
GetLogicalAddresses(void);
167 virtual void RescanActiveDevices(void);
168 virtual bool IsLibCECActiveSource(void);
171 virtual bool GetCurrentConfiguration(libcec_configuration
&configuration
);
172 virtual bool SetConfiguration(const libcec_configuration
&configuration
);
173 virtual bool CanPersistConfiguration(void);
174 virtual bool PersistConfiguration(const libcec_configuration
&configuration
);
175 virtual void SetPhysicalAddress(const libcec_configuration
&configuration
);
178 virtual void AddCommand(const cec_command
&command
);
179 virtual int MenuStateChanged(const cec_menu_state newState
);
180 virtual void Alert(const libcec_alert type
, const libcec_parameter
¶m
) { CallbackAlert(type
, param
); }
181 virtual void AddLog(const cec_log_message
&message
) { CallbackAddLog(message
); }
182 virtual void AddKey(bool bSendComboKey
= false);
183 virtual void AddKey(const cec_keypress
&key
);
184 virtual void SetCurrentButton(const cec_user_control_code iButtonCode
);
185 virtual void CheckKeypressTimeout(void);
186 virtual void SourceActivated(const cec_logical_address logicalAddress
);
187 virtual void SourceDeactivated(const cec_logical_address logicalAddress
);
191 * @brief Register this client in the processor
192 * @return True when registered, false otherwise.
194 virtual bool OnRegister(void);
197 * @brief Called by the processor when this client is unregistered
199 virtual void OnUnregister(void) { SetRegistered(false); SetInitialised(false); }
202 * @brief Set the registered state of this client.
203 * @param bSetTo The new value.
205 virtual void SetRegistered(bool bSetTo
);
208 * @brief Set the initialised state of this client.
209 * @param bSetTo The new value
211 virtual void SetInitialised(bool bSetTo
);
214 * @brief Change the TV vendor id override setting.
215 * @param id The new value.
217 virtual void SetTVVendorOverride(const cec_vendor_id id
);
220 * @brief Change the OSD name of the primary device that this client is controlling.
221 * @param strDeviceName The new value.
223 virtual void SetOSDName(const std::string
&strDeviceName
);
226 * @brief Change the value of the devices to wake.
227 * @param addresses The new value.
229 virtual void SetWakeDevices(const cec_logical_addresses
&addresses
);
232 * @brief Change the value of the client version setting.
233 * @param version The new version setting.
235 virtual void SetClientVersion(const cec_client_version version
);
238 * @brief Change the device types that this client is controlling.
239 * @param deviceTypes The new types.
240 * @return True when the client needs to be re-registered to pick up the new setting, false otherwise.
242 virtual bool SetDeviceTypes(const cec_device_type_list
&deviceTypes
);
245 * @return A pointer to the current configuration of this client.
247 virtual libcec_configuration
*GetConfiguration(void) { return &m_configuration
; }
250 * @brief Called by the processor when registering this client to allocate the logical addresses.
251 * @return True when the addresses for all types were allocated, false otherwise.
253 virtual bool AllocateLogicalAddresses(void);
256 * @brief Try to allocate a logical address for a recording device controlled by this client.
257 * @return The logical address that was allocated, or CECDEVICE_UNKNOWN if none could be allocated.
259 virtual cec_logical_address
AllocateLogicalAddressRecordingDevice(void);
262 * @brief Try to allocate a logical address for a tuner controlled by this client.
263 * @return The logical address that was allocated, or CECDEVICE_UNKNOWN if none could be allocated.
265 virtual cec_logical_address
AllocateLogicalAddressTuner(void);
268 * @brief Try to allocate a logical address for a playback device controlled by this client.
269 * @return The logical address that was allocated, or CECDEVICE_UNKNOWN if none could be allocated.
271 virtual cec_logical_address
AllocateLogicalAddressPlaybackDevice(void);
274 * @brief Try to allocate a logical address for an audiosystem controlled by this client.
275 * @return The logical address that was allocated, or CECDEVICE_UNKNOWN if none could be allocated.
277 virtual cec_logical_address
AllocateLogicalAddressAudioSystem(void);
280 * @brief Change the physical address of the devices controlled by this client.
281 * @param iPhysicalAddress The new physical address.
282 * @return True when changed, false otherwise.
284 virtual bool SetDevicePhysicalAddress(const uint16_t iPhysicalAddress
);
287 * @brief Try to autodetect the physical address.
288 * @return True when autodetected (and set in m_configuration), false otherwise.
290 virtual bool AutodetectPhysicalAddress(void);
293 * @brief Replaces all device types in m_configuration by types that are supported by the command handler of the TV
295 virtual void SetSupportedDeviceTypes(void);
297 virtual void CallbackAddCommand(const cec_command
&command
);
298 virtual void CallbackAddKey(const cec_keypress
&key
);
299 virtual void CallbackAddLog(const cec_log_message
&message
);
300 virtual void CallbackAlert(const libcec_alert type
, const libcec_parameter
¶m
);
301 virtual void CallbackConfigurationChanged(const libcec_configuration
&config
);
302 virtual int CallbackMenuStateChanged(const cec_menu_state newState
);
303 virtual void CallbackSourceActivated(bool bActivated
, const cec_logical_address logicalAddress
);
305 CCECProcessor
* m_processor
; /**< a pointer to the processor */
306 libcec_configuration m_configuration
; /**< the configuration of this client */
307 bool m_bInitialised
; /**< true when initialised, false otherwise */
308 bool m_bRegistered
; /**< true when registered in the processor, false otherwise */
309 PLATFORM::CMutex m_mutex
; /**< mutex for changes to this instance */
310 PLATFORM::CMutex m_cbMutex
; /**< mutex that is held when doing anything with callbacks */
311 cec_user_control_code m_iCurrentButton
; /**< the control code of the button that's currently held down (if any) */
312 int64_t m_buttontime
; /**< the timestamp when the button was pressed (in seconds since epoch), or 0 if none was pressed. */
313 int64_t m_iPreventForwardingPowerOffCommand
; /**< prevent forwarding standby commands until this time */
314 int64_t m_iLastKeypressTime
; /**< last time a key press was sent to the client */
315 cec_keypress m_lastKeypress
; /**< the last key press that was sent to the client */