MoreDevices/TradDriverLoaderLib/TestTradDriverLoaderLib/TestDriver/TestDriverMain.c

/*
    File:       TestDriverMain.c
 
    Contains:   Implementation of a very stupid device driver.
 
    Written by: Quinn
 
    Copyright:  Copyright © 1996-1999 by Apple Computer, Inc., all rights reserved.
 
                You may incorporate this Apple sample source code into your program(s) without
                restriction. This Apple sample source code has been provided "AS IS" and the
                responsibility for its operation is yours. You are not permitted to redistribute
                this Apple sample source code as "Apple sample source code" after having made
                changes. If you're going to re-distribute the source, we require that you make
                it clear in the source that the code was descended from Apple sample source
                code, but that you've made changes.
 
    Change History (most recent first):
 
         <2>    22/11/00    Quinn   Switch to "MacTypes.h".
         <1>     25/2/99    Quinn   First checked in.
*/
 
/////////////////////////////////////////////////////////////////
// MoreIsBetter Setup
 
#include "MoreSetup.h"
 
/////////////////////////////////////////////////////////////////
// Mac OS Interfaces
 
#include <MacTypes.h>
#include <Devices.h>
 
/////////////////////////////////////////////////////////////////
 
static pascal OSErr DRVROpen(ParmBlkPtr paramBlock, DCtlPtr devCtlEnt)
{
    #pragma unused (paramBlock)
    #pragma unused (devCtlEnt)
    return noErr;
}
 
static pascal OSErr DRVRPrime(ParmBlkPtr paramBlock, DCtlPtr devCtlEnt)
{
    #pragma unused (paramBlock)
    #pragma unused (devCtlEnt)
    return -1;
}
 
static pascal OSErr DRVRControl(ParmBlkPtr paramBlock, DCtlPtr devCtlEnt)
{
    #pragma unused (paramBlock)
    #pragma unused (devCtlEnt)
    return controlErr;
}
 
static pascal OSErr DRVRStatus(ParmBlkPtr paramBlock, DCtlPtr devCtlEnt)
{
    #pragma unused (paramBlock)
    #pragma unused (devCtlEnt)
    OSErr err;
    CntrlParamPtr cpb;
    
    cpb = (CntrlParamPtr) paramBlock;
    
    switch ( cpb->csCode ) {
        case 666:
            cpb->csParam[0] = cpb->ioCRefNum;
            err = noErr;
            break;
        default:
            err = statusErr;
    }
    
    return err;
}
 
static pascal OSErr DRVRClose(ParmBlkPtr paramBlock, DCtlPtr devCtlEnt)
{
    #pragma unused (paramBlock)
    #pragma unused (devCtlEnt)
    return noErr;
}
 
OSErr main(ParmBlkPtr paramBlock, DCtlPtr devCtlEnt, short dispatch)
{
//
//  Here A4 is already setup to point to our data segment. There is no need
//  to call long oldA4=SetCurrentA4();/SetA4(oldA4); as in code resources.
//
//  However you have to still have to use "#include <SetupA4.h>;RememberA4();..."
//  when using callback functions.
//
// If your routine returns 1 (asynch request can't be completed right away)
// the Metrowerks startup code will correctly jump to jIODone.  You don't need
// to worry about this issue in this driver.
//
    OSErr   err = noErr;
    
    switch(dispatch)
    {
    case 0: //  Open
        err = DRVROpen(paramBlock, devCtlEnt);
        break;
    case 1: //  Prime       return 1 if async request cannot be completed right away
        err = DRVRPrime(paramBlock, devCtlEnt);
        break;
    case 2: //  Control     return 1 if async request cannot be completed right away
        err = DRVRControl(paramBlock, devCtlEnt);
        break;
    case 3: //  Status      return 1 if async request cannot be completed right away
        err = DRVRStatus(paramBlock, devCtlEnt);
        break;
    case 4: //  Close
        err = DRVRClose(paramBlock, devCtlEnt);
        break;
    }
    return err;
}