1*c54f35caSApple OSS Distributions /*
2*c54f35caSApple OSS Distributions * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3*c54f35caSApple OSS Distributions *
4*c54f35caSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*c54f35caSApple OSS Distributions *
6*c54f35caSApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code
7*c54f35caSApple OSS Distributions * as defined in and that are subject to the Apple Public Source License
8*c54f35caSApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in
9*c54f35caSApple OSS Distributions * compliance with the License. The rights granted to you under the License
10*c54f35caSApple OSS Distributions * may not be used to create, or enable the creation or redistribution of,
11*c54f35caSApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to
12*c54f35caSApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any
13*c54f35caSApple OSS Distributions * terms of an Apple operating system software license agreement.
14*c54f35caSApple OSS Distributions *
15*c54f35caSApple OSS Distributions * Please obtain a copy of the License at
16*c54f35caSApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*c54f35caSApple OSS Distributions *
18*c54f35caSApple OSS Distributions * The Original Code and all software distributed under the License are
19*c54f35caSApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*c54f35caSApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*c54f35caSApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*c54f35caSApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*c54f35caSApple OSS Distributions * Please see the License for the specific language governing rights and
24*c54f35caSApple OSS Distributions * limitations under the License.
25*c54f35caSApple OSS Distributions *
26*c54f35caSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*c54f35caSApple OSS Distributions */
28*c54f35caSApple OSS Distributions #include <IOKit/pwr_mgt/IOPM.h>
29*c54f35caSApple OSS Distributions #include <IOKit/pwr_mgt/IOPMPowerSourceList.h>
30*c54f35caSApple OSS Distributions #include <IOKit/pwr_mgt/IOPMPowerSource.h>
31*c54f35caSApple OSS Distributions
32*c54f35caSApple OSS Distributions #define super OSObject
OSDefineMetaClassAndStructors(IOPMPowerSourceList,OSObject)33*c54f35caSApple OSS Distributions OSDefineMetaClassAndStructors(IOPMPowerSourceList, OSObject)
34*c54f35caSApple OSS Distributions
35*c54f35caSApple OSS Distributions //******************************************************************************
36*c54f35caSApple OSS Distributions // init
37*c54f35caSApple OSS Distributions //
38*c54f35caSApple OSS Distributions //******************************************************************************
39*c54f35caSApple OSS Distributions void
40*c54f35caSApple OSS Distributions IOPMPowerSourceList::initialize( void )
41*c54f35caSApple OSS Distributions {
42*c54f35caSApple OSS Distributions firstItem = NULL;
43*c54f35caSApple OSS Distributions length = 0;
44*c54f35caSApple OSS Distributions }
45*c54f35caSApple OSS Distributions
46*c54f35caSApple OSS Distributions //******************************************************************************
47*c54f35caSApple OSS Distributions // addToList
48*c54f35caSApple OSS Distributions //
49*c54f35caSApple OSS Distributions //******************************************************************************
50*c54f35caSApple OSS Distributions
51*c54f35caSApple OSS Distributions IOReturn
addToList(IOPMPowerSource * newPowerSource)52*c54f35caSApple OSS Distributions IOPMPowerSourceList::addToList(IOPMPowerSource *newPowerSource)
53*c54f35caSApple OSS Distributions {
54*c54f35caSApple OSS Distributions IOPMPowerSource * nextPowerSource;
55*c54f35caSApple OSS Distributions
56*c54f35caSApple OSS Distributions // Is new object already in the list?
57*c54f35caSApple OSS Distributions nextPowerSource = firstItem;
58*c54f35caSApple OSS Distributions while (nextPowerSource != NULL) {
59*c54f35caSApple OSS Distributions if (nextPowerSource == newPowerSource) {
60*c54f35caSApple OSS Distributions // yes, just return
61*c54f35caSApple OSS Distributions return IOPMNoErr;
62*c54f35caSApple OSS Distributions }
63*c54f35caSApple OSS Distributions nextPowerSource = nextInList(nextPowerSource);
64*c54f35caSApple OSS Distributions }
65*c54f35caSApple OSS Distributions
66*c54f35caSApple OSS Distributions // add it to list
67*c54f35caSApple OSS Distributions newPowerSource->nextInList = firstItem;
68*c54f35caSApple OSS Distributions firstItem = newPowerSource;
69*c54f35caSApple OSS Distributions length++;
70*c54f35caSApple OSS Distributions return IOPMNoErr;
71*c54f35caSApple OSS Distributions }
72*c54f35caSApple OSS Distributions
73*c54f35caSApple OSS Distributions
74*c54f35caSApple OSS Distributions //******************************************************************************
75*c54f35caSApple OSS Distributions // firstInList
76*c54f35caSApple OSS Distributions //
77*c54f35caSApple OSS Distributions //******************************************************************************
78*c54f35caSApple OSS Distributions
79*c54f35caSApple OSS Distributions IOPMPowerSource *
firstInList(void)80*c54f35caSApple OSS Distributions IOPMPowerSourceList::firstInList( void )
81*c54f35caSApple OSS Distributions {
82*c54f35caSApple OSS Distributions return firstItem;
83*c54f35caSApple OSS Distributions }
84*c54f35caSApple OSS Distributions
85*c54f35caSApple OSS Distributions //******************************************************************************
86*c54f35caSApple OSS Distributions // nextInList
87*c54f35caSApple OSS Distributions //
88*c54f35caSApple OSS Distributions //******************************************************************************
89*c54f35caSApple OSS Distributions
90*c54f35caSApple OSS Distributions IOPMPowerSource *
nextInList(IOPMPowerSource * currentItem)91*c54f35caSApple OSS Distributions IOPMPowerSourceList::nextInList(IOPMPowerSource *currentItem)
92*c54f35caSApple OSS Distributions {
93*c54f35caSApple OSS Distributions if (currentItem != NULL) {
94*c54f35caSApple OSS Distributions return currentItem->nextInList;
95*c54f35caSApple OSS Distributions }
96*c54f35caSApple OSS Distributions return NULL;
97*c54f35caSApple OSS Distributions }
98*c54f35caSApple OSS Distributions
99*c54f35caSApple OSS Distributions //******************************************************************************
100*c54f35caSApple OSS Distributions // numberOfItems
101*c54f35caSApple OSS Distributions //
102*c54f35caSApple OSS Distributions //******************************************************************************
103*c54f35caSApple OSS Distributions
104*c54f35caSApple OSS Distributions unsigned long
numberOfItems(void)105*c54f35caSApple OSS Distributions IOPMPowerSourceList::numberOfItems( void )
106*c54f35caSApple OSS Distributions {
107*c54f35caSApple OSS Distributions return length;
108*c54f35caSApple OSS Distributions }
109*c54f35caSApple OSS Distributions
110*c54f35caSApple OSS Distributions //******************************************************************************
111*c54f35caSApple OSS Distributions // removeFromList
112*c54f35caSApple OSS Distributions //
113*c54f35caSApple OSS Distributions // Find the item in the list, unlink it, and free it.
114*c54f35caSApple OSS Distributions //******************************************************************************
115*c54f35caSApple OSS Distributions
116*c54f35caSApple OSS Distributions IOReturn
removeFromList(IOPMPowerSource * theItem)117*c54f35caSApple OSS Distributions IOPMPowerSourceList::removeFromList( IOPMPowerSource * theItem )
118*c54f35caSApple OSS Distributions {
119*c54f35caSApple OSS Distributions IOPMPowerSource * item = firstItem;
120*c54f35caSApple OSS Distributions IOPMPowerSource * temp;
121*c54f35caSApple OSS Distributions
122*c54f35caSApple OSS Distributions if (NULL == item) {
123*c54f35caSApple OSS Distributions goto exit;
124*c54f35caSApple OSS Distributions }
125*c54f35caSApple OSS Distributions
126*c54f35caSApple OSS Distributions if (item == theItem) {
127*c54f35caSApple OSS Distributions firstItem = item->nextInList;
128*c54f35caSApple OSS Distributions length--;
129*c54f35caSApple OSS Distributions item->release();
130*c54f35caSApple OSS Distributions return IOPMNoErr;
131*c54f35caSApple OSS Distributions }
132*c54f35caSApple OSS Distributions while (item->nextInList != NULL) {
133*c54f35caSApple OSS Distributions if (item->nextInList == theItem) {
134*c54f35caSApple OSS Distributions temp = item->nextInList;
135*c54f35caSApple OSS Distributions item->nextInList = temp->nextInList;
136*c54f35caSApple OSS Distributions length--;
137*c54f35caSApple OSS Distributions temp->release();
138*c54f35caSApple OSS Distributions return IOPMNoErr;
139*c54f35caSApple OSS Distributions }
140*c54f35caSApple OSS Distributions item = item->nextInList;
141*c54f35caSApple OSS Distributions }
142*c54f35caSApple OSS Distributions
143*c54f35caSApple OSS Distributions exit:
144*c54f35caSApple OSS Distributions return IOPMNoErr;
145*c54f35caSApple OSS Distributions }
146*c54f35caSApple OSS Distributions
147*c54f35caSApple OSS Distributions
148*c54f35caSApple OSS Distributions //******************************************************************************
149*c54f35caSApple OSS Distributions // free
150*c54f35caSApple OSS Distributions //
151*c54f35caSApple OSS Distributions // Free all items in the list, and then free the list itself
152*c54f35caSApple OSS Distributions //******************************************************************************
153*c54f35caSApple OSS Distributions
154*c54f35caSApple OSS Distributions void
free(void)155*c54f35caSApple OSS Distributions IOPMPowerSourceList::free(void )
156*c54f35caSApple OSS Distributions {
157*c54f35caSApple OSS Distributions IOPMPowerSource * next = firstItem;
158*c54f35caSApple OSS Distributions
159*c54f35caSApple OSS Distributions while (next != NULL) {
160*c54f35caSApple OSS Distributions firstItem = next->nextInList;
161*c54f35caSApple OSS Distributions length--;
162*c54f35caSApple OSS Distributions next->release();
163*c54f35caSApple OSS Distributions next = firstItem;
164*c54f35caSApple OSS Distributions }
165*c54f35caSApple OSS Distributions super::free();
166*c54f35caSApple OSS Distributions }
167