HIDGamepadProvider.h [plain text]
#pragma once
#if ENABLE(GAMEPAD) && PLATFORM(MAC)
#include "GamepadProvider.h"
#include "HIDGamepad.h"
#include "Timer.h"
#include <IOKit/hid/IOHIDManager.h>
#include <wtf/Deque.h>
#include <wtf/HashMap.h>
#include <wtf/NeverDestroyed.h>
#include <wtf/RetainPtr.h>
namespace WebCore {
class GamepadProviderClient;
class HIDGamepadProvider : public GamepadProvider {
WTF_MAKE_NONCOPYABLE(HIDGamepadProvider);
friend class NeverDestroyed<HIDGamepadProvider>;
public:
WEBCORE_EXPORT static HIDGamepadProvider& singleton();
WEBCORE_EXPORT void startMonitoringGamepads(GamepadProviderClient&) final;
WEBCORE_EXPORT void stopMonitoringGamepads(GamepadProviderClient&) final;
const Vector<PlatformGamepad*>& platformGamepads() final { return m_gamepadVector; }
WEBCORE_EXPORT void stopMonitoringInput();
WEBCORE_EXPORT void startMonitoringInput();
void deviceAdded(IOHIDDeviceRef);
void deviceRemoved(IOHIDDeviceRef);
void valuesChanged(IOHIDValueRef);
private:
HIDGamepadProvider();
std::unique_ptr<HIDGamepad> removeGamepadForDevice(IOHIDDeviceRef);
void openAndScheduleManager();
void closeAndUnscheduleManager();
void connectionDelayTimerFired();
void inputNotificationTimerFired();
unsigned indexForNewlyConnectedDevice();
Vector<PlatformGamepad*> m_gamepadVector;
HashMap<IOHIDDeviceRef, std::unique_ptr<HIDGamepad>> m_gamepadMap;
RetainPtr<IOHIDManagerRef> m_manager;
bool m_shouldDispatchCallbacks;
Timer m_connectionDelayTimer;
Timer m_inputNotificationTimer;
};
}
#endif // ENABLE(GAMEPAD) && PLATFORM(MAC)