home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 April: Mac OS SDK / Dev.CD Apr 99 SDK1.toast / Development Kits / Mac OS USB DDK / Examples / MouseModule / MouseModuleHeader.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-10  |  4.9 KB  |  155 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        MouseModuleHeader.c
  3.  
  4.     Contains:    Mouse Module Header file
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 1997-1999 by Apple Computer, Inc., all rights reserved.
  9.  
  10. */
  11.  
  12. #include <Types.h>
  13. #include <Devices.h>
  14. #include <DriverServices.h>
  15. #include <USB.h>
  16.  
  17.  
  18. #include "MouseModule.h"
  19. #include "MouseModuleVersion.h"
  20.  
  21. static     OSStatus     MouseModuleInitialize (USBDeviceRef device, USBDeviceDescriptorPtr pDesc, UInt32 busPowerAvailable);
  22. static     OSStatus     MouseModuleFinalize(USBDeviceRef device, USBDeviceDescriptorPtr pDesc);
  23. static     OSStatus     MouseInterfaceInitialize (UInt32 interfacenum, USBInterfaceDescriptorPtr pInterface, USBDeviceDescriptorPtr pDesc, USBDeviceRef device);
  24. static     OSStatus    MouseNotifyProc(UInt32     notification, void *pointer, UInt32 refcon);
  25.  
  26. extern    usbMousePBStruct myMousePB;
  27.  
  28. //------------------------------------------------------
  29. //
  30. //    This is the driver description structure that the expert looks for first.
  31. //  If it's here, the information within is used to match the driver
  32. //  to the device whose descriptor was passed to the expert.
  33. //    Information in this block is also used by the expert when an
  34. //  entry is created in the Name Registry.
  35. //
  36. //------------------------------------------------------
  37. USBDriverDescription    TheUSBDriverDescription = 
  38. {
  39.     // Signature info
  40.     kTheUSBDriverDescriptionSignature,
  41.     kInitialUSBDriverDescriptor,
  42.     
  43.     // Device Info
  44.     0,                                        // vendor = not device specific
  45.     0,                                        // product = not device specific
  46.     0,                                        // version of product = not device specific
  47.     kUSBMouseInterfaceProtocol,                // protocol = not device specific
  48.     
  49.     // Interface Info    (* I don't think this would always be required...*)                
  50.     0,                                        // Configuration Value
  51.     0,                                        // Interface Number
  52.     kUSBHIDInterfaceClass,                    // Interface Class
  53.     kUSBBootInterfaceSubClass,                 // Interface SubClass
  54.     kUSBMouseInterfaceProtocol,                // Interface Protocol
  55.         
  56.     
  57.     // Driver Info
  58.     kMouseModuleName kMouseStringVersShort,    // Driver name for Name Registry
  59.     kUSBHIDInterfaceClass,                    // Device Class  (from USBDeviceDefines.h)
  60.     kUSBBootInterfaceSubClass,                // Device Subclass 
  61.     kMouseHexMajorVers, 
  62.     kMouseHexMinorVers, 
  63.     kMouseCurrentRelease, 
  64.     kMouseReleaseStage,                        // version of driver
  65.     
  66.     // Driver Loading Info
  67.     kUSBProtocolMustMatch                    // Flags (currently undefined)
  68. };
  69.  
  70. USBClassDriverPluginDispatchTable TheClassDriverPluginDispatchTable =
  71. {
  72.     kClassDriverPluginVersion,                // Version of this structure
  73.     0,                                        // Hardware Validation Procedure
  74.     MouseDeviceInitialize,                    // Initialization Procedure
  75.     MouseInterfaceInitialize,                // Interface Initialization Procedure
  76.     MouseModuleFinalize,                    // Finalization Procedure
  77.     MouseNotifyProc,                        // Driver Notification Procedure
  78. };
  79.     
  80.  
  81. // Initialization function
  82. // Called upon load by Expert
  83. static     OSStatus     MouseDeviceInitialize (USBDeviceRef device, USBDeviceDescriptorPtr pDesc, UInt32 busPowerAvailable)
  84. {
  85. #pragma unused (busPowerAvailable)
  86. #pragma unused (pDesc)
  87.     USBExpertStatus(device, kMouseModuleName": Entered via MouseDeviceInitialize!", device);
  88.     return (OSStatus)noErr;
  89. }
  90.  
  91. // Interface Initialization Initialization function
  92. // Called upon load by Expert
  93. static     OSStatus     MouseInterfaceInitialize (UInt32 interfacenum, USBInterfaceDescriptorPtr pInterface, USBDeviceDescriptorPtr pDesc, USBDeviceRef device)
  94. {
  95.     InterfaceEntry(interfacenum, pInterface, pDesc, device);
  96.     return (OSStatus)noErr;
  97. }
  98.  
  99. static OSStatus    MouseNotifyProc(UInt32     notification, void *pointer, UInt32 refcon)
  100. {
  101. #pragma unused (pointer)
  102. #pragma unused (refcon)
  103.  
  104. OSStatus        status = noErr; 
  105.  
  106.     switch (notification)
  107.     {
  108.         case kNotifyDriverBeingRemoved:
  109.             myMousePB.driverRemovalPending = true;
  110.             
  111.             USBExpertStatus(myMousePB.interfaceRef, kMouseModuleName": Notification that driver removal is pending...", notification);
  112.             if (myMousePB.pb.usbRefcon & kCompletionPending)
  113.             {
  114.                 USBExpertStatus(myMousePB.interfaceRef, kMouseModuleName": Waiting for transaction to complete", myMousePB.pb.usbRefcon);
  115.                 if (myMousePB.pipeRef)
  116.                 {
  117.                     USBExpertStatus(myMousePB.interfaceRef, kMouseModuleName": Aborting interrupt pipe", myMousePB.pipeRef);
  118.                     if (USBAbortPipeByReference(myMousePB.pipeRef) != noErr){
  119.                         myMousePB.pb.usbRefcon &=  ~kCompletionPending;   // don't expect the completion to be called either
  120.                     }
  121.                     myMousePB.intPipeAborted = true;
  122.                     myMousePB.pipeRef = nil;
  123.                 }
  124.                 status = kUSBDeviceBusy;
  125.             }
  126.             break;
  127.             
  128.         default:
  129.             break;
  130.     } // switch
  131.     
  132.     return(status);
  133. }
  134.  
  135.  
  136. // Termination function
  137. // Called by Expert when driver is being shut down
  138. static OSStatus MouseModuleFinalize(USBDeviceRef theDeviceRef, USBDeviceDescriptorPtr pDesc)
  139. {
  140. #pragma unused (pDesc)
  141. //USBHIDData        theMouseData;
  142.  
  143.     USBExpertStatus(theDeviceRef, kMouseModuleName": Finalize", 0);
  144.     
  145.     if (myMousePB.pCursorDeviceInfo != 0)                
  146.     {
  147.         USBExpertStatus(theDeviceRef, kMouseModuleName": Removing CDM device", 0);
  148.         CursorDeviceDisposeDevice(myMousePB.pCursorDeviceInfo);
  149.         myMousePB.pCursorDeviceInfo = 0;
  150.     }
  151.     
  152.     return (OSStatus)noErr;
  153. }
  154.  
  155.