| 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 DEVICE_GAMEPAD_XBOX_DATA_FETCHER_MAC_H_ | 5 #ifndef DEVICE_GAMEPAD_XBOX_DATA_FETCHER_MAC_H_ |
| 6 #define DEVICE_GAMEPAD_XBOX_DATA_FETCHER_MAC_H_ | 6 #define DEVICE_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 <memory> | 13 #include <memory> |
| 14 #include <set> | 14 #include <set> |
| 15 | 15 |
| 16 #include "base/mac/scoped_cftyperef.h" | 16 #include "base/mac/scoped_cftyperef.h" |
| 17 #include "base/mac/scoped_ioobject.h" | 17 #include "base/mac/scoped_ioobject.h" |
| 18 #include "base/mac/scoped_ioplugininterface.h" | 18 #include "base/mac/scoped_ioplugininterface.h" |
| 19 #include "base/macros.h" | 19 #include "base/macros.h" |
| 20 #include "device/gamepad/gamepad_data_fetcher.h" |
| 21 |
| 22 struct IOUSBDeviceStruct320; |
| 23 struct IOUSBInterfaceStruct300; |
| 24 |
| 25 namespace device { |
| 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 Loading... |
| 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 Loading... |
| 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 typedef GamepadDataFetcherFactoryImpl<XboxDataFetcher, |
| 142 public: | 149 GAMEPAD_SOURCE_MAC_XBOX> |
| 143 virtual void XboxDeviceAdd(XboxController* device) = 0; | 150 Factory; |
| 144 virtual void XboxDeviceRemove(XboxController* device) = 0; | |
| 145 virtual void XboxValueChanged(XboxController* device, | |
| 146 const XboxController::Data& data) = 0; | |
| 147 }; | |
| 148 | 151 |
| 149 explicit XboxDataFetcher(Delegate* delegate); | 152 XboxDataFetcher(); |
| 150 virtual ~XboxDataFetcher(); | 153 ~XboxDataFetcher() override; |
| 154 |
| 155 GamepadSource source() override; |
| 156 |
| 157 void GetGamepadData(bool devices_changed_hint) override; |
| 151 | 158 |
| 152 bool RegisterForNotifications(); | 159 bool RegisterForNotifications(); |
| 153 bool RegisterForDeviceNotifications( | 160 bool RegisterForDeviceNotifications( |
| 154 int vendor_id, | 161 int vendor_id, |
| 155 int product_id, | 162 int product_id, |
| 156 base::mac::ScopedIOObject<io_iterator_t>* added_iter, | 163 base::mac::ScopedIOObject<io_iterator_t>* added_iter, |
| 157 base::mac::ScopedIOObject<io_iterator_t>* removed_iter); | 164 base::mac::ScopedIOObject<io_iterator_t>* removed_iter); |
| 158 void UnregisterFromNotifications(); | 165 void UnregisterFromNotifications(); |
| 159 | 166 |
| 160 XboxController* ControllerForLocation(UInt32 location_id); | 167 XboxController* ControllerForLocation(UInt32 location_id); |
| 161 | 168 |
| 162 private: | 169 private: |
| 163 static void DeviceAdded(void* context, io_iterator_t iterator); | 170 static void DeviceAdded(void* context, io_iterator_t iterator); |
| 164 static void DeviceRemoved(void* context, io_iterator_t iterator); | 171 static void DeviceRemoved(void* context, io_iterator_t iterator); |
| 172 void OnAddedToProvider() override; |
| 165 void AddController(XboxController* controller); | 173 void AddController(XboxController* controller); |
| 166 void RemoveController(XboxController* controller); | 174 void RemoveController(XboxController* controller); |
| 167 void RemoveControllerByLocationID(uint32_t id); | 175 void RemoveControllerByLocationID(uint32_t id); |
| 168 void XboxControllerGotData(XboxController* controller, | 176 void XboxControllerGotData(XboxController* controller, |
| 169 const XboxController::Data& data) override; | 177 const XboxController::Data& data) override; |
| 170 void XboxControllerError(XboxController* controller) override; | 178 void XboxControllerError(XboxController* controller) override; |
| 171 | 179 |
| 172 Delegate* delegate_; | |
| 173 | |
| 174 std::set<XboxController*> controllers_; | 180 std::set<XboxController*> controllers_; |
| 175 | 181 |
| 176 bool listening_; | 182 bool listening_; |
| 177 | 183 |
| 178 // port_ owns source_, so this doesn't need to be a ScopedCFTypeRef, but we | 184 // 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. | 185 // do need to maintain a reference to it so we can invalidate it. |
| 180 CFRunLoopSourceRef source_; | 186 CFRunLoopSourceRef source_; |
| 181 IONotificationPortRef port_; | 187 IONotificationPortRef port_; |
| 182 base::mac::ScopedIOObject<io_iterator_t> xbox_360_device_added_iter_; | 188 base::mac::ScopedIOObject<io_iterator_t> xbox_360_device_added_iter_; |
| 183 base::mac::ScopedIOObject<io_iterator_t> xbox_360_device_removed_iter_; | 189 base::mac::ScopedIOObject<io_iterator_t> xbox_360_device_removed_iter_; |
| 184 base::mac::ScopedIOObject<io_iterator_t> xbox_one_device_added_iter_; | 190 base::mac::ScopedIOObject<io_iterator_t> xbox_one_device_added_iter_; |
| 185 base::mac::ScopedIOObject<io_iterator_t> xbox_one_device_removed_iter_; | 191 base::mac::ScopedIOObject<io_iterator_t> xbox_one_device_removed_iter_; |
| 186 | 192 |
| 187 DISALLOW_COPY_AND_ASSIGN(XboxDataFetcher); | 193 DISALLOW_COPY_AND_ASSIGN(XboxDataFetcher); |
| 188 }; | 194 }; |
| 189 | 195 |
| 196 } // namespace device |
| 197 |
| 190 #endif // DEVICE_GAMEPAD_XBOX_DATA_FETCHER_MAC_H_ | 198 #endif // DEVICE_GAMEPAD_XBOX_DATA_FETCHER_MAC_H_ |
| OLD | NEW |