1 // Copyright (c) 2012 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.
5 #ifndef CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_MAC_H_
6 #define CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_MAC_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/mac/scoped_cftyperef.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "build/build_config.h"
13 #include "content/browser/gamepad/gamepad_data_fetcher.h"
14 #include "content/browser/gamepad/gamepad_standard_mappings.h"
15 #include "content/browser/gamepad/xbox_data_fetcher_mac.h"
16 #include "content/common/gamepad_hardware_buffer.h"
17 #include "third_party/WebKit/public/platform/WebGamepads.h"
19 #include <CoreFoundation/CoreFoundation.h>
20 #include <IOKit/hid/IOHIDManager.h>
30 class GamepadPlatformDataFetcherMac
: public GamepadDataFetcher
,
31 public XboxDataFetcher::Delegate
{
33 GamepadPlatformDataFetcherMac();
34 virtual ~GamepadPlatformDataFetcherMac();
35 virtual void GetGamepadData(blink::WebGamepads
* pads
,
36 bool devices_changed_hint
) OVERRIDE
;
37 virtual void PauseHint(bool paused
) OVERRIDE
;
41 base::ScopedCFTypeRef
<IOHIDManagerRef
> hid_manager_ref_
;
43 static GamepadPlatformDataFetcherMac
* InstanceFromContext(void* context
);
44 static void DeviceAddCallback(void* context
,
48 static void DeviceRemoveCallback(void* context
,
52 static void ValueChangedCallback(void* context
,
57 size_t GetEmptySlot();
58 size_t GetSlotForDevice(IOHIDDeviceRef device
);
59 size_t GetSlotForXboxDevice(XboxController
* device
);
61 void DeviceAdd(IOHIDDeviceRef device
);
62 void AddButtonsAndAxes(NSArray
* elements
, size_t slot
);
63 void DeviceRemove(IOHIDDeviceRef device
);
64 void ValueChanged(IOHIDValueRef value
);
66 virtual void XboxDeviceAdd(XboxController
* device
) OVERRIDE
;
67 virtual void XboxDeviceRemove(XboxController
* device
) OVERRIDE
;
68 virtual void XboxValueChanged(XboxController
* device
,
69 const XboxController::Data
& data
) OVERRIDE
;
71 void RegisterForNotifications();
72 void UnregisterFromNotifications();
74 scoped_ptr
<XboxDataFetcher
> xbox_fetcher_
;
76 blink::WebGamepads data_
;
78 // Side-band data that's not passed to the consumer, but we need to maintain
80 struct AssociatedData
{
84 IOHIDDeviceRef device_ref
;
85 IOHIDElementRef button_elements
[blink::WebGamepad::buttonsLengthCap
];
86 IOHIDElementRef axis_elements
[blink::WebGamepad::axesLengthCap
];
87 CFIndex axis_minimums
[blink::WebGamepad::axesLengthCap
];
88 CFIndex axis_maximums
[blink::WebGamepad::axesLengthCap
];
89 // Function to map from device data to standard layout, if available.
90 // May be null if no mapping is available.
91 GamepadStandardMappingFunction mapper
;
94 XboxController
* device
;
99 AssociatedData associated_
[blink::WebGamepads::itemsLengthCap
];
101 DISALLOW_COPY_AND_ASSIGN(GamepadPlatformDataFetcherMac
);
104 } // namespace content
106 #endif // CONTENT_BROWSER_GAMEPAD_GAMEPAD_PLATFORM_DATA_FETCHER_MAC_H_