1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
|
/***************************************************************************
* Copyright (C) 2010 by Dario Freddi <drf@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
***************************************************************************/
#ifndef POWERDEVIL_BACKENDINTERFACE_H
#define POWERDEVIL_BACKENDINTERFACE_H
#include <QObject>
#include <QHash>
#include "powerdevilbrightnesslogic.h"
class KJob;
namespace PowerDevil {
class Q_DECL_EXPORT BackendInterface : public QObject
{
Q_OBJECT
Q_DISABLE_COPY(BackendInterface)
public:
explicit BackendInterface(QObject* parent = nullptr);
~BackendInterface() override;
/**
* This enum type defines the different states of the system battery.
*
* - NoBatteryState: No battery available
* - Normal: The battery is at its normal charge level
* - Warning: The battery is at its warning charge level
* - Low: The battery is at its low charge level
* - Critical: The battery is at its critical charge level
*/
enum BatteryState{ NoBatteryState, Normal, Warning, Low, Critical };
Q_ENUM(BatteryState)
/**
* This enum type defines the different states of the AC adapter.
*
* - UnknownAcAdapterState: The AC adapter has an unknown state
* - Plugged: The AC adapter is plugged
* - Unplugged: The AC adapter is unplugged
*/
enum AcAdapterState{ UnknownAcAdapterState, Plugged, Unplugged };
Q_ENUM(AcAdapterState)
/**
* This enum type defines the types of system button events.
*
* - UnknownButtonType: An unknown button
* - PowerDown: A power down pressed event, generally used to turn on or off the system. KWin emits on long power button presses.
* - PowerButton: A power button pressed event, generally used to turn on or off the system
* - SleepButton: A sleep button pressed event, generally used to make the system asleep
* - LidOpen: A laptop lid open event
* - LidClose: A laptop lid close event
*/
enum ButtonType{ UnknownButtonType, PowerButton, PowerDownButton, SleepButton, LidOpen, LidClose, HibernateButton };
Q_ENUM(ButtonType)
/**
* This enum type defines the different suspend methods.
*
* - UnknownSuspendMethod: The name says it all
* - Standby: Processes are stopped, some hardware is deactivated (ACPI S1)
* - ToRam: Most devices are deactivated, only RAM is powered (ACPI S3)
* - ToDisk: State of the machine is saved to disk, and it's powered down (ACPI S4)
* - SuspendThenHibernate: Same as ToRam, but after a delay it switches to ToDisk
*/
enum SuspendMethod{ UnknownSuspendMethod = 0, Standby = 1, ToRam = 2, ToDisk = 4, HybridSuspend = 8, SuspendThenHibernate = 16 };
Q_ENUM(SuspendMethod)
/**
* This type stores an OR combination of SuspendMethod values.
*/
Q_DECLARE_FLAGS(SuspendMethods, SuspendMethod)
/**
* This enum defines the different types of brightness controls.
*
* - UnknownBrightnessControl: Unknown
* - Screen: Brightness control for a monitor or laptop panel
* - Keyboard: Brightness control for a keyboard backlight
*/
enum BrightnessControlType{ UnknownBrightnessControl = 0, Screen = 1, Keyboard = 2 };
Q_ENUM(BrightnessControlType)
typedef QHash<QString, BrightnessControlType> BrightnessControlsList;
/**
* This enum defines capabilities of the backend
*
* - SignalResumeFromSuspend: The backend is able to stream the @c resumeFromSuspend signal accurately
*/
enum Capability { NoCapabilities = 0, SignalResumeFromSuspend = 1 };
Q_ENUM(Capability)
Q_DECLARE_FLAGS(Capabilities, Capability)
/**
* Initializes the backend. This function @b MUST be called before the backend is usable. Using
* any method in BackendInterface without initializing it might lead to undefined behavior. The signal
* @c backendReady or @c backendError will be streamed upon completion.
*
* @note Backend implementations @b MUST reimplement this function
*/
virtual void init() = 0;
/**
* @returns the capabilities of the backend
* @see PowerDevil::BackendInterface::Capability
*/
Capabilities capabilities() const;
/**
* Retrieves the current state of the system battery.
*
* @return the current battery state
* @see PowerDevil::BackendInterface::BatteryState
*/
BatteryState batteryState() const;
/**
* Retrieves the current estimated remaining time of the system batteries
*
* @return the current global estimated remaining time in milliseconds
*/
qulonglong batteryRemainingTime() const;
/**
* Retrieves the current state of the system AC adapter.
*
* @return the current AC adapter state
* @see PowerDevil::BackendInterface::AcAdapterState
*/
AcAdapterState acAdapterState() const;
/**
* Retrieves the set of suspend methods supported by the system.
*
* @return the suspend methods supported by this system
* @see PowerDevil::BackendInterface::SuspendMethod
* @see PowerDevil::BackendInterface::SuspendMethods
*/
SuspendMethods supportedSuspendMethods() const;
/**
* Requests a suspend of the system.
*
* @param method the suspend method to use
* @return the job handling the operation
*/
virtual KJob *suspend(SuspendMethod method) = 0;
/**
* Checks if brightness controls are enabled on this system.
*
* @return a list of the devices available to control
*/
BrightnessControlsList brightnessControlsAvailable() const;
/**
* Gets the device brightness value.
*
* @param device the name of the device that you would like to control
* @return the brightness of the device, as an integer from 0 to brightnessValueMax
*/
virtual int brightness(BrightnessControlType type = Screen) const;
/**
* Gets the maximum device brightness value.
*
* @param device the name of the device that you would like to control
* @return the maximum brightness of the device
*/
virtual int brightnessMax(BrightnessControlType type = Screen) const;
/**
* Gets the maximum device brightness step.
*
* @param device the name of the device that you would like to control
* @return the maximum brightness of the device
*/
virtual int brightnessSteps(BrightnessControlType type = Screen) const;
/**
* @returns whether the lid is closed or not.
*/
bool isLidClosed() const;
/**
* @returns whether the a lid is present
*/
bool isLidPresent() const;
void setLidPresent(bool present);
/**
* Sets the device brightness value.
*
* @param brightnessValue the desired device brightness, as an integer from 0 to brightnessValueMax
* @param device the name of the device that you would like to control
* @return true if the brightness change succeeded, false otherwise
*/
virtual void setBrightness(int value, BrightnessControlType type = Screen) = 0;
/**
* Should be called when the user presses a brightness key.
*
* @param type the type of the brightness key press
* @return the new brightness value, or -1 if it could not be changed or determined
* @see PowerDevil::BrightnessLogic::BrightnessKeyType
*/
virtual int brightnessKeyPressed(BrightnessLogic::BrightnessKeyType type, BrightnessControlType controlType = Screen) = 0;
/**
* Retrieves the capacities of the installed batteries in percentage.
*
* @returns A dictionary with the battery's capacity percentage mapped to the battery uuid.
*/
QHash<QString, uint> capacities() const;
Q_SIGNALS:
/**
* This signal is emitted when the AC adapter is plugged or unplugged.
*
* @param newState the new state of the AC adapter, it's one of the
* type @see PowerDevil::BackendInterface::AcAdapterState
*/
void acAdapterStateChanged(PowerDevil::BackendInterface::AcAdapterState newState);
/**
* This signal is emitted when the system battery state changed.
*
* @param newState the new state of the system battery, it's one of the
* type @see PowerDevil::BackendInterface::BatteryState
*/
void batteryStateChanged(PowerDevil::BackendInterface::BatteryState newState);
/**
* This signal is emitted when a button has been pressed.
*
* @param buttonType the pressed button type, it's one of the
* type @see PowerDevil::BackendInterface::ButtonType
*/
void buttonPressed(PowerDevil::BackendInterface::ButtonType buttonType);
/**
* This signal is emitted when the brightness changes.
*
* @param brightnessInfo a copy of the current brightness information
* @param type the device type
*/
void brightnessChanged(const BrightnessLogic::BrightnessInfo &brightnessInfo, BrightnessControlType type);
/**
* This signal is emitted when the estimated battery remaining time changes.
*
* @param time the new remaining time
*/
void batteryRemainingTimeChanged(qulonglong time);
/**
* This signal is emitted when the backend is ready to be used
*
* @see init
*/
void backendReady();
/**
* This signal is emitted if the backend could not be initialized
*
* @param error Details about the error occurred
* @see init
*/
void backendError(const QString &error);
/**
* This signal is emitted when the PC is resuming from suspension
*/
void resumeFromSuspend();
/**
* This signal is emitted when the PC is about to suspend
*/
void aboutToSuspend();
/**
* This signal is emitted when the laptop lid is closed or opened
*
* @param closed Whether the lid is now closed or not
*/
void lidClosedChanged(bool closed);
protected:
void setCapabilities(Capabilities capabilities);
void onBrightnessChanged(BrightnessControlType device, int value, int valueMax);
void setBatteryRemainingTime(qulonglong time);
void setButtonPressed(PowerDevil::BackendInterface::ButtonType type);
void setBatteryState(PowerDevil::BackendInterface::BatteryState state);
void setAcAdapterState(PowerDevil::BackendInterface::AcAdapterState state);
void setCapacityForBattery(const QString &batteryId, uint percent);
void setBackendIsReady(BrightnessControlsList availableBrightnessControls, SuspendMethods supportedSuspendMethods);
void setBackendHasError(const QString &errorDetails);
// Steps logic
int calculateNextStep(int value, int valueMax, BrightnessControlType controlType, BrightnessLogic::BrightnessKeyType type);
private:
class Private;
Private * const d;
friend class Core;
};
}
Q_DECLARE_OPERATORS_FOR_FLAGS(PowerDevil::BackendInterface::Capabilities)
Q_DECLARE_OPERATORS_FOR_FLAGS(PowerDevil::BackendInterface::SuspendMethods)
#endif // POWERDEVIL_BACKENDINTERFACE_H
|