Bug 1688354 [wpt PR 27298] - Treat 'rem' as an absolute unit for font size, a=testonly
[gecko.git] / dom / midi / MIDIPortParent.cpp
blob2da91d7653bfd22b5b75a20b31a83a77de54c1be
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 #include "mozilla/dom/MIDIPortParent.h"
8 #include "mozilla/dom/MIDIPlatformService.h"
9 #include "nsContentUtils.h"
11 // C++ file contents
12 namespace mozilla::dom {
14 // Keep an internal ID that we can use for passing information about specific
15 // MIDI ports back and forth to the Rust libraries.
16 static uint32_t gId = 0;
18 mozilla::ipc::IPCResult MIDIPortParent::RecvSend(
19 nsTArray<MIDIMessage>&& aMsgs) {
20 if (mConnectionState != MIDIPortConnectionState::Open) {
21 mMessageQueue.AppendElements(aMsgs);
22 if (MIDIPlatformService::IsRunning()) {
23 MIDIPlatformService::Get()->Open(this);
25 return IPC_OK();
27 if (MIDIPlatformService::IsRunning()) {
28 MIDIPlatformService::Get()->QueueMessages(MIDIPortInterface::mId, aMsgs);
30 return IPC_OK();
33 mozilla::ipc::IPCResult MIDIPortParent::RecvOpen() {
34 if (MIDIPlatformService::IsRunning()) {
35 MIDIPlatformService::Get()->Open(this);
37 return IPC_OK();
40 mozilla::ipc::IPCResult MIDIPortParent::RecvClose() {
41 if (mConnectionState != MIDIPortConnectionState::Closed) {
42 if (MIDIPlatformService::IsRunning()) {
43 MIDIPlatformService::Get()->Close(this);
46 return IPC_OK();
49 mozilla::ipc::IPCResult MIDIPortParent::RecvClear() {
50 if (MIDIPlatformService::IsRunning()) {
51 MIDIPlatformService::Get()->Clear(this);
53 return IPC_OK();
56 mozilla::ipc::IPCResult MIDIPortParent::RecvShutdown() {
57 if (mShuttingDown) {
58 return IPC_OK();
60 Teardown();
61 Unused << Send__delete__(this);
62 return IPC_OK();
65 void MIDIPortParent::Teardown() {
66 mMessageQueue.Clear();
67 MIDIPortInterface::Shutdown();
68 if (MIDIPlatformService::IsRunning()) {
69 MIDIPlatformService::Get()->RemovePort(this);
73 void MIDIPortParent::ActorDestroy(ActorDestroyReason) {}
75 bool MIDIPortParent::SendUpdateStatus(
76 const MIDIPortDeviceState& aDeviceState,
77 const MIDIPortConnectionState& aConnectionState) {
78 if (mShuttingDown) {
79 return true;
81 mDeviceState = aDeviceState;
82 mConnectionState = aConnectionState;
83 if (aConnectionState == MIDIPortConnectionState::Open &&
84 aDeviceState == MIDIPortDeviceState::Disconnected) {
85 mConnectionState = MIDIPortConnectionState::Pending;
86 } else if (aConnectionState == MIDIPortConnectionState::Open &&
87 aDeviceState == MIDIPortDeviceState::Connected &&
88 !mMessageQueue.IsEmpty()) {
89 if (MIDIPlatformService::IsRunning()) {
90 MIDIPlatformService::Get()->QueueMessages(MIDIPortInterface::mId,
91 mMessageQueue);
93 mMessageQueue.Clear();
95 return PMIDIPortParent::SendUpdateStatus(
96 static_cast<uint32_t>(mDeviceState),
97 static_cast<uint32_t>(mConnectionState));
100 MIDIPortParent::MIDIPortParent(const MIDIPortInfo& aPortInfo,
101 const bool aSysexEnabled)
102 : MIDIPortInterface(aPortInfo, aSysexEnabled), mInternalId(++gId) {
103 MOZ_ASSERT(MIDIPlatformService::IsRunning(),
104 "Shouldn't be able to add MIDI port without MIDI service!");
105 MIDIPlatformService::Get()->AddPort(this);
108 } // namespace mozilla::dom