]>
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@
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
;
47 nextPowerSource
= firstItem
; // Is new object already in the list?
48 while ( nextPowerSource
!= NULL
) {
49 if ( nextPowerSource
== newPowerSource
) {
50 return IOPMNoErr
; // yes, just return
52 nextPowerSource
= nextInList(nextPowerSource
);
54 newPowerSource
->nextInList
= firstItem
; // add it to list
55 firstItem
= newPowerSource
;
61 //*********************************************************************************
64 //*********************************************************************************
66 IOPMPowerSource
* IOPMPowerSourceList::firstInList ( void )
71 //*********************************************************************************
74 //*********************************************************************************
76 IOPMPowerSource
* IOPMPowerSourceList::nextInList ( IOPMPowerSource
* currentItem
)
78 if ( currentItem
!= NULL
) {
79 return (currentItem
->nextInList
);
84 //*********************************************************************************
87 //*********************************************************************************
89 unsigned long IOPMPowerSourceList::numberOfItems ( void )
94 //*********************************************************************************
97 // Find the item in the list, unlink it, and free it.
98 //*********************************************************************************
100 IOReturn
IOPMPowerSourceList::removeFromList ( IOPMPowerSource
* theItem
)
102 IOPMPowerSource
* item
= firstItem
;
103 IOPMPowerSource
* temp
;
105 if ( item
!= NULL
) {
106 if ( item
== theItem
) {
107 firstItem
= item
->nextInList
;
112 while ( item
->nextInList
!= NULL
) {
113 if ( item
->nextInList
== theItem
) {
114 temp
= item
->nextInList
;
115 item
->nextInList
= temp
->nextInList
;
120 item
= item
->nextInList
;
127 //*********************************************************************************
130 // Free all items in the list, and then free the list itself
131 //*********************************************************************************
133 void IOPMPowerSourceList::free (void )
135 IOPMPowerSource
* next
= firstItem
;
137 while ( next
!= NULL
) {
138 firstItem
= next
->nextInList
;