]>
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
;
53 nextPowerSource
= firstItem
; // Is new object already in the list?
54 while ( nextPowerSource
!= NULL
) {
55 if ( nextPowerSource
== newPowerSource
) {
56 return IOPMNoErr
; // yes, just return
58 nextPowerSource
= nextInList(nextPowerSource
);
60 newPowerSource
->nextInList
= firstItem
; // add it to list
61 firstItem
= newPowerSource
;
67 //*********************************************************************************
70 //*********************************************************************************
72 IOPMPowerSource
* IOPMPowerSourceList::firstInList ( void )
77 //*********************************************************************************
80 //*********************************************************************************
82 IOPMPowerSource
* IOPMPowerSourceList::nextInList ( IOPMPowerSource
* currentItem
)
84 if ( currentItem
!= NULL
) {
85 return (currentItem
->nextInList
);
90 //*********************************************************************************
93 //*********************************************************************************
95 unsigned long IOPMPowerSourceList::numberOfItems ( void )
100 //*********************************************************************************
103 // Find the item in the list, unlink it, and free it.
104 //*********************************************************************************
106 IOReturn
IOPMPowerSourceList::removeFromList ( IOPMPowerSource
* theItem
)
108 IOPMPowerSource
* item
= firstItem
;
109 IOPMPowerSource
* temp
;
111 if ( item
!= NULL
) {
112 if ( item
== theItem
) {
113 firstItem
= item
->nextInList
;
118 while ( item
->nextInList
!= NULL
) {
119 if ( item
->nextInList
== theItem
) {
120 temp
= item
->nextInList
;
121 item
->nextInList
= temp
->nextInList
;
126 item
= item
->nextInList
;
133 //*********************************************************************************
136 // Free all items in the list, and then free the list itself
137 //*********************************************************************************
139 void IOPMPowerSourceList::free (void )
141 IOPMPowerSource
* next
= firstItem
;
143 while ( next
!= NULL
) {
144 firstItem
= next
->nextInList
;