Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(457)

Side by Side Diff: content/browser/gamepad/xbox_data_fetcher_mac.h

Issue 1586663006: Refactoring gamepad polling to support dynamically added sources (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_GAMEPAD_XBOX_DATA_FETCHER_MAC_H_ 5 #ifndef CONTENT_BROWSER_GAMEPAD_XBOX_DATA_FETCHER_MAC_H_
6 #define CONTENT_BROWSER_GAMEPAD_XBOX_DATA_FETCHER_MAC_H_ 6 #define CONTENT_BROWSER_GAMEPAD_XBOX_DATA_FETCHER_MAC_H_
7 7
8 #include <CoreFoundation/CoreFoundation.h> 8 #include <CoreFoundation/CoreFoundation.h>
9 #include <IOKit/IOKitLib.h> 9 #include <IOKit/IOKitLib.h>
10 #include <stddef.h> 10 #include <stddef.h>
11 #include <stdint.h> 11 #include <stdint.h>
12 12
13 #include <set> 13 #include <set>
14 14
15 #include "base/mac/scoped_cftyperef.h" 15 #include "base/mac/scoped_cftyperef.h"
16 #include "base/mac/scoped_ioobject.h" 16 #include "base/mac/scoped_ioobject.h"
17 #include "base/mac/scoped_ioplugininterface.h" 17 #include "base/mac/scoped_ioplugininterface.h"
18 #include "base/macros.h" 18 #include "base/macros.h"
19 #include "base/memory/scoped_ptr.h" 19 #include "base/memory/scoped_ptr.h"
20 #include "content/browser/gamepad/gamepad_data_fetcher.h"
21
22 struct IOUSBDeviceStruct320;
23 struct IOUSBInterfaceStruct300;
24
25 namespace content {
20 26
21 class XboxController { 27 class XboxController {
22 public: 28 public:
23 enum ControllerType { 29 enum ControllerType {
24 UNKNOWN_CONTROLLER, 30 UNKNOWN_CONTROLLER,
25 XBOX_360_CONTROLLER, 31 XBOX_360_CONTROLLER,
26 XBOX_ONE_CONTROLLER 32 XBOX_ONE_CONTROLLER
27 }; 33 };
28 34
29 enum LEDPattern { 35 enum LEDPattern {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 void ProcessXbox360Packet(size_t length); 100 void ProcessXbox360Packet(size_t length);
95 void ProcessXboxOnePacket(size_t length); 101 void ProcessXboxOnePacket(size_t length);
96 void QueueRead(); 102 void QueueRead();
97 103
98 void IOError(); 104 void IOError();
99 105
100 void WriteXboxOneInit(); 106 void WriteXboxOneInit();
101 107
102 // Handle for the USB device. IOUSBDeviceStruct320 is the latest version of 108 // Handle for the USB device. IOUSBDeviceStruct320 is the latest version of
103 // the device API that is supported on Mac OS 10.6. 109 // the device API that is supported on Mac OS 10.6.
104 base::mac::ScopedIOPluginInterface<struct IOUSBDeviceStruct320> device_; 110 base::mac::ScopedIOPluginInterface<IOUSBDeviceStruct320> device_;
105 111
106 // Handle for the interface on the device which sends button and analog data. 112 // Handle for the interface on the device which sends button and analog data.
107 // The other interfaces (for the ChatPad and headset) are ignored. 113 // The other interfaces (for the ChatPad and headset) are ignored.
108 base::mac::ScopedIOPluginInterface<struct IOUSBInterfaceStruct300> interface_; 114 base::mac::ScopedIOPluginInterface<IOUSBInterfaceStruct300> interface_;
109 115
110 bool device_is_open_; 116 bool device_is_open_;
111 bool interface_is_open_; 117 bool interface_is_open_;
112 118
113 base::ScopedCFTypeRef<CFRunLoopSourceRef> source_; 119 base::ScopedCFTypeRef<CFRunLoopSourceRef> source_;
114 120
115 // This will be set to the max packet size reported by the interface, which 121 // This will be set to the max packet size reported by the interface, which
116 // is 32 bytes. I would have expected USB to do message framing itself, but 122 // is 32 bytes. I would have expected USB to do message framing itself, but
117 // somehow we still sometimes (rarely!) get packets off the interface which 123 // somehow we still sometimes (rarely!) get packets off the interface which
118 // aren't correctly framed. The 360 controller frames its packets with a 2 124 // aren't correctly framed. The 360 controller frames its packets with a 2
(...skipping 10 matching lines...) Expand all
129 135
130 Delegate* delegate_; 136 Delegate* delegate_;
131 137
132 ControllerType controller_type_; 138 ControllerType controller_type_;
133 int read_endpoint_; 139 int read_endpoint_;
134 int control_endpoint_; 140 int control_endpoint_;
135 141
136 DISALLOW_COPY_AND_ASSIGN(XboxController); 142 DISALLOW_COPY_AND_ASSIGN(XboxController);
137 }; 143 };
138 144
139 class XboxDataFetcher : public XboxController::Delegate { 145 class XboxDataFetcher : public GamepadDataFetcher,
146 public XboxController::Delegate {
140 public: 147 public:
141 class Delegate { 148 XboxDataFetcher();
142 public: 149 ~XboxDataFetcher() override;
143 virtual void XboxDeviceAdd(XboxController* device) = 0;
144 virtual void XboxDeviceRemove(XboxController* device) = 0;
145 virtual void XboxValueChanged(XboxController* device,
146 const XboxController::Data& data) = 0;
147 };
148 150
149 explicit XboxDataFetcher(Delegate* delegate); 151 void GetGamepadData(bool devices_changed_hint) override;
150 virtual ~XboxDataFetcher();
151 152
152 bool RegisterForNotifications(); 153 bool RegisterForNotifications();
153 bool RegisterForDeviceNotifications( 154 bool RegisterForDeviceNotifications(
154 int vendor_id, 155 int vendor_id,
155 int product_id, 156 int product_id,
156 base::mac::ScopedIOObject<io_iterator_t>* added_iter, 157 base::mac::ScopedIOObject<io_iterator_t>* added_iter,
157 base::mac::ScopedIOObject<io_iterator_t>* removed_iter); 158 base::mac::ScopedIOObject<io_iterator_t>* removed_iter);
158 void UnregisterFromNotifications(); 159 void UnregisterFromNotifications();
159 160
160 XboxController* ControllerForLocation(UInt32 location_id); 161 XboxController* ControllerForLocation(UInt32 location_id);
161 162
162 private: 163 private:
163 static void DeviceAdded(void* context, io_iterator_t iterator); 164 static void DeviceAdded(void* context, io_iterator_t iterator);
164 static void DeviceRemoved(void* context, io_iterator_t iterator); 165 static void DeviceRemoved(void* context, io_iterator_t iterator);
166 void OnAddedToProvider() override;
165 void AddController(XboxController* controller); 167 void AddController(XboxController* controller);
166 void RemoveController(XboxController* controller); 168 void RemoveController(XboxController* controller);
167 void RemoveControllerByLocationID(uint32_t id); 169 void RemoveControllerByLocationID(uint32_t id);
168 void XboxControllerGotData(XboxController* controller, 170 void XboxControllerGotData(XboxController* controller,
169 const XboxController::Data& data) override; 171 const XboxController::Data& data) override;
170 void XboxControllerError(XboxController* controller) override; 172 void XboxControllerError(XboxController* controller) override;
171 173
172 Delegate* delegate_; 174 //Delegate* delegate_;
scottmg 2016/01/18 22:54:52 Delete.
173 175
174 std::set<XboxController*> controllers_; 176 std::set<XboxController*> controllers_;
175 177
176 bool listening_; 178 bool listening_;
177 179
178 // port_ owns source_, so this doesn't need to be a ScopedCFTypeRef, but we 180 // port_ owns source_, so this doesn't need to be a ScopedCFTypeRef, but we
179 // do need to maintain a reference to it so we can invalidate it. 181 // do need to maintain a reference to it so we can invalidate it.
180 CFRunLoopSourceRef source_; 182 CFRunLoopSourceRef source_;
181 IONotificationPortRef port_; 183 IONotificationPortRef port_;
182 base::mac::ScopedIOObject<io_iterator_t> xbox_360_device_added_iter_; 184 base::mac::ScopedIOObject<io_iterator_t> xbox_360_device_added_iter_;
183 base::mac::ScopedIOObject<io_iterator_t> xbox_360_device_removed_iter_; 185 base::mac::ScopedIOObject<io_iterator_t> xbox_360_device_removed_iter_;
184 base::mac::ScopedIOObject<io_iterator_t> xbox_one_device_added_iter_; 186 base::mac::ScopedIOObject<io_iterator_t> xbox_one_device_added_iter_;
185 base::mac::ScopedIOObject<io_iterator_t> xbox_one_device_removed_iter_; 187 base::mac::ScopedIOObject<io_iterator_t> xbox_one_device_removed_iter_;
186 188
187 DISALLOW_COPY_AND_ASSIGN(XboxDataFetcher); 189 DISALLOW_COPY_AND_ASSIGN(XboxDataFetcher);
188 }; 190 };
189 191
192 } // namespace content
scottmg 2016/01/18 22:54:52 2 space before //
193
190 #endif // CONTENT_BROWSER_GAMEPAD_XBOX_DATA_FETCHER_MAC_H_ 194 #endif // CONTENT_BROWSER_GAMEPAD_XBOX_DATA_FETCHER_MAC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698