altos: Use stdbool true/false instead of TRUE/FALSE
[fw/altos] / src / kernel / ao_power.c
1 /*
2  * Copyright © 2016 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 #include <ao.h>
20 #include <ao_power.h>
21
22 static struct ao_power  *head, *tail;
23
24 void
25 ao_power_register(struct ao_power *power)
26 {
27         if (power->registered)
28                 return;
29         power->registered = true;
30         if (tail) {
31                 tail->next = power;
32                 power->prev = tail;
33                 tail = power;
34         } else {
35                 head = tail = power;
36         }
37 #ifdef AO_LED_POWER
38         ao_led_on(AO_LED_POWER);
39 #endif
40 }
41
42 void
43 ao_power_unregister(struct ao_power *power)
44 {
45         if (!power->registered)
46                 return;
47         power->registered = false;
48         if (power->prev)
49                 power->prev->next = power->next;
50         else
51                 head = power->next;
52         if (power->next)
53                 power->next->prev = power->prev;
54         else
55                 tail = power->prev;
56 }
57
58 void
59 ao_power_suspend(void)
60 {
61         struct ao_power *p;
62
63 #ifdef AO_LED_POWER
64         ao_led_off(AO_LED_POWER);
65 #endif
66         for (p = tail; p; p = p->prev)
67                 p->suspend(p->arg);
68 }
69
70 void
71 ao_power_resume(void)
72 {
73         struct ao_power *p;
74
75         for (p = head; p; p = p->next)
76                 p->resume(p->arg);
77 #ifdef AO_LED_POWER
78         ao_led_on(AO_LED_POWER);
79 #endif
80 }
81