1 //////////////////////////////////////////////////////////// 2 // 3 // SFML - Simple and Fast Multimedia Library 4 // Copyright (C) 2007-2018 Marco Antognini (antognini.marco@gmail.com), 5 // Laurent Gomila (laurent@sfml-dev.org) 6 // 7 // This software is provided 'as-is', without any express or implied warranty. 8 // In no event will the authors be held liable for any damages arising from the use of this software. 9 // 10 // Permission is granted to anyone to use this software for any purpose, 11 // including commercial applications, and to alter it and redistribute it freely, 12 // subject to the following restrictions: 13 // 14 // 1. The origin of this software must not be misrepresented; 15 // you must not claim that you wrote the original software. 16 // If you use this software in a product, an acknowledgment 17 // in the product documentation would be appreciated but is not required. 18 // 19 // 2. Altered source versions must be plainly marked as such, 20 // and must not be misrepresented as being the original software. 21 // 22 // 3. This notice may not be removed or altered from any source distribution. 23 // 24 //////////////////////////////////////////////////////////// 25 26 #ifndef SFML_HIDJOYSTICKMANAGER_HPP 27 #define SFML_HIDJOYSTICKMANAGER_HPP 28 29 //////////////////////////////////////////////////////////// 30 // Headers 31 //////////////////////////////////////////////////////////// 32 #include <SFML/System/NonCopyable.hpp> 33 #include <IOKit/hid/IOHIDDevice.h> 34 #include <IOKit/hid/IOHIDManager.h> 35 36 namespace sf 37 { 38 namespace priv 39 { 40 //////////////////////////////////////////////////////////// 41 /// \brief sf::priv::InputImpl helper 42 /// 43 /// This class manage as a singleton instance the joysticks. 44 /// It's only purpose is to help sf::priv::JoystickImpl class. 45 /// 46 //////////////////////////////////////////////////////////// 47 class HIDJoystickManager : NonCopyable 48 { 49 public: 50 51 //////////////////////////////////////////////////////////// 52 /// \brief Get the unique instance of the class 53 /// 54 /// \note Private use only 55 /// 56 /// \return Reference to the HIDJoystickManager instance 57 /// 58 //////////////////////////////////////////////////////////// 59 static HIDJoystickManager& getInstance(); 60 61 public: 62 63 //////////////////////////////////////////////////////////// 64 /// \brief Get the number of currently connected joystick 65 /// 66 //////////////////////////////////////////////////////////// 67 unsigned int getJoystickCount(); 68 69 //////////////////////////////////////////////////////////// 70 /// \brief Copy the devices associated with this HID manager 71 /// 72 /// \return a retained CFSetRef of IOHIDDeviceRef or NULL 73 /// 74 //////////////////////////////////////////////////////////// 75 CFSetRef copyJoysticks(); 76 77 private: 78 79 //////////////////////////////////////////////////////////// 80 /// \brief Default constructor 81 /// 82 //////////////////////////////////////////////////////////// 83 HIDJoystickManager(); 84 85 //////////////////////////////////////////////////////////// 86 /// \brief Destructor 87 /// 88 //////////////////////////////////////////////////////////// 89 ~HIDJoystickManager(); 90 91 //////////////////////////////////////////////////////////// 92 /// \brief Make sure all event have been processed in the run loop 93 /// 94 //////////////////////////////////////////////////////////// 95 void update(); 96 97 private: 98 99 //////////////////////////////////////////////////////////// 100 /// \brief Private "plug-in" callback 101 /// \note Only 'context' parameter is used. 102 /// \see IOHIDDeviceCallback 103 /// 104 //////////////////////////////////////////////////////////// 105 static void pluggedIn(void* context, IOReturn, void*, IOHIDDeviceRef); 106 107 //////////////////////////////////////////////////////////// 108 /// \brief Private "plug-out" callback 109 /// \note Only 'context' parameter is used. 110 /// \see IOHIDDeviceCallback 111 /// 112 //////////////////////////////////////////////////////////// 113 static void pluggedOut(void* context, IOReturn, void*, IOHIDDeviceRef); 114 115 private: 116 117 //////////////////////////////////////////////////////////// 118 // Member data 119 //////////////////////////////////////////////////////////// 120 IOHIDManagerRef m_manager; ///< HID Manager 121 unsigned int m_joystickCount;///< Number of joysticks currently connected 122 }; 123 124 125 } // namespace priv 126 127 } // namespace sf 128 129 #endif 130