Bug 1854367 - Mark storage-access-permission.sub.https.window.html subtest as intermi...
[gecko.git] / dom / gamepad / GamepadHandle.h
blobc13e2b912ecd1f0cd82bfe9f469a8c6bcf9ebdd2
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
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 // This file defines a strongly-typed opaque gamepad handle
8 //
9 // The handle is designed to be copied around and passed over IPC. It keeps
10 // track of which "provider" created the handle so it can ensure that
11 // providers are never mixed. It also allows each provider to have its own
12 // algorithm for generating gamepad IDs, since the VR and Platform services
13 // do it differently.
15 #ifndef mozilla_dom_gamepad_GamepadHandle_h
16 #define mozilla_dom_gamepad_GamepadHandle_h
18 #include "PLDHashTable.h"
19 #include <type_traits>
20 #include <cinttypes>
22 namespace IPC {
24 template <class>
25 struct ParamTraits;
27 } // namespace IPC
29 namespace mozilla::gfx {
31 class VRDisplayClient;
32 class VRManager;
34 } // namespace mozilla::gfx
36 namespace mozilla::dom {
38 class GamepadPlatformService;
39 class GamepadServiceTest;
40 class XRInputSource;
42 // The "kind" of a gamepad handle is based on which provider created it
43 enum class GamepadHandleKind : uint8_t {
44 GamepadPlatformManager,
45 VR,
48 class GamepadHandle {
49 public:
50 // Allow handle to be passed around as a simple object
51 GamepadHandle() = default;
52 GamepadHandle(const GamepadHandle&) = default;
53 GamepadHandle& operator=(const GamepadHandle&) = default;
55 // Helps code know which manager to send requests to
56 GamepadHandleKind GetKind() const;
58 // Define operators so the handle can compared and stored in maps
59 friend bool operator==(const GamepadHandle& a, const GamepadHandle& b);
60 friend bool operator!=(const GamepadHandle& a, const GamepadHandle& b);
61 friend bool operator<(const GamepadHandle& a, const GamepadHandle& b);
63 PLDHashNumber Hash() const;
65 private:
66 explicit GamepadHandle(uint32_t aValue, GamepadHandleKind aKind);
67 uint32_t GetValue() const { return mValue; }
69 uint32_t mValue{0};
70 GamepadHandleKind mKind{GamepadHandleKind::GamepadPlatformManager};
72 // These are the classes that are "gamepad managers". They are allowed to
73 // create new handles and inspect their actual value
74 friend class mozilla::dom::GamepadPlatformService;
75 friend class mozilla::dom::GamepadServiceTest;
76 friend class mozilla::dom::XRInputSource;
77 friend class mozilla::gfx::VRDisplayClient;
78 friend class mozilla::gfx::VRManager;
80 // Allow IPDL to serialize us
81 friend struct IPC::ParamTraits<mozilla::dom::GamepadHandle>;
84 static_assert(std::is_trivially_copyable<GamepadHandle>::value,
85 "GamepadHandle must be trivially copyable");
87 } // namespace mozilla::dom
89 #endif // mozilla_dom_gamepad_GamepadHandle_h