2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
11 class IPowerEventsCallback
14 virtual ~IPowerEventsCallback() = default;
16 virtual void OnSleep() = 0;
17 virtual void OnWake() = 0;
19 virtual void OnLowBattery() = 0;
23 using CreatePowerSyscallFunc
= IPowerSyscall
* (*)();
28 /**\brief Called by power manager to create platform power system adapter
30 * This method used to create platform specified power system adapter
32 static IPowerSyscall
* CreateInstance();
33 static void RegisterPowerSyscall(CreatePowerSyscallFunc createFunc
);
35 virtual ~IPowerSyscall() = default;
36 virtual bool Powerdown() = 0;
37 virtual bool Suspend() = 0;
38 virtual bool Hibernate() = 0;
39 virtual bool Reboot() = 0;
41 // Might need to be membervariables instead for speed
42 virtual bool CanPowerdown() = 0;
43 virtual bool CanSuspend() = 0;
44 virtual bool CanHibernate() = 0;
45 virtual bool CanReboot() = 0;
47 virtual int CountPowerFeatures() = 0;
49 // Battery related functions
50 virtual int BatteryLevel() = 0;
53 \brief Pump power related events back to xbmc.
55 PumpPowerEvents is called from Application Thread and the platform implementation may signal
56 power related events back to xbmc through the callback.
58 return true if an event occurred and false if not.
60 \param callback the callback to signal to
62 virtual bool PumpPowerEvents(IPowerEventsCallback
*callback
) = 0;
64 static const int MAX_COUNT_POWER_FEATURES
= 4;
67 static CreatePowerSyscallFunc m_createFunc
;
70 class CAbstractPowerSyscall
: public IPowerSyscall
73 int CountPowerFeatures() override
75 return (CanPowerdown() ? 1 : 0)
76 + (CanSuspend() ? 1 : 0)
77 + (CanHibernate() ? 1 : 0)
78 + (CanReboot() ? 1 : 0);
82 class CPowerSyscallWithoutEvents
: public CAbstractPowerSyscall
85 CPowerSyscallWithoutEvents() { m_OnResume
= false; m_OnSuspend
= false; }
87 bool Suspend() override
{ m_OnSuspend
= true; return false; }
88 bool Hibernate() override
{ m_OnSuspend
= true; return false; }
90 bool PumpPowerEvents(IPowerEventsCallback
*callback
) override