| 
									
										
										
										
											2015-05-24 06:55:12 +02:00
										 |  |  | // Copyright 2010 Dolphin Emulator Project
 | 
					
						
							| 
									
										
										
										
											2015-05-18 01:08:10 +02:00
										 |  |  | // Licensed under GPLv2+
 | 
					
						
							| 
									
										
										
										
											2014-02-10 13:54:46 -05:00
										 |  |  | // Refer to the license.txt file included.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <algorithm>
 | 
					
						
							| 
									
										
										
										
											2014-02-17 05:18:15 -05:00
										 |  |  | #include <map>
 | 
					
						
							|  |  |  | #include <sstream>
 | 
					
						
							|  |  |  | #include <string>
 | 
					
						
							|  |  |  | #include <vector>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-07 20:06:58 -05:00
										 |  |  | #include "Common/CommonTypes.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-17 05:18:15 -05:00
										 |  |  | #include "Common/Thread.h"
 | 
					
						
							|  |  |  | #include "InputCommon/ControllerInterface/Device.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-19 02:17:31 +01:00
										 |  |  | #include "InputCommon/ControllerInterface/ExpressionParser.h"
 | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | // enable disable sources
 | 
					
						
							|  |  |  | #ifdef _WIN32
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  | #define CIFACE_USE_XINPUT
 | 
					
						
							|  |  |  | #define CIFACE_USE_DINPUT
 | 
					
						
							| 
									
										
										
										
											2010-07-16 19:17:35 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | #if defined(HAVE_X11) && HAVE_X11
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  | #define CIFACE_USE_XLIB
 | 
					
						
							| 
									
										
										
										
											2010-07-16 19:17:35 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2010-04-02 09:41:43 +00:00
										 |  |  | #if defined(__APPLE__)
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  | #define CIFACE_USE_OSX
 | 
					
						
							| 
									
										
										
										
											2010-04-02 09:41:43 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2014-05-04 19:41:02 -05:00
										 |  |  | #if defined(HAVE_SDL) && HAVE_SDL
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  | #define CIFACE_USE_SDL
 | 
					
						
							| 
									
										
										
										
											2014-05-04 19:41:02 -05:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2015-06-29 12:17:35 +12:00
										 |  |  | #if defined(HAVE_LIBEVDEV) && defined(HAVE_LIBUDEV)
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  | #define CIFACE_USE_EVDEV
 | 
					
						
							| 
									
										
										
										
											2015-06-29 12:17:35 +12:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2015-10-24 20:20:03 -07:00
										 |  |  | #if defined(USE_PIPES)
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  | #define CIFACE_USE_PIPES
 | 
					
						
							| 
									
										
										
										
											2015-10-24 20:20:03 -07:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2013-06-16 20:07:10 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | //
 | 
					
						
							| 
									
										
										
										
											2014-01-30 19:51:21 -05:00
										 |  |  | // ControllerInterface
 | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | //
 | 
					
						
							| 
									
										
										
										
											2014-01-30 19:51:21 -05:00
										 |  |  | // Some crazy shit I made to control different device inputs and outputs
 | 
					
						
							|  |  |  | // from lots of different sources, hopefully more easily.
 | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | //
 | 
					
						
							| 
									
										
										
										
											2014-09-04 19:41:42 -05:00
										 |  |  | class ControllerInterface : public ciface::Core::DeviceContainer | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   //
 | 
					
						
							|  |  |  |   // ControlReference
 | 
					
						
							|  |  |  |   //
 | 
					
						
							|  |  |  |   // These are what you create to actually use the inputs, InputReference or OutputReference.
 | 
					
						
							|  |  |  |   //
 | 
					
						
							|  |  |  |   // After being bound to devices and controls with ControllerInterface::UpdateReference,
 | 
					
						
							|  |  |  |   // each one can link to multiple devices and controls
 | 
					
						
							|  |  |  |   // when you change a ControlReference's expression,
 | 
					
						
							|  |  |  |   // you must use ControllerInterface::UpdateReference on it to rebind controls
 | 
					
						
							|  |  |  |   //
 | 
					
						
							|  |  |  |   class ControlReference | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     friend class ControllerInterface; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   public: | 
					
						
							|  |  |  |     virtual ControlState State(const ControlState state = 0) = 0; | 
					
						
							|  |  |  |     virtual ciface::Core::Device::Control* Detect(const unsigned int ms, | 
					
						
							|  |  |  |                                                   ciface::Core::Device* const device) = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ControlState range; | 
					
						
							|  |  |  |     std::string expression; | 
					
						
							|  |  |  |     const bool is_input; | 
					
						
							|  |  |  |     ciface::ExpressionParser::ExpressionParseStatus parse_error; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     virtual ~ControlReference() { delete parsed_expression; } | 
					
						
							|  |  |  |     int BoundCount() | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       if (parsed_expression) | 
					
						
							|  |  |  |         return parsed_expression->num_controls; | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   protected: | 
					
						
							|  |  |  |     ControlReference(const bool _is_input) | 
					
						
							|  |  |  |         : range(1), is_input(_is_input), parsed_expression(nullptr) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     ciface::ExpressionParser::Expression* parsed_expression; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   //
 | 
					
						
							|  |  |  |   // InputReference
 | 
					
						
							|  |  |  |   //
 | 
					
						
							|  |  |  |   // Control reference for inputs
 | 
					
						
							|  |  |  |   //
 | 
					
						
							|  |  |  |   class InputReference : public ControlReference | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |   public: | 
					
						
							|  |  |  |     InputReference() : ControlReference(true) {} | 
					
						
							|  |  |  |     ControlState State(const ControlState state) override; | 
					
						
							|  |  |  |     ciface::Core::Device::Control* Detect(const unsigned int ms, | 
					
						
							|  |  |  |                                           ciface::Core::Device* const device) override; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   //
 | 
					
						
							|  |  |  |   // OutputReference
 | 
					
						
							|  |  |  |   //
 | 
					
						
							|  |  |  |   // Control reference for outputs
 | 
					
						
							|  |  |  |   //
 | 
					
						
							|  |  |  |   class OutputReference : public ControlReference | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |   public: | 
					
						
							|  |  |  |     OutputReference() : ControlReference(false) {} | 
					
						
							|  |  |  |     ControlState State(const ControlState state) override; | 
					
						
							|  |  |  |     ciface::Core::Device::Control* Detect(const unsigned int ms, | 
					
						
							|  |  |  |                                           ciface::Core::Device* const device) override; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ControllerInterface() : m_is_init(false), m_hwnd(nullptr) {} | 
					
						
							|  |  |  |   void Initialize(void* const hwnd); | 
					
						
							| 
									
										
										
										
											2016-10-16 13:39:05 -07:00
										 |  |  |   void RefreshDevices(); | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   void Shutdown(); | 
					
						
							| 
									
										
										
										
											2016-06-25 21:46:39 +02:00
										 |  |  |   void AddDevice(std::shared_ptr<ciface::Core::Device> device); | 
					
						
							| 
									
										
										
										
											2016-07-14 17:45:59 +02:00
										 |  |  |   void RemoveDevice(std::function<bool(const ciface::Core::Device*)> callback); | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   bool IsInit() const { return m_is_init; } | 
					
						
							|  |  |  |   void UpdateReference(ControlReference* control, | 
					
						
							|  |  |  |                        const ciface::Core::DeviceQualifier& default_device) const; | 
					
						
							|  |  |  |   void UpdateInput(); | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-13 11:11:47 +02:00
										 |  |  |   void RegisterHotplugCallback(std::function<void(void)> callback); | 
					
						
							|  |  |  |   void InvokeHotplugCallbacks() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2016-06-13 11:11:47 +02:00
										 |  |  |   std::vector<std::function<void()>> m_hotplug_callbacks; | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   bool m_is_init; | 
					
						
							|  |  |  |   void* m_hwnd; | 
					
						
							| 
									
										
										
										
											2010-04-02 02:48:24 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-12 19:42:29 +00:00
										 |  |  | extern ControllerInterface g_controller_interface; |