]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sleep: introduce high-level SleepOperation enum
authorLennart Poettering <lennart@poettering.net>
Thu, 20 May 2021 20:31:17 +0000 (22:31 +0200)
committerLennart Poettering <lennart@poettering.net>
Sat, 22 May 2021 08:58:22 +0000 (10:58 +0200)
src/shared/sleep-config.c
src/shared/sleep-config.h

index 6bb5d80a9515b48f39643b2ab8e342d7b9b9e575..a1ef64f6e904ba49604b2d49a406881079e615fe 100644 (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);
index 4b30e6db53c5640af0d463c8ad0c8e9f1a98a72e..c17a5241ab18c103438f2332e0e69b5fc3723372 100644 (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_;