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_MIDIOutputMap_h
8 #define mozilla_dom_MIDIOutputMap_h
10 #include "mozilla/dom/MIDIPort.h"
12 #include "nsTHashMap.h"
13 #include "nsWrapperCache.h"
15 class nsPIDOMWindowInner
;
17 namespace mozilla::dom
{
20 * Maplike DOM object that holds a list of all MIDI output ports available for
21 * access. Almost all functions are implemented automatically by WebIDL.
24 class MIDIOutputMap final
: public nsISupports
, public nsWrapperCache
{
26 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
27 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(MIDIOutputMap
)
29 explicit MIDIOutputMap(nsPIDOMWindowInner
* aParent
);
31 nsPIDOMWindowInner
* GetParentObject() const { return mParent
; }
33 JSObject
* WrapObject(JSContext
* aCx
,
34 JS::Handle
<JSObject
*> aGivenProto
) override
;
35 bool Has(nsAString
& aId
) { return mPorts
.Get(aId
) != nullptr; }
36 void Insert(nsAString
& aId
, RefPtr
<MIDIPort
> aPort
) {
37 mPorts
.InsertOrUpdate(aId
, aPort
);
39 void Remove(nsAString
& aId
) { mPorts
.Remove(aId
); }
42 ~MIDIOutputMap() = default;
43 nsTHashMap
<nsString
, RefPtr
<MIDIPort
>> mPorts
;
44 nsCOMPtr
<nsPIDOMWindowInner
> mParent
;
47 } // namespace mozilla::dom
49 #endif // mozilla_dom_MIDIOutputMap_h