Bug 1472338: part 2) Change `clipboard.readText()` to read from the clipboard asynchr...
[gecko.git] / dom / midi / midirMIDIPlatformService.h
blob0a918b91cdd5d0d346dca34870e936291854590e
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_midirMIDIPlatformService_h
8 #define mozilla_dom_midirMIDIPlatformService_h
10 #include "mozilla/StaticMutex.h"
11 #include "mozilla/dom/MIDIPlatformService.h"
12 #include "mozilla/dom/MIDITypes.h"
13 #include "mozilla/dom/midi/midir_impl_ffi_generated.h"
15 class nsIThread;
16 struct MidirWrapper;
18 namespace mozilla::dom {
20 class MIDIPortInterface;
22 /**
23 * Platform service implementation using the midir crate.
25 class midirMIDIPlatformService : public MIDIPlatformService {
26 public:
27 midirMIDIPlatformService();
28 virtual void Init() override;
29 virtual void Open(MIDIPortParent* aPort) override;
30 virtual void Stop() override;
31 virtual void ScheduleSend(const nsAString& aPort) override;
32 virtual void ScheduleClose(MIDIPortParent* aPort) override;
34 void SendMessage(const nsAString& aPort, const MIDIMessage& aMessage);
36 private:
37 virtual ~midirMIDIPlatformService();
39 static void AddPort(const nsString* aId, const nsString* aName, bool aInput);
40 static void CheckAndReceive(const nsString* aId, const uint8_t* aData,
41 size_t aLength, const GeckoTimeStamp* aTimeStamp,
42 uint64_t aMicros);
44 // Wrapper around the midir Rust implementation.
45 MidirWrapper* mImplementation;
47 // midir has its own internal threads and we can't execute jobs directly on
48 // them, instead we forward them to the background thread the service was
49 // created in.
50 static StaticMutex gBackgroundThreadMutex;
51 static nsCOMPtr<nsIThread> gBackgroundThread;
54 } // namespace mozilla::dom
56 #endif // mozilla_dom_midirMIDIPlatformService_h