Annotation of driverkit/libDriver/Kernel/IOBufDevice.m, revision 1.1.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: /*     Copyright (c) 1991 NeXT Computer, Inc.  All rights reserved. 
                     25:  *
                     26:  * IOBufDevice.m - Buffered Device abstract superclass.
                     27:  *
                     28:  * HISTORY
                     29:  * 13-Jan-93   John Seamons (jks) at NeXT
                     30:  *     Ported to i386.
                     31:  *
                     32:  * 23-Jun-92   Mike DeMoney ([email protected])
                     33:  *      Major hacks... 
                     34:  *
                     35:  * 16-Jul-91    Doug Mitchell at NeXT
                     36:  *      Created. 
                     37:  *
                     38:  * FIXME:
                     39:  *     Check unit number.  Clean-up unit number usage between this
                     40:  *     class and subclasses.
                     41:  */
                     42: 
                     43: #import <driverkit/IOBufDevice.h>
                     44: 
                     45: #import        <sys/errno.h>
                     46: 
                     47: @interface IOBufDevice (ProxyForSubclass)
                     48: - (IOReturn)initializeUnit                     : (unsigned) unitNumber;
                     49: - (IOReturn)shutdownUnit                       : (unsigned) unitNumber;
                     50: @end
                     51: 
                     52: @implementation IOBufDevice
                     53: 
                     54: - init
                     55: {
                     56:        unsigned unit;
                     57:        UnitInfo *unitInfoP;
                     58: 
                     59:        for (unit = 0; unit < MAX_IOBUFDEVICE_UNITS; unit += 1) {
                     60:                unitInfoP = &unitInfo[unit];
                     61:                unitInfoP->callbackId = nil;
                     62:                unitInfoP->deviceTag = 0;
                     63:                unitInfoP->ownerName[0] = '\0';
                     64:        }
                     65:        return self;
                     66: }
                     67: 
                     68: - (IOReturn)acquireUnit                                : (unsigned) unit
                     69:                                for             : (OwnerName) newName
                     70:                                callbackId      : (id) newId
                     71:                                deviceTag       : (Tag) newTag;
                     72: {
                     73:        UnitInfo *unitInfoP = &unitInfo[unit];
                     74: 
                     75:        if (unitInfoP->callbackId != NULL) {
                     76:                return /* FIXME */ IO_R_BUSY;
                     77:        }
                     78:        strncpy(unitInfoP->ownerName, newName, sizeof(unitInfoP->ownerName));
                     79:        unitInfoP->callbackId = newId;
                     80:        unitInfoP->deviceTag = newTag;
                     81:        [self initializeUnit:unit];
                     82:        return IO_R_SUCCESS;
                     83: }
                     84: 
                     85: 
                     86: - (IOReturn)releaseUnit                                : (unsigned) unit
                     87: {
                     88:        UnitInfo *unitInfoP = &unitInfo[unit];
                     89: 
                     90:        if (unitInfoP->callbackId == NULL) {
                     91:                return /* FIXME */ IO_R_NOT_OWNER;
                     92:        }
                     93:        [self shutdownUnit:unit];
                     94:        unitInfoP->callbackId = NULL;
                     95:        unitInfoP->ownerName[0] = '\0';
                     96:        return IO_R_SUCCESS;
                     97: }
                     98: 
                     99: - (IOReturn)ownerForUnit               : (unsigned) unit
                    100:                        isNamed         : (OwnerName) currentName
                    101: {
                    102:        UnitInfo *unitInfoP = &unitInfo[unit];
                    103: 
                    104:        strncpy(currentName, unitInfoP->ownerName, sizeof(currentName));
                    105:        return IO_R_SUCCESS;
                    106: }
                    107: 
                    108: /*
                    109:  * Convert an IOReturn to text. Subclasses which add additional
                    110:  * IOReturn's should override this method and call [super ioReturnText] if
                    111:  * the desired value is not found.
                    112:  */
                    113: - (const char *)stringFromReturn       : (IOReturn) rtn
                    114: {
                    115:        switch (rtn) {
                    116:        case IO_R_FLUSHED:
                    117:                return "Buffer Flushed";
                    118:        case IO_R_NOT_OWNER:
                    119:                return "Not Owner";
                    120:        }
                    121:        return [super stringFromReturn:rtn];
                    122: }
                    123: 
                    124: /*
                    125:  * Convert an IOReturn to a Unix errno.
                    126:  */
                    127: - (int)errnoFromReturn                         : (IOReturn) rtn
                    128: {
                    129:        switch (rtn) {
                    130:        case IO_R_FLUSHED:
                    131:                return ESHUTDOWN;
                    132:        case IO_R_NOT_OWNER:
                    133:                return EPERM;
                    134:        }
                    135:        return [super errnoFromReturn:rtn];
                    136: }
                    137: @end
                    138: 
                    139: @implementation IOBufDevice (ProxyForSubclass)
                    140: - (IOReturn)initializeUnit                     : (unsigned) unitNumber
                    141: {
                    142: }
                    143: 
                    144: - (IOReturn)shutdownUnit                       : (unsigned) unitNumber
                    145: {
                    146: }
                    147: @end

unix.superglobalmegacorp.com

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