/src/mozilla-central/dom/midi/MIDIMessageQueue.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim:set ts=2 sw=2 sts=2 et cindent: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef mozilla_dom_MIDIMessageQueue_h |
8 | | #define mozilla_dom_MIDIMessageQueue_h |
9 | | |
10 | | #include "nsTArray.h" |
11 | | |
12 | | namespace mozilla { |
13 | | namespace dom { |
14 | | |
15 | | class MIDIMessage; |
16 | | |
17 | | /** |
18 | | * Since some MIDI Messages can be scheduled to be sent in the future, the |
19 | | * MIDIMessageQueue is responsible for making sure all MIDI messages are |
20 | | * scheduled and sent in order. |
21 | | */ |
22 | | class MIDIMessageQueue |
23 | | { |
24 | | public: |
25 | | MIDIMessageQueue(); |
26 | 0 | ~MIDIMessageQueue() = default; |
27 | | // Adds an array of possibly out-of-order messages to our queue. |
28 | | void Add(nsTArray<MIDIMessage>& aMsg); |
29 | | // Retrieve all pending messages before the time specified. |
30 | | void GetMessagesBefore(TimeStamp aTimestamp, nsTArray<MIDIMessage>& aMsgArray); |
31 | | // Get all pending messages. |
32 | | void GetMessages(nsTArray<MIDIMessage>& aMsgArray); |
33 | | // Erase all pending messages. |
34 | | void Clear(); |
35 | | // Erase all pending messages that would be sent in the future. Useful for |
36 | | // when ports are closed, as we must send all messages with timestamps in the |
37 | | // past. |
38 | | void ClearAfterNow(); |
39 | | private: |
40 | | // Array of messages to be sent. |
41 | | nsTArray<MIDIMessage> mMessageQueue; |
42 | | // Mutex for coordinating cross thread array access. |
43 | | Mutex mMutex; |
44 | | }; |
45 | | |
46 | | } // namespace dom |
47 | | } // namespace mozilla |
48 | | |
49 | | #endif // mozilla_dom_MIDIMessageQueue_h |