cec: bump version to 1.6.3. check the client version, not the server version in libce...
[deb_libcec.git] / src / lib / adapter / USBCECAdapterMessage.h
CommitLineData
ef7696f5
LOK
1#pragma once
2/*
3 * This file is part of the libCEC(R) library.
4 *
b492c10e 5 * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved.
ef7696f5
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
24048d57 34#include "../platform/util/StdString.h"
a75e3a5a
LOK
35#include "../platform/util/buffer.h"
36#include "../platform/threads/mutex.h"
37#include "../../../include/cectypes.h"
ba65909d 38
ef7696f5
LOK
39namespace CEC
40{
a75e3a5a
LOK
41 typedef enum cec_adapter_message_state
42 {
43 ADAPTER_MESSAGE_STATE_UNKNOWN = 0, /**< the initial state */
44 ADAPTER_MESSAGE_STATE_WAITING_TO_BE_SENT, /**< waiting in the send queue of the adapter, or timed out */
45 ADAPTER_MESSAGE_STATE_SENT, /**< sent and waiting on an ACK */
46 ADAPTER_MESSAGE_STATE_SENT_NOT_ACKED, /**< sent, but failed to ACK */
47 ADAPTER_MESSAGE_STATE_SENT_ACKED, /**< sent, and ACK received */
48 ADAPTER_MESSAGE_STATE_INCOMING, /**< received from another device */
49 ADAPTER_MESSAGE_STATE_ERROR /**< an error occured */
50 } cec_adapter_message_state;
51
ef7696f5
LOK
52 class CCECAdapterMessage
53 {
54 public:
a75e3a5a
LOK
55 /*!
56 * @brief Create an empty message.
57 */
58 CCECAdapterMessage(void);
59
60 /*!
61 * @brief Create a message with a command that is to be transmitted over the CEC line.
62 * @param command The command to transmit.
33dd87a9 63 * @param iLineTimeout The line timeout to use when sending this message.
a75e3a5a 64 */
33dd87a9 65 CCECAdapterMessage(const cec_command &command, uint8_t iLineTimeout = 3);
a75e3a5a
LOK
66
67 /*!
68 * @return the message as human readable string.
69 */
70 CStdString ToString(void) const;
71
72 /*!
73 * @brief Translate the messagecode into a human readable string.
74 * @param msgCode The messagecode to translate.
75 * @return The messagecode as string.
76 */
77 static const char *ToString(cec_adapter_messagecode msgCode);
78
79 /*!
80 * @brief Get the byte at the given position.
81 * @param pos The position to get.
82 * @return The requested byte, or 0 when it's out of range.
83 */
84 uint8_t At(uint8_t pos) const;
85 uint8_t operator[](uint8_t pos) const;
86
87 /*!
88 * @return The size of the packet in bytes.
89 */
90 uint8_t Size(void) const;
91
92 /*!
93 * @return True when empty, false otherwise.
94 */
95 bool IsEmpty(void) const;
96
97 /*!
98 * @brief Clear this message and reset everything to the initial values.
99 */
100 void Clear(void);
101
102 /*!
103 * @brief Shift the message by the given number of bytes.
104 * @param iShiftBy The number of bytes to shift.
105 */
106 void Shift(uint8_t iShiftBy);
107
108 /*!
109 * @brief Append the given message to this message.
110 * @param data The message to append.
111 */
112 void Append(CCECAdapterMessage &data);
113
114 /*!
115 * @brief Append the given datapacket to this message.
116 * @param data The packet to add.
117 */
118 void Append(cec_datapacket &data);
119
120 /*!
121 * @brief Adds a byte to this message. Does not escape the byte.
122 * @param byte The byte to add.
123 */
124 void PushBack(uint8_t byte);
125
126 /*!
127 * @brief Adds a byte to this message and escapes the byte if needed.
128 * @param byte The byte to add.
129 */
130 void PushEscaped(uint8_t byte);
131
132 /*!
133 * @brief Adds a byte to this message.
134 * @param byte The byte to add.
135 * @return True when a full message was received, false otherwise.
136 */
137 bool PushReceivedByte(uint8_t byte);
138
139 /*!
140 * @return The messagecode inside this adapter message, or MSGCODE_NOTHING if there is none.
141 */
142 cec_adapter_messagecode Message(void) const;
143
144 /*!
145 * @return True when this message is a transmission, false otherwise.
146 */
147 bool IsTranmission(void) const;
148
149 /*!
150 * @return True when the EOM bit is set, false otherwise.
151 */
152 bool IsEOM(void) const;
153
154 /*!
155 * @return True when the ACK bit is set, false otherwise.
156 */
157 bool IsACK(void) const;
158
159 /*!
160 * @return True when this message has been replied with an error code, false otherwise.
161 */
162 bool IsError(void) const;
163
164 /*!
165 * @return True when this message has been replied with an error code and needs to be retried, false otherwise.
166 */
167 bool NeedsRetry(void) const;
168
169 /*!
170 * @return The logical address of the initiator, or CECDEVICE_UNKNOWN if unknown.
171 */
172 cec_logical_address Initiator(void) const;
173
174 /*!
175 * @return The logical address of the destination, or CECDEVICE_UNKNOWN if unknown.
176 */
177 cec_logical_address Destination(void) const;
178
179 /*!
180 * @return True when this message contains a start message, false otherwise.
181 */
182 bool HasStartMessage(void) const;
183
184 /*!
185 * @brief Push this adapter message to the end of the given cec_command.
186 * @param command The command to push this message to.
187 * @return True when a full CEC message was received, false otherwise.
188 */
189 bool PushToCecCommand(cec_command &command) const;
190
191 /*!
192 * @return The response messagecode.
193 */
194 cec_adapter_messagecode Reply(void) const;
195
196 uint8_t maxTries; /**< the maximum number of times to try to send this message */
a75e3a5a
LOK
197 cec_datapacket response; /**< the response to this message */
198 cec_datapacket packet; /**< the actual data */
199 cec_adapter_message_state state; /**< the current state of this message */
200 int32_t transmit_timeout; /**< the timeout to use when sending this message */
201 uint8_t lineTimeout; /**< the default CEC line timeout to use when sending this message */
a75e3a5a
LOK
202
203 private:
204 bool bNextByteIsEscaped; /**< true when the next byte that is added will be escaped, false otherwise */
ef7696f5
LOK
205 };
206}