]>
git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/IOPMPowerSourceList.cpp
   2  * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved. 
   4  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 
   6  * This file contains Original Code and/or Modifications of Original Code 
   7  * as defined in and that are subject to the Apple Public Source License 
   8  * Version 2.0 (the 'License'). You may not use this file except in 
   9  * compliance with the License. The rights granted to you under the License 
  10  * may not be used to create, or enable the creation or redistribution of, 
  11  * unlawful or unlicensed copies of an Apple operating system, or to 
  12  * circumvent, violate, or enable the circumvention or violation of, any 
  13  * terms of an Apple operating system software license agreement. 
  15  * Please obtain a copy of the License at 
  16  * http://www.opensource.apple.com/apsl/ and read it before using this file. 
  18  * The Original Code and all software distributed under the License are 
  19  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
  20  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
  21  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 
  22  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
  23  * Please see the License for the specific language governing rights and 
  24  * limitations under the License. 
  26  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 
  28 #include <IOKit/pwr_mgt/IOPM.h> 
  29 #include <IOKit/pwr_mgt/IOPMPowerSourceList.h> 
  30 #include <IOKit/pwr_mgt/IOPMPowerSource.h> 
  32 #define super OSObject 
  33 OSDefineMetaClassAndStructors(IOPMPowerSourceList
,OSObject
) 
  35 //****************************************************************************** 
  38 //****************************************************************************** 
  39 void IOPMPowerSourceList::initialize ( void ) 
  45 //****************************************************************************** 
  48 //****************************************************************************** 
  50 IOReturn 
IOPMPowerSourceList::addToList(IOPMPowerSource 
*newPowerSource
) 
  52     IOPMPowerSource 
* nextPowerSource
; 
  54     // Is new object already in the list? 
  55     nextPowerSource 
= firstItem
; 
  56     while (  nextPowerSource 
!= NULL 
)  
  58         if ( nextPowerSource 
== newPowerSource 
)  
  63         nextPowerSource 
= nextInList(nextPowerSource
); 
  67     newPowerSource
->nextInList 
= firstItem
; 
  68     firstItem 
= newPowerSource
; 
  74 //****************************************************************************** 
  77 //****************************************************************************** 
  79 IOPMPowerSource 
* IOPMPowerSourceList::firstInList ( void ) 
  84 //****************************************************************************** 
  87 //****************************************************************************** 
  89 IOPMPowerSource 
* IOPMPowerSourceList::nextInList(IOPMPowerSource 
*currentItem
) 
  91     if ( currentItem 
!= NULL 
) { 
  92        return (currentItem
->nextInList
); 
  97 //****************************************************************************** 
 100 //****************************************************************************** 
 102 unsigned long IOPMPowerSourceList::numberOfItems ( void ) 
 107 //****************************************************************************** 
 110 // Find the item in the list, unlink it, and free it. 
 111 //****************************************************************************** 
 113 IOReturn 
IOPMPowerSourceList::removeFromList ( IOPMPowerSource 
* theItem 
) 
 115     IOPMPowerSource 
* item 
= firstItem
; 
 116     IOPMPowerSource 
* temp
; 
 118     if ( NULL 
== item
) goto exit
; 
 120     if ( item  
== theItem 
) { 
 121         firstItem 
= item
->nextInList
; 
 126     while ( item
->nextInList 
!= NULL 
) { 
 127         if ( item
->nextInList 
== theItem 
) { 
 128             temp 
= item
->nextInList
; 
 129             item
->nextInList 
= temp
->nextInList
; 
 134         item 
= item
->nextInList
; 
 142 //****************************************************************************** 
 145 // Free all items in the list, and then free the list itself 
 146 //****************************************************************************** 
 148 void IOPMPowerSourceList::free (void ) 
 150     IOPMPowerSource 
* next 
= firstItem
; 
 152     while ( next 
!= NULL 
) { 
 153         firstItem 
= next
->nextInList
;