plugin-api: deviced: Add syscommon_plugin_deviced_battery_is_possible_to_notify_batte... 08/296408/5 accepted/tizen/unified/20230731.175325
authorYunhee Seo <yuni.seo@samsung.com>
Wed, 26 Jul 2023 11:00:04 +0000 (20:00 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Fri, 28 Jul 2023 04:07:37 +0000 (13:07 +0900)
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 <yuni.seo@samsung.com>
packaging/libsyscommon.spec
src/plugin-api/common/include/syscommon-plugin-common.h
src/plugin-api/common/src/syscommon-plugin-api-list.h
src/plugin-api/deviced/CMakeLists.txt
src/plugin-api/deviced/include/syscommon-plugin-deviced-battery-interface.h [new file with mode: 0644]
src/plugin-api/deviced/include/syscommon-plugin-deviced-battery.h [new file with mode: 0644]
src/plugin-api/deviced/src/common.h [new file with mode: 0644]
src/plugin-api/deviced/src/syscommon-plugin-deviced-battery.c [new file with mode: 0644]

index e7d9c82..bb2d003 100644 (file)
@@ -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
index d530c0a..c644453 100644 (file)
@@ -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,
 };
 
index 6257378..66a6c01 100644 (file)
@@ -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__ */
index 78af80a..a82642b 100644 (file)
@@ -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 (file)
index 0000000..1088509
--- /dev/null
@@ -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 <stdbool.h>
+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 (file)
index 0000000..3e376b0
--- /dev/null
@@ -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 <stdbool.h>
+
+/**
+ * @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 (file)
index 0000000..236c616
--- /dev/null
@@ -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 <dlog.h>
+
+#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 (file)
index 0000000..f242f2d
--- /dev/null
@@ -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 <glib.h>
+
+#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;
+}