2015-05-23 22:55:12 -06:00
|
|
|
// Copyright 2010 Dolphin Emulator Project
|
2015-05-17 17:08:10 -06:00
|
|
|
// Licensed under GPLv2+
|
2014-02-10 11:54:46 -07:00
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
2010-04-01 20:48:24 -06:00
|
|
|
|
2017-11-04 08:37:03 -06:00
|
|
|
#include <atomic>
|
2017-02-19 01:00:00 -07:00
|
|
|
#include <functional>
|
2019-01-10 08:02:38 -07:00
|
|
|
#include <list>
|
2017-11-10 13:29:25 -07:00
|
|
|
#include <memory>
|
|
|
|
#include <mutex>
|
2014-02-17 03:18:15 -07:00
|
|
|
|
2018-10-03 01:34:27 -06:00
|
|
|
#include "Common/WindowSystemInfo.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "InputCommon/ControllerInterface/Device.h"
|
2010-04-01 20:48:24 -06:00
|
|
|
|
|
|
|
// enable disable sources
|
|
|
|
#ifdef _WIN32
|
2017-11-10 10:56:13 -07:00
|
|
|
#define CIFACE_USE_WIN32
|
2010-07-16 13:17:35 -06:00
|
|
|
#endif
|
|
|
|
#if defined(HAVE_X11) && HAVE_X11
|
|
|
|
#define CIFACE_USE_XLIB
|
|
|
|
#endif
|
2010-04-02 03:41:43 -06:00
|
|
|
#if defined(__APPLE__)
|
|
|
|
#define CIFACE_USE_OSX
|
|
|
|
#endif
|
2015-06-28 18:17:35 -06:00
|
|
|
#if defined(HAVE_LIBEVDEV) && defined(HAVE_LIBUDEV)
|
|
|
|
#define CIFACE_USE_EVDEV
|
|
|
|
#endif
|
2015-10-24 21:20:03 -06:00
|
|
|
#if defined(USE_PIPES)
|
|
|
|
#define CIFACE_USE_PIPES
|
|
|
|
#endif
|
2019-10-26 10:05:16 -06:00
|
|
|
#define CIFACE_USE_DUALSHOCKUDPCLIENT
|
2013-06-16 18:07:10 -06:00
|
|
|
|
2010-04-01 20:48:24 -06:00
|
|
|
//
|
2014-01-30 17:51:21 -07:00
|
|
|
// ControllerInterface
|
2010-04-01 20:48:24 -06:00
|
|
|
//
|
2014-01-30 17:51:21 -07:00
|
|
|
// Some crazy shit I made to control different device inputs and outputs
|
|
|
|
// from lots of different sources, hopefully more easily.
|
2010-04-01 20:48:24 -06:00
|
|
|
//
|
2014-09-04 18:41:42 -06:00
|
|
|
class ControllerInterface : public ciface::Core::DeviceContainer
|
2010-04-01 20:48:24 -06:00
|
|
|
{
|
|
|
|
public:
|
2019-01-10 08:02:38 -07:00
|
|
|
using HotplugCallbackHandle = std::list<std::function<void()>>::iterator;
|
|
|
|
|
2018-10-03 01:34:27 -06:00
|
|
|
ControllerInterface() : m_is_init(false) {}
|
|
|
|
void Initialize(const WindowSystemInfo& wsi);
|
2018-10-27 04:06:35 -06:00
|
|
|
void ChangeWindow(void* hwnd);
|
2016-10-16 14:39:05 -06:00
|
|
|
void RefreshDevices();
|
2010-10-12 13:42:29 -06:00
|
|
|
void Shutdown();
|
2016-06-25 13:46:39 -06:00
|
|
|
void AddDevice(std::shared_ptr<ciface::Core::Device> device);
|
2016-07-14 09:45:59 -06:00
|
|
|
void RemoveDevice(std::function<bool(const ciface::Core::Device*)> callback);
|
2010-06-20 21:12:16 -06:00
|
|
|
bool IsInit() const { return m_is_init; }
|
2014-11-13 01:55:14 -07:00
|
|
|
void UpdateInput();
|
2010-04-01 20:48:24 -06:00
|
|
|
|
2019-01-10 08:02:38 -07:00
|
|
|
HotplugCallbackHandle RegisterDevicesChangedCallback(std::function<void(void)> callback);
|
|
|
|
void UnregisterDevicesChangedCallback(const HotplugCallbackHandle& handle);
|
2017-11-04 08:36:30 -06:00
|
|
|
void InvokeDevicesChangedCallbacks() const;
|
2016-06-13 03:11:47 -06:00
|
|
|
|
2010-04-01 20:48:24 -06:00
|
|
|
private:
|
2019-01-10 08:02:38 -07:00
|
|
|
std::list<std::function<void()>> m_devices_changed_callbacks;
|
2017-11-10 13:29:25 -07:00
|
|
|
mutable std::mutex m_callbacks_mutex;
|
2019-01-02 07:19:42 -07:00
|
|
|
std::atomic<bool> m_is_init;
|
2017-11-04 08:37:03 -06:00
|
|
|
std::atomic<bool> m_is_populating_devices{false};
|
2018-10-03 01:34:27 -06:00
|
|
|
WindowSystemInfo m_wsi;
|
2010-04-01 20:48:24 -06:00
|
|
|
};
|
|
|
|
|
2010-10-12 13:42:29 -06:00
|
|
|
extern ControllerInterface g_controller_interface;
|