]> git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/IOPMinformeeList.cpp
2ba440a145087c2f5bc51f54c831bd925042870c
[apple/xnu.git] / iokit / Kernel / IOPMinformeeList.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/IOPMinformeeList.h>
30 #include <IOKit/pwr_mgt/IOPMinformee.h>
31
32 #define super OSObject
33 OSDefineMetaClassAndStructors(IOPMinformeeList,OSObject)
34
35 //*********************************************************************************
36 // init
37 //
38 //*********************************************************************************
39 void IOPMinformeeList::initialize ( void )
40 {
41 firstItem = NULL;
42 length = 0;
43 }
44
45 //*********************************************************************************
46 // addToList
47 //
48 //*********************************************************************************
49
50 IOReturn IOPMinformeeList::addToList ( IOPMinformee * newInformee )
51 {
52 IOPMinformee * nextInformee;
53 nextInformee = firstItem; // Is new object already in the list?
54 while ( nextInformee != NULL ) {
55 if ( nextInformee->whatObject == newInformee->whatObject ) {
56 return IOPMNoErr; // yes, just return
57 }
58 nextInformee = nextInList(nextInformee);
59 }
60 newInformee->nextInList = firstItem; // add it to list
61 firstItem = newInformee;
62 length += 1;
63 return IOPMNoErr;
64 }
65
66
67 //*********************************************************************************
68 // firstInList
69 //
70 //*********************************************************************************
71
72 IOPMinformee * IOPMinformeeList::firstInList ( void )
73 {
74 return firstItem;
75 }
76
77 //*********************************************************************************
78 // nextInList
79 //
80 //*********************************************************************************
81
82 IOPMinformee * IOPMinformeeList::nextInList ( IOPMinformee * 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 IOPMinformeeList::numberOfItems ( void )
96 {
97 return length;
98 }
99
100 //*********************************************************************************
101 // findItem
102 //
103 // Look through the list for the one which points to the object identified
104 // by the parameter. Return a pointer to the list item or NULL.
105 //*********************************************************************************
106
107 IOPMinformee * IOPMinformeeList::findItem ( IOService * driverOrChild )
108 {
109 IOPMinformee * nextObject;
110
111 nextObject = firstInList();
112 while ( nextObject != NULL ) {
113 if ( nextObject->whatObject == driverOrChild ) {
114 return nextObject;
115 }
116 nextObject = nextInList(nextObject);
117 }
118 return NULL;
119 }
120
121
122 //*********************************************************************************
123 // removeFromList
124 //
125 // Find the item in the list, unlink it, and free it.
126 //*********************************************************************************
127
128 IOReturn IOPMinformeeList::removeFromList ( IOService * theItem )
129 {
130 IOPMinformee * item = firstItem;
131 IOPMinformee * temp;
132
133 if ( item != NULL ) {
134 if ( item->whatObject == theItem ) {
135 firstItem = item->nextInList;
136 length--;
137 item->release();
138 return IOPMNoErr;
139 }
140 while ( item->nextInList != NULL ) {
141 if ( item->nextInList->whatObject == theItem ) {
142 temp = item->nextInList;
143 item->nextInList = temp->nextInList;
144 length--;
145 temp->release();
146 return IOPMNoErr;
147 }
148 item = item->nextInList;
149 }
150 }
151 return IOPMNoErr;
152 }
153
154
155 //*********************************************************************************
156 // free
157 //
158 // Free all items in the list, and then free the list itself
159 //*********************************************************************************
160
161 void IOPMinformeeList::free (void )
162 {
163 IOPMinformee * next = firstItem;
164
165 while ( next != NULL ) {
166 firstItem = next->nextInList;
167 length--;
168 next->release();
169 next = firstItem;
170 }
171 super::free();
172 }
173