]> git.saurik.com Git - apple/xnu.git/blob - iokit/Families/IOHIDSystem/IOHIDDescriptorParser/HIDMaxUsageListLength.c
xnu-123.5.tar.gz
[apple/xnu.git] / iokit / Families / IOHIDSystem / IOHIDDescriptorParser / HIDMaxUsageListLength.c
1 /*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 File: HIDMaxUsageListLength.c
24
25 Contains: xxx put contents here xxx
26
27 Version: xxx put version here xxx
28
29 Copyright: © 1999 by Apple Computer, Inc., all rights reserved.
30
31 File Ownership:
32
33 DRI: xxx put dri here xxx
34
35 Other Contact: xxx put other contact here xxx
36
37 Technology: xxx put technology here xxx
38
39 Writers:
40
41 (BWS) Brent Schorsch
42
43 Change History (most recent first):
44
45 <USB3> 11/1/99 BWS [2405720] We need a better check for 'bit padding' items,
46 rather than just is constant. We will check to make sure the
47 item is constant, and has no usage, or zero usage. This means we
48 need to pass an additional parameter to some internal functions
49 <USB2> 3/6/99 BWS Eliminate warning
50 <USB1> 3/5/99 BWS first checked in
51 */
52
53 #include "HIDLib.h"
54
55 /*
56 *------------------------------------------------------------------------------
57 *
58 * HIDMaxUsageListLength
59 *
60 * Input:
61 * reportType - HIDP_Input, HIDP_Output, HIDP_Feature
62 * usagePage - Page Criteria or zero
63 * ptPreparsedData - Pre-Parsed Data
64 * Output:
65 * Returns: length of list
66 *
67 *------------------------------------------------------------------------------
68 */
69 UInt32
70 HIDMaxUsageListLength (HIDReportType reportType,
71 HIDUsage usagePage,
72 HIDPreparsedDataRef preparsedDataRef)
73 {
74 #pragma unused(usagePage) // not used, see comment below
75
76 HIDPreparsedDataPtr ptPreparsedData = (HIDPreparsedDataPtr) preparsedDataRef;
77 HIDReportItem *ptReportItem;
78 int iButtons;
79 int i;
80
81
82 /*
83 * Disallow Null Pointers
84 */
85 if (ptPreparsedData == NULL)
86 return 0;
87 if (ptPreparsedData->hidTypeIfValid != kHIDOSType)
88 return kHIDInvalidPreparsedDataErr;
89 /*
90 * Go through the ReportItems
91 * Filter on ReportType
92 * Sum the button counts
93 *
94 * NOTE: A more precise value for the maximum list length
95 * may be obtained by filtering out the usages that
96 * are not on the specified usage page. Most of
97 * the time the number returned below is the same
98 * as that returned by filtering usages. It is
99 * never smaller. The tradeoff is sometimes wasting
100 * a few words of RAM in exchange for speed.
101 */
102 iButtons = 0;
103 for (i=0; i<ptPreparsedData->reportItemCount; i++)
104 {
105 ptReportItem = &ptPreparsedData->reportItems[i];
106 if ((ptReportItem->reportType == reportType)
107 && HIDIsButton(ptReportItem, preparsedDataRef))
108 iButtons += ptReportItem->globals.reportCount;
109 }
110 return iButtons;
111 }