home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connectio…eloper Series 2005 March / Dev.CD Mar 05.iso / What's New / Technical Notes and Q&As / ADC Reference Library / technotes / tn2002 / downloads / tn2076.sit / HelloIOKitwithPowerManagement / HelloIOKitwithPowerManagement.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2003-06-17  |  2.0 KB  |  63 lines

  1. #include <IOKit/IOLib.h>
  2. #include "HelloIOKitwithPowerManagement.h"
  3. extern "C" {
  4. #include <pexpert/pexpert.h>
  5. }
  6. // Define my superclass
  7. #define super IOService
  8. // REQUIRED! This macro defines the class's constructors, destructors,
  9. // and several other methods I/O Kit requires. Do NOT use super as the
  10. // second parameter. You must use the literal name of the superclass.
  11. OSDefineMetaClassAndStructors(com_DTS_driver_HelloIOKitwithPowerManagement, IOService)
  12.  
  13. bool com_DTS_driver_HelloIOKitwithPowerManagement::init(OSDictionary *dict)
  14. {
  15. bool res = super::init(dict);
  16. IOLog("%s:DTS Sample Code\n",getName());
  17. if (res = true)
  18.     IOLog("%s:Initializing\n",getName());
  19. else
  20.     IOLog("%s:No Initialization\n",getName());
  21. return true;
  22. }
  23. void com_DTS_driver_HelloIOKitwithPowerManagement::free(void)
  24. {
  25. IOLog("%s:Freeing\n",getName());
  26. super::free();
  27. }
  28. IOService *com_DTS_driver_HelloIOKitwithPowerManagement::probe(IOService *provider,
  29. SInt32 *score)
  30. {
  31. IOService *res = super::probe(provider, score);
  32. IOLog("%s:Probing\n",getName());
  33. return res;
  34. }
  35. bool com_DTS_driver_HelloIOKitwithPowerManagement::start(IOService *provider)
  36. {
  37. IOReturn    myValue;
  38. bool res = super::start(provider);
  39. IOLog("%s:Starting\n",getName());
  40. // initialize superclass variables from IOService.h
  41.         PMinit();
  42. // register as controlling driver from IOService.h
  43.         myValue = registerPowerDriver(this, (IOPMPowerState *) ourPowerStates,
  44.                             kNumDTSStates );
  45.         if (myValue != kIOReturnSuccess) {
  46.         IOLog("%s: Failed to registerPowerDriver.\n", getName());
  47.         }
  48.         // join the tree from IOService.h
  49.         provider->joinPMtree(this);
  50.  
  51. return res;
  52. }
  53. void com_DTS_driver_HelloIOKitwithPowerManagement::stop(IOService *provider)
  54. {
  55. IOLog("%s:Stopping\n",getName());
  56. PMstop();
  57. super::stop(provider);
  58. }
  59. // set your device power on/off logic here
  60. IOReturn com_DTS_driver_HelloIOKitwithPowerManagement::setPowerState(unsigned long whatState, IOService* dontCare){
  61.     IOLog("%s:PowerManagement setting power state:%lu\n",getName(), whatState);
  62.     return IOPMAckImplied;
  63. }