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/
34 #include "lib/platform/util/buffer.h"
36 #include "lib/adapter/AdapterCommunication.h"
39 #include <interface/vmcs_host/vc_cecservice.h>
40 #include <interface/vchiq_arm/vchiq_if.h>
45 class CRPiCECAdapterCommunication
;
46 class CRPiCECAdapterMessageQueue
;
48 class CRPiCECAdapterMessageQueueEntry
51 CRPiCECAdapterMessageQueueEntry(CRPiCECAdapterMessageQueue
*queue
, const cec_command
&command
);
52 virtual ~CRPiCECAdapterMessageQueueEntry(void) {}
55 * @brief Signal waiting threads
59 bool MessageReceived(cec_opcode opcode
, cec_logical_address initiator
, cec_logical_address destination
, uint32_t response
);
62 * @brief Wait for a response to this command.
63 * @param iTimeout The timeout to use while waiting.
64 * @return True when a response was received before the timeout passed, false otherwise.
66 bool Wait(uint32_t iTimeout
);
69 * @return True while a thread is waiting for a signal or isn't waiting yet, false otherwise.
74 * @brief Query result from worker thread
76 uint32_t Result() const;
79 * @return The command that was sent in human readable form.
81 const char *ToString(void) const { return "CEC transmission"; }
83 CRPiCECAdapterMessageQueue
* m_queue
;
84 bool m_bWaiting
; /**< true while a thread is waiting or when it hasn't started waiting yet */
85 PLATFORM::CCondition
<bool> m_condition
; /**< the condition to wait on */
86 PLATFORM::CMutex m_mutex
; /**< mutex for changes to this class */
87 cec_command m_command
;
92 class CRPiCECAdapterMessageQueue
94 friend class CRPiCECAdapterMessageQueueEntry
;
98 * @brief Create a new message queue.
99 * @param com The communication handler callback to use.
100 * @param iQueueSize The outgoing message queue size.
102 CRPiCECAdapterMessageQueue(CRPiCECAdapterCommunication
*com
) :
108 virtual ~CRPiCECAdapterMessageQueue(void)
114 * @brief Signal and delete everything in the queue
118 void MessageReceived(cec_opcode opcode
, cec_logical_address initiator
, cec_logical_address destination
, uint32_t response
);
120 cec_adapter_message_state
Write(const cec_command
&command
, bool &bRetry
, uint32_t iLineTimeout
, bool bIsReply
, VC_CEC_ERROR_T
&vcReply
);
123 CRPiCECAdapterCommunication
* m_com
; /**< the communication handler */
124 PLATFORM::CMutex m_mutex
; /**< mutex for changes to this class */
125 std::map
<uint64_t, CRPiCECAdapterMessageQueueEntry
*> m_messages
; /**< the outgoing message queue */
126 uint64_t m_iNextMessage
; /**< the index of the next message */