Annotation of driverkit/tests/keyboard.m, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
        !             3:  *
        !             4:  * @APPLE_LICENSE_HEADER_START@
        !             5:  * 
        !             6:  * Portions Copyright (c) 1999 Apple Computer, Inc.  All Rights
        !             7:  * Reserved.  This file contains Original Code and/or Modifications of
        !             8:  * Original Code as defined in and that are subject to the Apple Public
        !             9:  * Source License Version 1.1 (the "License").  You may not use this file
        !            10:  * except in compliance with the License.  Please obtain a copy of the
        !            11:  * License at http://www.apple.com/publicsource and read it before using
        !            12:  * this file.
        !            13:  * 
        !            14:  * The Original Code and all software distributed under the License are
        !            15:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
        !            16:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
        !            17:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
        !            18:  * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT.  Please see the
        !            19:  * License for the specific language governing rights and limitations
        !            20:  * under the License.
        !            21:  * 
        !            22:  * @APPLE_LICENSE_HEADER_END@
        !            23:  */
        !            24: /*
        !            25:  * keyboard.m - adbKeyboard test. Requires FAKE_HARDWARE simulation in
        !            26:  *             the adbDriver object.
        !            27:  */
        !            28:  
        !            29: #define FAKE_HARDWARE  1
        !            30: 
        !            31: #import <adb/adbDriver.h>
        !            32: #import <driverkit/adbKeyboard.h>
        !            33: #import <driverkit/generalFuncs.h>
        !            34: #import <driverkit/debugging.h>
        !            35: #import <driverkit/KernDevUxpr.h>
        !            36: #import <libc.h>
        !            37: #import <driverkit/IOtsval.h>
        !            38: #import <driverkit/kernelDriver.h>
        !            39: 
        !            40: static struct tsval tsvalLast = {0,0};
        !            41: 
        !            42: /*
        !            43:  * prototypes for private functions.
        !            44:  */
        !            45: static void usage(char **argv);
        !            46: 
        !            47: /*
        !            48:  * Dumb little object which will be a client of AdbKeyboard.
        !            49:  */
        !            50: @interface adbClient : Object <adbDeviceClient>
        !            51: {
        !            52:        id      _keyboard;
        !            53: }
        !            54: 
        !            55: - setKeyboard : keyboard;
        !            56: @end
        !            57: 
        !            58: @implementation adbClient
        !            59: 
        !            60: /*
        !            61:  * Called when adbKeyboard detects one new ADB event.
        !            62:  */
        !            63: - (void)dispatchAdbEvent : (adbEvent *)event
        !            64: {
        !            65:        unsigned reg;
        !            66:        int regnum;
        !            67:        unsigned long long regval_l;
        !            68:        unsigned regval;
        !            69:        
        !            70:        printf("%u:%u  delta = %u\n",
        !            71:                event->timeStamp.high_val, event->timeStamp.low_val,
        !            72:                ts_diff(&event->timeStamp, &tsvalLast));
        !            73:        tsvalLast = event->timeStamp;
        !            74:        printf("   address %d\n", 
        !            75:                event->deviceAddress);
        !            76:        for(regnum=0; regnum<=3; regnum++) {
        !            77:                reg = *((unsigned *)(&event->regs[regnum].data.stand.byte[0]));
        !            78:                regval_l = adbDeviceRegisterData(&event->regs[regnum]);
        !            79:                if(regval_l > ULONG_MAX) {
        !            80:                        printf("***length exceeded; using ULONG_MAX\n");
        !            81:                        regval = ULONG_MAX;
        !            82:                }
        !            83:                else
        !            84:                        regval = regval_l;
        !            85:                printf("   register %d: length %d data 0x%x\n",
        !            86:                        regnum, event->regs[regnum].length, regval);
        !            87:        }
        !            88:        [_keyboard freeAdbEvent:event];
        !            89: }
        !            90: 
        !            91: - (IOReturn)relinquishOwnershipRequest : device;
        !            92: {
        !            93:        printf("adbClient: reset relinquishOwnershipRequest\n");
        !            94:        return IO_R_SUCCESS;
        !            95: }
        !            96: 
        !            97: - setKeyboard : keyboard
        !            98: {
        !            99:        _keyboard = keyboard;
        !           100:        return self;
        !           101: }
        !           102: 
        !           103: - (void)canBecomeOwner : device
        !           104: {
        !           105:        printf("adbClient: canBecomeOwner\n");
        !           106: }
        !           107: 
        !           108: @end
        !           109: 
        !           110: extern int verbose;
        !           111: 
        !           112: int main(int argc, char **argv)
        !           113: {
        !           114:        int arg;
        !           115:        id driverId;
        !           116:        id keyboardId;
        !           117:        id clientId;
        !           118:        int reset_interval = 0;
        !           119:        IOReturn drtn;
        !           120:        
        !           121:        if(argc < 1)
        !           122:                usage(argv);
        !           123:        for(arg=1; arg<argc; arg++) {
        !           124:                switch(argv[arg][0]) {
        !           125:                    case 'v':
        !           126:                        verbose++;
        !           127:                        break;
        !           128:                    case 'r':
        !           129:                        reset_interval = atoi(&argv[arg][2]);
        !           130:                        break;
        !           131:                    default:
        !           132:                        usage(argv);
        !           133:                }
        !           134:        }
        !           135: 
        !           136:         IOInitGeneralFuncs();
        !           137:        IOInitDDM(200, "adbXpr");
        !           138:        IOSetDDMMask(XPR_IODEVICE_INDEX, XPR_ADB);
        !           139: 
        !           140:        /*
        !           141:         * Instantiate and init a client, the keyboard device, and the driver.
        !           142:         */
        !           143:        clientId = [adbClient new];
        !           144:        [adbDriver probe:0 deviceMaster:PORT_NULL];
        !           145:        drtn = IOGetObjectForDeviceName("adb0", &driverId);
        !           146:        if(drtn) {
        !           147:                printf("IOGetObjectForDeviceName(adb0) returned %d\n", drtn);
        !           148:                exit(1);
        !           149:        }
        !           150:        if(driverId == nil) {
        !           151:                printf("adbDriver probe failed; exiting\n");
        !           152:                exit(1);
        !           153:        }
        !           154:        [adbKeyboard probe:driverId];
        !           155:        drtn = IOGetObjectForDeviceName("adbKeyboard0", &keyboardId);
        !           156:        if(drtn) {
        !           157:                printf("IOGetObjectForDeviceName(adbKeyboard0) returned %d\n", drtn);
        !           158:                exit(1);
        !           159:        }
        !           160:        if(keyboardId == nil) {
        !           161:                printf("adbKeyboard probe failed; exiting\n");
        !           162:                exit(1);
        !           163:        }
        !           164:        [clientId setKeyboard:keyboardId];
        !           165:        [keyboardId becomeOwner:clientId];
        !           166: 
        !           167:        while(1) {
        !           168:                if(reset_interval) {
        !           169:                        IOSleep(reset_interval * 1000);
        !           170:                        printf("...resetting bus\n");
        !           171:                        [driverId resetAdb];
        !           172:                }
        !           173:                else {
        !           174:                        IOSleep(10);
        !           175:                }
        !           176:        }
        !           177: }
        !           178: 
        !           179: static void usage(char **argv)
        !           180: {
        !           181:        printf("usage: %s [options]\n", argv[0]);
        !           182:        printf("Options:\n");
        !           183:        printf("\tv  verbose mode\n");
        !           184:        printf("\tr=reset_interval (in seconds; default is no reset)\n");
        !           185:        exit(1);
        !           186: }
        !           187: 

unix.superglobalmegacorp.com

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