]>
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 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
25 #include <IOKit/pwr_mgt/IOPM.h>
26 #include <IOKit/pwr_mgt/IOPMPowerSourceList.h>
27 #include <IOKit/pwr_mgt/IOPMPowerSource.h>
29 #define super OSObject
30 OSDefineMetaClassAndStructors(IOPMPowerSourceList
,OSObject
)
32 //*********************************************************************************
35 //*********************************************************************************
36 void IOPMPowerSourceList::initialize ( void )
42 //*********************************************************************************
45 //*********************************************************************************
47 IOReturn
IOPMPowerSourceList::addToList ( IOPMPowerSource
* newPowerSource
)
49 IOPMPowerSource
* nextPowerSource
;
50 nextPowerSource
= firstItem
; // Is new object already in the list?
51 while ( nextPowerSource
!= NULL
) {
52 if ( nextPowerSource
== newPowerSource
) {
53 return IOPMNoErr
; // yes, just return
55 nextPowerSource
= nextInList(nextPowerSource
);
57 newPowerSource
->nextInList
= firstItem
; // add it to list
58 firstItem
= newPowerSource
;
64 //*********************************************************************************
67 //*********************************************************************************
69 IOPMPowerSource
* IOPMPowerSourceList::firstInList ( void )
74 //*********************************************************************************
77 //*********************************************************************************
79 IOPMPowerSource
* IOPMPowerSourceList::nextInList ( IOPMPowerSource
* currentItem
)
81 if ( currentItem
!= NULL
) {
82 return (currentItem
->nextInList
);
87 //*********************************************************************************
90 //*********************************************************************************
92 unsigned long IOPMPowerSourceList::numberOfItems ( void )
97 //*********************************************************************************
100 // Find the item in the list, unlink it, and free it.
101 //*********************************************************************************
103 IOReturn
IOPMPowerSourceList::removeFromList ( IOPMPowerSource
* theItem
)
105 IOPMPowerSource
* item
= firstItem
;
106 IOPMPowerSource
* temp
;
108 if ( item
!= NULL
) {
109 if ( item
== theItem
) {
110 firstItem
= item
->nextInList
;
115 while ( item
->nextInList
!= NULL
) {
116 if ( item
->nextInList
== theItem
) {
117 temp
= item
->nextInList
;
118 item
->nextInList
= temp
->nextInList
;
123 item
= item
->nextInList
;
130 //*********************************************************************************
133 // Free all items in the list, and then free the list itself
134 //*********************************************************************************
136 void IOPMPowerSourceList::free (void )
138 IOPMPowerSource
* next
= firstItem
;
140 while ( next
!= NULL
) {
141 firstItem
= next
->nextInList
;