From: Yunhee Seo Date: Wed, 26 Jul 2023 11:00:04 +0000 (+0900) Subject: plugin-api: deviced: Add syscommon_plugin_deviced_battery_is_possible_to_notify_batte... X-Git-Tag: accepted/tizen/unified/20230731.175325^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F08%2F296408%2F5;p=platform%2Fcore%2Fsystem%2Flibsyscommon.git plugin-api: deviced: Add syscommon_plugin_deviced_battery_is_possible_to_notify_battery_full() To use deviced plugin battery module, plugin backend battery module getter/setter are added. And, new plugin module definition "SYSCOMMON_PLUGIN_MODULE_DEVICED_BATTERY" is added. Also, to utilize plugin backend battery module function, new battery interface header and source file was created. To use plugin backend module, these are newly added. - int syscommon_plugin_deviced_battery_get_backend(void); - int syscommon_plugin_deviced_battery_put_backend(void); - int syscommon_plugin_deviced_battery_is_possible_to_notify_battery_full(bool *possible_notify); -> This is used to determine whether to inform the fully charged or not. * libsyscommon.spec typo was also corrected. Change-Id: I30a76504cd27ab44000459080fb7cd0f72f42c92 Signed-off-by: Yunhee Seo --- diff --git a/packaging/libsyscommon.spec b/packaging/libsyscommon.spec index e7d9c82..bb2d003 100644 --- a/packaging/libsyscommon.spec +++ b/packaging/libsyscommon.spec @@ -103,7 +103,7 @@ PLUGIN_API_DEVICED_MAJORVER=$(echo %{libsyscommon_plugin_api_deviced_version} | -DPLUGIN_API_DEVICED_MAJORVER=${PLUGIN_API_DEVICED_MAJORVER} \ -DPLUGIN_API_COMMON_ENABLE_DLOG=1 \ -DPLUGIN_API_RESOURCED_ENABLE_DLOG=1 \ - -DPLUGIN_API_DEVICEDD_ENABLE_DLOG=1 + -DPLUGIN_API_DEVICED_ENABLE_DLOG=1 make %{?_smp_mflags} %install diff --git a/src/plugin-api/common/include/syscommon-plugin-common.h b/src/plugin-api/common/include/syscommon-plugin-common.h index d530c0a..c644453 100644 --- a/src/plugin-api/common/include/syscommon-plugin-common.h +++ b/src/plugin-api/common/include/syscommon-plugin-common.h @@ -34,6 +34,7 @@ extern "C" { enum syscommon_plugin_module { SYSCOMMON_PLUGIN_MODULE_UNKNOWN = 0, SYSCOMMON_PLUGIN_MODULE_RESOURCED_MEMORY_LMK, + SYSCOMMON_PLUGIN_MODULE_DEVICED_BATTERY, SYSCOMMON_PLUGIN_MODULE_END, }; diff --git a/src/plugin-api/common/src/syscommon-plugin-api-list.h b/src/plugin-api/common/src/syscommon-plugin-api-list.h index 6257378..66a6c01 100644 --- a/src/plugin-api/common/src/syscommon-plugin-api-list.h +++ b/src/plugin-api/common/src/syscommon-plugin-api-list.h @@ -63,6 +63,18 @@ static struct __plugin_module_info g_plugin_module_info[] = { .num_abi_versions = ARRAY_SIZE(abi_version_match_data[SYSCOMMON_PLUGIN_MODULE_RESOURCED_MEMORY_LMK]), .abi_versions = abi_version_match_data[SYSCOMMON_PLUGIN_MODULE_RESOURCED_MEMORY_LMK], }, + [SYSCOMMON_PLUGIN_MODULE_DEVICED_BATTERY] = { + .group = PLUGIN_GROUP_DEVICED, + .module = SYSCOMMON_PLUGIN_MODULE_DEVICED_BATTERY, + .license = PLUGIN_LICENSE_APACHE_2_0, + .module_name = "SYSCOMMON_PLUGIN_MODULE_DEVICED_BATTERY", + .backend_module_name = "deviced-battery", + .library_name = "/usr/lib/system/plugin/libplugin-backend-deviced-battery.so", + .library_name_64bit = "/usr/lib64/system/plugin/libplugin-backend-deviced-battery.so", + .symbol_name = "system_plugin_backend_deviced_battery", + .num_abi_versions = ARRAY_SIZE(abi_version_match_data[SYSCOMMON_PLUGIN_MODULE_DEVICED_BATTERY]), + .abi_versions = abi_version_match_data[SYSCOMMON_PLUGIN_MODULE_DEVICED_BATTERY], + }, }; #endif /* __PLUGIN_API_LIST_H__ */ diff --git a/src/plugin-api/deviced/CMakeLists.txt b/src/plugin-api/deviced/CMakeLists.txt index 78af80a..a82642b 100644 --- a/src/plugin-api/deviced/CMakeLists.txt +++ b/src/plugin-api/deviced/CMakeLists.txt @@ -40,6 +40,7 @@ SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") # Please remove them from SRCS and add 'syscommon-plugin-api-common' # to PKG_MODULES. SET(SRCS src/syscommon-plugin-deviced-display.c + src/syscommon-plugin-deviced-battery.c ../common/src/syscommon-plugin-api-common.c ../common/src/syscommon-plugin-api-conf.c) diff --git a/src/plugin-api/deviced/include/syscommon-plugin-deviced-battery-interface.h b/src/plugin-api/deviced/include/syscommon-plugin-deviced-battery-interface.h new file mode 100644 index 0000000..1088509 --- /dev/null +++ b/src/plugin-api/deviced/include/syscommon-plugin-deviced-battery-interface.h @@ -0,0 +1,42 @@ +/** + * MIT License + * + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef __SYSCOMMON_PLUGIN_DEVICED_BATTERY_INTERFACE_H__ +#define __SYSCOMMON_PLUGIN_DEVICED_BATTERY_INTERFACE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +typedef struct _syscommon_plugin_backend_deviced_battery_funcs { + bool (*is_possible_to_notify_battery_full) (void); + +} syscommon_plugin_backend_deviced_battery_funcs; + +#ifdef __cplusplus +} +#endif + +#endif //__SYSCOMMON_PLUGIN_DEVICED_BATTERY_INTERFACE_H__ diff --git a/src/plugin-api/deviced/include/syscommon-plugin-deviced-battery.h b/src/plugin-api/deviced/include/syscommon-plugin-deviced-battery.h new file mode 100644 index 0000000..3e376b0 --- /dev/null +++ b/src/plugin-api/deviced/include/syscommon-plugin-deviced-battery.h @@ -0,0 +1,56 @@ +/** + * MIT License + * + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef __SYSCOMMON_PLUGIN_DEVICED_BATTERY_H__ +#define __SYSCOMMON_PLUGIN_DEVICED_BATTERY_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/** + * @brief Get the backend data of deviced-battery module + * @return @c 0 on success, otherwise a negative error value + */ +int syscommon_plugin_deviced_battery_get_backend(void); + +/** + * @brief Put the backend data of deviced-battery module + * @return @c 0 on success, otherwise a negative error value + */ +int syscommon_plugin_deviced_battery_put_backend(void); + +/** + * @brief Call the is_possible_to_notify_battery_full function of deviced-battery module + * @return @c 0 on success, otherwise a negative error value + */ +int syscommon_plugin_deviced_battery_is_possible_to_notify_battery_full(bool *possible_notify); + +#ifdef __cplusplus +} +#endif + +#endif //__SYSCOMMON_PLUGIN_DEVICED_BATTERY_H__ diff --git a/src/plugin-api/deviced/src/common.h b/src/plugin-api/deviced/src/common.h new file mode 100644 index 0000000..236c616 --- /dev/null +++ b/src/plugin-api/deviced/src/common.h @@ -0,0 +1,42 @@ +/** + * MIT License + * + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef __COMMON_H__ +#define __COMMON_H__ + +#ifdef ENABLE_DLOG +#include + +#define _D(fmt, args...) SLOGD(fmt, ##args) +#define _I(fmt, args...) SLOGI(fmt, ##args) +#define _W(fmt, args...) SLOGW(fmt, ##args) +#define _E(fmt, args...) SLOGE(fmt, ##args) +#else +#define _D(fmt, args...) do { } while(0) +#define _I(fmt, args...) do { } while(0) +#define _W(fmt, args...) do { } while(0) +#define _E(fmt, args...) do { } while(0) +#endif + +#endif /* __COMMON_H__ */ diff --git a/src/plugin-api/deviced/src/syscommon-plugin-deviced-battery.c b/src/plugin-api/deviced/src/syscommon-plugin-deviced-battery.c new file mode 100644 index 0000000..f242f2d --- /dev/null +++ b/src/plugin-api/deviced/src/syscommon-plugin-deviced-battery.c @@ -0,0 +1,102 @@ +/** + * MIT License + * + * Copyright (c) 2023 Samsung Electronics Co., Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#include + +#include "syscommon-plugin-common.h" + +#include "common.h" +#include "syscommon-plugin-deviced-battery.h" +#include "syscommon-plugin-deviced-battery-interface.h" + +#ifndef EXPORT +#define EXPORT __attribute__((visibility("default"))) +#endif + +static syscommon_plugin_backend_deviced_battery_funcs *funcs = NULL; + +EXPORT +int syscommon_plugin_deviced_battery_get_backend(void) +{ + int ret = 0; + + if (funcs) + return 0; + + ret = syscommon_plugin_common_get_backend( + SYSCOMMON_PLUGIN_MODULE_DEVICED_BATTERY, + (void **)&funcs); + if (ret < 0) { + _E("Failed to get deviced_battery backend: %d", ret); + return ret; + } + + _I("Success to get deviced_battery backend: %d", ret); + + return 0; +} + +EXPORT +int syscommon_plugin_deviced_battery_put_backend(void) +{ + int ret = 0; + + if (!funcs) + return 0; + + ret = syscommon_plugin_common_put_backend( + SYSCOMMON_PLUGIN_MODULE_DEVICED_BATTERY, + (void *)funcs); + if (ret < 0) { + _E("Failed to put deviced_battery backend: %d", ret); + return ret; + } + funcs = NULL; + + _I("Success to put deviced_battery backend: %d", ret); + + return 0; +} + +EXPORT +int syscommon_plugin_deviced_battery_is_possible_to_notify_battery_full(bool *possible_notify) +{ + int ret = 0; + + if (!possible_notify) + return -EINVAL; + + if (!funcs) { + ret = syscommon_plugin_deviced_battery_get_backend(); + if (ret < 0) + return ret; + } + + if (!funcs || !funcs->is_possible_to_notify_battery_full) { + _E("No backend or no \"is_possible_to_notify_battery_full\" function"); + return -ENOTSUP; + } + + *possible_notify = funcs->is_possible_to_notify_battery_full(); + return 0; +}