2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
23 File: HIDGetCollectionNodes.c
25 Contains: xxx put contents here xxx
27 Version: xxx put version here xxx
29 Copyright: © 1999 by Apple Computer, Inc., all rights reserved.
33 DRI: xxx put dri here xxx
35 Other Contact: xxx put other contact here xxx
37 Technology: xxx put technology here xxx
43 Change History (most recent first):
45 <USB1> 3/5/99 BWS first checked in
51 *------------------------------------------------------------------------------
53 * HIDGetCollectionNodes - Get the Collections Database
56 * ptLinkCollectionNodes - Node Array provided by caller
57 * piLinkCollectionNodesLength - Maximum Nodes
59 * piLinkCollectionNodesLength - Actual number of Nodes
61 * kHIDSuccess - Success
62 * kHIDNullPointerErr - Argument, Pointer was Null
63 * HidP_NotEnoughRoom - More Nodes than space for them
65 *------------------------------------------------------------------------------
67 OSStatus
HIDGetCollectionNodes(HIDCollectionNodePtr ptLinkCollectionNodes
,
68 UInt32
*piLinkCollectionNodesLength
,
69 HIDPreparsedDataRef preparsedDataRef
)
71 HIDPreparsedDataPtr ptPreparsedData
= (HIDPreparsedDataPtr
) preparsedDataRef
;
72 HIDCollectionNodePtr ptLink
;
73 HIDCollection
*ptCollection
;
74 HIDP_UsageItem
*ptFirstUsageItem
;
80 * Disallow Null Pointers
82 if ((ptLinkCollectionNodes
== NULL
)
83 || (piLinkCollectionNodesLength
== NULL
)
84 || (ptPreparsedData
== NULL
))
85 return kHIDNullPointerErr
;
86 if (ptPreparsedData
->hidTypeIfValid
!= kHIDOSType
)
87 return kHIDInvalidPreparsedDataErr
;
89 * Remember the size of the output array
91 iMaxNodes
= *piLinkCollectionNodesLength
;
92 collectionCount
= ptPreparsedData
->collectionCount
;
93 *piLinkCollectionNodesLength
= collectionCount
;
95 * Report if there's not enough room
97 if (collectionCount
> iMaxNodes
)
98 return kHIDBufferTooSmallErr
;
102 for (i
=0; i
<collectionCount
; i
++)
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
;
116 * Report if there wasn't enough space
118 if (iMaxNodes
< ptPreparsedData
->collectionCount
)
119 return kHIDBufferTooSmallErr
;