home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 August: Tool Chest / Dev.CD Aug 99 TC.toast / What's New? / Development Kits / Hardware / Mac OS USB DDK v1.3a1 / Examples / MouseModule / MouseModuleHeader.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-06-16  |  5.1 KB  |  160 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. extern    usbMousePBStruct watchDogPB;
  28.  
  29. //------------------------------------------------------
  30. //
  31. //    This is the driver description structure that the expert looks for first.
  32. //  If it's here, the information within is used to match the driver
  33. //  to the device whose descriptor was passed to the expert.
  34. //    Information in this block is also used by the expert when an
  35. //  entry is created in the Name Registry.
  36. //
  37. //------------------------------------------------------
  38. USBDriverDescription    TheUSBDriverDescription = 
  39. {
  40.     // Signature info
  41.     kTheUSBDriverDescriptionSignature,
  42.     kInitialUSBDriverDescriptor,
  43.     
  44.     // Device Info
  45.     0,                                        // vendor = not device specific
  46.     0,                                        // product = not device specific
  47.     0,                                        // version of product = not device specific
  48.     kUSBMouseInterfaceProtocol,                // protocol = not device specific
  49.     
  50.     // Interface Info    (* I don't think this would always be required...*)                
  51.     0,                                        // Configuration Value
  52.     0,                                        // Interface Number
  53.     kUSBHIDInterfaceClass,                    // Interface Class
  54.     kUSBBootInterfaceSubClass,                 // Interface SubClass
  55.     kUSBMouseInterfaceProtocol,                // Interface Protocol
  56.         
  57.     
  58.     // Driver Info
  59.     kMouseModuleName kMouseStringVersShort,    // Driver name for Name Registry
  60.     kUSBHIDInterfaceClass,                    // Device Class  (from USBDeviceDefines.h)
  61.     kUSBBootInterfaceSubClass,                // Device Subclass 
  62.     kMouseHexMajorVers, 
  63.     kMouseHexMinorVers, 
  64.     kMouseCurrentRelease, 
  65.     kMouseReleaseStage,                        // version of driver
  66.     
  67.     // Driver Loading Info
  68.     kUSBProtocolMustMatch                    // Flags (currently undefined)
  69. };
  70.  
  71. USBClassDriverPluginDispatchTable TheClassDriverPluginDispatchTable =
  72. {
  73.     kClassDriverPluginVersion,                // Version of this structure
  74.     0,                                        // Hardware Validation Procedure
  75.     MouseDeviceInitialize,                    // Initialization Procedure
  76.     MouseInterfaceInitialize,                // Interface Initialization Procedure
  77.     MouseModuleFinalize,                    // Finalization Procedure
  78.     MouseNotifyProc,                        // Driver Notification Procedure
  79. };
  80.     
  81.  
  82. // Initialization function
  83. // Called upon load by Expert
  84. static     OSStatus     MouseDeviceInitialize (USBDeviceRef device, USBDeviceDescriptorPtr pDesc, UInt32 busPowerAvailable)
  85. {
  86. #pragma unused (busPowerAvailable)
  87. #pragma unused (pDesc)
  88.     USBExpertStatus(device, kMouseModuleName": Entered via MouseDeviceInitialize!", device);
  89.     return (OSStatus)noErr;
  90. }
  91.  
  92. // Interface Initialization Initialization function
  93. // Called upon load by Expert
  94. static     OSStatus     MouseInterfaceInitialize (UInt32 interfacenum, USBInterfaceDescriptorPtr pInterface, USBDeviceDescriptorPtr pDesc, USBDeviceRef device)
  95. {
  96.     InterfaceEntry(interfacenum, pInterface, pDesc, device);
  97.     return (OSStatus)noErr;
  98. }
  99.  
  100. static OSStatus    MouseNotifyProc(UInt32     notification, void *pointer, UInt32 refcon)
  101. {
  102. #pragma unused (pointer)
  103. #pragma unused (refcon)
  104.  
  105. OSStatus        status = noErr; 
  106.  
  107.     switch (notification)
  108.     {
  109.         case kNotifyExpertTerminating:            // TCC <USB22>
  110.                 return(noErr);
  111.             break;
  112.         case kNotifyDriverBeingRemoved:
  113.             myMousePB.driverRemovalPending = true;
  114.             watchDogPB.driverRemovalPending = true;
  115.             
  116.             USBExpertStatus(myMousePB.interfaceRef, kMouseModuleName": Notification that driver removal is pending...", notification);
  117.             if (myMousePB.pb.usbRefcon & kCompletionPending)
  118.             {
  119.                 USBExpertStatus(myMousePB.interfaceRef, kMouseModuleName": Waiting for transaction to complete", myMousePB.pb.usbRefcon);
  120.                 if (myMousePB.pipeRef)
  121.                 {
  122.                     USBExpertStatus(myMousePB.interfaceRef, kMouseModuleName": Aborting interrupt pipe", myMousePB.pipeRef);
  123.                     if (USBAbortPipeByReference(myMousePB.pipeRef) != noErr){
  124.                         myMousePB.pb.usbRefcon &=  ~kCompletionPending;   // don't expect the completion to be called either
  125.                     }
  126.                     myMousePB.intPipeAborted = true;
  127.                     myMousePB.pipeRef = nil;
  128.                 }
  129.                 status = kUSBDeviceBusy;
  130.             }
  131.             break;
  132.             
  133.         default:
  134.             break;
  135.     } // switch
  136.     
  137.     return(status);
  138. }
  139.  
  140.  
  141. // Termination function
  142. // Called by Expert when driver is being shut down
  143. static OSStatus MouseModuleFinalize(USBDeviceRef theDeviceRef, USBDeviceDescriptorPtr pDesc)
  144. {
  145. #pragma unused (pDesc)
  146. //USBHIDData        theMouseData;
  147.  
  148.     USBExpertStatus(theDeviceRef, kMouseModuleName": Finalize", 0);
  149.     
  150.     if (myMousePB.pCursorDeviceInfo != 0)                
  151.     {
  152.         USBExpertStatus(theDeviceRef, kMouseModuleName": Removing CDM device", 0);
  153.         CursorDeviceDisposeDevice(myMousePB.pCursorDeviceInfo);
  154.         myMousePB.pCursorDeviceInfo = 0;
  155.     }
  156.     
  157.     return (OSStatus)noErr;
  158. }
  159.  
  160.