]> git.saurik.com Git - apple/xnu.git/blob - iokit/Families/IOHIDSystem/IOHIDDescriptorParser/HIDGetNextUsageValueInfo.c
xnu-124.13.tar.gz
[apple/xnu.git] / iokit / Families / IOHIDSystem / IOHIDDescriptorParser / HIDGetNextUsageValueInfo.c
1 /*
2 * Copyright (c) 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: HIDGetNextUsageValueInfo.c
24
25 Contains: HIDGetNextUsageValueInfo call for HID Library
26
27 Version: 1.0d1
28
29 Copyright: © 2000 by Apple Computer, Inc., all rights reserved.
30
31 File Ownership:
32
33 DRI: David Ferguson
34
35 Other Contact: Keithen Hayenga
36
37 Technology: technologies, usb
38
39 Writers:
40
41 (KH) Keithen Hayenga
42
43 Change History (most recent first):
44
45 <USB1> 2/14/00 KH first checked in
46 */
47
48 #include "HIDLib.h"
49
50 /*
51 *------------------------------------------------------------------------------
52 *
53 * HIDGetNextUsageValueInfo - Get report id and collection for a usage. In keeping
54 * with USBGetNextInterface, we find the usage in the
55 * next collection, so that you can find usages that
56 * have the same usage and usage page.
57 *
58 * Input:
59 * reportType - HIDP_Input, HIDP_Output, HIDP_Feature
60 * usagePage - Page Criteria or zero
61 * usage - The usage to get the information for
62 * collection - Starting Collection Criteria or zero
63 * preparsedDataRef - Pre-Parsed Data
64 * Output:
65 * collection - Final Collection Criteria or no change
66 * reportID - Report ID or no change
67 * Returns:
68 * kHIDBadParameterErr when there are no more collections to search.
69 *
70 *------------------------------------------------------------------------------
71 */
72 OSStatus HIDGetNextUsageValueInfo
73 (HIDReportType reportType,
74 HIDUsage usagePage,
75 HIDUsage usage,
76 UInt32 * collection,
77 UInt8 * reportID,
78 HIDPreparsedDataRef preparsedDataRef)
79 {
80 HIDPreparsedDataPtr ptPreparsedData = (HIDPreparsedDataPtr)preparsedDataRef;
81 HIDReportItem *ptReportItem;
82 UInt32 iCollection;
83 UInt32 newCollection = 0xFFFFFFFF;
84 int iR;
85 UInt8 newReportID = 0;
86 OSStatus iStatus = kHIDUsageNotFoundErr;
87
88 //Disallow Null Pointers
89
90 if ((ptPreparsedData == NULL) || (collection == NULL) || (reportID == NULL))
91 return kHIDNullPointerErr;
92 if (ptPreparsedData->hidTypeIfValid != kHIDOSType)
93 return kHIDInvalidPreparsedDataErr;
94
95 // The Collection must be in range
96
97 iCollection = *collection;
98 // Umm... an unsigned number can never be less than 0!
99 if ((iCollection < 0) || (iCollection >= ptPreparsedData->collectionCount))
100 return kHIDBadParameterErr;
101
102 // HIDGetNextUsageValueInfo is different from HIDGetUsageValue in how it treats
103 // the collection parameter. HIDGetUsageValue will only look at report items that
104 // are within the collection and can therefore limit it's searches to starting at
105 // ptPreparsedData->collections[iCollection]->firstReportItem and only check
106 // ptPreparsedData->collections[iCollection]->reportItemCount. Since we want to
107 // find the NEXT collection as well, we need to cycle through all of the reports.
108
109 for (iR = 0; iR < ptPreparsedData->reportItemCount; iR++)
110 {
111 SInt32 minUsage;
112 SInt32 maxUsage;
113 HIDP_UsageItem thisUsage;
114
115 ptReportItem = &ptPreparsedData->reportItems[iR];
116
117 thisUsage = ptPreparsedData->usageItems[ptReportItem->firstUsageItem];
118
119 if (thisUsage.isRange)
120 {
121 minUsage = thisUsage.usageMinimum;
122 maxUsage = thisUsage.usageMaximum;
123 }
124 else
125 {
126 minUsage = thisUsage.usage;
127 maxUsage = thisUsage.usage;
128 }
129
130 if (ptReportItem->reportType == reportType &&
131 (usagePage == 0 || ptReportItem->globals.usagePage == usagePage) &&
132 (usage >= minUsage && usage <= maxUsage) &&
133 ptReportItem->parent > iCollection &&
134 HIDIsVariable(ptReportItem, preparsedDataRef))
135 {
136 if (ptReportItem->parent < newCollection)
137 {
138 newCollection = ptReportItem->parent;
139 newReportID = iR;
140 iStatus = noErr;
141 }
142 }
143 }
144
145 if (iStatus == noErr)
146 {
147 *reportID = newReportID;
148 *collection = newCollection;
149 }
150
151 return iStatus;
152 }
153