]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
6601e61a | 4 | * @APPLE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
6601e61a A |
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. | |
8f6c56a5 | 11 | * |
6601e61a A |
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 | |
8f6c56a5 A |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
6601e61a A |
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. | |
8f6c56a5 | 19 | * |
6601e61a | 20 | * @APPLE_LICENSE_HEADER_END@ |
1c79356b | 21 | */ |
1c79356b A |
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 | ||
0c530ab8 | 29 | //****************************************************************************** |
1c79356b A |
30 | // init |
31 | // | |
0c530ab8 | 32 | //****************************************************************************** |
1c79356b A |
33 | void IOPMPowerSourceList::initialize ( void ) |
34 | { | |
35 | firstItem = NULL; | |
36 | length = 0; | |
37 | } | |
38 | ||
0c530ab8 | 39 | //****************************************************************************** |
1c79356b A |
40 | // addToList |
41 | // | |
0c530ab8 | 42 | //****************************************************************************** |
1c79356b | 43 | |
0c530ab8 | 44 | IOReturn IOPMPowerSourceList::addToList(IOPMPowerSource *newPowerSource) |
1c79356b A |
45 | { |
46 | IOPMPowerSource * nextPowerSource; | |
0c530ab8 A |
47 | |
48 | // Is new object already in the list? | |
49 | nextPowerSource = firstItem; | |
50 | while ( nextPowerSource != NULL ) | |
51 | { | |
52 | if ( nextPowerSource == newPowerSource ) | |
53 | { | |
54 | // yes, just return | |
55 | return IOPMNoErr; | |
1c79356b A |
56 | } |
57 | nextPowerSource = nextInList(nextPowerSource); | |
58 | } | |
0c530ab8 A |
59 | |
60 | // add it to list | |
61 | newPowerSource->nextInList = firstItem; | |
1c79356b | 62 | firstItem = newPowerSource; |
0c530ab8 | 63 | length++; |
1c79356b A |
64 | return IOPMNoErr; |
65 | } | |
66 | ||
67 | ||
0c530ab8 | 68 | //****************************************************************************** |
1c79356b A |
69 | // firstInList |
70 | // | |
0c530ab8 | 71 | //****************************************************************************** |
1c79356b A |
72 | |
73 | IOPMPowerSource * IOPMPowerSourceList::firstInList ( void ) | |
74 | { | |
75 | return firstItem; | |
76 | } | |
77 | ||
0c530ab8 | 78 | //****************************************************************************** |
1c79356b A |
79 | // nextInList |
80 | // | |
0c530ab8 | 81 | //****************************************************************************** |
1c79356b | 82 | |
0c530ab8 | 83 | IOPMPowerSource * IOPMPowerSourceList::nextInList(IOPMPowerSource *currentItem) |
1c79356b A |
84 | { |
85 | if ( currentItem != NULL ) { | |
86 | return (currentItem->nextInList); | |
87 | } | |
88 | return NULL; | |
89 | } | |
90 | ||
0c530ab8 | 91 | //****************************************************************************** |
1c79356b A |
92 | // numberOfItems |
93 | // | |
0c530ab8 | 94 | //****************************************************************************** |
1c79356b A |
95 | |
96 | unsigned long IOPMPowerSourceList::numberOfItems ( void ) | |
97 | { | |
98 | return length; | |
99 | } | |
100 | ||
0c530ab8 | 101 | //****************************************************************************** |
1c79356b A |
102 | // removeFromList |
103 | // | |
104 | // Find the item in the list, unlink it, and free it. | |
0c530ab8 | 105 | //****************************************************************************** |
1c79356b A |
106 | |
107 | IOReturn IOPMPowerSourceList::removeFromList ( IOPMPowerSource * theItem ) | |
108 | { | |
109 | IOPMPowerSource * item = firstItem; | |
110 | IOPMPowerSource * temp; | |
111 | ||
0c530ab8 A |
112 | if ( NULL == item) goto exit; |
113 | ||
114 | if ( item == theItem ) { | |
115 | firstItem = item->nextInList; | |
116 | length--; | |
117 | item->release(); | |
118 | return IOPMNoErr; | |
119 | } | |
120 | while ( item->nextInList != NULL ) { | |
121 | if ( item->nextInList == theItem ) { | |
122 | temp = item->nextInList; | |
123 | item->nextInList = temp->nextInList; | |
1c79356b | 124 | length--; |
0c530ab8 | 125 | temp->release(); |
1c79356b A |
126 | return IOPMNoErr; |
127 | } | |
0c530ab8 | 128 | item = item->nextInList; |
1c79356b | 129 | } |
0c530ab8 A |
130 | |
131 | exit: | |
1c79356b A |
132 | return IOPMNoErr; |
133 | } | |
134 | ||
135 | ||
0c530ab8 | 136 | //****************************************************************************** |
1c79356b A |
137 | // free |
138 | // | |
139 | // Free all items in the list, and then free the list itself | |
0c530ab8 | 140 | //****************************************************************************** |
1c79356b A |
141 | |
142 | void IOPMPowerSourceList::free (void ) | |
143 | { | |
144 | IOPMPowerSource * next = firstItem; | |
145 | ||
146 | while ( next != NULL ) { | |
147 | firstItem = next->nextInList; | |
148 | length--; | |
149 | next->release(); | |
150 | next = firstItem; | |
151 | } | |
0c530ab8 | 152 | super::free(); |
1c79356b A |
153 | } |
154 | ||
155 | ||
156 | ||
157 | ||
158 | ||
159 | ||
160 |