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