Bug 1890844 - Tiny cleanup of classes implementing nsDOMCSSDeclaration r=layout-revie...
[gecko.git] / dom / midi / MIDIPlatformRunnables.h
blob15727a99ccc93c439f9809213c85f61ce5e6b50a
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_MIDIPlatformRunnables_h
8 #define mozilla_dom_MIDIPlatformRunnables_h
10 #include "mozilla/dom/MIDITypes.h"
12 namespace mozilla::dom {
14 enum class MIDIPortConnectionState : uint8_t;
15 enum class MIDIPortDeviceState : uint8_t;
17 class MIDIPortParent;
18 class MIDIMessage;
19 class MIDIPortInfo;
21 /**
22 * Base class for runnables to be fired to the platform-specific MIDI service
23 * thread in PBackground.
25 class MIDIBackgroundRunnable : public Runnable {
26 public:
27 MIDIBackgroundRunnable(const char* aName) : Runnable(aName) {}
28 virtual ~MIDIBackgroundRunnable() = default;
29 NS_IMETHOD Run() override;
30 virtual void RunInternal() = 0;
33 /**
34 * Runnable fired from platform-specific MIDI service thread to PBackground
35 * Thread whenever messages need to be sent to a MIDI device.
38 class ReceiveRunnable final : public MIDIBackgroundRunnable {
39 public:
40 ReceiveRunnable(const nsAString& aPortId, const nsTArray<MIDIMessage>& aMsgs)
41 : MIDIBackgroundRunnable("ReceiveRunnable"),
42 mMsgs(aMsgs.Clone()),
43 mPortId(aPortId) {}
44 // Used in tests
45 ReceiveRunnable(const nsAString& aPortId, const MIDIMessage& aMsgs)
46 : MIDIBackgroundRunnable("ReceiveRunnable"), mPortId(aPortId) {
47 mMsgs.AppendElement(aMsgs);
49 ~ReceiveRunnable() = default;
50 void RunInternal() override;
52 private:
53 nsTArray<MIDIMessage> mMsgs;
54 nsString mPortId;
57 /**
58 * Runnable fired from platform-specific MIDI service thread to PBackground
59 * Thread whenever a device is connected.
62 class AddPortRunnable final : public MIDIBackgroundRunnable {
63 public:
64 explicit AddPortRunnable(const MIDIPortInfo& aPortInfo)
65 : MIDIBackgroundRunnable("AddPortRunnable"), mPortInfo(aPortInfo) {}
66 ~AddPortRunnable() = default;
67 void RunInternal() override;
69 private:
70 MIDIPortInfo mPortInfo;
73 /**
74 * Runnable fired from platform-specific MIDI service thread to PBackground
75 * Thread whenever a device is disconnected.
78 class RemovePortRunnable final : public MIDIBackgroundRunnable {
79 public:
80 explicit RemovePortRunnable(const MIDIPortInfo& aPortInfo)
81 : MIDIBackgroundRunnable("RemovePortRunnable"), mPortInfo(aPortInfo) {}
82 ~RemovePortRunnable() = default;
83 void RunInternal() override;
85 private:
86 MIDIPortInfo mPortInfo;
89 /**
90 * Runnable used to delay calls to SendPortList, which is requires to make sure
91 * MIDIManager actor initialization happens correctly. Also used for testing.
94 class SendPortListRunnable final : public MIDIBackgroundRunnable {
95 public:
96 SendPortListRunnable() : MIDIBackgroundRunnable("SendPortListRunnable") {}
97 ~SendPortListRunnable() = default;
98 void RunInternal() override;
102 * Runnable fired from platform-specific MIDI service thread to PBackground
103 * Thread whenever a device is disconnected.
106 class SetStatusRunnable final : public MIDIBackgroundRunnable {
107 public:
108 SetStatusRunnable(MIDIPortParent* aPort, MIDIPortDeviceState aState,
109 MIDIPortConnectionState aConnection)
110 : MIDIBackgroundRunnable("SetStatusRunnable"),
111 mPort(aPort),
112 mState(aState),
113 mConnection(aConnection) {}
114 ~SetStatusRunnable() = default;
115 void RunInternal() override;
117 private:
118 RefPtr<MIDIPortParent> mPort;
119 MIDIPortDeviceState mState;
120 MIDIPortConnectionState mConnection;
123 } // namespace mozilla::dom
125 #endif // mozilla_dom_MIDIPlatformRunnables_h