device-power: Apply HAL ABI versioning rule 16/310016/1
authorYunhee Seo <yuni.seo@samsung.com>
Fri, 19 Apr 2024 06:28:00 +0000 (15:28 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Fri, 19 Apr 2024 06:36:06 +0000 (15:36 +0900)
In HAL-API-[module], source file name should follow hal-api-[module].c format
for applying HAL ABI versioning.

hal-api-device-power.c
 -> HAL-INTERFACE Wrapper call according to major version and implemenation of
    functions declared in hal-device-power.h

To apply HAL ABI versioning, the backend function structure memory allocation part
was moved to hal-api-device-power.

Furthermore, existing interface file is devided.
Below is a description of the purpose of header files.

hal-device-power-types.h
 -> Common data types like structures or enums used between the device-power
    HAL-API and HAL-BACKEND
hal-device-power-interface-1.h
 -> Declaration of functions to be implemented in the device-power HAL-BACKEND(Major version 1),
    as well as definitions of data structures used between the HAL-API and HAL-BACKEND(Major version 1)
hal-device-power-interface.h
 -> Includes the hal-device-power-interface-[major].h files for each supported
    major version.
hal-device-power.h
 -> Declaration of the device-power HAL-API functions

As applying HAL ABI versioning, definitions are also chaged in Native API style.

Change-Id: Id65f850e9714e7174f7e2f74bc725d7c1f0ea7f0
Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
include/hal-device-power-interface-1.h [new file with mode: 0644]
include/hal-device-power-interface.h
include/hal-device-power-types.h [new file with mode: 0644]
include/hal-device-power.h
src/hal-api-device-power.c [new file with mode: 0644]
src/power.c [deleted file]

diff --git a/include/hal-device-power-interface-1.h b/include/hal-device-power-interface-1.h
new file mode 100644 (file)
index 0000000..4bf97c7
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * 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__ */
index 275869bfae66288356e83c381941b22b95f2a843..566603947b4a58749f19196c2de194cbb72e505c 100644 (file)
 #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__ */
diff --git a/include/hal-device-power-types.h b/include/hal-device-power-types.h
new file mode 100644 (file)
index 0000000..06606c7
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * 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__ */
index 5c8114460b1c02fd20b1b8896c7661e81e5fb72d..a63502c19738d625673391a24d6a5d9d1c9bffe1 100644 (file)
@@ -25,7 +25,7 @@ extern "C" {
 
 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
 }
diff --git a/src/hal-api-device-power.c b/src/hal-api-device-power.c
new file mode 100644 (file)
index 0000000..3965f61
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * 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);
+}
diff --git a/src/power.c b/src/power.c
deleted file mode 100644 (file)
index 997db61..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * 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);
-}