From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- dom/midi/MIDIPlatformRunnables.h | 125 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 dom/midi/MIDIPlatformRunnables.h (limited to 'dom/midi/MIDIPlatformRunnables.h') diff --git a/dom/midi/MIDIPlatformRunnables.h b/dom/midi/MIDIPlatformRunnables.h new file mode 100644 index 0000000000..15727a99cc --- /dev/null +++ b/dom/midi/MIDIPlatformRunnables.h @@ -0,0 +1,125 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim:set ts=2 sw=2 sts=2 et cindent: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef mozilla_dom_MIDIPlatformRunnables_h +#define mozilla_dom_MIDIPlatformRunnables_h + +#include "mozilla/dom/MIDITypes.h" + +namespace mozilla::dom { + +enum class MIDIPortConnectionState : uint8_t; +enum class MIDIPortDeviceState : uint8_t; + +class MIDIPortParent; +class MIDIMessage; +class MIDIPortInfo; + +/** + * Base class for runnables to be fired to the platform-specific MIDI service + * thread in PBackground. + */ +class MIDIBackgroundRunnable : public Runnable { + public: + MIDIBackgroundRunnable(const char* aName) : Runnable(aName) {} + virtual ~MIDIBackgroundRunnable() = default; + NS_IMETHOD Run() override; + virtual void RunInternal() = 0; +}; + +/** + * Runnable fired from platform-specific MIDI service thread to PBackground + * Thread whenever messages need to be sent to a MIDI device. + * + */ +class ReceiveRunnable final : public MIDIBackgroundRunnable { + public: + ReceiveRunnable(const nsAString& aPortId, const nsTArray& aMsgs) + : MIDIBackgroundRunnable("ReceiveRunnable"), + mMsgs(aMsgs.Clone()), + mPortId(aPortId) {} + // Used in tests + ReceiveRunnable(const nsAString& aPortId, const MIDIMessage& aMsgs) + : MIDIBackgroundRunnable("ReceiveRunnable"), mPortId(aPortId) { + mMsgs.AppendElement(aMsgs); + } + ~ReceiveRunnable() = default; + void RunInternal() override; + + private: + nsTArray mMsgs; + nsString mPortId; +}; + +/** + * Runnable fired from platform-specific MIDI service thread to PBackground + * Thread whenever a device is connected. + * + */ +class AddPortRunnable final : public MIDIBackgroundRunnable { + public: + explicit AddPortRunnable(const MIDIPortInfo& aPortInfo) + : MIDIBackgroundRunnable("AddPortRunnable"), mPortInfo(aPortInfo) {} + ~AddPortRunnable() = default; + void RunInternal() override; + + private: + MIDIPortInfo mPortInfo; +}; + +/** + * Runnable fired from platform-specific MIDI service thread to PBackground + * Thread whenever a device is disconnected. + * + */ +class RemovePortRunnable final : public MIDIBackgroundRunnable { + public: + explicit RemovePortRunnable(const MIDIPortInfo& aPortInfo) + : MIDIBackgroundRunnable("RemovePortRunnable"), mPortInfo(aPortInfo) {} + ~RemovePortRunnable() = default; + void RunInternal() override; + + private: + MIDIPortInfo mPortInfo; +}; + +/** + * Runnable used to delay calls to SendPortList, which is requires to make sure + * MIDIManager actor initialization happens correctly. Also used for testing. + * + */ +class SendPortListRunnable final : public MIDIBackgroundRunnable { + public: + SendPortListRunnable() : MIDIBackgroundRunnable("SendPortListRunnable") {} + ~SendPortListRunnable() = default; + void RunInternal() override; +}; + +/** + * Runnable fired from platform-specific MIDI service thread to PBackground + * Thread whenever a device is disconnected. + * + */ +class SetStatusRunnable final : public MIDIBackgroundRunnable { + public: + SetStatusRunnable(MIDIPortParent* aPort, MIDIPortDeviceState aState, + MIDIPortConnectionState aConnection) + : MIDIBackgroundRunnable("SetStatusRunnable"), + mPort(aPort), + mState(aState), + mConnection(aConnection) {} + ~SetStatusRunnable() = default; + void RunInternal() override; + + private: + RefPtr mPort; + MIDIPortDeviceState mState; + MIDIPortConnectionState mConnection; +}; + +} // namespace mozilla::dom + +#endif // mozilla_dom_MIDIPlatformRunnables_h -- cgit v1.2.3