]>
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_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@
23 #include <IOKit/pwr_mgt/IOPM.h>
24 #include <IOKit/pwr_mgt/IOPMPowerSourceList.h>
25 #include <IOKit/pwr_mgt/IOPMPowerSource.h>
27 #define super OSObject
28 OSDefineMetaClassAndStructors(IOPMPowerSourceList
,OSObject
)
30 //*********************************************************************************
33 //*********************************************************************************
34 void IOPMPowerSourceList::initialize ( void )
40 //*********************************************************************************
43 //*********************************************************************************
45 IOReturn
IOPMPowerSourceList::addToList ( IOPMPowerSource
* newPowerSource
)
47 IOPMPowerSource
* nextPowerSource
;
48 nextPowerSource
= firstItem
; // Is new object already in the list?
49 while ( nextPowerSource
!= NULL
) {
50 if ( nextPowerSource
== newPowerSource
) {
51 return IOPMNoErr
; // yes, just return
53 nextPowerSource
= nextInList(nextPowerSource
);
55 newPowerSource
->nextInList
= firstItem
; // add it to list
56 firstItem
= newPowerSource
;
62 //*********************************************************************************
65 //*********************************************************************************
67 IOPMPowerSource
* IOPMPowerSourceList::firstInList ( void )
72 //*********************************************************************************
75 //*********************************************************************************
77 IOPMPowerSource
* IOPMPowerSourceList::nextInList ( IOPMPowerSource
* currentItem
)
79 if ( currentItem
!= NULL
) {
80 return (currentItem
->nextInList
);
85 //*********************************************************************************
88 //*********************************************************************************
90 unsigned long IOPMPowerSourceList::numberOfItems ( void )
95 //*********************************************************************************
98 // Find the item in the list, unlink it, and free it.
99 //*********************************************************************************
101 IOReturn
IOPMPowerSourceList::removeFromList ( IOPMPowerSource
* theItem
)
103 IOPMPowerSource
* item
= firstItem
;
104 IOPMPowerSource
* temp
;
106 if ( item
!= NULL
) {
107 if ( item
== theItem
) {
108 firstItem
= item
->nextInList
;
113 while ( item
->nextInList
!= NULL
) {
114 if ( item
->nextInList
== theItem
) {
115 temp
= item
->nextInList
;
116 item
->nextInList
= temp
->nextInList
;
121 item
= item
->nextInList
;
128 //*********************************************************************************
131 // Free all items in the list, and then free the list itself
132 //*********************************************************************************
134 void IOPMPowerSourceList::free (void )
136 IOPMPowerSource
* next
= firstItem
;
138 while ( next
!= NULL
) {
139 firstItem
= next
->nextInList
;