1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/osx/core/hid.h
3 // Purpose: DARWIN HID layer for WX
7 // Copyright: (c) Ryan Norton
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ===========================================================================
13 // ===========================================================================
15 // ---------------------------------------------------------------------------
17 // ---------------------------------------------------------------------------
19 #ifndef _WX_MACCARBONHID_H_
20 #define _WX_MACCARBONHID_H_
23 #include "wx/string.h"
28 #include <IOKit/IOKitLib.h>
29 #include <IOKit/IOCFPlugIn.h>
30 #include <IOKit/hid/IOHIDLib.h>
31 #include <IOKit/hid/IOHIDKeys.h>
32 #include <Kernel/IOKit/hidsystem/IOHIDUsageTables.h>
34 //Darn apple - doesn't properly wrap their headers in extern "C"!
35 //http://www.macosx.com/forums/archive/index.php/t-68069.html
37 #include <mach/mach_port.h>
40 #include <mach/mach.h> //this actually includes mach_port.h (see above)
42 // ===========================================================================
44 // ===========================================================================
47 // ---------------------------------------------------------------------------
50 // A wrapper around OS X HID Manager procedures.
51 // The tutorial "Working With HID Class Device Interfaces" Is
52 // Quite good, as is the sample program associated with it
53 // (Depite the author's protests!).
54 // ---------------------------------------------------------------------------
55 class WXDLLIMPEXP_CORE wxHIDDevice
58 wxHIDDevice() : m_ppDevice(NULL
), m_ppQueue(NULL
), m_pCookies(NULL
) {}
60 bool Create (int nClass
= -1, int nType
= -1, int nDev
= 1);
62 static size_t GetCount(int nClass
= -1, int nType
= -1);
64 void AddCookie(CFTypeRef Data
, int i
);
65 void AddCookieInQueue(CFTypeRef Data
, int i
);
66 void InitCookies(size_t dwSize
, bool bQueue
= false);
68 //Must be implemented by derived classes
69 //builds the cookie array -
70 //first call InitCookies to initialize the cookie
71 //array, then AddCookie to add a cookie at a certain point in an array
72 virtual void BuildCookies(CFArrayRef Array
) = 0;
74 //checks to see whether the cookie at nIndex is active (element value != 0)
75 bool IsActive(int nIndex
);
77 //checks to see whether an element in the internal cookie array
79 bool HasElement(int nIndex
);
81 //closes the device and cleans the queue and cookies
82 virtual ~wxHIDDevice();
85 IOHIDDeviceInterface
** m_ppDevice
; //this, essentially
86 IOHIDQueueInterface
** m_ppQueue
; //queue (if we want one)
87 IOHIDElementCookie
* m_pCookies
; //cookies
89 wxString m_szProductName
; //product name
90 int m_nProductId
; //product id
91 int m_nManufacturerId
; //manufacturer id
92 mach_port_t m_pPort
; //mach port to use
95 // ---------------------------------------------------------------------------
98 // Semi-simple implementation that opens a connection to the first
99 // keyboard of the machine. Used in wxGetKeyState.
100 // ---------------------------------------------------------------------------
101 class WXDLLIMPEXP_CORE wxHIDKeyboard
: public wxHIDDevice
104 static int GetCount();
105 bool Create(int nDev
= 1);
106 void AddCookie(CFTypeRef Data
, int i
);
107 virtual void BuildCookies(CFArrayRef Array
);
108 void DoBuildCookies(CFArrayRef Array
);
114 // _WX_MACCARBONHID_H_