]> git.saurik.com Git - apple/xnu.git/blame - iokit/Kernel/IOPMPowerSourceList.cpp
xnu-7195.101.1.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@
0a7de745 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.
0a7de745 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.
0a7de745 17 *
2d21ac55
A
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.
0a7de745 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
0a7de745 33OSDefineMetaClassAndStructors(IOPMPowerSourceList, OSObject)
1c79356b 34
0c530ab8 35//******************************************************************************
1c79356b
A
36// init
37//
0c530ab8 38//******************************************************************************
0a7de745
A
39void
40IOPMPowerSourceList::initialize( void )
1c79356b 41{
0a7de745
A
42 firstItem = NULL;
43 length = 0;
1c79356b
A
44}
45
0c530ab8 46//******************************************************************************
1c79356b
A
47// addToList
48//
0c530ab8 49//******************************************************************************
1c79356b 50
0a7de745
A
51IOReturn
52IOPMPowerSourceList::addToList(IOPMPowerSource *newPowerSource)
1c79356b 53{
0a7de745
A
54 IOPMPowerSource * nextPowerSource;
55
56 // Is new object already in the list?
57 nextPowerSource = firstItem;
58 while (nextPowerSource != NULL) {
59 if (nextPowerSource == newPowerSource) {
60 // yes, just return
61 return IOPMNoErr;
62 }
63 nextPowerSource = nextInList(nextPowerSource);
64 }
65
66 // add it to list
67 newPowerSource->nextInList = firstItem;
68 firstItem = newPowerSource;
69 length++;
70 return IOPMNoErr;
1c79356b
A
71}
72
73
0c530ab8 74//******************************************************************************
1c79356b
A
75// firstInList
76//
0c530ab8 77//******************************************************************************
1c79356b 78
0a7de745
A
79IOPMPowerSource *
80IOPMPowerSourceList::firstInList( void )
1c79356b 81{
0a7de745 82 return firstItem;
1c79356b
A
83}
84
0c530ab8 85//******************************************************************************
1c79356b
A
86// nextInList
87//
0c530ab8 88//******************************************************************************
1c79356b 89
0a7de745
A
90IOPMPowerSource *
91IOPMPowerSourceList::nextInList(IOPMPowerSource *currentItem)
1c79356b 92{
0a7de745
A
93 if (currentItem != NULL) {
94 return currentItem->nextInList;
95 }
96 return NULL;
1c79356b
A
97}
98
0c530ab8 99//******************************************************************************
1c79356b
A
100// numberOfItems
101//
0c530ab8 102//******************************************************************************
1c79356b 103
0a7de745
A
104unsigned long
105IOPMPowerSourceList::numberOfItems( void )
1c79356b 106{
0a7de745 107 return length;
1c79356b
A
108}
109
0c530ab8 110//******************************************************************************
1c79356b
A
111// removeFromList
112//
113// Find the item in the list, unlink it, and free it.
0c530ab8 114//******************************************************************************
1c79356b 115
0a7de745
A
116IOReturn
117IOPMPowerSourceList::removeFromList( IOPMPowerSource * theItem )
1c79356b 118{
0a7de745
A
119 IOPMPowerSource * item = firstItem;
120 IOPMPowerSource * temp;
121
122 if (NULL == item) {
123 goto exit;
124 }
125
126 if (item == theItem) {
127 firstItem = item->nextInList;
128 length--;
129 item->release();
130 return IOPMNoErr;
131 }
132 while (item->nextInList != NULL) {
133 if (item->nextInList == theItem) {
134 temp = item->nextInList;
135 item->nextInList = temp->nextInList;
136 length--;
137 temp->release();
138 return IOPMNoErr;
139 }
140 item = item->nextInList;
141 }
0c530ab8
A
142
143exit:
0a7de745 144 return IOPMNoErr;
1c79356b
A
145}
146
147
0c530ab8 148//******************************************************************************
1c79356b
A
149// free
150//
151// Free all items in the list, and then free the list itself
0c530ab8 152//******************************************************************************
1c79356b 153
0a7de745
A
154void
155IOPMPowerSourceList::free(void )
1c79356b 156{
0a7de745
A
157 IOPMPowerSource * next = firstItem;
158
159 while (next != NULL) {
160 firstItem = next->nextInList;
161 length--;
162 next->release();
163 next = firstItem;
164 }
165 super::free();
1c79356b 166}