]> git.saurik.com Git - apple/xnu.git/blob - iokit/Families/IOHIDSystem/IOHIDDescriptorParser/HIDGetCollectionNodes.c
f824c72479bf69486762c50be565b4ad4614b4f7
[apple/xnu.git] / iokit / Families / IOHIDSystem / IOHIDDescriptorParser / HIDGetCollectionNodes.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: HIDGetCollectionNodes.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 * HIDGetCollectionNodes - Get the Collections Database
54 *
55 * Input:
56 * ptLinkCollectionNodes - Node Array provided by caller
57 * piLinkCollectionNodesLength - Maximum Nodes
58 * Output:
59 * piLinkCollectionNodesLength - Actual number of Nodes
60 * Returns:
61 * kHIDSuccess - Success
62 * kHIDNullPointerErr - Argument, Pointer was Null
63 * HidP_NotEnoughRoom - More Nodes than space for them
64 *
65 *------------------------------------------------------------------------------
66 */
67 OSStatus HIDGetCollectionNodes(HIDCollectionNodePtr ptLinkCollectionNodes,
68 UInt32 *piLinkCollectionNodesLength,
69 HIDPreparsedDataRef preparsedDataRef)
70 {
71 HIDPreparsedDataPtr ptPreparsedData = (HIDPreparsedDataPtr) preparsedDataRef;
72 HIDCollectionNodePtr ptLink;
73 HIDCollection *ptCollection;
74 HIDP_UsageItem *ptFirstUsageItem;
75 int iMaxNodes;
76 int collectionCount;
77 int firstUsageItem;
78 int i;
79 /*
80 * Disallow Null Pointers
81 */
82 if ((ptLinkCollectionNodes == NULL)
83 || (piLinkCollectionNodesLength == NULL)
84 || (ptPreparsedData == NULL))
85 return kHIDNullPointerErr;
86 if (ptPreparsedData->hidTypeIfValid != kHIDOSType)
87 return kHIDInvalidPreparsedDataErr;
88 /*
89 * Remember the size of the output array
90 */
91 iMaxNodes = *piLinkCollectionNodesLength;
92 collectionCount = ptPreparsedData->collectionCount;
93 *piLinkCollectionNodesLength = collectionCount;
94 /*
95 * Report if there's not enough room
96 */
97 if (collectionCount > iMaxNodes)
98 return kHIDBufferTooSmallErr;
99 /*
100 * Copy the nodes
101 */
102 for (i=0; i<collectionCount; i++)
103 {
104 ptCollection = &ptPreparsedData->collections[i];
105 ptLink = &ptLinkCollectionNodes[i];
106 firstUsageItem = ptCollection->firstUsageItem;
107 ptFirstUsageItem = &ptPreparsedData->usageItems[firstUsageItem];
108 ptLink->collectionUsage = ptFirstUsageItem->usage;
109 ptLink->collectionUsagePage = ptCollection->usagePage;
110 ptLink->parent = ptCollection->parent;
111 ptLink->numberOfChildren = ptCollection->children;
112 ptLink->nextSibling = ptCollection->nextSibling;
113 ptLink->firstChild = ptCollection->firstChild;
114 }
115 /*
116 * Report if there wasn't enough space
117 */
118 if (iMaxNodes < ptPreparsedData->collectionCount)
119 return kHIDBufferTooSmallErr;
120 return kHIDSuccess;
121 }