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;
22 * Base class for runnables to be fired to the platform-specific MIDI service
23 * thread in PBackground.
25 class MIDIBackgroundRunnable
: public Runnable
{
27 MIDIBackgroundRunnable(const char* aName
) : Runnable(aName
) {}
28 virtual ~MIDIBackgroundRunnable() = default;
29 NS_IMETHOD
Run() override
;
30 virtual void RunInternal() = 0;
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
{
40 ReceiveRunnable(const nsAString
& aPortId
, const nsTArray
<MIDIMessage
>& aMsgs
)
41 : MIDIBackgroundRunnable("ReceiveRunnable"),
45 ReceiveRunnable(const nsAString
& aPortId
, const MIDIMessage
& aMsgs
)
46 : MIDIBackgroundRunnable("ReceiveRunnable"), mPortId(aPortId
) {
47 mMsgs
.AppendElement(aMsgs
);
49 ~ReceiveRunnable() = default;
50 void RunInternal() override
;
53 nsTArray
<MIDIMessage
> mMsgs
;
58 * Runnable fired from platform-specific MIDI service thread to PBackground
59 * Thread whenever a device is connected.
62 class AddPortRunnable final
: public MIDIBackgroundRunnable
{
64 explicit AddPortRunnable(const MIDIPortInfo
& aPortInfo
)
65 : MIDIBackgroundRunnable("AddPortRunnable"), mPortInfo(aPortInfo
) {}
66 ~AddPortRunnable() = default;
67 void RunInternal() override
;
70 MIDIPortInfo mPortInfo
;
74 * Runnable fired from platform-specific MIDI service thread to PBackground
75 * Thread whenever a device is disconnected.
78 class RemovePortRunnable final
: public MIDIBackgroundRunnable
{
80 explicit RemovePortRunnable(const MIDIPortInfo
& aPortInfo
)
81 : MIDIBackgroundRunnable("RemovePortRunnable"), mPortInfo(aPortInfo
) {}
82 ~RemovePortRunnable() = default;
83 void RunInternal() override
;
86 MIDIPortInfo mPortInfo
;
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
{
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
{
108 SetStatusRunnable(MIDIPortParent
* aPort
, MIDIPortDeviceState aState
,
109 MIDIPortConnectionState aConnection
)
110 : MIDIBackgroundRunnable("SetStatusRunnable"),
113 mConnection(aConnection
) {}
114 ~SetStatusRunnable() = default;
115 void RunInternal() override
;
118 MIDIPortParent
* mPort
;
119 MIDIPortDeviceState mState
;
120 MIDIPortConnectionState mConnection
;
123 } // namespace mozilla::dom
125 #endif // mozilla_dom_MIDIPlatformRunnables_h