sleep: introduce high-level SleepOperation enum

This commit is contained in:
Lennart Poettering
2021-05-22 10:58:22 +02:00
parent 86204ae145
commit be2a4b0d7e
2 changed files with 22 additions and 0 deletions
+10
View File
@@ -29,6 +29,7 @@
#include "path-util.h"
#include "sleep-config.h"
#include "stdio-util.h"
#include "string-table.h"
#include "string-util.h"
#include "strv.h"
#include "time-util.h"
@@ -699,3 +700,12 @@ SleepConfig* free_sleep_config(SleepConfig *sc) {
return mfree(sc);
}
static const char* const sleep_operation_table[_SLEEP_OPERATION_MAX] = {
[SLEEP_SUSPEND] = "suspend",
[SLEEP_HIBERNATE] = "hibernate",
[SLEEP_HYBRID_SLEEP] = "hybrid-sleep",
[SLEEP_SUSPEND_THEN_HIBERNATE] = "suspend-then-hibernate",
};
DEFINE_STRING_TABLE_LOOKUP(sleep_operation, SleepOperation);
+12
View File
@@ -4,6 +4,15 @@
#include <linux/fiemap.h>
#include "time-util.h"
typedef enum SleepOperation {
SLEEP_SUSPEND,
SLEEP_HIBERNATE,
SLEEP_HYBRID_SLEEP,
SLEEP_SUSPEND_THEN_HIBERNATE,
_SLEEP_OPERATION_MAX,
_SLEEP_OPERATION_INVALID = -EINVAL,
} SleepOperation;
typedef struct SleepConfig {
bool allow_suspend; /* AllowSuspend */
bool allow_hibernate; /* AllowHibernation */
@@ -57,3 +66,6 @@ int find_hibernate_location(HibernateLocation **ret_hibernate_location);
int can_sleep(const char *verb);
int can_sleep_disk(char **types);
int can_sleep_state(char **types);
const char* sleep_operation_to_string(SleepOperation s) _const_;
SleepOperation sleep_operation_from_string(const char *s) _pure_;