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