]>
git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/IOPMPowerSourceList.cpp
cace37fa4c05f995269c83b9e026891c27dc37ff
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 #include <IOKit/pwr_mgt/IOPM.h>
23 #include <IOKit/pwr_mgt/IOPMPowerSourceList.h>
24 #include <IOKit/pwr_mgt/IOPMPowerSource.h>
26 #define super OSObject
27 OSDefineMetaClassAndStructors(IOPMPowerSourceList
,OSObject
)
29 //******************************************************************************
32 //******************************************************************************
33 void IOPMPowerSourceList::initialize ( void )
39 //******************************************************************************
42 //******************************************************************************
44 IOReturn
IOPMPowerSourceList::addToList(IOPMPowerSource
*newPowerSource
)
46 IOPMPowerSource
* nextPowerSource
;
48 // Is new object already in the list?
49 nextPowerSource
= firstItem
;
50 while ( nextPowerSource
!= NULL
)
52 if ( nextPowerSource
== newPowerSource
)
57 nextPowerSource
= nextInList(nextPowerSource
);
61 newPowerSource
->nextInList
= firstItem
;
62 firstItem
= newPowerSource
;
68 //******************************************************************************
71 //******************************************************************************
73 IOPMPowerSource
* IOPMPowerSourceList::firstInList ( void )
78 //******************************************************************************
81 //******************************************************************************
83 IOPMPowerSource
* IOPMPowerSourceList::nextInList(IOPMPowerSource
*currentItem
)
85 if ( currentItem
!= NULL
) {
86 return (currentItem
->nextInList
);
91 //******************************************************************************
94 //******************************************************************************
96 unsigned long IOPMPowerSourceList::numberOfItems ( void )
101 //******************************************************************************
104 // Find the item in the list, unlink it, and free it.
105 //******************************************************************************
107 IOReturn
IOPMPowerSourceList::removeFromList ( IOPMPowerSource
* theItem
)
109 IOPMPowerSource
* item
= firstItem
;
110 IOPMPowerSource
* temp
;
112 if ( NULL
== item
) goto exit
;
114 if ( item
== theItem
) {
115 firstItem
= item
->nextInList
;
120 while ( item
->nextInList
!= NULL
) {
121 if ( item
->nextInList
== theItem
) {
122 temp
= item
->nextInList
;
123 item
->nextInList
= temp
->nextInList
;
128 item
= item
->nextInList
;
136 //******************************************************************************
139 // Free all items in the list, and then free the list itself
140 //******************************************************************************
142 void IOPMPowerSourceList::free (void )
144 IOPMPowerSource
* next
= firstItem
;
146 while ( next
!= NULL
) {
147 firstItem
= next
->nextInList
;