Merge pull request #3383 from arnova/no_volamp_with_passthrough
[vuplus_xbmc] / xbmc / powermanagement / IPowerSyscall.h
1 #pragma once
2
3 /*
4  *      Copyright (C) 2005-2013 Team XBMC
5  *      http://xbmc.org
6  *
7  *  This Program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2, or (at your option)
10  *  any later version.
11  *
12  *  This Program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with XBMC; see the file COPYING.  If not, see
19  *  <http://www.gnu.org/licenses/>.
20  *
21  */
22
23 class IPowerEventsCallback
24 {
25 public:
26   virtual ~IPowerEventsCallback() { }
27
28   virtual void OnSleep() = 0;
29   virtual void OnWake() = 0;
30
31   virtual void OnLowBattery() = 0;
32 };
33
34 class IPowerSyscall
35 {
36 public:
37   virtual ~IPowerSyscall() {};
38   virtual bool Powerdown()    = 0;
39   virtual bool Suspend()      = 0;
40   virtual bool Hibernate()    = 0;
41   virtual bool Reboot()       = 0;
42
43 // Might need to be membervariables instead for speed
44   virtual bool CanPowerdown() = 0;
45   virtual bool CanSuspend()   = 0;
46   virtual bool CanHibernate() = 0;
47   virtual bool CanReboot()    = 0;
48   
49 // Battery related functions
50   virtual int  BatteryLevel() = 0;
51
52   /*!
53    \brief Pump power related events back to xbmc.
54
55    PumpPowerEvents is called from Application Thread and the platform implementation may signal
56    power related events back to xbmc through the callback.
57
58    return true if an event occured and false if not.
59    
60    \param callback the callback to signal to
61    */
62   virtual bool PumpPowerEvents(IPowerEventsCallback *callback) = 0;
63 };
64
65 class CPowerSyscallWithoutEvents : public IPowerSyscall
66 {
67 public:
68   CPowerSyscallWithoutEvents() { m_OnResume = false; m_OnSuspend = false; }
69
70   virtual bool Suspend() { m_OnSuspend = true; return false; }
71   virtual bool Hibernate() { m_OnSuspend = true; return false; }
72
73   virtual bool PumpPowerEvents(IPowerEventsCallback *callback)
74   {
75     if (m_OnSuspend)
76     {
77       callback->OnSleep();
78       m_OnSuspend = false;
79       m_OnResume = true;
80       return true;
81     }
82     else if (m_OnResume)
83     {
84       callback->OnWake();
85       m_OnResume = false;
86       return true;
87     }
88     else
89       return false;
90   }
91 private:
92   bool m_OnResume;
93   bool m_OnSuspend;
94 };