Annotation of XNU/iokit/Families/IOHIDSystem/IOHIDDescriptorParser/HIDHasUsage.c, revision 1.1.1.1

1.1       root        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:           HIDHasUsage.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:  * HidP_UsageFromIndex
                     54:  *
                     55:  *      Input:
                     56:  *                       ptPreparsedData               - The Preparsed Data
                     57:  *                       ptReportItem                  - The Report Item
                     58:  *                       usagePage                        - The usage Page to find
                     59:  *                       usage                            - The usage to find
                     60:  *                       piIndex(optional)             - The usage Index pointer
                     61:  *                       piCount(optional)             - The usage Count pointer
                     62:  *      Output:
                     63:  *                       piIndex                               - The usage Index
                     64:  *      Returns:
                     65:  *                       The usage
                     66:  *
                     67:  *------------------------------------------------------------------------------
                     68: */
                     69: Boolean HIDHasUsage (HIDPreparsedDataRef preparsedDataRef,
                     70:                                           HIDReportItem *ptReportItem,
                     71:                                           HIDUsage usagePage, HIDUsage usage,
                     72:                                           UInt32 *piIndex, UInt32 *piCount)
                     73: {
                     74:        HIDPreparsedDataPtr ptPreparsedData = (HIDPreparsedDataPtr) preparsedDataRef;
                     75:        int iUsageItem;
                     76:        UInt32 iUsageIndex;
                     77:        int iUsages;
                     78:        int i;
                     79:        UInt32 iCountsLeft;
                     80:        HIDP_UsageItem *ptUsageItem;
                     81:        Boolean bOnPage;
                     82: /*
                     83:  *     Disallow Null Pointers
                     84: */
                     85:        if ((ptPreparsedData == NULL)
                     86:         || (ptReportItem == NULL))
                     87:                return 0;
                     88:        if (ptPreparsedData->hidTypeIfValid != kHIDOSType)
                     89:                return 0;
                     90: /*
                     91:  *     Look through the usage Items for this usage
                     92: */
                     93:        iUsageItem = ptReportItem->firstUsageItem;
                     94:        iUsageIndex = 0;
                     95:        for (i=0; i<ptReportItem->usageItemCount; i++)
                     96:        {
                     97: /*
                     98:  *        Each usage Item is either a usage or a usage range
                     99: */
                    100:                ptUsageItem = &ptPreparsedData->usageItems[iUsageItem++];
                    101:                bOnPage = ((usagePage == 0) || (usagePage == ptUsageItem->usagePage));
                    102:                if (ptUsageItem->isRange)
                    103:                {
                    104: /*
                    105:  *                     For usage Ranges
                    106:  *                       If the index is in the range
                    107:  *                             then return the usage
                    108:  *                       Otherwise adjust the index by the size of the range
                    109: */
                    110:                        if ((usage >= ptUsageItem->usageMinimum)
                    111:                         && (usage <= ptUsageItem->usageMaximum))
                    112:                        {
                    113:                                if (piIndex != NULL)
                    114:                                        *piIndex = iUsageIndex + (ptUsageItem->usageMinimum - usage);
                    115: /*
                    116:  *                             If this usage is the last one for this ReportItem
                    117:  *                               then it gets all of the remaining reportCount
                    118: */
                    119:                                if (piCount != NULL)
                    120:                                {
                    121:                                        if (((i+1) == ptReportItem->usageItemCount)
                    122:                                         && (usage == ptUsageItem->usageMaximum))
                    123:                                        {
                    124:                                                iCountsLeft = ptReportItem->globals.reportCount - iUsageIndex - 1;
                    125:                                                if (iCountsLeft > 1)
                    126:                                                        *piCount = iCountsLeft;
                    127:                                                else
                    128:                                                        *piCount = 1;
                    129:                                        }
                    130:                                        else
                    131:                                                *piCount = 1;
                    132:                                }
                    133:                                if (bOnPage)
                    134:                                        return true;
                    135:                        }
                    136:                        iUsages = ptUsageItem->usageMaximum - ptUsageItem->usageMinimum + 1;
                    137:                        if (iUsages < 0)
                    138:                                iUsages = -iUsages;
                    139:                        iUsageIndex += iUsages;
                    140:                }
                    141:                else
                    142:                {
                    143: /*
                    144:  *                     For Usages
                    145:  *                     If the index is zero
                    146:  *                       then return this usage
                    147:  *                     Otherwise one less to index through
                    148: */
                    149:                        if (usage == ptUsageItem->usage)
                    150:                        {
                    151:                                if (piIndex != NULL)
                    152:                                        *piIndex = iUsageIndex;
                    153:                                if (piCount != NULL)
                    154:                                {
                    155:                                        if ((i+1) == ptReportItem->usageItemCount)
                    156:                                        {
                    157:                                                iCountsLeft = ptReportItem->globals.reportCount - iUsageIndex - 1;
                    158:                                                if (iCountsLeft > 1)
                    159:                                                        *piCount = iCountsLeft;
                    160:                                                else
                    161:                                                   *piCount = 1;
                    162:                                        }
                    163:                                        else
                    164:                                                *piCount = 1;
                    165:                                }
                    166:                                if (bOnPage)
                    167:                                        return true;
                    168:                        }
                    169:                        iUsageIndex++;
                    170:                }
                    171:        }
                    172:        return false;
                    173: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.