home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Technology Seed / ADC Seed CD - July 1999.toast / USB / Mac OS USB DDK v1.2 / Examples / MouseModule / MouseModuleHeader.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-04-15  |  5.0 KB  |  158 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 kNotifyExpertTerminating:            // TCC <USB22>
  109.                 return(noErr);
  110.             break;
  111.         case kNotifyDriverBeingRemoved:
  112.             myMousePB.driverRemovalPending = true;
  113.             
  114.             USBExpertStatus(myMousePB.interfaceRef, kMouseModuleName": Notification that driver removal is pending...", notification);
  115.             if (myMousePB.pb.usbRefcon & kCompletionPending)
  116.             {
  117.                 USBExpertStatus(myMousePB.interfaceRef, kMouseModuleName": Waiting for transaction to complete", myMousePB.pb.usbRefcon);
  118.                 if (myMousePB.pipeRef)
  119.                 {
  120.                     USBExpertStatus(myMousePB.interfaceRef, kMouseModuleName": Aborting interrupt pipe", myMousePB.pipeRef);
  121.                     if (USBAbortPipeByReference(myMousePB.pipeRef) != noErr){
  122.                         myMousePB.pb.usbRefcon &=  ~kCompletionPending;   // don't expect the completion to be called either
  123.                     }
  124.                     myMousePB.intPipeAborted = true;
  125.                     myMousePB.pipeRef = nil;
  126.                 }
  127.                 status = kUSBDeviceBusy;
  128.             }
  129.             break;
  130.             
  131.         default:
  132.             break;
  133.     } // switch
  134.     
  135.     return(status);
  136. }
  137.  
  138.  
  139. // Termination function
  140. // Called by Expert when driver is being shut down
  141. static OSStatus MouseModuleFinalize(USBDeviceRef theDeviceRef, USBDeviceDescriptorPtr pDesc)
  142. {
  143. #pragma unused (pDesc)
  144. //USBHIDData        theMouseData;
  145.  
  146.     USBExpertStatus(theDeviceRef, kMouseModuleName": Finalize", 0);
  147.     
  148.     if (myMousePB.pCursorDeviceInfo != 0)                
  149.     {
  150.         USBExpertStatus(theDeviceRef, kMouseModuleName": Removing CDM device", 0);
  151.         CursorDeviceDisposeDevice(myMousePB.pCursorDeviceInfo);
  152.         myMousePB.pCursorDeviceInfo = 0;
  153.     }
  154.     
  155.     return (OSStatus)noErr;
  156. }
  157.  
  158.