]>
Commit | Line | Data |
---|---|---|
ec8bd392 RN |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: hid.h | |
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 | ///////////////////////////////////////////////////////////////////////////// | |
1553abf4 RN |
11 | // =========================================================================== |
12 | // declarations | |
13 | // =========================================================================== | |
14 | ||
15 | // --------------------------------------------------------------------------- | |
16 | // headers | |
17 | // --------------------------------------------------------------------------- | |
18 | ||
19 | #ifndef _WX_MACCARBONHID_H_ | |
20 | #define _WX_MACCARBONHID_H_ | |
21 | ||
22 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) | |
23 | #pragma interface "hid.h" | |
24 | #endif | |
ec8bd392 RN |
25 | |
26 | #include "wx/defs.h" | |
65442ab6 | 27 | #include "wx/string.h" |
1553abf4 RN |
28 | |
29 | // --------------------------------------------------------------------------- | |
30 | // definitions | |
31 | // --------------------------------------------------------------------------- | |
32 | ||
33 | //Mac OSX only | |
ec8bd392 RN |
34 | #ifdef __DARWIN__ |
35 | ||
52479aef SC |
36 | #include <IOKit/IOKitLib.h> |
37 | #include <IOKit/IOCFPlugIn.h> | |
38 | #include <IOKit/hid/IOHIDLib.h> | |
39 | #include <IOKit/hid/IOHIDKeys.h> | |
40 | #include <Kernel/IOKit/hidsystem/IOHIDUsageTables.h> | |
41 | ||
42 | #include <mach/mach.h> | |
43 | ||
2a32f173 RN |
44 | //Utility wrapper around CFArray |
45 | class wxCFArray | |
46 | { | |
47 | public: | |
48 | wxCFArray(CFTypeRef pData) : pArray((CFArrayRef) pData) {} | |
49 | CFTypeRef operator [] (const int& nIndex) {return CFArrayGetValueAtIndex(pArray, nIndex); } | |
50 | int Count() {return CFArrayGetCount(pArray);} | |
51 | private: | |
52 | CFArrayRef pArray; | |
53 | }; | |
52479aef SC |
54 | |
55 | // | |
56 | // A wrapper around OS X HID Manager procedures. | |
57 | // The tutorial "Working With HID Class Device Interfaces" Is | |
58 | // Quite good, as is the sample program associated with it | |
59 | // (Depite the author's protests!). | |
60 | class wxHIDDevice | |
61 | { | |
62 | public: | |
63 | wxHIDDevice() : m_ppDevice(NULL), m_ppQueue(NULL), m_pCookies(NULL) {} | |
64 | //kHIDPage_GenericDesktop | |
65 | //kHIDUsage_GD_Joystick,kHIDUsage_GD_Mouse,kHIDUsage_GD_Keyboard | |
4cb1d3da RN |
66 | bool Create (int nClass = -1, int nType = -1, int nDev = 1); |
67 | ||
68 | static int GetCount(int nClass = -1, int nType = -1); | |
52479aef | 69 | |
4cb1d3da RN |
70 | void AddCookie(CFTypeRef Data, int i); |
71 | void AddCookieInQueue(CFTypeRef Data, int i); | |
72 | void InitCookies(size_t dwSize, bool bQueue = false); | |
52479aef SC |
73 | |
74 | //Must be implemented by derived classes | |
75 | //builds the cookie array - | |
76 | //first call InitCookies to initialize the cookie | |
77 | //array, then AddCookie to add a cookie at a certain point in an array | |
78 | virtual void BuildCookies(wxCFArray& Array) = 0; | |
79 | ||
4cb1d3da RN |
80 | //checks to see whether the cookie at nIndex is active (element value != 0) |
81 | bool IsActive(int nIndex); | |
82 | ||
83 | //checks to see whether the cookie at nIndex exists | |
84 | bool HasElement(int nIndex); | |
52479aef SC |
85 | |
86 | //closes the device and cleans the queue and cookies | |
87 | virtual ~wxHIDDevice(); | |
4cb1d3da RN |
88 | |
89 | protected: | |
52479aef SC |
90 | IOHIDDeviceInterface** m_ppDevice; //this, essentially |
91 | IOHIDQueueInterface** m_ppQueue; //queue (if we want one) | |
92 | IOHIDElementCookie* m_pCookies; //cookies | |
93 | ||
65442ab6 RN |
94 | wxString m_szProductName; //product name |
95 | int m_nProductId; //product id | |
96 | int m_nManufacturerId; //manufacturer id | |
52479aef SC |
97 | mach_port_t m_pPort; |
98 | }; | |
99 | ||
100 | class wxHIDKeyboard : public wxHIDDevice | |
101 | { | |
102 | public: | |
103 | bool Create(); | |
104 | virtual void BuildCookies(wxCFArray& Array); | |
ec8bd392 RN |
105 | }; |
106 | ||
1553abf4 RN |
107 | #endif //__DARWIN__ |
108 | ||
109 | #endif | |
110 | //WX_MACCARBONHID_H |