/src/ois/includes/mac/MacHIDManager.h

https://bitbucket.org/cabalistic/ogredeps/ · C Header · 103 lines · 52 code · 18 blank · 33 comment · 0 complexity · 2c8a1eb12d7e5e840443a8d8d706cc66 MD5 · raw file

  1. /*
  2. The zlib/libpng License
  3. Copyright (c) 2007 Phillip
  4. This software is provided 'as-is', without any express or implied warranty. In no event will
  5. the authors be held liable for any damages arising from the use of this software.
  6. Permission is granted to anyone to use this software for any purpose, including commercial
  7. applications, and to alter it and redistribute it freely, subject to the following
  8. restrictions:
  9. 1. The origin of this software must not be misrepresented; you must not claim that
  10. you wrote the original software. If you use this software in a product,
  11. an acknowledgment in the product documentation would be appreciated but is
  12. not required.
  13. 2. Altered source versions must be plainly marked as such, and must not be
  14. misrepresented as being the original software.
  15. 3. This notice may not be removed or altered from any source distribution.
  16. */
  17. #ifndef OIS_MacHIDManager_Header
  18. #define OIS_MacHIDManager_Header
  19. #include "OISPrereqs.h"
  20. #include "mac/MacPrereqs.h"
  21. #include "OISFactoryCreator.h"
  22. #import <CoreFoundation/CFString.h>
  23. #import <IOKit/IOKitLib.h>
  24. #import <IOKit/IOCFPlugIn.h>
  25. #import <IOKit/hid/IOHIDLib.h>
  26. #import <IOKit/hid/IOHIDKeys.h>
  27. #import <Kernel/IOKit/hidsystem/IOHIDUsageTables.h>
  28. namespace OIS
  29. {
  30. //Information needed to create Mac HID Devices
  31. class HidInfo
  32. {
  33. public:
  34. HidInfo() : type(OISUnknown), numButtons(0), numHats(0), numAxes(0), inUse(false), interface(0)
  35. {
  36. }
  37. //Useful tracking information
  38. Type type;
  39. std::string vendor;
  40. std::string productKey;
  41. std::string combinedKey;
  42. //Retain some count information for recreating devices without having to reparse
  43. int numButtons;
  44. int numHats;
  45. int numAxes;
  46. bool inUse;
  47. //Used for opening a read/write/tracking interface to device
  48. IOHIDDeviceInterface **interface;
  49. };
  50. typedef std::vector<HidInfo*> HidInfoList;
  51. class MacHIDManager : public FactoryCreator
  52. {
  53. public:
  54. MacHIDManager();
  55. ~MacHIDManager();
  56. void initialize();
  57. void iterateAndOpenDevices(io_iterator_t iterator);
  58. io_iterator_t lookUpDevices(int usage, int page);
  59. //FactoryCreator Overrides
  60. /** @copydoc FactoryCreator::deviceList */
  61. DeviceList freeDeviceList();
  62. /** @copydoc FactoryCreator::totalDevices */
  63. int totalDevices(Type iType);
  64. /** @copydoc FactoryCreator::freeDevices */
  65. int freeDevices(Type iType);
  66. /** @copydoc FactoryCreator::vendorExist */
  67. bool vendorExist(Type iType, const std::string & vendor);
  68. /** @copydoc FactoryCreator::createObject */
  69. Object* createObject(InputManager* creator, Type iType, bool bufferMode, const std::string & vendor = "");
  70. /** @copydoc FactoryCreator::destroyObject */
  71. void destroyObject(Object* obj);
  72. private:
  73. HidInfo* enumerateDeviceProperties(CFMutableDictionaryRef propertyMap);
  74. void parseDeviceProperties(CFDictionaryRef properties);
  75. void parseDevicePropertiesGroup(CFDictionaryRef properties);
  76. HidInfoList mDeviceList;
  77. };
  78. }
  79. #endif