From: Yunhee Seo Date: Fri, 19 Apr 2024 06:28:00 +0000 (+0900) Subject: device-power: Apply HAL ABI versioning rule X-Git-Tag: accepted/tizen/unified/20240614.084933~13 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3d3e1f8d00ca2dc06b3d71228b1dffdeddf9dab5;p=platform%2Fhal%2Fapi%2Fdevice.git device-power: Apply HAL ABI versioning rule 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 --- diff --git a/include/hal-device-power-interface-1.h b/include/hal-device-power-interface-1.h new file mode 100644 index 0000000..4bf97c7 --- /dev/null +++ b/include/hal-device-power-interface-1.h @@ -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__ */ diff --git a/include/hal-device-power-interface.h b/include/hal-device-power-interface.h index 275869b..5666039 100644 --- a/include/hal-device-power-interface.h +++ b/include/hal-device-power-interface.h @@ -17,49 +17,7 @@ #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 index 0000000..06606c7 --- /dev/null +++ b/include/hal-device-power-types.h @@ -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__ */ diff --git a/include/hal-device-power.h b/include/hal-device-power.h index 5c81144..a63502c 100644 --- a/include/hal-device-power.h +++ b/include/hal-device-power.h @@ -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 index 0000000..3965f61 --- /dev/null +++ b/src/hal-api-device-power.c @@ -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 + +#include + +#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 index 997db61..0000000 --- a/src/power.c +++ /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 - -#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); -}