]> git.saurik.com Git - wxWidgets.git/blame - include/wx/osx/core/hid.h
wxMessageBox off the main thread lost result code.
[wxWidgets.git] / include / wx / osx / core / hid.h
CommitLineData
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
5c6eb3a8
SC
7// Copyright: (c) Ryan Norton
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
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//Mac OSX only
26#ifdef __DARWIN__
27
28#include <IOKit/IOKitLib.h>
29#include <IOKit/IOCFPlugIn.h>
30#include <IOKit/hid/IOHIDLib.h>
31#include <IOKit/hid/IOHIDKeys.h>
32#include <Kernel/IOKit/hidsystem/IOHIDUsageTables.h>
33
34//Darn apple - doesn't properly wrap their headers in extern "C"!
35//http://www.macosx.com/forums/archive/index.php/t-68069.html
5c6eb3a8
SC
36extern "C" {
37#include <mach/mach_port.h>
38}
39
40#include <mach/mach.h> //this actually includes mach_port.h (see above)
41
42// ===========================================================================
43// definitions
44// ===========================================================================
45
46
47// ---------------------------------------------------------------------------
48// wxHIDDevice
49//
50// A wrapper around OS X HID Manager procedures.
51// The tutorial "Working With HID Class Device Interfaces" Is
52// Quite good, as is the sample program associated with it
53// (Depite the author's protests!).
54// ---------------------------------------------------------------------------
55class WXDLLIMPEXP_CORE wxHIDDevice
56{
57public:
58 wxHIDDevice() : m_ppDevice(NULL), m_ppQueue(NULL), m_pCookies(NULL) {}
59
60 bool Create (int nClass = -1, int nType = -1, int nDev = 1);
61
62 static size_t GetCount(int nClass = -1, int nType = -1);
63
64 void AddCookie(CFTypeRef Data, int i);
65 void AddCookieInQueue(CFTypeRef Data, int i);
66 void InitCookies(size_t dwSize, bool bQueue = false);
67
68 //Must be implemented by derived classes
69 //builds the cookie array -
70 //first call InitCookies to initialize the cookie
71 //array, then AddCookie to add a cookie at a certain point in an array
72 virtual void BuildCookies(CFArrayRef Array) = 0;
73
74 //checks to see whether the cookie at nIndex is active (element value != 0)
75 bool IsActive(int nIndex);
76
77 //checks to see whether an element in the internal cookie array
78 //exists
79 bool HasElement(int nIndex);
80
81 //closes the device and cleans the queue and cookies
82 virtual ~wxHIDDevice();
83
84protected:
85 IOHIDDeviceInterface** m_ppDevice; //this, essentially
86 IOHIDQueueInterface** m_ppQueue; //queue (if we want one)
87 IOHIDElementCookie* m_pCookies; //cookies
88
89 wxString m_szProductName; //product name
90 int m_nProductId; //product id
91 int m_nManufacturerId; //manufacturer id
92 mach_port_t m_pPort; //mach port to use
93};
94
95// ---------------------------------------------------------------------------
96// wxHIDKeyboard
97//
98// Semi-simple implementation that opens a connection to the first
99// keyboard of the machine. Used in wxGetKeyState.
100// ---------------------------------------------------------------------------
101class WXDLLIMPEXP_CORE wxHIDKeyboard : public wxHIDDevice
102{
103public:
104 static int GetCount();
105 bool Create(int nDev = 1);
106 void AddCookie(CFTypeRef Data, int i);
107 virtual void BuildCookies(CFArrayRef Array);
108 void DoBuildCookies(CFArrayRef Array);
109};
110
111#endif //__DARWIN__
112
113#endif
114 // _WX_MACCARBONHID_H_