]> git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/IOPMPowerSourceList.cpp
xnu-792.24.17.tar.gz
[apple/xnu.git] / iokit / Kernel / IOPMPowerSourceList.cpp
1 /*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 #include <IOKit/pwr_mgt/IOPM.h>
23 #include <IOKit/pwr_mgt/IOPMPowerSourceList.h>
24 #include <IOKit/pwr_mgt/IOPMPowerSource.h>
25
26 #define super OSObject
27 OSDefineMetaClassAndStructors(IOPMPowerSourceList,OSObject)
28
29 //*********************************************************************************
30 // init
31 //
32 //*********************************************************************************
33 void IOPMPowerSourceList::initialize ( void )
34 {
35 firstItem = NULL;
36 length = 0;
37 }
38
39 //*********************************************************************************
40 // addToList
41 //
42 //*********************************************************************************
43
44 IOReturn IOPMPowerSourceList::addToList ( IOPMPowerSource * newPowerSource )
45 {
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
51 }
52 nextPowerSource = nextInList(nextPowerSource);
53 }
54 newPowerSource->nextInList = firstItem; // add it to list
55 firstItem = newPowerSource;
56 length += 1;
57 return IOPMNoErr;
58 }
59
60
61 //*********************************************************************************
62 // firstInList
63 //
64 //*********************************************************************************
65
66 IOPMPowerSource * IOPMPowerSourceList::firstInList ( void )
67 {
68 return firstItem;
69 }
70
71 //*********************************************************************************
72 // nextInList
73 //
74 //*********************************************************************************
75
76 IOPMPowerSource * IOPMPowerSourceList::nextInList ( IOPMPowerSource * currentItem )
77 {
78 if ( currentItem != NULL ) {
79 return (currentItem->nextInList);
80 }
81 return NULL;
82 }
83
84 //*********************************************************************************
85 // numberOfItems
86 //
87 //*********************************************************************************
88
89 unsigned long IOPMPowerSourceList::numberOfItems ( void )
90 {
91 return length;
92 }
93
94 //*********************************************************************************
95 // removeFromList
96 //
97 // Find the item in the list, unlink it, and free it.
98 //*********************************************************************************
99
100 IOReturn IOPMPowerSourceList::removeFromList ( IOPMPowerSource * theItem )
101 {
102 IOPMPowerSource * item = firstItem;
103 IOPMPowerSource * temp;
104
105 if ( item != NULL ) {
106 if ( item == theItem ) {
107 firstItem = item->nextInList;
108 length--;
109 item->release();
110 return IOPMNoErr;
111 }
112 while ( item->nextInList != NULL ) {
113 if ( item->nextInList == theItem ) {
114 temp = item->nextInList;
115 item->nextInList = temp->nextInList;
116 length--;
117 temp->release();
118 return IOPMNoErr;
119 }
120 item = item->nextInList;
121 }
122 }
123 return IOPMNoErr;
124 }
125
126
127 //*********************************************************************************
128 // free
129 //
130 // Free all items in the list, and then free the list itself
131 //*********************************************************************************
132
133 void IOPMPowerSourceList::free (void )
134 {
135 IOPMPowerSource * next = firstItem;
136
137 while ( next != NULL ) {
138 firstItem = next->nextInList;
139 length--;
140 next->release();
141 next = firstItem;
142 }
143 super::free();
144 }
145
146
147
148
149
150
151