]> git.saurik.com Git - apple/xnu.git/blame_incremental - iokit/Kernel/IOPMPowerSourceList.cpp
xnu-4570.71.2.tar.gz
[apple/xnu.git] / iokit / Kernel / IOPMPowerSourceList.cpp
... / ...
CommitLineData
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/IOPMPowerSourceList.h>
30#include <IOKit/pwr_mgt/IOPMPowerSource.h>
31
32#define super OSObject
33OSDefineMetaClassAndStructors(IOPMPowerSourceList,OSObject)
34
35//******************************************************************************
36// init
37//
38//******************************************************************************
39void IOPMPowerSourceList::initialize ( void )
40{
41 firstItem = NULL;
42 length = 0;
43}
44
45//******************************************************************************
46// addToList
47//
48//******************************************************************************
49
50IOReturn IOPMPowerSourceList::addToList(IOPMPowerSource *newPowerSource)
51{
52 IOPMPowerSource * nextPowerSource;
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;
62 }
63 nextPowerSource = nextInList(nextPowerSource);
64 }
65
66 // add it to list
67 newPowerSource->nextInList = firstItem;
68 firstItem = newPowerSource;
69 length++;
70 return IOPMNoErr;
71}
72
73
74//******************************************************************************
75// firstInList
76//
77//******************************************************************************
78
79IOPMPowerSource * IOPMPowerSourceList::firstInList ( void )
80{
81 return firstItem;
82}
83
84//******************************************************************************
85// nextInList
86//
87//******************************************************************************
88
89IOPMPowerSource * IOPMPowerSourceList::nextInList(IOPMPowerSource *currentItem)
90{
91 if ( currentItem != NULL ) {
92 return (currentItem->nextInList);
93 }
94 return NULL;
95}
96
97//******************************************************************************
98// numberOfItems
99//
100//******************************************************************************
101
102unsigned long IOPMPowerSourceList::numberOfItems ( void )
103{
104 return length;
105}
106
107//******************************************************************************
108// removeFromList
109//
110// Find the item in the list, unlink it, and free it.
111//******************************************************************************
112
113IOReturn IOPMPowerSourceList::removeFromList ( IOPMPowerSource * theItem )
114{
115 IOPMPowerSource * item = firstItem;
116 IOPMPowerSource * temp;
117
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;
130 length--;
131 temp->release();
132 return IOPMNoErr;
133 }
134 item = item->nextInList;
135 }
136
137exit:
138 return IOPMNoErr;
139}
140
141
142//******************************************************************************
143// free
144//
145// Free all items in the list, and then free the list itself
146//******************************************************************************
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 }
158 super::free();
159}
160
161
162
163
164
165
166