]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/corefoundation/hid.h
6ea4535f3a084ab085f43d2c13957dc3e9ffb51c
[wxWidgets.git] / include / wx / mac / corefoundation / hid.h
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 // 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
25
26 #include "wx/defs.h"
27 #include "wx/string.h"
28
29 // ---------------------------------------------------------------------------
30 // definitions
31 // ---------------------------------------------------------------------------
32
33 //Mac OSX only
34 #ifdef __DARWIN__
35
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
44 #include "wx/mac/corefoundation/cfwrappers.h"
45
46 //
47 // A wrapper around OS X HID Manager procedures.
48 // The tutorial "Working With HID Class Device Interfaces" Is
49 // Quite good, as is the sample program associated with it
50 // (Depite the author's protests!).
51 class wxHIDDevice
52 {
53 public:
54 wxHIDDevice() : m_ppDevice(NULL), m_ppQueue(NULL), m_pCookies(NULL) {}
55 //kHIDPage_GenericDesktop
56 //kHIDUsage_GD_Joystick,kHIDUsage_GD_Mouse,kHIDUsage_GD_Keyboard
57 bool Create (int nClass = -1, int nType = -1, int nDev = 1);
58
59 static int GetCount(int nClass = -1, int nType = -1);
60
61 void AddCookie(CFTypeRef Data, int i);
62 void AddCookieInQueue(CFTypeRef Data, int i);
63 void InitCookies(size_t dwSize, bool bQueue = false);
64
65 //Must be implemented by derived classes
66 //builds the cookie array -
67 //first call InitCookies to initialize the cookie
68 //array, then AddCookie to add a cookie at a certain point in an array
69 virtual void BuildCookies(wxCFArray& Array) = 0;
70
71 //checks to see whether the cookie at nIndex is active (element value != 0)
72 bool IsActive(int nIndex);
73
74 //checks to see whether the cookie at nIndex exists
75 bool HasElement(int nIndex);
76
77 //closes the device and cleans the queue and cookies
78 virtual ~wxHIDDevice();
79
80 protected:
81 IOHIDDeviceInterface** m_ppDevice; //this, essentially
82 IOHIDQueueInterface** m_ppQueue; //queue (if we want one)
83 IOHIDElementCookie* m_pCookies; //cookies
84
85 wxString m_szProductName; //product name
86 int m_nProductId; //product id
87 int m_nManufacturerId; //manufacturer id
88 mach_port_t m_pPort;
89 };
90
91 class wxHIDKeyboard : public wxHIDDevice
92 {
93 public:
94 bool Create();
95 virtual void BuildCookies(wxCFArray& Array);
96 };
97
98 #endif //__DARWIN__
99
100 #endif
101 //WX_MACCARBONHID_H