]> git.saurik.com Git - apple/xnu.git/blame - iokit/Kernel/IOPMinformeeList.cpp
xnu-344.49.tar.gz
[apple/xnu.git] / iokit / Kernel / IOPMinformeeList.cpp
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
43866e37 6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
1c79356b 7 *
43866e37
A
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1c79356b
A
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
43866e37
A
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
1c79356b
A
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
1c79356b
A
25#include <IOKit/pwr_mgt/IOPM.h>
26#include <IOKit/pwr_mgt/IOPMinformeeList.h>
27#include <IOKit/pwr_mgt/IOPMinformee.h>
28
29#define super OSObject
30OSDefineMetaClassAndStructors(IOPMinformeeList,OSObject)
31
32//*********************************************************************************
33// init
34//
35//*********************************************************************************
36void IOPMinformeeList::initialize ( void )
37{
38 firstItem = NULL;
39 length = 0;
40}
41
42//*********************************************************************************
43// addToList
44//
45//*********************************************************************************
46
47IOReturn IOPMinformeeList::addToList ( IOPMinformee * newInformee )
48{
49 IOPMinformee * nextInformee;
50 nextInformee = firstItem; // Is new object already in the list?
51 while ( nextInformee != NULL ) {
52 if ( nextInformee->whatObject == newInformee->whatObject ) {
53 return IOPMNoErr; // yes, just return
54 }
55 nextInformee = nextInList(nextInformee);
56 }
57 newInformee->nextInList = firstItem; // add it to list
58 firstItem = newInformee;
59 length += 1;
60 return IOPMNoErr;
61}
62
63
64//*********************************************************************************
65// firstInList
66//
67//*********************************************************************************
68
69IOPMinformee * IOPMinformeeList::firstInList ( void )
70{
71 return firstItem;
72}
73
74//*********************************************************************************
75// nextInList
76//
77//*********************************************************************************
78
79IOPMinformee * IOPMinformeeList::nextInList ( IOPMinformee * currentItem )
80{
81 if ( currentItem != NULL ) {
82 return (currentItem->nextInList);
83 }
84 return NULL;
85}
86
87//*********************************************************************************
88// numberOfItems
89//
90//*********************************************************************************
91
92unsigned long IOPMinformeeList::numberOfItems ( void )
93{
94 return length;
95}
96
97//*********************************************************************************
98// findItem
99//
100// Look through the list for the one which points to the object identified
101// by the parameter. Return a pointer to the list item or NULL.
102//*********************************************************************************
103
104IOPMinformee * IOPMinformeeList::findItem ( IOService * driverOrChild )
105{
106 IOPMinformee * nextObject;
107
108 nextObject = firstInList();
109 while ( nextObject != NULL ) {
110 if ( nextObject->whatObject == driverOrChild ) {
111 return nextObject;
112 }
113 nextObject = nextInList(nextObject);
114 }
115 return NULL;
116}
117
118
119//*********************************************************************************
120// removeFromList
121//
122// Find the item in the list, unlink it, and free it.
123//*********************************************************************************
124
125IOReturn IOPMinformeeList::removeFromList ( IOService * theItem )
126{
127 IOPMinformee * item = firstItem;
128 IOPMinformee * temp;
129
130 if ( item != NULL ) {
131 if ( item->whatObject == theItem ) {
132 firstItem = item->nextInList;
133 length--;
134 item->release();
135 return IOPMNoErr;
136 }
137 while ( item->nextInList != NULL ) {
138 if ( item->nextInList->whatObject == theItem ) {
139 temp = item->nextInList;
140 item->nextInList = temp->nextInList;
141 length--;
142 temp->release();
143 return IOPMNoErr;
144 }
145 item = item->nextInList;
146 }
147 }
148 return IOPMNoErr;
149}
150
151
152//*********************************************************************************
153// free
154//
155// Free all items in the list, and then free the list itself
156//*********************************************************************************
157
158void IOPMinformeeList::free (void )
159{
160 IOPMinformee * next = firstItem;
161
162 while ( next != NULL ) {
163 firstItem = next->nextInList;
164 length--;
165 next->release();
166 next = firstItem;
167 }
168super::free();
169}
170