Bug 1733673 [wpt PR 31066] - Annotate CSS Transforms WPT reftests as fuzzy where...
[gecko.git] / dom / midi / MIDIAccessManager.h
blob2ffb7e6f534b870af8c46d08130bb88a162bcf88
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/. */
7 #ifndef mozilla_dom_MIDIAccessManager_h
8 #define mozilla_dom_MIDIAccessManager_h
10 #include "nsPIDOMWindow.h"
11 #include "mozilla/dom/MIDITypes.h"
12 #include "mozilla/Observer.h"
14 namespace mozilla {
15 namespace dom {
17 class MIDIAccess;
18 class MIDIManagerChild;
19 struct MIDIOptions;
20 class MIDIPortChangeEvent;
21 class MIDIPortInfo;
22 class Promise;
24 /**
25 * MIDIAccessManager manages creation and lifetime of MIDIAccess objects for the
26 * process it lives in. It is in charge of dealing with permission requests,
27 * creating new MIDIAccess objects, and updating live MIDIAccess objects with
28 * new device listings.
30 * While a process/window can have many MIDIAccess objects, there is only one
31 * MIDIAccessManager for any one process.
33 class MIDIAccessManager final {
34 public:
35 NS_INLINE_DECL_REFCOUNTING(MIDIAccessManager);
36 // Handles requests from Navigator for MIDI permissions and MIDIAccess
37 // creation.
38 already_AddRefed<Promise> RequestMIDIAccess(nsPIDOMWindowInner* aWindow,
39 const MIDIOptions& aOptions,
40 ErrorResult& aRv);
41 // Creates a new MIDIAccess object
42 void CreateMIDIAccess(nsPIDOMWindowInner* aWindow, bool aNeedsSysex,
43 Promise* aPromise);
44 // Getter for manager singleton
45 static MIDIAccessManager* Get();
46 // True if manager singleton has been created
47 static bool IsRunning();
48 // Send device connection updates to all known MIDIAccess objects.
49 void Update(const MIDIPortList& aEvent);
50 // Adds a device update observer (usually a MIDIAccess object)
51 bool AddObserver(Observer<MIDIPortList>* aObserver);
52 // Removes a device update observer (usually a MIDIAccess object)
53 void RemoveObserver(Observer<MIDIPortList>* aObserver);
55 private:
56 MIDIAccessManager();
57 ~MIDIAccessManager();
58 // True if object has received a device list from the MIDI platform service.
59 bool mHasPortList;
60 // List of known ports for the system.
61 MIDIPortList mPortList;
62 // Holds MIDIAccess objects until we've received the first list of devices
63 // from the MIDI Service.
64 nsTArray<RefPtr<MIDIAccess>> mAccessHolder;
65 // Device state update observers (usually MIDIAccess objects)
66 ObserverList<MIDIPortList> mChangeObservers;
67 // IPC Object for MIDIManager. Created on first MIDIAccess object creation,
68 // destroyed on last MIDIAccess object destruction.
69 RefPtr<MIDIManagerChild> mChild;
72 } // namespace dom
73 } // namespace mozilla
75 #endif // mozilla_dom_MIDIAccessManager_h