plugin-api: deviced: power: Add syscommon_plugin_deviced_power_convert_to_power_state() 69/297369/3
authorChanwoo Choi <cw00.choi@samsung.com>
Thu, 17 Aug 2023 10:44:15 +0000 (19:44 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Fri, 18 Aug 2023 01:00:39 +0000 (10:00 +0900)
syscommon_plugin_deviced_power_convert_to_power_state() plugin api
converts the power action string to DEVICED_POWER_STATE_* enumeration.

Change-Id: I14fb07cfa64527fceba58116977b32986c14edda
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
src/plugin-api/deviced/include/syscommon-plugin-deviced-power-interface.h

index 4f05328..95394c1 100644 (file)
@@ -73,6 +73,26 @@ enum {
 
 #define DEVICED_POWER_STATE_INDEX(state)               (__builtin_ctzll(state))
 
+static inline u_int64_t syscommon_plugin_deviced_power_convert_to_power_state(const char *str)
+{
+       if (MATCH(str, "start"))
+               return DEVICED_POWER_STATE_START;
+       else if (MATCH(str, "sleep"))
+               return DEVICED_POWER_STATE_SLEEP;
+       else if (MATCH(str, "normal"))
+               return DEVICED_POWER_STATE_NORMAL;
+       else if (MATCH(str, "poweroff"))
+               return DEVICED_POWER_STATE_POWEROFF;
+       else if (MATCH(str, "reboot"))
+               return DEVICED_POWER_STATE_REBOOT;
+       else if (MATCH(str, "exit"))
+               return DEVICED_POWER_STATE_EXIT;
+       else if (MATCH(str, "current"))
+               return DEVICED_POWER_STATE_ALL;
+
+       return DEVICED_POWER_STATE_UNDEFINED;
+}
+
 #ifdef __cplusplus
 }
 #endif