]>
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 <stddef.h> | |
23 | #include <IOKit/pwr_mgt/IOPM.h> | |
24 | #include <IOKit/pwr_mgt/IOPMPowerSourceList.h> | |
25 | #include <IOKit/pwr_mgt/IOPMPowerSource.h> | |
26 | ||
27 | #define super OSObject | |
28 | OSDefineMetaClassAndStructors(IOPMPowerSourceList,OSObject) | |
29 | ||
30 | //********************************************************************************* | |
31 | // init | |
32 | // | |
33 | //********************************************************************************* | |
34 | void IOPMPowerSourceList::initialize ( void ) | |
35 | { | |
36 | firstItem = NULL; | |
37 | length = 0; | |
38 | } | |
39 | ||
40 | //********************************************************************************* | |
41 | // addToList | |
42 | // | |
43 | //********************************************************************************* | |
44 | ||
45 | IOReturn IOPMPowerSourceList::addToList ( IOPMPowerSource * newPowerSource ) | |
46 | { | |
47 | IOPMPowerSource * nextPowerSource; | |
48 | nextPowerSource = firstItem; // Is new object already in the list? | |
49 | while ( nextPowerSource != NULL ) { | |
50 | if ( nextPowerSource == newPowerSource ) { | |
51 | return IOPMNoErr; // yes, just return | |
52 | } | |
53 | nextPowerSource = nextInList(nextPowerSource); | |
54 | } | |
55 | newPowerSource->nextInList = firstItem; // add it to list | |
56 | firstItem = newPowerSource; | |
57 | length += 1; | |
58 | return IOPMNoErr; | |
59 | } | |
60 | ||
61 | ||
62 | //********************************************************************************* | |
63 | // firstInList | |
64 | // | |
65 | //********************************************************************************* | |
66 | ||
67 | IOPMPowerSource * IOPMPowerSourceList::firstInList ( void ) | |
68 | { | |
69 | return firstItem; | |
70 | } | |
71 | ||
72 | //********************************************************************************* | |
73 | // nextInList | |
74 | // | |
75 | //********************************************************************************* | |
76 | ||
77 | IOPMPowerSource * IOPMPowerSourceList::nextInList ( IOPMPowerSource * currentItem ) | |
78 | { | |
79 | if ( currentItem != NULL ) { | |
80 | return (currentItem->nextInList); | |
81 | } | |
82 | return NULL; | |
83 | } | |
84 | ||
85 | //********************************************************************************* | |
86 | // numberOfItems | |
87 | // | |
88 | //********************************************************************************* | |
89 | ||
90 | unsigned long IOPMPowerSourceList::numberOfItems ( void ) | |
91 | { | |
92 | return length; | |
93 | } | |
94 | ||
95 | //********************************************************************************* | |
96 | // removeFromList | |
97 | // | |
98 | // Find the item in the list, unlink it, and free it. | |
99 | //********************************************************************************* | |
100 | ||
101 | IOReturn IOPMPowerSourceList::removeFromList ( IOPMPowerSource * theItem ) | |
102 | { | |
103 | IOPMPowerSource * item = firstItem; | |
104 | IOPMPowerSource * temp; | |
105 | ||
106 | if ( item != NULL ) { | |
107 | if ( item == theItem ) { | |
108 | firstItem = item->nextInList; | |
109 | length--; | |
110 | item->release(); | |
111 | return IOPMNoErr; | |
112 | } | |
113 | while ( item->nextInList != NULL ) { | |
114 | if ( item->nextInList == theItem ) { | |
115 | temp = item->nextInList; | |
116 | item->nextInList = temp->nextInList; | |
117 | length--; | |
118 | temp->release(); | |
119 | return IOPMNoErr; | |
120 | } | |
121 | item = item->nextInList; | |
122 | } | |
123 | } | |
124 | return IOPMNoErr; | |
125 | } | |
126 | ||
127 | ||
128 | //********************************************************************************* | |
129 | // free | |
130 | // | |
131 | // Free all items in the list, and then free the list itself | |
132 | //********************************************************************************* | |
133 | ||
134 | void IOPMPowerSourceList::free (void ) | |
135 | { | |
136 | IOPMPowerSource * next = firstItem; | |
137 | ||
138 | while ( next != NULL ) { | |
139 | firstItem = next->nextInList; | |
140 | length--; | |
141 | next->release(); | |
142 | next = firstItem; | |
143 | } | |
144 | super::free(); | |
145 | } | |
146 | ||
147 | ||
148 | ||
149 | ||
150 | ||
151 | ||
152 |