]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/mac/corefoundation/hid.h
Updated version to 2.5.5
[wxWidgets.git] / include / wx / mac / corefoundation / hid.h
... / ...
CommitLineData
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//Utility wrapper around CFArray
45class wxCFArray
46{
47public:
48 wxCFArray(CFTypeRef pData) : pArray((CFArrayRef) pData) {}
49 CFTypeRef operator [] (const int& nIndex) {return CFArrayGetValueAtIndex(pArray, nIndex); }
50 int Count() {return CFArrayGetCount(pArray);}
51private:
52 CFArrayRef pArray;
53};
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!).
60class wxHIDDevice
61{
62public:
63 wxHIDDevice() : m_ppDevice(NULL), m_ppQueue(NULL), m_pCookies(NULL) {}
64 //kHIDPage_GenericDesktop
65 //kHIDUsage_GD_Joystick,kHIDUsage_GD_Mouse,kHIDUsage_GD_Keyboard
66 bool Create (int nClass = -1, int nType = -1, int nDev = 1);
67
68 static int GetCount(int nClass = -1, int nType = -1);
69
70 void AddCookie(CFTypeRef Data, int i);
71 void AddCookieInQueue(CFTypeRef Data, int i);
72 void InitCookies(size_t dwSize, bool bQueue = false);
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
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);
85
86 //closes the device and cleans the queue and cookies
87 virtual ~wxHIDDevice();
88
89protected:
90 IOHIDDeviceInterface** m_ppDevice; //this, essentially
91 IOHIDQueueInterface** m_ppQueue; //queue (if we want one)
92 IOHIDElementCookie* m_pCookies; //cookies
93
94 wxString m_szProductName; //product name
95 int m_nProductId; //product id
96 int m_nManufacturerId; //manufacturer id
97 mach_port_t m_pPort;
98};
99
100class wxHIDKeyboard : public wxHIDDevice
101{
102public:
103 bool Create();
104 virtual void BuildCookies(wxCFArray& Array);
105};
106
107#endif //__DARWIN__
108
109#endif
110 //WX_MACCARBONHID_H