home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 July: Mac OS SDK / Dev.CD Jul 00 SDK2.toast / Development Kits / Hardware / Mac OS USB DDK / Mac OS USB DDK 1.4.1 / Examples / USBSampleStorageDriver / UnitTableDriver / UnitTableDoDriverIO.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-25  |  3.9 KB  |  139 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        UnitTableDoDriverIO
  3.  
  4.     Contains:    This file contains the sole entry point into the driver
  5.                 from the system, and the sole return command completion point.
  6.  
  7.     Version:    1.0
  8.  
  9.     Copyright:    © 1998-1999 by Apple Computer, Inc., all rights reserved.
  10.  
  11. */
  12.  
  13.  
  14. #include "UnitTableDoDriverIO.h"
  15. #include "UnitTableFunctions.h"
  16.  
  17. //----------------------------------------------------------------------------------
  18. //    The DoDriverIO Function -
  19. //     This function is the only entry to our driver from the Device Manager
  20. //----------------------------------------------------------------------------------
  21.  
  22. OSStatus DoDriverIO(    AddressSpaceID        addressSpaceID,
  23.                         IOCommandID            ioCommandID,
  24.                         IOCommandContents    ioCommandContents,
  25.                         IOCommandCode        ioCommandCode,
  26.                         IOCommandKind        ioCommandKind)
  27. {
  28. #pragma unused ( addressSpaceID )
  29.     OSStatus    status;
  30.  
  31.     // All mangement of the Address space should be handled here.  Currently the
  32.     // MacOS only supports one address space so nothing needs to be done.
  33.     
  34.     /*
  35.         Note: Initialize, Open, KillIO, Close, and Finalize are either synchronous
  36.         or immediate. Read, Write, Control, and Status may be immediate,
  37.         synchronous, or asynchronous.
  38.     */
  39.     switch (ioCommandCode)
  40.     {
  41.         case kInitializeCommand:        /* Always immediate */
  42.             status = DriverInitializeCmd ( ioCommandContents.initialInfo->refNum, &ioCommandContents.initialInfo->deviceEntry );
  43.             break;
  44.         
  45.         case kFinalizeCommand:            /* Always immediate */
  46.             status = DriverFinalizeCmd ( ioCommandContents.finalInfo->refNum, &ioCommandContents.finalInfo->deviceEntry );
  47.             break;
  48.         
  49.         case kSupersededCommand:        /* Always immediate */
  50.             status = DriverSupersededCmd ( ioCommandContents.supersededInfo->refNum, &ioCommandContents.supersededInfo->deviceEntry );
  51.             break;
  52.         
  53.         case kReplaceCommand:            /* Always immediate, replace an old driver */
  54.             status = DriverReplaceCmd (  ioCommandContents.replaceInfo->refNum, &ioCommandContents.replaceInfo->deviceEntry );
  55.             break;
  56.         
  57.         case kOpenCommand:                /* Always immediate */
  58.             status = DriverOpenCmd ( ioCommandContents.pb);
  59.             break;
  60.         
  61.         case kCloseCommand:                /* Always immediate */
  62.             status = DriverCloseCmd ( ioCommandContents.pb );
  63.             break;
  64.         
  65.         case kControlCommand:
  66.             status = DriverControlCmd ( ioCommandID, ioCommandContents.pb );
  67.             break;
  68.         
  69.         case kStatusCommand:
  70.             status = DriverStatusCmd ( ioCommandID, ioCommandContents.pb );
  71.             break;
  72.         
  73.         case kReadCommand:
  74.             status = DriverReadCmd (  ioCommandID, ioCommandContents.pb );
  75.             break;
  76.         
  77.         case kWriteCommand:
  78.             status = DriverWriteCmd ( ioCommandID, ioCommandContents.pb );
  79.             break;
  80.         
  81.         case kKillIOCommand:            /* Always immediate */
  82.             status = DriverKillIOCmd ( ioCommandContents.pb );
  83.             break;
  84.         
  85.         default:
  86.             status = paramErr;
  87.             break;
  88.     }
  89.     
  90.     if ((ioCommandKind & kImmediateIOCommandKind) != 0)
  91.     {
  92.         // We have an immediate command, return the status.
  93.         return status;
  94.     }
  95.     else
  96.     {
  97.         // The command may not yet have finished, FinishCommandProcessing
  98.         // will handle appropriately
  99.         return FinishCommandProcessing(ioCommandID, status);
  100.     }
  101. }
  102.     
  103. OSStatus FinishCommandProcessing(IOCommandID ioCommandID, OSStatus incomingStatus)
  104. {
  105.     OSStatus             status;
  106.     IOCommandContents     ioCommandContents;
  107.     IOCommandCode         ioCommandCode;
  108.     IOCommandKind         ioCommandKind;
  109.  
  110.     status = GetIOCommandInfo( ioCommandID, &ioCommandContents, &ioCommandCode, &ioCommandKind);
  111.     if ( status != noErr )
  112.     {
  113.         return status;
  114.     }
  115.  
  116.     status = incomingStatus;
  117.     
  118.     if ((ioCommandKind & kImmediateIOCommandKind) != 0)
  119.     {
  120.         /* Immediate commands return the operation status and don't call IOCommandIsComplete */
  121.         IfDebugging("\pImmd cmd complete");
  122.     }
  123.     else if (incomingStatus == ioInProgress)
  124.     {
  125.         IfDebugging("\pincomingStatus == ioInProgress");
  126.         /* Perform the action and call IOCommandIsComplete at some later time */
  127.         status = noErr;
  128.     }
  129.     else
  130.     {
  131.         IfDebugging("\pDo Command Is Complete");        
  132.         status = IOCommandIsComplete (ioCommandID, incomingStatus);
  133.     }
  134.  
  135.     IfDebugging("\pExit FinishCommandProcessing");
  136.     return (status);
  137. }
  138.  
  139.