]> git.saurik.com Git - apple/xnu.git/blame - iokit/Kernel/IOPMPowerSourceList.cpp
xnu-4570.71.2.tar.gz
[apple/xnu.git] / iokit / Kernel / IOPMPowerSourceList.cpp
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
2d21ac55
A
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.
8f6c56a5 14 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b 27 */
1c79356b
A
28#include <IOKit/pwr_mgt/IOPM.h>
29#include <IOKit/pwr_mgt/IOPMPowerSourceList.h>
30#include <IOKit/pwr_mgt/IOPMPowerSource.h>
31
32#define super OSObject
33OSDefineMetaClassAndStructors(IOPMPowerSourceList,OSObject)
34
0c530ab8 35//******************************************************************************
1c79356b
A
36// init
37//
0c530ab8 38//******************************************************************************
1c79356b
A
39void IOPMPowerSourceList::initialize ( void )
40{
41 firstItem = NULL;
42 length = 0;
43}
44
0c530ab8 45//******************************************************************************
1c79356b
A
46// addToList
47//
0c530ab8 48//******************************************************************************
1c79356b 49
0c530ab8 50IOReturn IOPMPowerSourceList::addToList(IOPMPowerSource *newPowerSource)
1c79356b
A
51{
52 IOPMPowerSource * nextPowerSource;
0c530ab8
A
53
54 // Is new object already in the list?
55 nextPowerSource = firstItem;
56 while ( nextPowerSource != NULL )
57 {
58 if ( nextPowerSource == newPowerSource )
59 {
60 // yes, just return
61 return IOPMNoErr;
1c79356b
A
62 }
63 nextPowerSource = nextInList(nextPowerSource);
64 }
0c530ab8
A
65
66 // add it to list
67 newPowerSource->nextInList = firstItem;
1c79356b 68 firstItem = newPowerSource;
0c530ab8 69 length++;
1c79356b
A
70 return IOPMNoErr;
71}
72
73
0c530ab8 74//******************************************************************************
1c79356b
A
75// firstInList
76//
0c530ab8 77//******************************************************************************
1c79356b
A
78
79IOPMPowerSource * IOPMPowerSourceList::firstInList ( void )
80{
81 return firstItem;
82}
83
0c530ab8 84//******************************************************************************
1c79356b
A
85// nextInList
86//
0c530ab8 87//******************************************************************************
1c79356b 88
0c530ab8 89IOPMPowerSource * IOPMPowerSourceList::nextInList(IOPMPowerSource *currentItem)
1c79356b
A
90{
91 if ( currentItem != NULL ) {
92 return (currentItem->nextInList);
93 }
94 return NULL;
95}
96
0c530ab8 97//******************************************************************************
1c79356b
A
98// numberOfItems
99//
0c530ab8 100//******************************************************************************
1c79356b
A
101
102unsigned long IOPMPowerSourceList::numberOfItems ( void )
103{
104 return length;
105}
106
0c530ab8 107//******************************************************************************
1c79356b
A
108// removeFromList
109//
110// Find the item in the list, unlink it, and free it.
0c530ab8 111//******************************************************************************
1c79356b
A
112
113IOReturn IOPMPowerSourceList::removeFromList ( IOPMPowerSource * theItem )
114{
115 IOPMPowerSource * item = firstItem;
116 IOPMPowerSource * temp;
117
0c530ab8
A
118 if ( NULL == item) goto exit;
119
120 if ( item == theItem ) {
121 firstItem = item->nextInList;
122 length--;
123 item->release();
124 return IOPMNoErr;
125 }
126 while ( item->nextInList != NULL ) {
127 if ( item->nextInList == theItem ) {
128 temp = item->nextInList;
129 item->nextInList = temp->nextInList;
1c79356b 130 length--;
0c530ab8 131 temp->release();
1c79356b
A
132 return IOPMNoErr;
133 }
0c530ab8 134 item = item->nextInList;
1c79356b 135 }
0c530ab8
A
136
137exit:
1c79356b
A
138 return IOPMNoErr;
139}
140
141
0c530ab8 142//******************************************************************************
1c79356b
A
143// free
144//
145// Free all items in the list, and then free the list itself
0c530ab8 146//******************************************************************************
1c79356b
A
147
148void IOPMPowerSourceList::free (void )
149{
150 IOPMPowerSource * next = firstItem;
151
152 while ( next != NULL ) {
153 firstItem = next->nextInList;
154 length--;
155 next->release();
156 next = firstItem;
157 }
0c530ab8 158 super::free();
1c79356b
A
159}
160
161
162
163
164
165
166