OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef COMPONENTS_EXO_GAMEPAD_H_ | |
6 #define COMPONENTS_EXO_GAMEPAD_H_ | |
7 | |
8 #include <memory> | |
9 | |
10 #include "base/macros.h" | |
11 #include "base/sequenced_task_runner.h" | |
12 #include "base/threading/thread.h" | |
13 #include "base/threading/thread_task_runner_handle.h" | |
14 #include "device/gamepad/gamepad_data_fetcher.h" | |
15 | |
16 namespace exo { | |
17 class GamepadDelegate; | |
18 | |
19 // This class represents a gamepad, it implements a background thread | |
reveman
2016/06/29 21:55:44
s/a gamepad/one or more gamepads/ as discussed
denniskempin
2016/06/30 00:29:21
Done.
| |
20 // for polling gamepad devices and notifies the GamepadDelegate of any | |
21 // changes. | |
22 class Gamepad { | |
23 public: | |
24 // This class will post tasks to invoke the delegate on the thread runner | |
25 // which is associated with the thread that is creating this instance. | |
26 Gamepad(size_t id, GamepadDelegate* delegate); | |
reveman
2016/06/29 21:55:45
remove id as discussed
denniskempin
2016/06/30 00:29:22
Done.
| |
27 | |
28 // Allows test cases to specify a GamepadDataFetcher to provide mock gamepad | |
29 // data. | |
30 Gamepad(size_t id, | |
reveman
2016/06/29 21:55:45
remove id as discussed
denniskempin
2016/06/30 00:29:22
Done.
| |
31 GamepadDelegate* delegate, | |
32 std::unique_ptr<device::GamepadDataFetcher> fetcher); | |
33 virtual ~Gamepad(); | |
34 | |
35 private: | |
36 // Schedules a poll on the polling thread. Can be called from any thread. | |
37 void ScheduleOnPoll(); | |
38 | |
39 // Polls devices for new data and posts delegate updates. | |
40 // Can only be called on the polling thread. | |
41 void OnPoll(); | |
42 | |
43 // Posts updates of gamepad data to delegate. | |
44 // Can only be called on the polling thread. | |
45 void PostGamepadChanges(const blink::WebGamepads new_state); | |
46 | |
47 // Initializes the underlying gamepad data fetcher. | |
48 // Can only be called on the polling thread. | |
49 void InitializePollingThread(); | |
50 | |
51 // Gamepad id | |
52 size_t id_; | |
reveman
2016/06/29 21:55:45
remove as discussed
denniskempin
2016/06/30 00:29:21
Done.
| |
53 | |
54 // The delegate instance that all events are dispatched to. | |
55 GamepadDelegate* const delegate_; | |
56 | |
57 // Implements the logic to fetch gamepad information from connected devices. | |
58 std::unique_ptr<device::GamepadDataFetcher> fetcher_; | |
59 | |
60 // The thread on which the polling is executed. | |
61 std::unique_ptr<base::Thread> polling_thread_; | |
reveman
2016/06/29 21:55:45
fyi, one thread per gamepad interface instances is
denniskempin
2016/06/30 00:29:21
I agree. We will need some kind of shared service
| |
62 | |
63 // The current state of gamepad. | |
64 blink::WebGamepads state_; | |
65 | |
66 // Reference to the task runner of the thread that created this instance. | |
67 scoped_refptr<base::SingleThreadTaskRunner> origin_task_runner_; | |
68 | |
69 base::ThreadChecker thread_checker_; | |
70 | |
71 DISALLOW_COPY_AND_ASSIGN(Gamepad); | |
72 }; | |
73 | |
74 } // namespace exo | |
75 | |
76 #endif // COMPONENTS_EXO_GAMEPAD_H_ | |
OLD | NEW |