| OLD | NEW |
| 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 { | |
| 26 | 20 |
| 27 class XboxController { | 21 class XboxController { |
| 28 public: | 22 public: |
| 29 enum ControllerType { | 23 enum ControllerType { |
| 30 UNKNOWN_CONTROLLER, | 24 UNKNOWN_CONTROLLER, |
| 31 XBOX_360_CONTROLLER, | 25 XBOX_360_CONTROLLER, |
| 32 XBOX_ONE_CONTROLLER | 26 XBOX_ONE_CONTROLLER |
| 33 }; | 27 }; |
| 34 | 28 |
| 35 enum LEDPattern { | 29 enum LEDPattern { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 void ProcessXbox360Packet(size_t length); | 94 void ProcessXbox360Packet(size_t length); |
| 101 void ProcessXboxOnePacket(size_t length); | 95 void ProcessXboxOnePacket(size_t length); |
| 102 void QueueRead(); | 96 void QueueRead(); |
| 103 | 97 |
| 104 void IOError(); | 98 void IOError(); |
| 105 | 99 |
| 106 void WriteXboxOneInit(); | 100 void WriteXboxOneInit(); |
| 107 | 101 |
| 108 // Handle for the USB device. IOUSBDeviceStruct320 is the latest version of | 102 // Handle for the USB device. IOUSBDeviceStruct320 is the latest version of |
| 109 // the device API that is supported on Mac OS 10.6. | 103 // the device API that is supported on Mac OS 10.6. |
| 110 base::mac::ScopedIOPluginInterface<IOUSBDeviceStruct320> device_; | 104 base::mac::ScopedIOPluginInterface<struct IOUSBDeviceStruct320> device_; |
| 111 | 105 |
| 112 // Handle for the interface on the device which sends button and analog data. | 106 // Handle for the interface on the device which sends button and analog data. |
| 113 // The other interfaces (for the ChatPad and headset) are ignored. | 107 // The other interfaces (for the ChatPad and headset) are ignored. |
| 114 base::mac::ScopedIOPluginInterface<IOUSBInterfaceStruct300> interface_; | 108 base::mac::ScopedIOPluginInterface<struct IOUSBInterfaceStruct300> interface_; |
| 115 | 109 |
| 116 bool device_is_open_; | 110 bool device_is_open_; |
| 117 bool interface_is_open_; | 111 bool interface_is_open_; |
| 118 | 112 |
| 119 base::ScopedCFTypeRef<CFRunLoopSourceRef> source_; | 113 base::ScopedCFTypeRef<CFRunLoopSourceRef> source_; |
| 120 | 114 |
| 121 // This will be set to the max packet size reported by the interface, which | 115 // This will be set to the max packet size reported by the interface, which |
| 122 // is 32 bytes. I would have expected USB to do message framing itself, but | 116 // is 32 bytes. I would have expected USB to do message framing itself, but |
| 123 // somehow we still sometimes (rarely!) get packets off the interface which | 117 // somehow we still sometimes (rarely!) get packets off the interface which |
| 124 // aren't correctly framed. The 360 controller frames its packets with a 2 | 118 // aren't correctly framed. The 360 controller frames its packets with a 2 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 135 | 129 |
| 136 Delegate* delegate_; | 130 Delegate* delegate_; |
| 137 | 131 |
| 138 ControllerType controller_type_; | 132 ControllerType controller_type_; |
| 139 int read_endpoint_; | 133 int read_endpoint_; |
| 140 int control_endpoint_; | 134 int control_endpoint_; |
| 141 | 135 |
| 142 DISALLOW_COPY_AND_ASSIGN(XboxController); | 136 DISALLOW_COPY_AND_ASSIGN(XboxController); |
| 143 }; | 137 }; |
| 144 | 138 |
| 145 class XboxDataFetcher : public GamepadDataFetcher, | 139 class XboxDataFetcher : public XboxController::Delegate { |
| 146 public XboxController::Delegate { | |
| 147 public: | 140 public: |
| 148 XboxDataFetcher(); | 141 class Delegate { |
| 149 ~XboxDataFetcher() override; | 142 public: |
| 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 }; |
| 150 | 148 |
| 151 void GetGamepadData(bool devices_changed_hint) override; | 149 explicit XboxDataFetcher(Delegate* delegate); |
| 150 virtual ~XboxDataFetcher(); |
| 152 | 151 |
| 153 bool RegisterForNotifications(); | 152 bool RegisterForNotifications(); |
| 154 bool RegisterForDeviceNotifications( | 153 bool RegisterForDeviceNotifications( |
| 155 int vendor_id, | 154 int vendor_id, |
| 156 int product_id, | 155 int product_id, |
| 157 base::mac::ScopedIOObject<io_iterator_t>* added_iter, | 156 base::mac::ScopedIOObject<io_iterator_t>* added_iter, |
| 158 base::mac::ScopedIOObject<io_iterator_t>* removed_iter); | 157 base::mac::ScopedIOObject<io_iterator_t>* removed_iter); |
| 159 void UnregisterFromNotifications(); | 158 void UnregisterFromNotifications(); |
| 160 | 159 |
| 161 XboxController* ControllerForLocation(UInt32 location_id); | 160 XboxController* ControllerForLocation(UInt32 location_id); |
| 162 | 161 |
| 163 private: | 162 private: |
| 164 static void DeviceAdded(void* context, io_iterator_t iterator); | 163 static void DeviceAdded(void* context, io_iterator_t iterator); |
| 165 static void DeviceRemoved(void* context, io_iterator_t iterator); | 164 static void DeviceRemoved(void* context, io_iterator_t iterator); |
| 166 void OnAddedToProvider() override; | |
| 167 void AddController(XboxController* controller); | 165 void AddController(XboxController* controller); |
| 168 void RemoveController(XboxController* controller); | 166 void RemoveController(XboxController* controller); |
| 169 void RemoveControllerByLocationID(uint32_t id); | 167 void RemoveControllerByLocationID(uint32_t id); |
| 170 void XboxControllerGotData(XboxController* controller, | 168 void XboxControllerGotData(XboxController* controller, |
| 171 const XboxController::Data& data) override; | 169 const XboxController::Data& data) override; |
| 172 void XboxControllerError(XboxController* controller) override; | 170 void XboxControllerError(XboxController* controller) override; |
| 173 | 171 |
| 172 Delegate* delegate_; |
| 173 |
| 174 std::set<XboxController*> controllers_; | 174 std::set<XboxController*> controllers_; |
| 175 | 175 |
| 176 bool listening_; | 176 bool listening_; |
| 177 | 177 |
| 178 // port_ owns source_, so this doesn't need to be a ScopedCFTypeRef, but we | 178 // 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. | 179 // do need to maintain a reference to it so we can invalidate it. |
| 180 CFRunLoopSourceRef source_; | 180 CFRunLoopSourceRef source_; |
| 181 IONotificationPortRef port_; | 181 IONotificationPortRef port_; |
| 182 base::mac::ScopedIOObject<io_iterator_t> xbox_360_device_added_iter_; | 182 base::mac::ScopedIOObject<io_iterator_t> xbox_360_device_added_iter_; |
| 183 base::mac::ScopedIOObject<io_iterator_t> xbox_360_device_removed_iter_; | 183 base::mac::ScopedIOObject<io_iterator_t> xbox_360_device_removed_iter_; |
| 184 base::mac::ScopedIOObject<io_iterator_t> xbox_one_device_added_iter_; | 184 base::mac::ScopedIOObject<io_iterator_t> xbox_one_device_added_iter_; |
| 185 base::mac::ScopedIOObject<io_iterator_t> xbox_one_device_removed_iter_; | 185 base::mac::ScopedIOObject<io_iterator_t> xbox_one_device_removed_iter_; |
| 186 | 186 |
| 187 DISALLOW_COPY_AND_ASSIGN(XboxDataFetcher); | 187 DISALLOW_COPY_AND_ASSIGN(XboxDataFetcher); |
| 188 }; | 188 }; |
| 189 | 189 |
| 190 } // namespace content | |
| 191 | |
| 192 #endif // CONTENT_BROWSER_GAMEPAD_XBOX_DATA_FETCHER_MAC_H_ | 190 #endif // CONTENT_BROWSER_GAMEPAD_XBOX_DATA_FETCHER_MAC_H_ |
| OLD | NEW |