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