Added another id for vendor Harman/Kardon (0x001950)
[deb_libcec.git] / src / lib / adapter / AdapterCommunication.h
CommitLineData
abbca718
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.
abbca718
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
2b44051c 34#include <string>
ef7696f5 35
abbca718
LOK
36namespace CEC
37{
004b8382
LOK
38 class CLibCEC;
39
2b44051c
LOK
40 typedef enum cec_adapter_message_state
41 {
42 ADAPTER_MESSAGE_STATE_UNKNOWN = 0, /**< the initial state */
43 ADAPTER_MESSAGE_STATE_WAITING_TO_BE_SENT, /**< waiting in the send queue of the adapter, or timed out */
44 ADAPTER_MESSAGE_STATE_SENT, /**< sent and waiting on an ACK */
45 ADAPTER_MESSAGE_STATE_SENT_NOT_ACKED, /**< sent, but failed to ACK */
46 ADAPTER_MESSAGE_STATE_SENT_ACKED, /**< sent, and ACK received */
47 ADAPTER_MESSAGE_STATE_INCOMING, /**< received from another device */
48 ADAPTER_MESSAGE_STATE_ERROR /**< an error occured */
49 } cec_adapter_message_state;
50
9ceaabcd 51 class IAdapterCommunicationCallback
b1f94db1
LOK
52 {
53 public:
9ceaabcd
LOK
54 IAdapterCommunicationCallback(void) {}
55 virtual ~IAdapterCommunicationCallback(void) {}
56
b1f94db1
LOK
57 /*!
58 * @brief Callback method for IAdapterCommunication, called when a new cec_command is received
59 * @param command The command that has been received
60 * @return True when it was handled by this listener, false otherwise.
61 */
62 virtual bool OnCommandReceived(const cec_command &command) = 0;
a75e3a5a
LOK
63
64 /*!
65 * @brief Callback method for IAdapterCommunication, called when a poll was received.
66 * @param initiator The initiator that sent the poll.
67 * @param destination The destination of the poll message.
68 */
69 virtual void HandlePoll(cec_logical_address initiator, cec_logical_address destination) = 0;
70
71 /*!
72 * @brief Callback method for IAdapterCommunication, called when a receive failed message was received.
73 * @param initiator The initiator that sent the receive failed message.
74 * @return True when this is an error, false otherwise.
75 */
76 virtual bool HandleReceiveFailed(cec_logical_address initiator) = 0;
004b8382 77
9768d061
LOK
78 /*!
79 * @brief Callback method for IAdapterCommunication, called when a logical address that libCEC uses was taken by another device.
f60ee8b3 80 * @param oldAddress The logical address that was taken by another device.
9768d061 81 */
171c7eb0 82 virtual void HandleLogicalAddressLost(cec_logical_address oldAddress) = 0;
9768d061 83
49ba42d4
LOK
84 /*!
85 * @brief Callback method for IAdapterCommunication, called when the physical address changed.
86 * @param iNewAddress The new physical address.
87 */
88 virtual void HandlePhysicalAddressChanged(uint16_t iNewAddress) = 0;
89
004b8382 90 virtual CLibCEC *GetLib(void) const = 0;
b1f94db1
LOK
91 };
92
9ceaabcd 93 class IAdapterCommunication
abbca718
LOK
94 {
95 public:
a75e3a5a
LOK
96 /*!
97 * @param callback The callback struct. if set to NULL, the Read() method has to be used to read commands. if set, OnCommandReceived() will be called for each command that was received
98 */
99 IAdapterCommunication(IAdapterCommunicationCallback *callback) :
100 m_callback(callback) {}
9ceaabcd
LOK
101 virtual ~IAdapterCommunication(void) {}
102
7bb4ed43
LOK
103 /*!
104 * @brief Open a connection to the CEC adapter
105 * @param iTimeoutMs Connection timeout in ms
a2198e5e 106 * @param bSkipChecks Skips all initial checks of the adapter, and starts the reader/writer threads directly after connecting.
f80cd208 107 * @param bStartListening Start a listener thread when true. False to just open a connection, read the device info, and close the connection.
7bb4ed43
LOK
108 * @return True when connected, false otherwise
109 */
b32ffd87 110 virtual bool Open(uint32_t iTimeoutMs = CEC_DEFAULT_CONNECT_TIMEOUT, bool bSkipChecks = false, bool bStartListening = true) = 0;
7bb4ed43
LOK
111
112 /*!
113 * @brief Close an open connection
114 */
115 virtual void Close(void) = 0;
116
117 /*!
118 * @return True when the connection is open, false otherwise
119 */
120 virtual bool IsOpen(void) = 0;
121
122 /*!
123 * @return The last error message, or an empty string if there was none
124 */
2b44051c 125 virtual std::string GetError(void) const = 0;
7bb4ed43 126
7bb4ed43
LOK
127 /*!
128 * @brief Write a cec_command to the adapter
129 * @param data The command to write
33dd87a9
MK
130 * @param bRetry The command can be retried
131 * @param iLineTimeout The line timeout to be used
2b44051c 132 * @param bIsReply True when this message is a reply, false otherwise
7bb4ed43
LOK
133 * @return The last state of the transmitted command
134 */
2b44051c 135 virtual cec_adapter_message_state Write(const cec_command &data, bool &bRetry, uint8_t iLineTimeout, bool bIsReply) = 0;
ef7696f5 136
7bb4ed43
LOK
137 /*!
138 * @brief Change the current line timeout on the CEC bus
139 * @param iTimeout The new timeout
140 * @return True when set, false otherwise
141 */
142 virtual bool SetLineTimeout(uint8_t iTimeout) = 0;
ef7696f5 143
7bb4ed43
LOK
144 /*!
145 * @brief Put the device in bootloader mode (which will disrupt CEC communication when it succeeds)
146 * @return True when the bootloader command has been sent, false otherwise.
147 */
148 virtual bool StartBootloader(void) = 0;
ef7696f5 149
2b44051c
LOK
150 virtual bool SetLogicalAddresses(const cec_logical_addresses &addresses) = 0;
151 virtual cec_logical_addresses GetLogicalAddresses(void) = 0;
6729ac71 152
7bb4ed43
LOK
153 /*!
154 * @brief Check whether the CEC adapter responds
155 * @return True when the ping was sent and acked, false otherwise.
156 */
157 virtual bool PingAdapter(void) = 0;
ef7696f5 158
7bb4ed43 159 /*!
e69d8f19 160 * @return The firmware version of this CEC adapter, or 0 if it's unknown.
7bb4ed43
LOK
161 */
162 virtual uint16_t GetFirmwareVersion(void) = 0;
b057edad 163
b2f56d35
LOK
164 /*!
165 * @return The build date in seconds since epoch, or 0 when no (valid) reply was received.
166 */
167 virtual uint32_t GetFirmwareBuildDate(void) = 0;
168
5daed059
LOK
169 /*!
170 * @return True when this adapter is using the latest firmware build, or when the latest firmware build for this adapter type is unknown. False otherwise.
171 */
172 virtual bool IsRunningLatestFirmware(void) = 0;
173
b057edad
BL
174 /*!
175 * @return True when the control mode has been set, false otherwise.
176 */
177 virtual bool SetControlledMode(bool controlled) = 0;
224ea877
LOK
178
179 /*!
180 * @brief Persist the given configuration in adapter (if supported)
181 * @brief The configuration to store.
182 * @return True when the configuration was persisted, false otherwise.
183 */
c0152c09 184 virtual bool PersistConfiguration(const libcec_configuration &configuration) = 0;
cba904a6 185
12a36be9
LOK
186 /*!
187 * @brief Get the persisted configuration from the adapter (if supported)
188 * @param configuration The updated configuration.
189 * @return True when the configuration was updated, false otherwise.
190 */
c0152c09 191 virtual bool GetConfiguration(libcec_configuration &configuration) = 0;
12a36be9 192
cba904a6
LOK
193 /*!
194 * @return The name of the port
195 */
2b44051c 196 virtual std::string GetPortName(void) = 0;
8670c970
LOK
197
198 /*!
199 * @return The physical address, if the adapter supports this. 0 otherwise.
200 */
201 virtual uint16_t GetPhysicalAddress(void) = 0;
a75e3a5a 202
2b44051c
LOK
203 /*!
204 * @return The vendor id for this device
205 */
206 virtual cec_vendor_id GetVendorId(void) = 0;
207
208 /*!
209 * @brief Checks whether a logical address is supported by the adapter.
210 * @param address The address to check.
211 * @return True when supported, false otherwise.
212 */
213 virtual bool SupportsSourceLogicalAddress(const cec_logical_address address) = 0;
214
2d418322
LOK
215 /*!
216 * @return The type of adapter that this instance is connected to.
217 */
218 virtual cec_adapter_type GetAdapterType(void) = 0;
219
8768aeca
LOK
220 /*!
221 * @return The (virtual) USB vendor id
222 */
223 virtual uint16_t GetAdapterVendorId(void) const = 0;
224
225 /*!
226 * @return The (virtual) USB product id
227 */
228 virtual uint16_t GetAdapterProductId(void) const = 0;
229
a582c2bb
LOK
230 /*!
231 * @brief Marks the adapter as active or inactive source
232 * @param bSetTo True to mark as active source, false to mark as inactive source
233 * @param bClientUnregistered True when the client was unregistered, false when the device was explicitly marked as (in)active source
234 */
235 virtual void SetActiveSource(bool bSetTo, bool bClientUnregistered) = 0;
236
a75e3a5a 237 IAdapterCommunicationCallback *m_callback;
abbca718
LOK
238 };
239};