]>
Commit | Line | Data |
---|---|---|
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 | ||
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; | |
56 | } | |
57 | nextPowerSource = nextInList(nextPowerSource); | |
58 | } | |
59 | ||
60 | // add it to list | |
61 | newPowerSource->nextInList = firstItem; | |
62 | firstItem = newPowerSource; | |
63 | length++; | |
64 | return IOPMNoErr; | |
65 | } | |
66 | ||
67 | ||
68 | //****************************************************************************** | |
69 | // firstInList | |
70 | // | |
71 | //****************************************************************************** | |
72 | ||
73 | IOPMPowerSource * IOPMPowerSourceList::firstInList ( void ) | |
74 | { | |
75 | return firstItem; | |
76 | } | |
77 | ||
78 | //****************************************************************************** | |
79 | // nextInList | |
80 | // | |
81 | //****************************************************************************** | |
82 | ||
83 | IOPMPowerSource * IOPMPowerSourceList::nextInList(IOPMPowerSource *currentItem) | |
84 | { | |
85 | if ( currentItem != NULL ) { | |
86 | return (currentItem->nextInList); | |
87 | } | |
88 | return NULL; | |
89 | } | |
90 | ||
91 | //****************************************************************************** | |
92 | // numberOfItems | |
93 | // | |
94 | //****************************************************************************** | |
95 | ||
96 | unsigned long IOPMPowerSourceList::numberOfItems ( void ) | |
97 | { | |
98 | return length; | |
99 | } | |
100 | ||
101 | //****************************************************************************** | |
102 | // removeFromList | |
103 | // | |
104 | // Find the item in the list, unlink it, and free it. | |
105 | //****************************************************************************** | |
106 | ||
107 | IOReturn IOPMPowerSourceList::removeFromList ( IOPMPowerSource * theItem ) | |
108 | { | |
109 | IOPMPowerSource * item = firstItem; | |
110 | IOPMPowerSource * temp; | |
111 | ||
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; | |
124 | length--; | |
125 | temp->release(); | |
126 | return IOPMNoErr; | |
127 | } | |
128 | item = item->nextInList; | |
129 | } | |
130 | ||
131 | exit: | |
132 | return IOPMNoErr; | |
133 | } | |
134 | ||
135 | ||
136 | //****************************************************************************** | |
137 | // free | |
138 | // | |
139 | // Free all items in the list, and then free the list itself | |
140 | //****************************************************************************** | |
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 | } | |
152 | super::free(); | |
153 | } | |
154 | ||
155 | ||
156 | ||
157 | ||
158 | ||
159 | ||
160 |