summaryrefslogtreecommitdiff
path: root/chromium/ui/events/ozone/gamepad/gamepad_provider_ozone.h
blob: bcf2487ca8578334c3539ed4b4e1d017fffcf3c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_EVENTS_OZONE_GAMEPAD_GAMEPAD_PROVIDER_OZONE_H_
#define UI_EVENTS_OZONE_GAMEPAD_GAMEPAD_PROVIDER_OZONE_H_

#include <set>
#include <vector>
#include "base/component_export.h"
#include "base/macros.h"
#include "base/observer_list.h"
#include "base/time/time.h"
#include "ui/events/devices/gamepad_device.h"
#include "ui/events/ozone/gamepad/gamepad_observer.h"

namespace base {
template <typename T>
struct DefaultSingletonTraits;
}

namespace ui {

class COMPONENT_EXPORT(EVENTS_OZONE) GamepadProviderOzone {
 public:
  // Get the GamepadProviderOzone instance.
  static GamepadProviderOzone* GetInstance();

  // Dispatch GamepadDevicesUpdate event when gamepad device is connected or
  // disconnected. This function must be called on UI thread.
  void DispatchGamepadDevicesUpdated(
      std::vector<GamepadDevice> gamepad_devices);

  // Dispatch button event when gamepad event is seen.
  // Code is the index of gamepad button or gamepad axis defined in W3C standard
  // gamepad.
  // This function must be called on UI thread.
  void DispatchGamepadEvent(const GamepadEvent& event);

  // Add observer to gamepad provider. This function must be called on UI
  // thread.
  void AddGamepadObserver(GamepadObserver* observer);

  // Remove observer from gamepad provider. This function must be called on UI
  // thread.
  void RemoveGamepadObserver(GamepadObserver* observer);

  // Get the list of currently connected gamepad devices. This function must be
  // called on UI thread.
  std::vector<GamepadDevice> GetGamepadDevices();

 private:
  GamepadProviderOzone();

  ~GamepadProviderOzone();

  // Make SingletonTraits friend to enable singleton.
  friend struct base::DefaultSingletonTraits<GamepadProviderOzone>;

  // Registered observers will receive gamepad device update event and gamepad
  // event.
  base::ObserverList<GamepadObserver>::Unchecked observers_;

  // List of current connected gamepad events.
  std::vector<GamepadDevice> gamepad_devices_;

  DISALLOW_COPY_AND_ASSIGN(GamepadProviderOzone);
};

}  // namespace ui

#endif  // UI_EVENTS_OZONE_GAMEPAD_GAMEPAD_PROVIDER_OZONE_H_