]> git.saurik.com Git - apple/xnu.git/blob - iokit/Families/IOHIDSystem/IOHIDDescriptorParser/HIDUsageListDifference.c
xnu-124.13.tar.gz
[apple/xnu.git] / iokit / Families / IOHIDSystem / IOHIDDescriptorParser / HIDUsageListDifference.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: HIDUsageListDifference.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 <USB1> 3/5/99 BWS first checked in
46 */
47
48 #include "HIDLib.h"
49
50 /*
51 *------------------------------------------------------------------------------
52 *
53 * In - Is a usage in a UsageList?
54 *
55 * Input:
56 * piUsageList - usage List
57 * iUsageListLength - Max entries in usage Lists
58 * usage - The usage
59 * Output:
60 * Returns: true or false
61 *
62 *------------------------------------------------------------------------------
63 */
64 static Boolean IsUsageInUsageList(HIDUsage *piUsageList, UInt32 iUsageListLength, HIDUsage usage)
65 {
66 unsigned int i;
67 for (i = 0; i < iUsageListLength; i++)
68 if (piUsageList[i] == usage)
69 return true;
70 return false;
71 }
72
73 /*
74 *------------------------------------------------------------------------------
75 *
76 * HIDUsageListDifference - Return adds and drops given present and past
77 *
78 * Input:
79 * piPreviouUL - Previous usage List
80 * piCurrentUL - Current usage List
81 * piBreakUL - Break usage List
82 * piMakeUL - Make usage List
83 * iUsageListLength - Max entries in usage Lists
84 * Output:
85 * piBreakUL - Break usage List
86 * piMakeUL - Make usage List
87 * Returns:
88 *
89 *------------------------------------------------------------------------------
90 */
91 OSStatus HIDUsageListDifference(HIDUsage *piPreviousUL, HIDUsage *piCurrentUL, HIDUsage *piBreakUL, HIDUsage *piMakeUL, UInt32 iUsageListLength)
92 {
93 int i;
94 HIDUsage usage;
95 int iBreakLength=0;
96 int iMakeLength=0;
97 for (i = 0; i < iUsageListLength; i++)
98 {
99 /*
100 * If in Current but not Previous then it's a Make
101 */
102 usage = piCurrentUL[i];
103 if ((usage != 0) && (!IsUsageInUsageList(piPreviousUL,iUsageListLength,usage))
104 && (!IsUsageInUsageList(piMakeUL,iMakeLength,usage)))
105 piMakeUL[iMakeLength++] = usage;
106 /*
107 * If in Previous but not Current then it's a Break
108 */
109 usage = piPreviousUL[i];
110 if ((usage != 0) && (!IsUsageInUsageList(piCurrentUL,iUsageListLength,usage))
111 && (!IsUsageInUsageList(piBreakUL,iBreakLength,usage)))
112 piBreakUL[iBreakLength++] = usage;
113 }
114 /*
115 * Clear the rest of the usage Lists
116 */
117 while (iMakeLength < iUsageListLength)
118 piMakeUL[iMakeLength++] = 0;
119 while (iBreakLength < iUsageListLength)
120 piBreakUL[iBreakLength++] = 0;
121 return kHIDSuccess;
122 }