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