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