]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/io/io/server/src/pm.h
Update
[l4.git] / l4 / pkg / io / io / server / src / pm.h
1 /*
2  * (c) 2013 Alexander Warg <warg@os.inf.tu-dresden.de>
3  *     economic rights: Technische Universität Dresden (Germany)
4  *
5  * This file is part of TUD:OS and distributed under the terms of the
6  * GNU General Public License 2.
7  * Please see the COPYING-GPL-2 file for details.
8  */
9 #pragma once
10
11 #include <l4/cxx/hlist>
12
13 struct Pm : public cxx::H_list_item_t<Pm>
14 {
15   enum Pm_state
16   {
17     Pm_disabled,
18     Pm_failed,
19     Pm_suspended,
20     Pm_online
21   };
22
23   Pm() : _state(Pm_disabled) {}
24
25   Pm_state pm_power_state() const { return _state; }
26   bool pm_is_disabled() const { return _state == Pm_disabled; }
27   bool pm_is_suspended() const { return _state == Pm_suspended; }
28   bool pm_is_online() const { return _state == Pm_online; }
29   bool pm_is_failed() const { return _state == Pm_failed; }
30
31   virtual int pm_init() = 0;
32   virtual int pm_suspend() = 0;
33   virtual int pm_resume() = 0;
34   virtual ~Pm() = 0;
35
36   static int pm_suspend_all();
37   static int pm_resume_all();
38
39 protected:
40   void pm_set_state(Pm_state state)
41   {
42     Pm_state old = _state;
43
44     if (old == state)
45       return;
46
47     _state = state;
48
49     switch (old)
50       {
51       case Pm_suspended: _suspended.remove(this); break;
52       case Pm_online:    _online.remove(this); break;
53       default: break;
54       }
55
56     switch (state)
57       {
58       case Pm_suspended: _suspended.push_front(this); break;
59       case Pm_online:    _online.push_front(this); break;
60       default: break;
61       }
62   }
63
64   typedef cxx::H_list_t<Pm> Pm_list;
65
66   static Pm_list _online;
67   static Pm_list _suspended;
68
69 private:
70   Pm_state _state;
71 };
72
73 inline Pm::~Pm() {}