#ifndef DEVICE_GAMEPAD_GAMEPAD_DEVICE_MAC_H_
#define DEVICE_GAMEPAD_GAMEPAD_DEVICE_MAC_H_
#include <stddef.h>
#include <CoreFoundation/CoreFoundation.h>
#include <ForceFeedback/ForceFeedback.h>
#include <IOKit/hid/IOHIDManager.h>
#include "base/memory/weak_ptr.h"
#include "device/gamepad/abstract_haptic_gamepad.h"
#include "device/gamepad/gamepad_standard_mappings.h"
#include "device/gamepad/public/cpp/gamepad.h"
namespace device {
class Dualshock4Controller;
class HidHapticGamepad;
class XboxHidController;
class GamepadDeviceMac final : public AbstractHapticGamepad {
public:
GamepadDeviceMac(int location_id,
IOHIDDeviceRef device_ref,
base::StringPiece product_name,
int vendor_id,
int product_id);
~GamepadDeviceMac() override;
bool AddButtonsAndAxes(Gamepad* gamepad);
void UpdateGamepadForValue(IOHIDValueRef value, Gamepad* gamepad);
int GetLocationId() { return location_id_; }
bool IsSameDevice(IOHIDDeviceRef device) { return device == device_ref_; }
bool SupportsVibration();
void SetVibration(mojom::GamepadEffectParametersPtr params) override;
void SetZeroVibration() override;
base::WeakPtr<AbstractHapticGamepad> GetWeakPtr() override;
private:
void DoShutdown() override;
bool AddButtons(Gamepad* gamepad);
bool AddAxes(Gamepad* gamepad);
static bool CheckCollection(IOHIDElementRef element);
static FFDeviceObjectReference CreateForceFeedbackDevice(
IOHIDDeviceRef device_ref);
static FFEffectObjectReference CreateForceFeedbackEffect(
FFDeviceObjectReference ff_device_ref,
FFEFFECT* ff_effect,
FFCUSTOMFORCE* ff_custom_force,
LONG* force_data,
DWORD* axes_data,
LONG* direction_data);
int location_id_;
IOHIDDeviceRef device_ref_;
GamepadBusType bus_type_;
IOHIDElementRef button_elements_[Gamepad::kButtonsLengthCap];
IOHIDElementRef axis_elements_[Gamepad::kAxesLengthCap];
CFIndex axis_minimums_[Gamepad::kAxesLengthCap];
CFIndex axis_maximums_[Gamepad::kAxesLengthCap];
CFIndex axis_report_sizes_[Gamepad::kAxesLengthCap];
FFDeviceObjectReference ff_device_ref_;
FFEffectObjectReference ff_effect_ref_;
FFEFFECT ff_effect_;
FFCUSTOMFORCE ff_custom_force_;
LONG force_data_[2];
DWORD axes_data_[2];
LONG direction_data_[2];
std::unique_ptr<Dualshock4Controller> dualshock4_;
std::unique_ptr<XboxHidController> xbox_hid_;
std::unique_ptr<HidHapticGamepad> hid_haptics_;
base::WeakPtrFactory<GamepadDeviceMac> weak_factory_{this};
};
}
#endif