Annotation of driverkit/Examples/loadable/Kernel/myHandler.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: /*
                     25:  * Simple loadable kernel Handler example.
                     26:  *
                     27:  * This Handler accepts one message, setDevicePort(). This is how the
                     28:  * user-level module, XXX, passes the device port obtained from Config
                     29:  * down to a kernel-level IODevice.
                     30:  */
                     31: #import <kernserv/kern_server_types.h>
                     32: #import <kernserv/printf.h>
                     33: #import <mach/mig_errors.h>
                     34: #import "myDevice.h"
                     35: #import "myHandlerHandler.h"
                     36: #import <driverkit/kernelDriver.h>
                     37: #import <driverkit/generalFuncs.h>
                     38: 
                     39: kern_return_t setDevicePort(void *arg, port_t devicePort);
                     40: kern_return_t initDevice(void *arg);
                     41: kern_return_t shutDown(void *arg);
                     42: 
                     43: static id myDeviceId;
                     44: 
                     45: /*
                     46:  * Create the struct used by mig-generated code to convert from 
                     47:  * message to setDevicePort() callout.
                     48:  */
                     49: myHandler_t myHandlerStruct = {
                     50:        0,
                     51:        100,
                     52:        setDevicePort,
                     53:        initDevice,
                     54:        shutDown
                     55: };
                     56: 
                     57: /*
                     58:  * Allocate an instance variable to be used by the kernel server interface
                     59:  * routines for initializing and accessing this service.
                     60:  */
                     61: kern_server_t myHandlerInstance;
                     62: 
                     63: /*
                     64:  * Stamp our arival.
                     65:  */
                     66: void myHandlerInit(void)
                     67: {
                     68:        printf("myHandler initialized\n");
                     69: }
                     70: 
                     71: /*
                     72:  * Notify the world that we're going away.
                     73:  */
                     74: void myHandlerSignoff(void)
                     75: {
                     76:        printf("myHandler unloaded\n");
                     77: }
                     78: 
                     79: kern_return_t setDevicePort(
                     80:        void *arg,              // what's this?
                     81:        port_t devicePort)
                     82: {
                     83: #if    0
                     84:        port_t devicePortIOTask = convertPortToIOTask(devicePort);
                     85: #else  0
                     86:        port_t devicePortIOTask = IOConvertPort(devicePort,
                     87:                IO_CurrentTask, IO_KernelIOTask);
                     88: #endif 0
                     89:        IOLog("myHandler setDevicePort: devicePort %d; %d in IOTask space\n", 
                     90:                devicePort, devicePortIOTask);
                     91:        myDeviceId = [myDevice alloc];
                     92:        [myDeviceId setDevicePort:devicePortIOTask];
                     93:        return KERN_SUCCESS;
                     94: }
                     95: 
                     96: kern_return_t initDevice(void *arg)
                     97: {
                     98:        IOLog("myHandler initDevice\n");
                     99:        [myDeviceId init];
                    100:        return KERN_SUCCESS;
                    101: }
                    102: 
                    103: kern_return_t shutDown(void *arg)
                    104: {
                    105:        IOLog("myHandler shutDown\n");
                    106:        [myDeviceId shutDown];
                    107:        [myDevice free];
                    108:        return KERN_SUCCESS;
                    109: }

unix.superglobalmegacorp.com

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