From: Lennart Poettering Date: Thu, 20 May 2021 20:31:17 +0000 (+0200) Subject: sleep: introduce high-level SleepOperation enum X-Git-Tag: v249-rc1~174^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=be2a4b0d7e49d766742b1c7f991563d6dcb95c85;p=thirdparty%2Fsystemd.git sleep: introduce high-level SleepOperation enum --- diff --git a/src/shared/sleep-config.c b/src/shared/sleep-config.c index 6bb5d80a951..a1ef64f6e90 100644 --- a/src/shared/sleep-config.c +++ b/src/shared/sleep-config.c @@ -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); diff --git a/src/shared/sleep-config.h b/src/shared/sleep-config.h index 4b30e6db53c..c17a5241ab1 100644 --- a/src/shared/sleep-config.h +++ b/src/shared/sleep-config.h @@ -4,6 +4,15 @@ #include #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_;