1/*
2 * @APPLE_LICENSE_HEADER_START@
3 *
4 * Copyright (c) 1999-2003 Apple Computer, Inc.  All Rights Reserved.
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23/*
24	File:		HIDUsageListDifference.c
25
26	Contains:	xxx put contents here xxx
27
28	Version:	xxx put version here xxx
29
30	Copyright:	� 1999 by Apple Computer, Inc., all rights reserved.
31
32	File Ownership:
33
34		DRI:				xxx put dri here xxx
35
36		Other Contact:		xxx put other contact here xxx
37
38		Technology:			xxx put technology here xxx
39
40	Writers:
41
42		(BWS)	Brent Schorsch
43
44	Change History (most recent first):
45
46	  <USB1>	  3/5/99	BWS		first checked in
47*/
48
49#include "HIDLib.h"
50
51/*
52 *------------------------------------------------------------------------------
53 *
54 * In - Is a usage in a UsageList?
55 *
56 *	 Input:
57 *			  piUsageList			- usage List
58 *			  iUsageListLength		- Max entries in usage Lists
59 *			  usage				   - The usage
60 *	 Output:
61 *	 Returns: true or false
62 *
63 *------------------------------------------------------------------------------
64*/
65static Boolean IsUsageInUsageList(HIDUsage *piUsageList, UInt32 iUsageListLength, HIDUsage usage)
66{
67	unsigned int i;
68	for (i = 0; i < iUsageListLength; i++)
69		if (piUsageList[i] == usage)
70			return true;
71	return false;
72}
73
74/*
75 *------------------------------------------------------------------------------
76 *
77 * HIDUsageListDifference - Return adds and drops given present and past
78 *
79 *	 Input:
80 *			  piPreviouUL			- Previous usage List
81 *			  piCurrentUL			- Current usage List
82 *			  piBreakUL				- Break usage List
83 *			  piMakeUL				- Make usage List
84 *			  iUsageListLength		- Max entries in usage Lists
85 *	 Output:
86 *			  piBreakUL				- Break usage List
87 *			  piMakeUL				- Make usage List
88 *	 Returns:
89 *
90 *------------------------------------------------------------------------------
91*/
92OSStatus HIDUsageListDifference(HIDUsage *piPreviousUL, HIDUsage *piCurrentUL, HIDUsage *piBreakUL, HIDUsage *piMakeUL, UInt32 iUsageListLength)
93{
94	int i;
95	HIDUsage usage;
96	int iBreakLength=0;
97	int iMakeLength=0;
98	for (i = 0; i < iUsageListLength; i++)
99	{
100/*
101 *		If in Current but not Previous then it's a Make
102*/
103		usage = piCurrentUL[i];
104		if ((usage != 0) && (!IsUsageInUsageList(piPreviousUL,iUsageListLength,usage))
105						  && (!IsUsageInUsageList(piMakeUL,iMakeLength,usage)))
106			piMakeUL[iMakeLength++] = usage;
107/*
108 *		If in Previous but not Current then it's a Break
109*/
110		usage = piPreviousUL[i];
111		if ((usage != 0) && (!IsUsageInUsageList(piCurrentUL,iUsageListLength,usage))
112						  && (!IsUsageInUsageList(piBreakUL,iBreakLength,usage)))
113			piBreakUL[iBreakLength++] = usage;
114	}
115/*
116 *	Clear the rest of the usage Lists
117*/
118	while (iMakeLength < iUsageListLength)
119		piMakeUL[iMakeLength++] = 0;
120	while (iBreakLength < iUsageListLength)
121		piBreakUL[iBreakLength++] = 0;
122	return kHIDSuccess;
123}
124