]>
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 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #include "wx/defs.h" | |
13 | ||
14 | #ifdef __DARWIN__ | |
15 | ||
52479aef SC |
16 | #include <IOKit/IOKitLib.h> |
17 | #include <IOKit/IOCFPlugIn.h> | |
18 | #include <IOKit/hid/IOHIDLib.h> | |
19 | #include <IOKit/hid/IOHIDKeys.h> | |
20 | #include <Kernel/IOKit/hidsystem/IOHIDUsageTables.h> | |
21 | ||
22 | #include <mach/mach.h> | |
23 | ||
24 | //Utility wrapper around CFArray | |
25 | class wxCFArray | |
26 | { | |
27 | public: | |
28 | wxCFArray(CFTypeRef pData) : pArray((CFArrayRef) pData) {} | |
29 | CFTypeRef operator [] (const int& nIndex) {return CFArrayGetValueAtIndex(pArray, nIndex); } | |
30 | int Count() {return CFArrayGetCount(pArray);} | |
31 | private: | |
32 | CFArrayRef pArray; | |
33 | }; | |
34 | ||
35 | // | |
36 | // A wrapper around OS X HID Manager procedures. | |
37 | // The tutorial "Working With HID Class Device Interfaces" Is | |
38 | // Quite good, as is the sample program associated with it | |
39 | // (Depite the author's protests!). | |
40 | class wxHIDDevice | |
41 | { | |
42 | public: | |
43 | wxHIDDevice() : m_ppDevice(NULL), m_ppQueue(NULL), m_pCookies(NULL) {} | |
44 | //kHIDPage_GenericDesktop | |
45 | //kHIDUsage_GD_Joystick,kHIDUsage_GD_Mouse,kHIDUsage_GD_Keyboard | |
46 | bool Create (const int& nClass = -1, const int& nType = -1); | |
47 | ||
48 | inline void AddCookie(CFTypeRef Data, const int& i); | |
49 | inline void AddCookieInQueue(CFTypeRef Data, const int& i); | |
50 | inline void InitCookies(const size_t& dwSize, bool bQueue = false); | |
51 | ||
52 | //Must be implemented by derived classes | |
53 | //builds the cookie array - | |
54 | //first call InitCookies to initialize the cookie | |
55 | //array, then AddCookie to add a cookie at a certain point in an array | |
56 | virtual void BuildCookies(wxCFArray& Array) = 0; | |
57 | ||
58 | //checks to see whether the cookie at index nIndex is active (element value != 0) | |
59 | bool IsActive(const int& nIndex); | |
60 | ||
61 | //closes the device and cleans the queue and cookies | |
62 | virtual ~wxHIDDevice(); | |
63 | private: | |
64 | IOHIDDeviceInterface** m_ppDevice; //this, essentially | |
65 | IOHIDQueueInterface** m_ppQueue; //queue (if we want one) | |
66 | IOHIDElementCookie* m_pCookies; //cookies | |
67 | ||
68 | const char* m_szName; //(product) name | |
69 | mach_port_t m_pPort; | |
70 | }; | |
71 | ||
72 | class wxHIDKeyboard : public wxHIDDevice | |
73 | { | |
74 | public: | |
75 | bool Create(); | |
76 | virtual void BuildCookies(wxCFArray& Array); | |
ec8bd392 RN |
77 | }; |
78 | ||
79 | #endif //__DARWIN__ |