]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/corefoundation/hid.h
don't use a floating point value as a boolean flag; gcc4 (correctly) complains when...
[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 #include "wx/defs.h"
23 #include "wx/string.h"
24
25 // ---------------------------------------------------------------------------
26 // definitions
27 // ---------------------------------------------------------------------------
28
29 //Mac OSX only
30 #ifdef __DARWIN__
31
32 #include <IOKit/IOKitLib.h>
33 #include <IOKit/IOCFPlugIn.h>
34 #include <IOKit/hid/IOHIDLib.h>
35 #include <IOKit/hid/IOHIDKeys.h>
36 #include <Kernel/IOKit/hidsystem/IOHIDUsageTables.h>
37
38 #include <mach/mach.h>
39
40 //Utility wrapper around CFArray
41 class wxCFArray
42 {
43 public:
44 wxCFArray(CFTypeRef pData) : pArray((CFArrayRef) pData) {}
45 CFTypeRef operator [] (const int& nIndex) {return CFArrayGetValueAtIndex(pArray, nIndex); }
46 int Count() {return CFArrayGetCount(pArray);}
47 private:
48 CFArrayRef pArray;
49 };
50
51 //
52 // A wrapper around OS X HID Manager procedures.
53 // The tutorial "Working With HID Class Device Interfaces" Is
54 // Quite good, as is the sample program associated with it
55 // (Depite the author's protests!).
56 class wxHIDDevice
57 {
58 public:
59 wxHIDDevice() : m_ppDevice(NULL), m_ppQueue(NULL), m_pCookies(NULL) {}
60 //kHIDPage_GenericDesktop
61 //kHIDUsage_GD_Joystick,kHIDUsage_GD_Mouse,kHIDUsage_GD_Keyboard
62 bool Create (int nClass = -1, int nType = -1, int nDev = 1);
63
64 static int GetCount(int nClass = -1, int nType = -1);
65
66 void AddCookie(CFTypeRef Data, int i);
67 void AddCookieInQueue(CFTypeRef Data, int i);
68 void InitCookies(size_t dwSize, bool bQueue = false);
69
70 //Must be implemented by derived classes
71 //builds the cookie array -
72 //first call InitCookies to initialize the cookie
73 //array, then AddCookie to add a cookie at a certain point in an array
74 virtual void BuildCookies(wxCFArray& Array) = 0;
75
76 //checks to see whether the cookie at nIndex is active (element value != 0)
77 bool IsActive(int nIndex);
78
79 //checks to see whether the cookie at nIndex 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;
94 };
95
96 class wxHIDKeyboard : public wxHIDDevice
97 {
98 public:
99 bool Create();
100 virtual void BuildCookies(wxCFArray& Array);
101 };
102
103 #endif //__DARWIN__
104
105 #endif
106 //WX_MACCARBONHID_H