HIDGetCollectionNodes.c [plain text]
#include "HIDLib.h"
OSStatus HIDGetCollectionNodes(HIDCollectionNodePtr ptLinkCollectionNodes,
UInt32 *piLinkCollectionNodesLength,
HIDPreparsedDataRef preparsedDataRef)
{
HIDPreparsedDataPtr ptPreparsedData = (HIDPreparsedDataPtr) preparsedDataRef;
HIDCollectionNodePtr ptLink;
HIDCollection *ptCollection;
HIDP_UsageItem *ptFirstUsageItem;
int iMaxNodes;
int collectionCount;
int firstUsageItem;
int i;
if ((ptLinkCollectionNodes == NULL)
|| (piLinkCollectionNodesLength == NULL)
|| (ptPreparsedData == NULL))
return kHIDNullPointerErr;
if (ptPreparsedData->hidTypeIfValid != kHIDOSType)
return kHIDInvalidPreparsedDataErr;
iMaxNodes = *piLinkCollectionNodesLength;
collectionCount = ptPreparsedData->collectionCount;
*piLinkCollectionNodesLength = collectionCount;
if (collectionCount > iMaxNodes)
return kHIDBufferTooSmallErr;
for (i=0; i<collectionCount; i++)
{
ptCollection = &ptPreparsedData->collections[i];
ptLink = &ptLinkCollectionNodes[i];
firstUsageItem = ptCollection->firstUsageItem;
ptFirstUsageItem = &ptPreparsedData->usageItems[firstUsageItem];
ptLink->collectionUsage = ptFirstUsageItem->usage;
ptLink->collectionUsagePage = ptCollection->usagePage;
ptLink->parent = ptCollection->parent;
ptLink->numberOfChildren = ptCollection->children;
ptLink->nextSibling = ptCollection->nextSibling;
ptLink->firstChild = ptCollection->firstChild;
}
if (iMaxNodes < ptPreparsedData->collectionCount)
return kHIDBufferTooSmallErr;
return kHIDSuccess;
}
OSStatus HIDGetCollectionExtendedNodes( HIDCollectionExtendedNodePtr ptLinkCollectionNodes,
UInt32 *piLinkCollectionNodesLength,
HIDPreparsedDataRef preparsedDataRef)
{
HIDPreparsedDataPtr ptPreparsedData = (HIDPreparsedDataPtr) preparsedDataRef;
HIDCollectionExtendedNodePtr ptLink;
HIDCollection *ptCollection;
HIDP_UsageItem *ptFirstUsageItem;
int iMaxNodes;
int collectionCount;
int firstUsageItem;
int i;
if ((ptLinkCollectionNodes == NULL)
|| (piLinkCollectionNodesLength == NULL)
|| (ptPreparsedData == NULL))
return kHIDNullPointerErr;
if (ptPreparsedData->hidTypeIfValid != kHIDOSType)
return kHIDInvalidPreparsedDataErr;
iMaxNodes = *piLinkCollectionNodesLength;
collectionCount = ptPreparsedData->collectionCount;
*piLinkCollectionNodesLength = collectionCount;
if (collectionCount > iMaxNodes)
return kHIDBufferTooSmallErr;
for (i=0; i<collectionCount; i++)
{
ptCollection = &ptPreparsedData->collections[i];
ptLink = &ptLinkCollectionNodes[i];
firstUsageItem = ptCollection->firstUsageItem;
ptFirstUsageItem = &ptPreparsedData->usageItems[firstUsageItem];
ptLink->collectionUsage = ptFirstUsageItem->usage;
ptLink->collectionUsagePage = ptCollection->usagePage;
ptLink->parent = ptCollection->parent;
ptLink->numberOfChildren = ptCollection->children;
ptLink->nextSibling = ptCollection->nextSibling;
ptLink->firstChild = ptCollection->firstChild;
ptLink->data = ptCollection->data;
}
if (iMaxNodes < ptPreparsedData->collectionCount)
return kHIDBufferTooSmallErr;
return kHIDSuccess;
}