tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

MIDIMessageQueue.h (1800B)


      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 "mozilla/Mutex.h"
     11 #include "nsTArray.h"
     12 
     13 // XXX Avoid including this here by moving function implementations to the cpp
     14 // file.
     15 #include "mozilla/dom/MIDITypes.h"
     16 
     17 namespace mozilla {
     18 
     19 class TimeStamp;
     20 
     21 namespace dom {
     22 
     23 class MIDIMessage;
     24 
     25 /**
     26 * Since some MIDI Messages can be scheduled to be sent in the future, the
     27 * MIDIMessageQueue is responsible for making sure all MIDI messages are
     28 * scheduled and sent in order.
     29 */
     30 class MIDIMessageQueue {
     31 public:
     32  MIDIMessageQueue();
     33  ~MIDIMessageQueue() = default;
     34  // Adds an array of possibly out-of-order messages to our queue.
     35  void Add(nsTArray<MIDIMessage>& aMsg);
     36  // Retrieve all pending messages before the time specified.
     37  void GetMessagesBefore(TimeStamp aTimestamp,
     38                         nsTArray<MIDIMessage>& aMsgQueue);
     39  // Get all pending messages.
     40  void GetMessages(nsTArray<MIDIMessage>& aMsgQueue);
     41  // Erase all pending messages.
     42  void Clear();
     43  // Erase all pending messages that would be sent in the future. Useful for
     44  // when ports are closed, as we must send all messages with timestamps in the
     45  // past.
     46  void ClearAfterNow();
     47 
     48 private:
     49  // Array of messages to be sent.
     50  nsTArray<MIDIMessage> mMessageQueue;
     51  // Mutex for coordinating cross thread array access.
     52  Mutex mMutex MOZ_UNANNOTATED;
     53 };
     54 
     55 }  // namespace dom
     56 }  // namespace mozilla
     57 
     58 #endif  // mozilla_dom_MIDIMessageQueue_h