3 * This file is part of the libCEC(R) library.
5 * libCEC(R) is Copyright (C) 2011-2012 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/
34 #include "lib/platform/util/buffer.h"
39 class CRPiCECAdapterCommunication
;
40 class CRPiCECAdapterMessageQueue
;
42 class CRPiCECAdapterMessageQueueEntry
45 CRPiCECAdapterMessageQueueEntry(CRPiCECAdapterMessageQueue
*queue
, const cec_command
&command
);
46 virtual ~CRPiCECAdapterMessageQueueEntry(void) {}
49 * @brief Signal waiting threads
53 bool MessageReceived(cec_opcode opcode
, cec_logical_address initiator
, cec_logical_address destination
, uint32_t response
);
56 * @brief Wait for a response to this command.
57 * @param iTimeout The timeout to use while waiting.
58 * @return True when a response was received before the timeout passed, false otherwise.
60 bool Wait(uint32_t iTimeout
);
63 * @return True while a thread is waiting for a signal or isn't waiting yet, false otherwise.
68 * @return The command that was sent in human readable form.
70 const char *ToString(void) const { return "CEC transmission"; }
72 CRPiCECAdapterMessageQueue
* m_queue
;
73 bool m_bWaiting
; /**< true while a thread is waiting or when it hasn't started waiting yet */
74 PLATFORM::CCondition
<bool> m_condition
; /**< the condition to wait on */
75 PLATFORM::CMutex m_mutex
; /**< mutex for changes to this class */
76 cec_command m_command
;
81 class CRPiCECAdapterMessageQueue
83 friend class CRPiCECAdapterMessageQueueEntry
;
87 * @brief Create a new message queue.
88 * @param com The communication handler callback to use.
89 * @param iQueueSize The outgoing message queue size.
91 CRPiCECAdapterMessageQueue(CRPiCECAdapterCommunication
*com
) :
97 virtual ~CRPiCECAdapterMessageQueue(void)
103 * @brief Signal and delete everything in the queue
107 void MessageReceived(cec_opcode opcode
, cec_logical_address initiator
, cec_logical_address destination
, uint32_t response
);
109 bool Write(const cec_command
&command
, bool bIsReply
);
112 CRPiCECAdapterCommunication
* m_com
; /**< the communication handler */
113 PLATFORM::CMutex m_mutex
; /**< mutex for changes to this class */
114 std::map
<uint64_t, CRPiCECAdapterMessageQueueEntry
*> m_messages
; /**< the outgoing message queue */
115 uint64_t m_iNextMessage
; /**< the index of the next message */