HIDGamepadProvider.h [plain text]
#ifndef HIDGamepadProvider_h
#define HIDGamepadProvider_h
#if ENABLE(GAMEPAD)
#include "GamepadProvider.h"
#include "HIDGamepad.h"
#include "Timer.h"
#include <IOKit/hid/IOHIDManager.h>
#include <wtf/Deque.h>
#include <wtf/HashMap.h>
#include <wtf/HashSet.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();
virtual void startMonitoringGamepads(GamepadProviderClient*);
virtual void stopMonitoringGamepads(GamepadProviderClient*);
virtual const Vector<PlatformGamepad*>& platformGamepads() { return m_gamepadVector; }
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;
HashSet<GamepadProviderClient*> m_clients;
bool m_shouldDispatchCallbacks;
Timer m_connectionDelayTimer;
Timer m_inputNotificationTimer;
};
}
#endif // ENABLE(GAMEPAD)
#endif // HIDGamepadProvider_h