]>
Commit | Line | Data |
---|---|---|
5c6eb3a8 | 1 | ///////////////////////////////////////////////////////////////////////////// |
233f5738 | 2 | // Name: wx/osx/core/hid.h |
5c6eb3a8 SC |
3 | // Purpose: DARWIN HID layer for WX |
4 | // Author: Ryan Norton | |
5 | // Modified by: | |
6 | // Created: 11/11/2003 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Ryan Norton | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // =========================================================================== | |
13 | // declarations | |
14 | // =========================================================================== | |
15 | ||
16 | // --------------------------------------------------------------------------- | |
17 | // headers | |
18 | // --------------------------------------------------------------------------- | |
19 | ||
20 | #ifndef _WX_MACCARBONHID_H_ | |
21 | #define _WX_MACCARBONHID_H_ | |
22 | ||
23 | #include "wx/defs.h" | |
24 | #include "wx/string.h" | |
25 | ||
26 | //Mac OSX only | |
27 | #ifdef __DARWIN__ | |
28 | ||
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> | |
34 | ||
35 | //Darn apple - doesn't properly wrap their headers in extern "C"! | |
36 | //http://www.macosx.com/forums/archive/index.php/t-68069.html | |
5c6eb3a8 SC |
37 | extern "C" { |
38 | #include <mach/mach_port.h> | |
39 | } | |
40 | ||
41 | #include <mach/mach.h> //this actually includes mach_port.h (see above) | |
42 | ||
43 | // =========================================================================== | |
44 | // definitions | |
45 | // =========================================================================== | |
46 | ||
47 | ||
48 | // --------------------------------------------------------------------------- | |
49 | // wxHIDDevice | |
50 | // | |
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 | |
57 | { | |
58 | public: | |
59 | wxHIDDevice() : m_ppDevice(NULL), m_ppQueue(NULL), m_pCookies(NULL) {} | |
60 | ||
61 | bool Create (int nClass = -1, int nType = -1, int nDev = 1); | |
62 | ||
63 | static size_t GetCount(int nClass = -1, int nType = -1); | |
64 | ||
65 | void AddCookie(CFTypeRef Data, int i); | |
66 | void AddCookieInQueue(CFTypeRef Data, int i); | |
67 | void InitCookies(size_t dwSize, bool bQueue = false); | |
68 | ||
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; | |
74 | ||
75 | //checks to see whether the cookie at nIndex is active (element value != 0) | |
76 | bool IsActive(int nIndex); | |
77 | ||
78 | //checks to see whether an element in the internal cookie array | |
79 | //exists | |
80 | bool HasElement(int nIndex); | |
81 | ||
82 | //closes the device and cleans the queue and cookies | |
83 | virtual ~wxHIDDevice(); | |
84 | ||
85 | protected: | |
86 | IOHIDDeviceInterface** m_ppDevice; //this, essentially | |
87 | IOHIDQueueInterface** m_ppQueue; //queue (if we want one) | |
88 | IOHIDElementCookie* m_pCookies; //cookies | |
89 | ||
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 | |
94 | }; | |
95 | ||
96 | // --------------------------------------------------------------------------- | |
97 | // wxHIDKeyboard | |
98 | // | |
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 | |
103 | { | |
104 | public: | |
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); | |
110 | }; | |
111 | ||
112 | #endif //__DARWIN__ | |
113 | ||
114 | #endif | |
115 | // _WX_MACCARBONHID_H_ |