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:		HIDProcessCollection.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 * HIDProcessCollection - Process a Collection MainItem
55 *
56 *	 Input:
57 *			  ptDescriptor			- The Descriptor Structure
58 *			  ptPreparsedData		- The PreParsedData Structure
59 *	 Output:
60 *			  ptDescriptor			- The Descriptor Structure
61 *			  ptPreparsedData		- The PreParsedData Structure
62 *	 Returns:
63 *			  kHIDSuccess		   - Success
64 *			  kHIDNullPointerErr	  - Argument, Pointer was Null
65 *
66 *------------------------------------------------------------------------------
67*/
68OSStatus HIDProcessCollection(HIDReportDescriptor *ptDescriptor, HIDPreparsedDataPtr ptPreparsedData)
69{
70	HIDCollection *collections;
71	HIDCollection *ptCollection;
72	int parent;
73	int iCollection;
74/*
75 *	Disallow NULL Pointers
76*/
77	if ((ptDescriptor == NULL) || (ptPreparsedData == NULL))
78		return kHIDNullPointerErr;
79/*
80 *	Initialize the new Collection Structure
81*/
82	iCollection = ptPreparsedData->collectionCount++;
83	collections = ptPreparsedData->collections;
84	ptCollection = &collections[iCollection];
85	ptCollection->data = ptDescriptor->item.unsignedValue;
86	ptCollection->firstUsageItem = ptDescriptor->firstUsageItem;
87	ptCollection->usageItemCount = ptPreparsedData->usageItemCount - ptDescriptor->firstUsageItem;
88	ptDescriptor->firstUsageItem = ptPreparsedData->usageItemCount;
89	ptCollection->children = 0;
90	ptCollection->nextSibling = ptDescriptor->sibling;
91	ptDescriptor->sibling = 0;
92	ptCollection->firstChild = 0;
93	ptCollection->usagePage = ptDescriptor->globals.usagePage;
94	ptCollection->firstReportItem = ptPreparsedData->reportItemCount;
95/*
96 *	Set up the relationship with the parent Collection
97*/
98	parent = ptDescriptor->parent;
99	ptCollection->parent = parent;
100	collections[parent].firstChild = iCollection;
101	collections[parent].children++;
102	ptDescriptor->parent = iCollection;
103/*
104 *	Save the parent Collection Information on the stack
105*/
106	ptDescriptor->collectionStack[ptDescriptor->collectionNesting++] = parent;
107	return kHIDSuccess;
108}
109
110/*
111 *------------------------------------------------------------------------------
112 *
113 * HIDProcessEndCollection - Process an EndCollection MainItem
114 *
115 *	 Input:
116 *			  ptDescriptor			- The Descriptor Structure
117 *			  ptPreparsedData		- The PreParsedData Structure
118 *	 Output:
119 *			  ptPreparsedData		- The PreParsedData Structure
120 *	 Returns:
121 *			  kHIDSuccess		   - Success
122 *			  kHIDNullPointerErr	  - Argument, Pointer was Null
123 *
124 *------------------------------------------------------------------------------
125*/
126OSStatus HIDProcessEndCollection(HIDReportDescriptor *ptDescriptor, HIDPreparsedDataPtr ptPreparsedData)
127{
128	HIDCollection *ptCollection;
129	int iCollection;
130/*
131 *	Remember the number of ReportItem MainItems in this Collection
132*/
133	ptCollection = &ptPreparsedData->collections[ptDescriptor->parent];
134	ptCollection->reportItemCount = ptPreparsedData->reportItemCount - ptCollection->firstReportItem;
135/*
136 *	Restore the parent Collection Data
137*/
138	iCollection = ptDescriptor->collectionStack[--ptDescriptor->collectionNesting];
139	ptDescriptor->sibling = ptDescriptor->parent;
140	ptDescriptor->parent = iCollection;
141	return kHIDSuccess;
142}
143