--- /dev/null
+/*
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __HAL_DEVICE_POWER_INTERFACE_1_H__
+#define __HAL_DEVICE_POWER_INTERFACE_1_H__
+
+#include "hal-device-power-types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct _hal_backend_device_power_funcs {
+ int (*get_wakeup_reason)(hal_device_power_transition_reason_e *reason);
+} hal_backend_device_power_funcs;
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __HAL_DEVICE_POWER_INTERFACE_1_H__ */
#ifndef __HAL_DEVICE_POWER_INTERFACE_H__
#define __HAL_DEVICE_POWER_INTERFACE_H__
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include "hal-device-power-types.h"
+#include "hal-device-power-interface-1.h"
-enum hal_device_power_transition_reason {
- HAL_DEVICE_POWER_TRANSITION_REASON_UNKNOWN,
- HAL_DEVICE_POWER_TRANSITION_REASON_POWER_KEY,
- HAL_DEVICE_POWER_TRANSITION_REASON_VOLUME_UP_KEY,
- HAL_DEVICE_POWER_TRANSITION_REASON_VOLUME_DOWN_KEY,
- HAL_DEVICE_POWER_TRANSITION_REASON_BATTERY_NORMAL_LEVEL,
- HAL_DEVICE_POWER_TRANSITION_REASON_BATTERY_WARNING_LEVEL,
- HAL_DEVICE_POWER_TRANSITION_REASON_BATTERY_CRITICAL_LEVEL,
- HAL_DEVICE_POWER_TRANSITION_REASON_BATTERY_POWEROFF_LEVEL,
- HAL_DEVICE_POWER_TRANSITION_REASON_DISPLAY_OFF,
- HAL_DEVICE_POWER_TRANSITION_REASON_DISPLAY_OFF_TIMEOUT,
- HAL_DEVICE_POWER_TRANSITION_REASON_TOUCH_KEY,
- HAL_DEVICE_POWER_TRANSITION_REASON_TOUCH_SCREEN,
- HAL_DEVICE_POWER_TRANSITION_REASON_USB,
- HAL_DEVICE_POWER_TRANSITION_REASON_CHARGER,
- HAL_DEVICE_POWER_TRANSITION_REASON_HDMI,
- HAL_DEVICE_POWER_TRANSITION_REASON_DISPLAY_PORT,
- HAL_DEVICE_POWER_TRANSITION_REASON_EMBEDDED_DISPLAY_PORT,
- HAL_DEVICE_POWER_TRANSITION_REASON_WIFI,
- HAL_DEVICE_POWER_TRANSITION_REASON_BLUETOOTH,
- HAL_DEVICE_POWER_TRANSITION_REASON_NFC,
- HAL_DEVICE_POWER_TRANSITION_REASON_TELEPHONY,
- HAL_DEVICE_POWER_TRANSITION_REASON_ZIGBEE,
- HAL_DEVICE_POWER_TRANSITION_REASON_ETHERNET,
- HAL_DEVICE_POWER_TRANSITION_REASON_AUDIO,
- HAL_DEVICE_POWER_TRANSITION_REASON_ALARM,
- HAL_DEVICE_POWER_TRANSITION_REASON_SENSOR,
- HAL_DEVICE_POWER_TRANSITION_REASON_RTC,
- HAL_DEVICE_POWER_TRANSITION_REASON_HEADSET,
- HAL_DEVICE_POWER_TRANSITION_REASON_EXTERNAL_MEMORY,
-
- HAL_DEVICE_POWER_TRANSITION_REASON_CUSTOM = 1000, /**< Define custom reason from here */
-};
-
-typedef struct _hal_backend_device_power_funcs {
- int (*get_wakeup_reason)(enum hal_device_power_transition_reason *reason);
-} hal_backend_device_power_funcs;
-
-#ifdef __cplusplus
-}
-#endif
#endif /* __HAL_DEVICE_POWER_INTERFACE_H__ */
--- /dev/null
+/*
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __HAL_DEVICE_POWER_TYPES_H__
+#define __HAL_DEVICE_POWER_TYPES_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/**
+ * @brief Enumeration for representing power transition reason.
+ * @since HAL_MODULE_DEVICE_POWER 1.0
+ */
+typedef enum {
+ HAL_DEVICE_POWER_TRANSITION_REASON_UNKNOWN,
+ HAL_DEVICE_POWER_TRANSITION_REASON_POWER_KEY,
+ HAL_DEVICE_POWER_TRANSITION_REASON_VOLUME_UP_KEY,
+ HAL_DEVICE_POWER_TRANSITION_REASON_VOLUME_DOWN_KEY,
+ HAL_DEVICE_POWER_TRANSITION_REASON_BATTERY_NORMAL_LEVEL,
+ HAL_DEVICE_POWER_TRANSITION_REASON_BATTERY_WARNING_LEVEL,
+ HAL_DEVICE_POWER_TRANSITION_REASON_BATTERY_CRITICAL_LEVEL,
+ HAL_DEVICE_POWER_TRANSITION_REASON_BATTERY_POWEROFF_LEVEL,
+ HAL_DEVICE_POWER_TRANSITION_REASON_DISPLAY_OFF,
+ HAL_DEVICE_POWER_TRANSITION_REASON_DISPLAY_OFF_TIMEOUT,
+ HAL_DEVICE_POWER_TRANSITION_REASON_TOUCH_KEY,
+ HAL_DEVICE_POWER_TRANSITION_REASON_TOUCH_SCREEN,
+ HAL_DEVICE_POWER_TRANSITION_REASON_USB,
+ HAL_DEVICE_POWER_TRANSITION_REASON_CHARGER,
+ HAL_DEVICE_POWER_TRANSITION_REASON_HDMI,
+ HAL_DEVICE_POWER_TRANSITION_REASON_DISPLAY_PORT,
+ HAL_DEVICE_POWER_TRANSITION_REASON_EMBEDDED_DISPLAY_PORT,
+ HAL_DEVICE_POWER_TRANSITION_REASON_WIFI,
+ HAL_DEVICE_POWER_TRANSITION_REASON_BLUETOOTH,
+ HAL_DEVICE_POWER_TRANSITION_REASON_NFC,
+ HAL_DEVICE_POWER_TRANSITION_REASON_TELEPHONY,
+ HAL_DEVICE_POWER_TRANSITION_REASON_ZIGBEE,
+ HAL_DEVICE_POWER_TRANSITION_REASON_ETHERNET,
+ HAL_DEVICE_POWER_TRANSITION_REASON_AUDIO,
+ HAL_DEVICE_POWER_TRANSITION_REASON_ALARM,
+ HAL_DEVICE_POWER_TRANSITION_REASON_SENSOR,
+ HAL_DEVICE_POWER_TRANSITION_REASON_RTC,
+ HAL_DEVICE_POWER_TRANSITION_REASON_HEADSET,
+ HAL_DEVICE_POWER_TRANSITION_REASON_EXTERNAL_MEMORY,
+
+ HAL_DEVICE_POWER_TRANSITION_REASON_CUSTOM = 1000, /**< Define custom reason from here (Since HAL_MODULE_DEVICE_POWER 1.0) */
+} hal_device_power_transition_reason_e;
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __HAL_DEVICE_POWER_TYPES_H__ */
int hal_device_power_get_backend(void);
int hal_device_power_put_backend(void);
-int hal_device_power_get_wakeup_reason(enum hal_device_power_transition_reason *reason);
+int hal_device_power_get_wakeup_reason(hal_device_power_transition_reason_e *reason);
#ifdef __cplusplus
}
--- /dev/null
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <stdlib.h>
+
+#include <hal/hal-common.h>
+
+#include "hal-device-power-interface.h"
+#include "common.h"
+
+static hal_backend_device_power_funcs *hal_device_power_funcs = NULL;
+
+int hal_device_power_get_backend(void)
+{
+ int ret;
+
+ if (hal_device_power_funcs)
+ return 0;
+
+ hal_device_power_funcs = calloc(1, sizeof(hal_backend_device_power_funcs));
+ if (!hal_device_power_funcs)
+ return -ENOMEM;
+
+ ret = hal_common_get_backend(HAL_MODULE_DEVICE_POWER, (void **)&hal_device_power_funcs);
+ if (ret < 0) {
+ _E("Failed to get device power backend");
+ free(hal_device_power_funcs);
+ hal_device_power_funcs = NULL;
+ return -ENOTSUP;
+ }
+
+ return 0;
+}
+
+int hal_device_power_put_backend(void)
+{
+ int ret;
+
+ if (!hal_device_power_funcs)
+ return 0;
+
+ ret = hal_common_put_backend(HAL_MODULE_DEVICE_POWER, (void *)hal_device_power_funcs);
+ if (ret < 0) {
+ _E("Failed to put device power backend");
+ return ret;
+ }
+
+ free(hal_device_power_funcs);
+ hal_device_power_funcs = NULL;
+
+ return 0;
+}
+
+int hal_device_power_get_wakeup_reason(hal_device_power_transition_reason_e *reason)
+{
+ int ret;
+
+ if (!reason)
+ return -EINVAL;
+
+ if (!hal_device_power_funcs) {
+ if ((ret = hal_device_power_get_backend()) < 0)
+ return ret;
+ }
+
+ if (!hal_device_power_funcs ||
+ !hal_device_power_funcs->get_wakeup_reason)
+ return -ENOTSUP;
+
+ return hal_device_power_funcs->get_wakeup_reason(reason);
+}
+++ /dev/null
-/*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <hal/hal-common.h>
-
-#include "hal-device-power-interface.h"
-#include "common.h"
-
-static hal_backend_device_power_funcs *hal_device_power_funcs = NULL;
-
-int hal_device_power_get_backend(void)
-{
- int ret;
- if (hal_device_power_funcs)
- return 0;
-
- ret = hal_common_get_backend(HAL_MODULE_DEVICE_POWER, (void **)&hal_device_power_funcs);
- if (ret < 0) {
- _E("Failed to get device power backend");
- return ret;
- }
-
- return 0;
-}
-
-int hal_device_power_put_backend(void)
-{
- int ret;
- if (!hal_device_power_funcs)
- return 0;
-
- ret = hal_common_put_backend(HAL_MODULE_DEVICE_POWER, (void *)hal_device_power_funcs);
- if (ret < 0) {
- _E("Failed to put device power backend");
- return ret;
- }
-
- hal_device_power_funcs = NULL;
-
- return 0;
-}
-
-int hal_device_power_get_wakeup_reason(enum hal_device_power_transition_reason *reason)
-{
- int ret;
-
- if (!hal_device_power_funcs) {
- if ((ret = hal_device_power_get_backend()) < 0)
- return ret;
- }
-
- if (!hal_device_power_funcs ||
- !hal_device_power_funcs->get_wakeup_reason)
- return -ENODEV;
-
- return hal_device_power_funcs->get_wakeup_reason(reason);
-}