From ba823a0294b55f2eefa317a069578c6c64a26f8d Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 16 Mar 2023 12:54:51 +0900 Subject: [PATCH 01/16] Revert "resource-manager: Relocate add_resource() in create_resource()" This reverts commit 5880b22f3e55b60c7b9326c51012b95f05416145. The resource instance must be added to hashtable prior to the operation driver->ops.create(resource->id). As this operation passes resource id, it is possible that the operation work based on that resource id, which denotes resource instance and must have been registered to hashtable. Therefore, add_resource() must be followed by driver->ops.create(). Change-Id: I05b8a9f85741313c14201501fe6bbc4a5b8c7233 Signed-off-by: Youngjae Cho --- src/resource-manager/resource-manager.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/resource-manager/resource-manager.c b/src/resource-manager/resource-manager.c index a870a0b..b3f3b9d 100644 --- a/src/resource-manager/resource-manager.c +++ b/src/resource-manager/resource-manager.c @@ -248,6 +248,12 @@ create_resource(int *resource_id, int resource_type, int instance_type) return -ENOMEM; } + ret = add_resource(resource); + if (ret < 0) { + free_resource(resource); + return ret; + } + for (i = 0; i < resource->num_attrs; i++) resource->attrs_value[i].type = driver->attrs[i].type; @@ -265,14 +271,6 @@ create_resource(int *resource_id, int resource_type, int instance_type) *resource_id = resource->id; - ret = add_resource(resource); - if (ret < 0) { - if (driver->ops.delete) - driver->ops.delete(resource->id); - free_resource(resource); - return ret; - } - return 0; } -- 2.7.4 From 92ee2e600ff54f91f2ba38c0261153dfe12b5bf3 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 16 Mar 2023 13:07:42 +0900 Subject: [PATCH 02/16] resource-manager: cleanup resource instance correctly On failure during create_resource(), remove resource instance from hashtable if it has been registered hashtable via add_resource(). Change-Id: I124add4633b06be0e3a2bc2786f1eee8b69acce0 Signed-off-by: Youngjae Cho --- src/resource-manager/resource-manager.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/resource-manager/resource-manager.c b/src/resource-manager/resource-manager.c index b3f3b9d..6fd1f5e 100644 --- a/src/resource-manager/resource-manager.c +++ b/src/resource-manager/resource-manager.c @@ -264,7 +264,7 @@ create_resource(int *resource_id, int resource_type, int instance_type) if (driver->ops.create) { ret = driver->ops.create(resource->id); if (ret < 0) { - free_resource(resource); + g_hash_table_remove(g_resource_hash_table, GINT_TO_POINTER(resource->id)); return ret; } } -- 2.7.4 From 22b8578535821c5c0b5354b1f20554a14c1a4238 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Fri, 17 Mar 2023 09:40:27 +0900 Subject: [PATCH 03/16] packaging: Rearrange %package directive As those relocated %packages overwrite the %{version} of libsyscommon, define %{libsyscommon_version} to maintain its value. Change-Id: I0049a45fdd343515e09c97a4abf0f8aa6ea9704a Signed-off-by: Youngjae Cho --- packaging/libsyscommon.spec | 81 +++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 40 deletions(-) diff --git a/packaging/libsyscommon.spec b/packaging/libsyscommon.spec index 415db65..be70866 100644 --- a/packaging/libsyscommon.spec +++ b/packaging/libsyscommon.spec @@ -1,9 +1,10 @@ +%define libsyscommon_version 5.0.0 %define plugin_api_common_version 0.1.0 %define plugin_api_resourced_version 0.1.0 Name: libsyscommon Summary: System Libraries -Version: 5.0.0 +Version: %{libsyscommon_version} Release: 0%{?release_flags} License: MIT Group: System/Libraries @@ -39,6 +40,44 @@ Requires: pkgconfig(capi-system-info) %description -n libsyscommon-devel Development header files for system common library. +# Packages for plugin-api +%package -n plugin-api-common +Summary: Common plugin APIs +Version: %{plugin_api_common_version} +License: MIT +Requires: pkgconfig(gio-2.0) +Requires: pkgconfig(dlog) + +%package -n plugin-api-common-devel +Summary: Header files for common plugin APIs +Version: %{plugin_api_common_version} +License: MIT +Requires: pkgconfig(gio-2.0) +Requires: pkgconfig(dlog) + +%description -n plugin-api-common-devel +Development header files for common plugin APIs. + +%package -n plugin-api-resourced +Summary: Plugin APIs for the resourced +Version: %{plugin_api_resourced_version} +License: MIT +Requires: pkgconfig(gio-2.0) +Requires: pkgconfig(dlog) + +%description -n plugin-api-resourced +Plugin APIs for the resourced. + +%package -n plugin-api-resourced-devel +Summary: Header files for plugin APIs for the resourced +Version: %{plugin_api_resourced_version} +License: MIT +Requires: pkgconfig(gio-2.0) +Requires: pkgconfig(dlog) + +%description -n plugin-api-resourced-devel +Development header files for plugin APIs for the resourced. + %prep %setup -q cp %{SOURCE1001} . @@ -46,7 +85,7 @@ cp %{SOURCE1001} . %build PLUGIN_API_COMMON_MAJORVER=$(echo %{plugin_api_common_version} | cut -d'.' -f1) PLUGIN_API_RESOURCED_MAJORVER=$(echo %{plugin_api_resourced_version} | cut -d'.' -f1) -%cmake . -DFULLVER=%{version} \ +%cmake . -DFULLVER=%{libsyscommon_version} \ -DPLUGIN_API_COMMON_VERSION=%{plugin_api_common_version} \ -DPLUGIN_API_COMMON_MAJORVER=${PLUGIN_API_COMMON_MAJORVER} \ -DPLUGIN_API_RESOURCED_VERSION=%{plugin_api_resourced_version} \ @@ -81,14 +120,6 @@ touch debugsources.list %{_includedir}/libsyscommon/*.h %{_libdir}/pkgconfig/libsyscommon.pc -# Packages for plugin-api -%package -n plugin-api-common -Summary: Common plugin APIs -Version: %{plugin_api_common_version} -License: MIT -Requires: pkgconfig(gio-2.0) -Requires: pkgconfig(dlog) - %description -n plugin-api-common Common plugin APIs to load another APIs from backend. @@ -103,16 +134,6 @@ chsmack -a "_" libplugin-api-common.so.%{plugin_api_common_version} popd /sbin/ldconfig -%package -n plugin-api-common-devel -Summary: Header files for common plugin APIs -Version: %{plugin_api_common_version} -License: MIT -Requires: pkgconfig(gio-2.0) -Requires: pkgconfig(dlog) - -%description -n plugin-api-common-devel -Development header files for common plugin APIs. - %files -n plugin-api-common-devel %defattr(-,root,root,-) %license LICENSE.MIT @@ -120,16 +141,6 @@ Development header files for common plugin APIs. %{_libdir}/pkgconfig/plugin-api-common.pc %{_libdir}/libplugin-api-common.so -%package -n plugin-api-resourced -Summary: Plugin APIs for the resourced -Version: %{plugin_api_resourced_version} -License: MIT -Requires: pkgconfig(gio-2.0) -Requires: pkgconfig(dlog) - -%description -n plugin-api-resourced -Plugin APIs for the resourced. - %files -n plugin-api-resourced %defattr(-,root,root,-) %license LICENSE.MIT @@ -141,16 +152,6 @@ chsmack -a "_" libplugin-api-resourced.so.%{plugin_api_resourced_version} popd /sbin/ldconfig -%package -n plugin-api-resourced-devel -Summary: Header files for plugin APIs for the resourced -Version: %{plugin_api_resourced_version} -License: MIT -Requires: pkgconfig(gio-2.0) -Requires: pkgconfig(dlog) - -%description -n plugin-api-resourced-devel -Development header files for plugin APIs for the resourced. - %files -n plugin-api-resourced-devel %defattr(-,root,root,-) %license LICENSE.MIT -- 2.7.4 From 35ae84e72bf86544d55841a3fda9ed5e8707e0e2 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Fri, 17 Mar 2023 09:57:59 +0900 Subject: [PATCH 04/16] plugin-api: deviced: Add plugin-api-deviced Initialize plugin-api for deviced. It creates package plugin-api-deviced and the package contains empty library. Change-Id: I2a91b9185e4b9f0ffbe61c4d71801d20a15b0df2 Signed-off-by: Youngjae Cho --- CMakeLists.txt | 1 + packaging/libsyscommon.spec | 39 ++++++++++++- src/plugin-api/deviced/CMakeLists.txt | 66 ++++++++++++++++++++++ .../include/plugin-deviced-display-interface.h | 36 ++++++++++++ .../deviced/include/plugin-deviced-display.h | 36 ++++++++++++ src/plugin-api/deviced/plugin-api-deviced.pc.in | 17 ++++++ .../deviced/src/plugin-deviced-display.c | 23 ++++++++ 7 files changed, 217 insertions(+), 1 deletion(-) create mode 100644 src/plugin-api/deviced/CMakeLists.txt create mode 100644 src/plugin-api/deviced/include/plugin-deviced-display-interface.h create mode 100644 src/plugin-api/deviced/include/plugin-deviced-display.h create mode 100644 src/plugin-api/deviced/plugin-api-deviced.pc.in create mode 100644 src/plugin-api/deviced/src/plugin-deviced-display.c diff --git a/CMakeLists.txt b/CMakeLists.txt index c6a6b54..d28713b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src/shared) ADD_SUBDIRECTORY(src/plugin-api/common) ADD_SUBDIRECTORY(src/plugin-api/resourced) +ADD_SUBDIRECTORY(src/plugin-api/deviced) # ADD_SUBDIRECTORY(src/libgdbus) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) diff --git a/packaging/libsyscommon.spec b/packaging/libsyscommon.spec index be70866..a7c8cb5 100644 --- a/packaging/libsyscommon.spec +++ b/packaging/libsyscommon.spec @@ -1,6 +1,7 @@ %define libsyscommon_version 5.0.0 %define plugin_api_common_version 0.1.0 %define plugin_api_resourced_version 0.1.0 +%define plugin_api_deviced_version 0.1.0 Name: libsyscommon Summary: System Libraries @@ -78,6 +79,26 @@ Requires: pkgconfig(dlog) %description -n plugin-api-resourced-devel Development header files for plugin APIs for the resourced. +%package -n plugin-api-deviced +Summary: Plugin APIs for the deviced +Version: %{plugin_api_deviced_version} +License: MIT + +%description -n plugin-api-deviced +Plugin APIs for the deviced. + +%package -n plugin-api-deviced-devel +Summary: Header files for plugin APIs for the deviced +Version: %{plugin_api_deviced_version} +License: MIT + +%description -n plugin-api-deviced-devel +Development header files for plugin APIs for the deviced. + + +###### + + %prep %setup -q cp %{SOURCE1001} . @@ -85,13 +106,17 @@ cp %{SOURCE1001} . %build PLUGIN_API_COMMON_MAJORVER=$(echo %{plugin_api_common_version} | cut -d'.' -f1) PLUGIN_API_RESOURCED_MAJORVER=$(echo %{plugin_api_resourced_version} | cut -d'.' -f1) +PLUGIN_API_DEVICED_MAJORVER=$(echo %{plugin_api_deviced_version} | cut -d'.' -f1) %cmake . -DFULLVER=%{libsyscommon_version} \ -DPLUGIN_API_COMMON_VERSION=%{plugin_api_common_version} \ -DPLUGIN_API_COMMON_MAJORVER=${PLUGIN_API_COMMON_MAJORVER} \ -DPLUGIN_API_RESOURCED_VERSION=%{plugin_api_resourced_version} \ -DPLUGIN_API_RESOURCED_MAJORVER=${PLUGIN_API_RESOURCED_MAJORVER} \ + -DPLUGIN_API_DEVICED_VERSION=%{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_RESOURCED_ENABLE_DLOG=1 \ + -DPLUGIN_API_DEVICEDD_ENABLE_DLOG=1 make %{?_smp_mflags} %install @@ -158,3 +183,15 @@ popd %{_includedir}/plugin/plugin-resourced*.h %{_libdir}/pkgconfig/plugin-api-resourced.pc %{_libdir}/libplugin-api-resourced.so + +%files -n plugin-api-deviced +%defattr(-,root,root,-) +%license LICENSE.MIT +%{_libdir}/libplugin-api-deviced.so.* + +%files -n plugin-api-deviced-devel +%defattr(-,root,root,-) +%license LICENSE.MIT +%{_includedir}/plugin/plugin-deviced*.h +%{_libdir}/pkgconfig/plugin-api-deviced.pc +%{_libdir}/libplugin-api-deviced.so diff --git a/src/plugin-api/deviced/CMakeLists.txt b/src/plugin-api/deviced/CMakeLists.txt new file mode 100644 index 0000000..89ed42d --- /dev/null +++ b/src/plugin-api/deviced/CMakeLists.txt @@ -0,0 +1,66 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(plugin-api-deviced) + +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(EXEC_PREFIX "${PREFIX}/bin") +SET(LIBDIR ${LIB_INSTALL_DIR}) +SET(INCLUDEDIR "${PREFIX}/include/plugin") +SET(VERSION ${PLUGIN_API_DEVICED_VERSION}) + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) +# Including below should be removed if the repository of plugin-api-common is +# separated. +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../common/include) + +if (${PLUGIN_API_DEVICED_ENABLE_DLOG}) + SET(PKG_MODULES + glib-2.0 + dlog) + ADD_DEFINITIONS("-DENABLE_DLOG") + ADD_DEFINITIONS("-DLOG_TAG=\"PLUGIN_API_DEVICED\"") +else() + SET(PKG_MODULES + glib-2.0) +endif() + +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs REQUIRED ${PKG_MODULES}) +FOREACH(flag ${pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -fPIC") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g -fno-omit-frame-pointer -finstrument-functions") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall -lrt") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl") +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") + +# plugin-api-common.c and plugin-api-conf.c are unnecessary if the repository of +# plugin-api-common is separated. +# Please remove them from SRCS and add 'plugin-api-common' to PKG_MODULES. +SET(SRCS src/plugin-deviced-display.c + ../common/src/plugin-api-common.c + ../common/src/plugin-api-conf.c) + +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} + -ldl -Wl,-z,nodelete,--no-undefined) + +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${PLUGIN_API_DEVICED_VERSION}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${PLUGIN_API_DEVICED_MAJORVER}) + +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}) +INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ + DESTINATION ${INCLUDEDIR} + FILES_MATCHING PATTERN "*.h" +) + +# CONFIGURE .pc FILE +FOREACH(include_dirs ${pkgs_INCLUDE_DIRS}) + SET(PLUGIN_DEVICED_INCLUDEDIR "${PLUGIN_DEVICED_INCLUDEDIR} -I${include_dirs}") +ENDFOREACH(include_dirs) +FOREACH(libraries ${pkgs_LIBRARIES}) + SET(PLUGIN_DEVICED_LIBS "${PLUGIN_DEVICED_LIBS} -l${libraries}") +ENDFOREACH(libraries) +CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) diff --git a/src/plugin-api/deviced/include/plugin-deviced-display-interface.h b/src/plugin-api/deviced/include/plugin-deviced-display-interface.h new file mode 100644 index 0000000..2a0c909 --- /dev/null +++ b/src/plugin-api/deviced/include/plugin-deviced-display-interface.h @@ -0,0 +1,36 @@ +/** + * 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 __PLUGIN_DEVICED_DISPLAY_INTERFACE_H__ +#define __PLUGIN_DEVICED_DISPLAY_INTERFACE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif //__PLUGIN_DEVICED_DISPLAY_INTERFACE_H__ diff --git a/src/plugin-api/deviced/include/plugin-deviced-display.h b/src/plugin-api/deviced/include/plugin-deviced-display.h new file mode 100644 index 0000000..14e5c6c --- /dev/null +++ b/src/plugin-api/deviced/include/plugin-deviced-display.h @@ -0,0 +1,36 @@ +/** + * 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 __PLUGIN_DEVICED_DISPLAY_H__ +#define __PLUGIN_DEVICED_DISPLAY_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif //__PLUGIN_DEVICED_DISPLAY_H__ diff --git a/src/plugin-api/deviced/plugin-api-deviced.pc.in b/src/plugin-api/deviced/plugin-api-deviced.pc.in new file mode 100644 index 0000000..a328de4 --- /dev/null +++ b/src/plugin-api/deviced/plugin-api-deviced.pc.in @@ -0,0 +1,17 @@ +# Package Information for pkg-config +# +# Copyright (c) 2023 Samsung Electronics Co., Ltd. +# All rights reserved. +# + +prefix=@PREFIX@ +exec_prefix=@EXEC_PREFIX@ +libdir=@LIBDIR@ +includedir=@INCLUDEDIR@ + +Name: plugin-api-deviced +Description: Plugin APIs for the deviced +Version: @VERSION@ +Requires.private: plugin-api-common +Cflags: -I${includedir} @PLUGIN_DEVICED_INCLUDEDIR@ +Libs: -L${libdir} -lplugin-api-deviced @PLUGIN_DEVICED_LIBS@ diff --git a/src/plugin-api/deviced/src/plugin-deviced-display.c b/src/plugin-api/deviced/src/plugin-deviced-display.c new file mode 100644 index 0000000..f07bd13 --- /dev/null +++ b/src/plugin-api/deviced/src/plugin-deviced-display.c @@ -0,0 +1,23 @@ +/** + * 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. + */ -- 2.7.4 From 5c5c7f315c8d675eb98abc53dd9c6170c30cfaba Mon Sep 17 00:00:00 2001 From: SangYoun Kwak Date: Thu, 16 Mar 2023 20:45:18 +0900 Subject: [PATCH 05/16] plugin-api: Fix the prefix for pkg_check_modules of CMakeLists.txt The command pkg_check_modules in CMakeLists.txt checks modules and sets variables about these modules. The names of these variables have their prefix designated by the command pkg_check_modules like below: pkg_check_modules( REQUIRED ) Previously, in plugin-api-common, prefix was "pkgs", which is not a unique name. In plugin-api-resourced, prefix was ${PROJECT_NAME} but when calling variables, "pkgs" was used for prefix, which is not correct usage. This fault was fixed by replacing their prefix as their ${PROJECT_NAME}. Change-Id: Ide1db4b707f2c6e9f632c0cc36ab4ec654383887 Signed-off-by: SangYoun Kwak --- src/plugin-api/common/CMakeLists.txt | 10 +++++----- src/plugin-api/resourced/CMakeLists.txt | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/plugin-api/common/CMakeLists.txt b/src/plugin-api/common/CMakeLists.txt index 326139c..8f0e0fe 100644 --- a/src/plugin-api/common/CMakeLists.txt +++ b/src/plugin-api/common/CMakeLists.txt @@ -25,8 +25,8 @@ else() endif() INCLUDE(FindPkgConfig) -pkg_check_modules(pkgs REQUIRED ${PKG_MODULES}) -FOREACH(flag ${pkgs_CFLAGS}) +pkg_check_modules(${PROJECT_NAME} REQUIRED ${PKG_MODULES}) +FOREACH(flag ${${PROJECT_NAME}_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") ENDFOREACH(flag) @@ -41,7 +41,7 @@ SET(SRCS src/plugin-api-conf.c) ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${${PROJECT_NAME}_LDFLAGS} -ldl -Wl,-z,nodelete,--no-undefined) SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${PLUGIN_API_COMMON_MAJORVER}) SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${VERSION}) @@ -52,10 +52,10 @@ INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ FILES_MATCHING PATTERN "*.h") # CONFIGURE .pc FILE -FOREACH(include_dirs ${pkgs_INCLUDE_DIRS}) +FOREACH(include_dirs ${${PROJECT_NAME}_INCLUDE_DIRS}) SET(PLUGIN_COMMON_INCLUDEDIR "${PLUGIN_COMMON_INCLUDEDIR} -I${include_dirs}") ENDFOREACH(include_dirs) -FOREACH(libraries ${pkgs_LIBRARIES}) +FOREACH(libraries ${${PROJECT_NAME}_LIBRARIES}) SET(PLUGIN_COMMON_LIBS "${PLUGIN_COMMON_LIBS} -l${libraries}") ENDFOREACH(libraries) CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) diff --git a/src/plugin-api/resourced/CMakeLists.txt b/src/plugin-api/resourced/CMakeLists.txt index c428dd1..114cbcb 100644 --- a/src/plugin-api/resourced/CMakeLists.txt +++ b/src/plugin-api/resourced/CMakeLists.txt @@ -44,7 +44,7 @@ SET(SRCS src/plugin-resourced-memory-lmk.c ../common/src/plugin-api-conf.c) ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${${PROJECT_NAME}_LDFLAGS} -ldl -Wl,-z,nodelete,--no-undefined) SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${PLUGIN_API_RESOURCED_VERSION}) @@ -57,10 +57,10 @@ INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ ) # CONFIGURE .pc FILE -FOREACH(include_dirs ${pkgs_INCLUDE_DIRS}) +FOREACH(include_dirs ${${PROJECT_NAME}_INCLUDE_DIRS}) SET(PLUGIN_RESOURCED_INCLUDEDIR "${PLUGIN_RESOURCED_INCLUDEDIR} -I${include_dirs}") ENDFOREACH(include_dirs) -FOREACH(libraries ${pkgs_LIBRARIES}) +FOREACH(libraries ${${PROJECT_NAME}_LIBRARIES}) SET(PLUGIN_RESOURCED_LIBS "${PLUGIN_RESOURCED_LIBS} -l${libraries}") ENDFOREACH(libraries) CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) -- 2.7.4 From 13584c15d345712dfbddb20ae6440fdfb4cd883d Mon Sep 17 00:00:00 2001 From: SangYoun Kwak Date: Thu, 27 Apr 2023 14:13:39 +0900 Subject: [PATCH 06/16] plugin-api: Rename 'plugin' to 'syscommon-plugin' Since the plugin-api is the plugin feature which is only used in system scope and it is located in libsyscommon, plugin was changed to syscommon-plugin to indicate its usage and location. Change rule: * Basically, plugin becomes syscommon-plugin to indicate it is from the libsyscommon repository * Symbols which are used internally can omit the prefix 'syscommon'. Changed: * Package name: plugin-api... -> libsyscommon-plugin-api... * Package config file name: plugin-api-....pc -> libsyscommon-plugin-api....pc * .so name: libplugin-api-....so -> libsyscommon-plugin-api....so Change-Id: Ia56c935ebf97a93cad7efd0235508c540ee0348d Signed-off-by: SangYoun Kwak --- packaging/libsyscommon.spec | 124 ++++++++++----------- src/plugin-api/common/CMakeLists.txt | 15 +-- ...rface.h => syscommon-plugin-common-interface.h} | 28 ++--- .../{plugin-common.h => syscommon-plugin-common.h} | 57 ++++++---- ....pc.in => libsyscommon-plugin-api-common.pc.in} | 6 +- src/plugin-api/common/src/common.h | 12 +- ...-api-common.c => syscommon-plugin-api-common.c} | 87 ++++++++------- ...ugin-api-conf.c => syscommon-plugin-api-conf.c} | 25 +++-- ...ugin-api-conf.h => syscommon-plugin-api-conf.h} | 15 +-- ...ugin-api-list.h => syscommon-plugin-api-list.h} | 33 +++--- src/plugin-api/deviced/CMakeLists.txt | 28 ++--- ...> syscommon-plugin-deviced-display-interface.h} | 6 +- ...isplay.h => syscommon-plugin-deviced-display.h} | 6 +- ...pc.in => libsyscommon-plugin-api-deviced.pc.in} | 8 +- ...isplay.c => syscommon-plugin-deviced-display.c} | 0 src/plugin-api/resourced/CMakeLists.txt | 28 ++--- ...common-plugin-resourced-memory-lmk-interface.h} | 10 +- ...k.h => syscommon-plugin-resourced-memory-lmk.h} | 13 ++- ....in => libsyscommon-plugin-api-resourced.pc.in} | 8 +- ...k.c => syscommon-plugin-resourced-memory-lmk.c} | 27 +++-- 20 files changed, 282 insertions(+), 254 deletions(-) rename src/plugin-api/common/include/{plugin-common-interface.h => syscommon-plugin-common-interface.h} (66%) rename src/plugin-api/common/include/{plugin-common.h => syscommon-plugin-common.h} (76%) rename src/plugin-api/common/{plugin-api-common.pc.in => libsyscommon-plugin-api-common.pc.in} (64%) rename src/plugin-api/common/src/{plugin-api-common.c => syscommon-plugin-api-common.c} (81%) rename src/plugin-api/common/src/{plugin-api-conf.c => syscommon-plugin-api-conf.c} (86%) rename src/plugin-api/common/src/{plugin-api-conf.h => syscommon-plugin-api-conf.h} (78%) rename src/plugin-api/common/src/{plugin-api-list.h => syscommon-plugin-api-list.h} (56%) rename src/plugin-api/deviced/include/{plugin-deviced-display-interface.h => syscommon-plugin-deviced-display-interface.h} (87%) rename src/plugin-api/deviced/include/{plugin-deviced-display.h => syscommon-plugin-deviced-display.h} (89%) rename src/plugin-api/deviced/{plugin-api-deviced.pc.in => libsyscommon-plugin-api-deviced.pc.in} (56%) rename src/plugin-api/deviced/src/{plugin-deviced-display.c => syscommon-plugin-deviced-display.c} (100%) rename src/plugin-api/resourced/include/{plugin-resourced-memory-lmk-interface.h => syscommon-plugin-resourced-memory-lmk-interface.h} (81%) rename src/plugin-api/resourced/include/{plugin-resourced-memory-lmk.h => syscommon-plugin-resourced-memory-lmk.h} (88%) rename src/plugin-api/resourced/{plugin-api-resourced.pc.in => libsyscommon-plugin-api-resourced.pc.in} (55%) rename src/plugin-api/resourced/src/{plugin-resourced-memory-lmk.c => syscommon-plugin-resourced-memory-lmk.c} (74%) diff --git a/packaging/libsyscommon.spec b/packaging/libsyscommon.spec index a7c8cb5..0ce2272 100644 --- a/packaging/libsyscommon.spec +++ b/packaging/libsyscommon.spec @@ -1,7 +1,7 @@ %define libsyscommon_version 5.0.0 -%define plugin_api_common_version 0.1.0 -%define plugin_api_resourced_version 0.1.0 -%define plugin_api_deviced_version 0.1.0 +%define libsyscommon_plugin_api_common_version 0.1.0 +%define libsyscommon_plugin_api_resourced_version 0.1.0 +%define libsyscommon_plugin_api_deviced_version 0.1.0 Name: libsyscommon Summary: System Libraries @@ -41,59 +41,59 @@ Requires: pkgconfig(capi-system-info) %description -n libsyscommon-devel Development header files for system common library. -# Packages for plugin-api -%package -n plugin-api-common -Summary: Common plugin APIs -Version: %{plugin_api_common_version} +# Packages for system plugin api +%package -n libsyscommon-plugin-api-common +Summary: Common system plugin APIs +Version: %{libsyscommon_plugin_api_common_version} License: MIT Requires: pkgconfig(gio-2.0) Requires: pkgconfig(dlog) -%package -n plugin-api-common-devel -Summary: Header files for common plugin APIs -Version: %{plugin_api_common_version} +%package -n libsyscommon-plugin-api-common-devel +Summary: Header files for common system plugin APIs +Version: %{libsyscommon_plugin_api_common_version} License: MIT Requires: pkgconfig(gio-2.0) Requires: pkgconfig(dlog) -%description -n plugin-api-common-devel -Development header files for common plugin APIs. +%description -n libsyscommon-plugin-api-common-devel +Development header files for common system plugin APIs. -%package -n plugin-api-resourced -Summary: Plugin APIs for the resourced -Version: %{plugin_api_resourced_version} +%package -n libsyscommon-plugin-api-resourced +Summary: System plugin APIs for the resourced +Version: %{libsyscommon_plugin_api_resourced_version} License: MIT Requires: pkgconfig(gio-2.0) Requires: pkgconfig(dlog) -%description -n plugin-api-resourced -Plugin APIs for the resourced. +%description -n libsyscommon-plugin-api-resourced +System plugin APIs for the resourced. -%package -n plugin-api-resourced-devel -Summary: Header files for plugin APIs for the resourced -Version: %{plugin_api_resourced_version} +%package -n libsyscommon-plugin-api-resourced-devel +Summary: Header files for system plugin APIs for the resourced +Version: %{libsyscommon_plugin_api_resourced_version} License: MIT Requires: pkgconfig(gio-2.0) Requires: pkgconfig(dlog) -%description -n plugin-api-resourced-devel -Development header files for plugin APIs for the resourced. +%description -n libsyscommon-plugin-api-resourced-devel +Development header files for system plugin APIs for the resourced. -%package -n plugin-api-deviced -Summary: Plugin APIs for the deviced -Version: %{plugin_api_deviced_version} +%package -n libsyscommon-plugin-api-deviced +Summary: System plugin APIs for the deviced +Version: %{libsyscommon_plugin_api_deviced_version} License: MIT -%description -n plugin-api-deviced -Plugin APIs for the deviced. +%description -n libsyscommon-plugin-api-deviced +System plugin APIs for the deviced. -%package -n plugin-api-deviced-devel -Summary: Header files for plugin APIs for the deviced -Version: %{plugin_api_deviced_version} +%package -n libsyscommon-plugin-api-deviced-devel +Summary: Header files for system plugin APIs for the deviced +Version: %{libsyscommon_plugin_api_deviced_version} License: MIT -%description -n plugin-api-deviced-devel -Development header files for plugin APIs for the deviced. +%description -n libsyscommon-plugin-api-deviced-devel +Development header files for system plugin APIs for the deviced. ###### @@ -104,15 +104,15 @@ Development header files for plugin APIs for the deviced. cp %{SOURCE1001} . %build -PLUGIN_API_COMMON_MAJORVER=$(echo %{plugin_api_common_version} | cut -d'.' -f1) -PLUGIN_API_RESOURCED_MAJORVER=$(echo %{plugin_api_resourced_version} | cut -d'.' -f1) -PLUGIN_API_DEVICED_MAJORVER=$(echo %{plugin_api_deviced_version} | cut -d'.' -f1) +PLUGIN_API_COMMON_MAJORVER=$(echo %{libsyscommon_plugin_api_common_version} | cut -d'.' -f1) +PLUGIN_API_RESOURCED_MAJORVER=$(echo %{libsyscommon_plugin_api_resourced_version} | cut -d'.' -f1) +PLUGIN_API_DEVICED_MAJORVER=$(echo %{libsyscommon_plugin_api_deviced_version} | cut -d'.' -f1) %cmake . -DFULLVER=%{libsyscommon_version} \ - -DPLUGIN_API_COMMON_VERSION=%{plugin_api_common_version} \ + -DPLUGIN_API_COMMON_VERSION=%{libsyscommon_plugin_api_common_version} \ -DPLUGIN_API_COMMON_MAJORVER=${PLUGIN_API_COMMON_MAJORVER} \ - -DPLUGIN_API_RESOURCED_VERSION=%{plugin_api_resourced_version} \ + -DPLUGIN_API_RESOURCED_VERSION=%{libsyscommon_plugin_api_resourced_version} \ -DPLUGIN_API_RESOURCED_MAJORVER=${PLUGIN_API_RESOURCED_MAJORVER} \ - -DPLUGIN_API_DEVICED_VERSION=%{plugin_api_deviced_version} \ + -DPLUGIN_API_DEVICED_VERSION=%{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 \ @@ -145,53 +145,53 @@ touch debugsources.list %{_includedir}/libsyscommon/*.h %{_libdir}/pkgconfig/libsyscommon.pc -%description -n plugin-api-common -Common plugin APIs to load another APIs from backend. +%description -n libsyscommon-plugin-api-common +Common system plugin APIs to load another APIs from backend. -%files -n plugin-api-common +%files -n libsyscommon-plugin-api-common %defattr(-,root,root,-) %license LICENSE.MIT -%{_libdir}/libplugin-api-common.so.* +%{_libdir}/libsyscommon-plugin-api-common.so.* -%post -n plugin-api-common +%post -n libsyscommon-plugin-api-common pushd %{_libdir} -chsmack -a "_" libplugin-api-common.so.%{plugin_api_common_version} +chsmack -a "_" libsyscommon-plugin-api-common.so.%{libsyscommon_plugin_api_common_version} popd /sbin/ldconfig -%files -n plugin-api-common-devel +%files -n libsyscommon-plugin-api-common-devel %defattr(-,root,root,-) %license LICENSE.MIT -%{_includedir}/plugin/plugin-common*.h -%{_libdir}/pkgconfig/plugin-api-common.pc -%{_libdir}/libplugin-api-common.so +%{_includedir}/system/syscommon-plugin-common*.h +%{_libdir}/pkgconfig/libsyscommon-plugin-api-common.pc +%{_libdir}/libsyscommon-plugin-api-common.so -%files -n plugin-api-resourced +%files -n libsyscommon-plugin-api-resourced %defattr(-,root,root,-) %license LICENSE.MIT -%{_libdir}/libplugin-api-resourced.so.* +%{_libdir}/libsyscommon-plugin-api-resourced.so.* -%post -n plugin-api-resourced +%post -n libsyscommon-plugin-api-resourced pushd %{_libdir} -chsmack -a "_" libplugin-api-resourced.so.%{plugin_api_resourced_version} +chsmack -a "_" libsyscommon-plugin-api-resourced.so.%{libsyscommon_plugin_api_resourced_version} popd /sbin/ldconfig -%files -n plugin-api-resourced-devel +%files -n libsyscommon-plugin-api-resourced-devel %defattr(-,root,root,-) %license LICENSE.MIT -%{_includedir}/plugin/plugin-resourced*.h -%{_libdir}/pkgconfig/plugin-api-resourced.pc -%{_libdir}/libplugin-api-resourced.so +%{_includedir}/system/syscommon-plugin-resourced*.h +%{_libdir}/pkgconfig/libsyscommon-plugin-api-resourced.pc +%{_libdir}/libsyscommon-plugin-api-resourced.so -%files -n plugin-api-deviced +%files -n libsyscommon-plugin-api-deviced %defattr(-,root,root,-) %license LICENSE.MIT -%{_libdir}/libplugin-api-deviced.so.* +%{_libdir}/libsyscommon-plugin-api-deviced.so.* -%files -n plugin-api-deviced-devel +%files -n libsyscommon-plugin-api-deviced-devel %defattr(-,root,root,-) %license LICENSE.MIT -%{_includedir}/plugin/plugin-deviced*.h -%{_libdir}/pkgconfig/plugin-api-deviced.pc -%{_libdir}/libplugin-api-deviced.so +%{_includedir}/system/syscommon-plugin-deviced*.h +%{_libdir}/pkgconfig/libsyscommon-plugin-api-deviced.pc +%{_libdir}/libsyscommon-plugin-api-deviced.so diff --git a/src/plugin-api/common/CMakeLists.txt b/src/plugin-api/common/CMakeLists.txt index 8f0e0fe..666d51f 100644 --- a/src/plugin-api/common/CMakeLists.txt +++ b/src/plugin-api/common/CMakeLists.txt @@ -1,17 +1,17 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT(plugin-api-common) +PROJECT(syscommon-plugin-api-common) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(EXEC_PREFIX "${PREFIX}/bin") SET(LIBDIR ${LIB_INSTALL_DIR}) -SET(INCLUDEDIR "${PREFIX}/include/plugin") +SET(INCLUDEDIR "${PREFIX}/include/system") SET(VERSION ${PLUGIN_API_COMMON_VERSION}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) if (${PLUGIN_API_COMMON_ENABLE_DLOG}) ADD_DEFINITIONS("-DENABLE_DLOG=1") - ADD_DEFINITIONS("-DLOG_TAG=\"PLUGIN_API_COMMON\"") + ADD_DEFINITIONS("-DLOG_TAG=\"SYSTEM_PLUGIN_API_COMMON\"") SET(PKG_MODULES dlog gio-2.0 @@ -37,8 +37,8 @@ SET(CMAKE_EXE_LINKER_FLAGS "-pie") SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") SET(SRCS - src/plugin-api-common.c - src/plugin-api-conf.c) + src/syscommon-plugin-api-common.c + src/syscommon-plugin-api-conf.c) ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${${PROJECT_NAME}_LDFLAGS} @@ -58,5 +58,6 @@ ENDFOREACH(include_dirs) FOREACH(libraries ${${PROJECT_NAME}_LIBRARIES}) SET(PLUGIN_COMMON_LIBS "${PLUGIN_COMMON_LIBS} -l${libraries}") ENDFOREACH(libraries) -CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) -INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) +SET(PACKAGE_CONFIG_FILE "lib${PROJECT_NAME}.pc") +CONFIGURE_FILE(${PACKAGE_CONFIG_FILE}.in ${PACKAGE_CONFIG_FILE} @ONLY) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_CONFIG_FILE} DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) diff --git a/src/plugin-api/common/include/plugin-common-interface.h b/src/plugin-api/common/include/syscommon-plugin-common-interface.h similarity index 66% rename from src/plugin-api/common/include/plugin-common-interface.h rename to src/plugin-api/common/include/syscommon-plugin-common-interface.h index 37f201a..1cda550 100644 --- a/src/plugin-api/common/include/plugin-common-interface.h +++ b/src/plugin-api/common/include/syscommon-plugin-common-interface.h @@ -22,35 +22,35 @@ * THE SOFTWARE. */ -#ifndef __PLUGIN_COMMON_INTERFACE__ -#define __PLUGIN_COMMON_INTERFACE__ +#ifndef __SYSCOMMON_PLUGIN_COMMON_INTERFACE__ +#define __SYSCOMMON_PLUGIN_COMMON_INTERFACE__ #ifdef __cplusplus extern "C" { #endif -enum plugin_abi_version { - PLUGIN_ABI_VERSION_UNKNOWN = 0, - PLUGIN_ABI_VERSION_TIZEN_7_0, - PLUGIN_ABI_VERSION_TIZEN_7_5, - PLUGIN_ABI_VERSION_END, +enum syscommon_plugin_abi_version { + SYSCOMMON_PLUGIN_ABI_VERSION_UNKNOWN = 0, + SYSCOMMON_PLUGIN_ABI_VERSION_TIZEN_7_0, + SYSCOMMON_PLUGIN_ABI_VERSION_TIZEN_7_5, + SYSCOMMON_PLUGIN_ABI_VERSION_END, }; -static const char *const plugin_abi_version_str[] = { - [PLUGIN_ABI_VERSION_UNKNOWN] = "Unknown PLUGIN ABI Version", - [PLUGIN_ABI_VERSION_TIZEN_7_0] = "PLUGIN_ABI_VERSION_TIZEN_7_0", - [PLUGIN_ABI_VERSION_TIZEN_7_5] = "PLUGIN_ABI_VERSION_TIZEN_7_5", +static const char *const syscommon_plugin_abi_version_str[] = { + [SYSCOMMON_PLUGIN_ABI_VERSION_UNKNOWN] = "Unknown PLUGIN ABI Version", + [SYSCOMMON_PLUGIN_ABI_VERSION_TIZEN_7_0] = "PLUGIN_ABI_VERSION_TIZEN_7_0", + [SYSCOMMON_PLUGIN_ABI_VERSION_TIZEN_7_5] = "PLUGIN_ABI_VERSION_TIZEN_7_5", }; -typedef struct __plugin_backend { +typedef struct __syscommon_plugin_backend { const char *name; const char *vendor; const unsigned int abi_version; int (*init) (void **data); int (*exit) (void *data); -} plugin_backend; +} syscommon_plugin_backend; #ifdef __cplusplus } #endif -#endif /* __PLUGIN_COMMON_INTERFACE__ */ +#endif /* __SYSCOMMON_PLUGIN_COMMON_INTERFACE__ */ diff --git a/src/plugin-api/common/include/plugin-common.h b/src/plugin-api/common/include/syscommon-plugin-common.h similarity index 76% rename from src/plugin-api/common/include/plugin-common.h rename to src/plugin-api/common/include/syscommon-plugin-common.h index d7856bc..d530c0a 100644 --- a/src/plugin-api/common/include/plugin-common.h +++ b/src/plugin-api/common/include/syscommon-plugin-common.h @@ -22,19 +22,19 @@ * THE SOFTWARE. */ -#ifndef __PLUGIN_COMMON__ -#define __PLUGIN_COMMON__ +#ifndef __SYSCOMMON_PLUGIN_COMMON__ +#define __SYSCOMMON_PLUGIN_COMMON__ -#include "plugin-common-interface.h" +#include "syscommon-plugin-common-interface.h" #ifdef __cplusplus extern "C" { #endif -enum plugin_module { - PLUGIN_MODULE_UNKNOWN = 0, - PLUGIN_MODULE_RESOURCED_MEMORY_LMK, - PLUGIN_MODULE_END, +enum syscommon_plugin_module { + SYSCOMMON_PLUGIN_MODULE_UNKNOWN = 0, + SYSCOMMON_PLUGIN_MODULE_RESOURCED_MEMORY_LMK, + SYSCOMMON_PLUGIN_MODULE_END, }; /** @@ -44,7 +44,9 @@ enum plugin_module { * @param[in] Arrary size of name[] * @return @c 0 on success, otherwise a negative error value */ -int plugin_common_get_backend_library_name(enum plugin_module module, char *name, int size); +int syscommon_plugin_common_get_backend_library_name( + enum syscommon_plugin_module module, + char *name, int size); /** * @brief Get the backend symbol name according to the type of PLUGIN module @@ -53,7 +55,8 @@ int plugin_common_get_backend_library_name(enum plugin_module module, char *name * @param[in] Arrary size of name[] * @return @c 0 on success, otherwise a negative error value */ -int plugin_common_get_backend_symbol_name(enum plugin_module module, char *name, int size); +int syscommon_plugin_common_get_backend_symbol_name( + enum syscommon_plugin_module module, char *name, int size); /** * @brief Get the backend data according to the type of PLUGIN module @@ -62,7 +65,8 @@ int plugin_common_get_backend_symbol_name(enum plugin_module module, char *name, * should be stored from PLUGIN backend binary. * @return @c 0 on success, otherwise a negative error value */ -int plugin_common_get_backend(enum plugin_module module, void **data); +int syscommon_plugin_common_get_backend(enum syscommon_plugin_module module, + void **data); /** * @brief Put the backend data according to the type of PLUGIN module @@ -70,7 +74,8 @@ int plugin_common_get_backend(enum plugin_module module, void **data); * @param[in] Data pointer where 'plugin_backend_[module]_funcs' instance * @return @c 0 on success, otherwise a negative error value */ -int plugin_common_put_backend(enum plugin_module module, void *data); +int syscommon_plugin_common_put_backend(enum syscommon_plugin_module module, + void *data); /** * @brief Get the backend data with the specific library name according to the type of PLUGIN module @@ -80,7 +85,8 @@ int plugin_common_put_backend(enum plugin_module module, void *data); * @param[in] PLUGIN backend library name which is not default library name * @return @c 0 on success, otherwise a negative error value */ -int plugin_common_get_backend_with_library_name(enum plugin_module module, +int syscommon_plugin_common_get_backend_with_library_name( + enum syscommon_plugin_module module, void **data, const char *library_name); /** @@ -90,7 +96,8 @@ int plugin_common_get_backend_with_library_name(enum plugin_module module, * @param[in] PLUGIN backend library name which is not default library name * @return @c 0 on success, otherwise a negative error value */ -int plugin_common_put_backend_with_library_name(enum plugin_module module, +int syscommon_plugin_common_put_backend_with_library_name( + enum syscommon_plugin_module module, void *data, const char *library_name); /** @@ -99,15 +106,17 @@ int plugin_common_put_backend_with_library_name(enum plugin_module module, * @param[in] PLUGIN ABI version of backend module among enum plugin_abi_version * @return @c 0 on success, otherwise a negative error value */ -int plugin_common_check_backend_abi_version(enum plugin_module module, - enum plugin_abi_version abi_version); +int syscommon_plugin_common_check_backend_abi_version( + enum syscommon_plugin_module module, + enum syscommon_plugin_abi_version abi_version); /** * @brief Get the backend PLUGIN ABI version according to the type of PLUGIN module * @param[in] PLUGIN module id among enum plugin_moudle * @return @c positive integer value on success, otherwise a zero error value */ -unsigned int plugin_common_get_backend_abi_version(enum plugin_module module); +unsigned int syscommon_plugin_common_get_backend_abi_version( + enum syscommon_plugin_module module); /** * @brief Get the backend name according to the type of PLUGIN module @@ -116,7 +125,9 @@ unsigned int plugin_common_get_backend_abi_version(enum plugin_module module); * @param[in] Arrary size of name[] * @return @c positive integer value on success, otherwise a zero error value */ -int plugin_common_get_backend_name(enum plugin_module module, char *name, int size); +int syscommon_plugin_common_get_backend_name( + enum syscommon_plugin_module module, + char *name, int size); /** * @brief Get the backend vendor description according to the type of PLUGIN module @@ -125,14 +136,17 @@ int plugin_common_get_backend_name(enum plugin_module module, char *name, int si * @param[in] Arrary size of vendor[] * @return @c positive integer value on success, otherwise a zero error value */ -int plugin_common_get_backend_vendor(enum plugin_module module, char *vendor, int size); +int syscommon_plugin_common_get_backend_vendor( + enum syscommon_plugin_module module, + char *vendor, int size); /** * @brief Get the number of the backend libraries according to the type of PLUGIN module * @param[in] PLUGIN module id among enum plugin_moudle * @return @c 0 on success, otherwise a negative error value */ -int plugin_common_get_backend_count(enum plugin_module module); +int syscommon_plugin_common_get_backend_count( + enum syscommon_plugin_module module); /** * @brief Get the backend library names according to the type of PLUGIN module @@ -142,7 +156,8 @@ int plugin_common_get_backend_count(enum plugin_module module); * @param[in] Maximum length of the library name * @return @c 0 on success, otherwise a negative error value */ -int plugin_common_get_backend_library_names(enum plugin_module module, +int syscommon_plugin_common_get_backend_library_names( + enum syscommon_plugin_module module, char **library_names, int library_count, int library_name_size); @@ -150,4 +165,4 @@ int plugin_common_get_backend_library_names(enum plugin_module module, #ifdef __cplusplus } #endif -#endif /* __PLUGIN_COMMON__ */ +#endif /* __SYSCOMMON_PLUGIN_COMMON__ */ diff --git a/src/plugin-api/common/plugin-api-common.pc.in b/src/plugin-api/common/libsyscommon-plugin-api-common.pc.in similarity index 64% rename from src/plugin-api/common/plugin-api-common.pc.in rename to src/plugin-api/common/libsyscommon-plugin-api-common.pc.in index 4738a7f..4271f1b 100644 --- a/src/plugin-api/common/plugin-api-common.pc.in +++ b/src/plugin-api/common/libsyscommon-plugin-api-common.pc.in @@ -9,8 +9,8 @@ exec_prefix=@EXEC_PREFIX@ libdir=@LIBDIR@ includedir=@INCLUDEDIR@ -Name: plugin-api-common -Description: Common plugin APIs +Name: libsyscommon-plugin-api-common +Description: Common system plugin APIs Version: @VERSION@ Cflags: -I${includedir} @PLUGIN_COMMON_INCLUDEDIR@ -Libs: -L${libdir} -lplugin-api-common @PLUGIN_COMMON_LIBS@ +Libs: -L${libdir} -lsyscommon-plugin-api-common @PLUGIN_COMMON_LIBS@ diff --git a/src/plugin-api/common/src/common.h b/src/plugin-api/common/src/common.h index 33e4560..a89fe09 100644 --- a/src/plugin-api/common/src/common.h +++ b/src/plugin-api/common/src/common.h @@ -27,7 +27,7 @@ #include -#include "plugin-common.h" +#include "syscommon-plugin-common.h" #ifdef __cplusplus extern "C" { @@ -71,7 +71,7 @@ static const char *const plugin_group_string[] = { }; /** - * plugin-api-common provides the PLUGIN ABI * (Application Binary Interface) + * syscommon-plugin-api-common provides the PLUGIN ABI * (Application Binary Interface) * version check feature which is used to check the ABI compatibility between * PLUGIN API package and PLUGIN backend package. * In order to compare ABI version between two binary, Tizen core platform @@ -86,15 +86,15 @@ static const char *const plugin_group_string[] = { * released officially. */ struct plugin_abi_version_match { - enum plugin_abi_version platform_abi_version; - enum plugin_abi_version backend_min_abi_version; + enum syscommon_plugin_abi_version platform_abi_version; + enum syscommon_plugin_abi_version backend_min_abi_version; }; struct __plugin_module_info { int usage_count; enum plugin_group group; - enum plugin_module module; + enum syscommon_plugin_module module; enum plugin_license license; char *module_name; char *backend_module_name; @@ -102,7 +102,7 @@ struct __plugin_module_info { char *library_name; char *library_name_64bit; void *handle; - plugin_backend *backend; + syscommon_plugin_backend *backend; char *symbol_name; unsigned int num_abi_versions; diff --git a/src/plugin-api/common/src/plugin-api-common.c b/src/plugin-api/common/src/syscommon-plugin-api-common.c similarity index 81% rename from src/plugin-api/common/src/plugin-api-common.c rename to src/plugin-api/common/src/syscommon-plugin-api-common.c index 0f5dcc6..b6fb3db 100644 --- a/src/plugin-api/common/src/plugin-api-common.c +++ b/src/plugin-api/common/src/syscommon-plugin-api-common.c @@ -36,7 +36,7 @@ #include #include "common.h" -#include "plugin-api-conf.h" +#include "syscommon-plugin-api-conf.h" extern char *program_invocation_name; @@ -44,11 +44,11 @@ extern char *program_invocation_name; #define EXPORT __attribute__ ((visibility("default"))) #endif -static enum plugin_abi_version g_platform_curr_abi_version; +static enum syscommon_plugin_abi_version g_platform_curr_abi_version; G_LOCK_DEFINE_STATIC(plugin_common_lock); EXPORT -int plugin_common_get_backend_library_name(enum plugin_module module, char *name, int size) +int syscommon_plugin_common_get_backend_library_name(enum syscommon_plugin_module module, char *name, int size) { const char *library_name = NULL; struct __plugin_module_info *info = NULL; @@ -56,7 +56,7 @@ int plugin_common_get_backend_library_name(enum plugin_module module, char *name int len_library_name; /* Check parameter whether is valid or not */ - if (module <= PLUGIN_MODULE_UNKNOWN || module >= PLUGIN_MODULE_END) { + if (module <= SYSCOMMON_PLUGIN_MODULE_UNKNOWN || module >= SYSCOMMON_PLUGIN_MODULE_END) { _E("Invalid parameter of PLUGIN module (%d)\n", module); return -EINVAL; } @@ -94,7 +94,7 @@ out: } EXPORT -int plugin_common_get_backend_symbol_name(enum plugin_module module, char *name, int size) +int syscommon_plugin_common_get_backend_symbol_name(enum syscommon_plugin_module module, char *name, int size) { struct __plugin_module_info *info = NULL; char *symbol_name = NULL; @@ -102,7 +102,7 @@ int plugin_common_get_backend_symbol_name(enum plugin_module module, char *name, int len_symbol_name; /* Check parameter whether is valid or not */ - if (module <= PLUGIN_MODULE_UNKNOWN || module >= PLUGIN_MODULE_END) { + if (module <= SYSCOMMON_PLUGIN_MODULE_UNKNOWN || module >= SYSCOMMON_PLUGIN_MODULE_END) { _E("Invalid paramer of PLUGIN module (%d)\n", module); return -EINVAL; } @@ -233,7 +233,7 @@ static int __init_backend(struct __plugin_module_info *info, void **data, } /* Check PLUGIN ABI Version */ - ret = plugin_common_check_backend_abi_version(info->module, + ret = syscommon_plugin_common_check_backend_abi_version(info->module, info->backend->abi_version); if (ret < 0) { _E("%s: Failed to check ABI version\n", info->module_name); @@ -276,13 +276,13 @@ static int __exit_backend(struct __plugin_module_info *info, void *data, return 0; } -static int __get_backend(enum plugin_module module, void **data, +static int __get_backend(enum syscommon_plugin_module module, void **data, const char *library_name) { struct __plugin_module_info *info = NULL; int ret; - if (module <= PLUGIN_MODULE_UNKNOWN || module >= PLUGIN_MODULE_END) { + if (module <= SYSCOMMON_PLUGIN_MODULE_UNKNOWN || module >= SYSCOMMON_PLUGIN_MODULE_END) { _E("Invalid parameter of PLUGIN module (%d)\n", module); return -EINVAL; } @@ -334,14 +334,14 @@ err: return ret; } -static int __put_backend(enum plugin_module module, void *data, +static int __put_backend(enum syscommon_plugin_module module, void *data, const char *library_name) { struct __plugin_module_info *info = NULL; int ret; /* Check parameter whether is valid or not */ - if (module <= PLUGIN_MODULE_UNKNOWN || module >= PLUGIN_MODULE_END) { + if (module <= SYSCOMMON_PLUGIN_MODULE_UNKNOWN || module >= SYSCOMMON_PLUGIN_MODULE_END) { _E("Invalid parameter of PLUGIN module (%d)\n", module); return -EINVAL; } @@ -397,13 +397,13 @@ out: return ret; } -static int __get_backend_data(enum plugin_module module, unsigned int *abi_version, +static int __get_backend_data(enum syscommon_plugin_module module, unsigned int *abi_version, char *name, int name_size, char *vendor, int vendor_size) { struct __plugin_module_info *info = NULL; int ret, len; - if (module <= PLUGIN_MODULE_UNKNOWN || module >= PLUGIN_MODULE_END) { + if (module <= SYSCOMMON_PLUGIN_MODULE_UNKNOWN || module >= SYSCOMMON_PLUGIN_MODULE_END) { _E("Invalid parameter of PLUGIN module (%d)\n", module); return 0; } @@ -411,14 +411,14 @@ static int __get_backend_data(enum plugin_module module, unsigned int *abi_versi G_LOCK(plugin_common_lock); if (_plugin_api_conf_init()) { - ret = PLUGIN_ABI_VERSION_UNKNOWN; + ret = SYSCOMMON_PLUGIN_ABI_VERSION_UNKNOWN; goto err_unlock; } info = _plugin_api_conf_get_module_info(module, NULL); if (info == NULL) { _E("Failed to get PLUGIN module(%d) information\n", module); - ret = PLUGIN_ABI_VERSION_UNKNOWN; + ret = SYSCOMMON_PLUGIN_ABI_VERSION_UNKNOWN; goto err_conf_exit; } @@ -468,47 +468,47 @@ err_unlock: } EXPORT -int plugin_common_get_backend(enum plugin_module module, void **data) +int syscommon_plugin_common_get_backend(enum syscommon_plugin_module module, void **data) { return __get_backend(module, data, NULL); } EXPORT -int plugin_common_put_backend(enum plugin_module module, void *data) +int syscommon_plugin_common_put_backend(enum syscommon_plugin_module module, void *data) { return __put_backend(module, data, NULL); } EXPORT -int plugin_common_get_backend_with_library_name(enum plugin_module module, +int syscommon_plugin_common_get_backend_with_library_name(enum syscommon_plugin_module module, void **data, const char *library_name) { return __get_backend(module, data, library_name); } EXPORT -int plugin_common_put_backend_with_library_name(enum plugin_module module, +int syscommon_plugin_common_put_backend_with_library_name(enum syscommon_plugin_module module, void *data, const char *library_name) { return __put_backend(module, data, library_name); } EXPORT -int plugin_common_check_backend_abi_version(enum plugin_module module, - enum plugin_abi_version abi_version) +int syscommon_plugin_common_check_backend_abi_version(enum syscommon_plugin_module module, + enum syscommon_plugin_abi_version abi_version) { struct __plugin_module_info *info = NULL; int i; int ret; /* Check parameter whether is valid or not */ - if (module <= PLUGIN_MODULE_UNKNOWN || module >= PLUGIN_MODULE_END) { + if (module <= SYSCOMMON_PLUGIN_MODULE_UNKNOWN || module >= SYSCOMMON_PLUGIN_MODULE_END) { _E("Invalid paramer of PLUGIN module(%d)\n", module); return -EINVAL; } - if (abi_version <= PLUGIN_ABI_VERSION_UNKNOWN - || abi_version >= PLUGIN_ABI_VERSION_END) { + if (abi_version <= SYSCOMMON_PLUGIN_ABI_VERSION_UNKNOWN + || abi_version >= SYSCOMMON_PLUGIN_ABI_VERSION_END) { _E("Invalid paramer of PLUGIN ABI version(%d) for PLUGIN module(%d)\n", abi_version, module); return -EINVAL; @@ -534,8 +534,8 @@ int plugin_common_check_backend_abi_version(enum plugin_module module, g_platform_curr_abi_version = _plugin_api_conf_get_platform_abi_version(); - if (g_platform_curr_abi_version <= PLUGIN_ABI_VERSION_UNKNOWN - || g_platform_curr_abi_version >= PLUGIN_ABI_VERSION_END) { + if (g_platform_curr_abi_version <= SYSCOMMON_PLUGIN_ABI_VERSION_UNKNOWN + || g_platform_curr_abi_version >= SYSCOMMON_PLUGIN_ABI_VERSION_END) { _E("Invalid paramer of current PLUGIN ABI version(%d)(%d)\n", g_platform_curr_abi_version, module); ret = -EINVAL; @@ -549,8 +549,8 @@ int plugin_common_check_backend_abi_version(enum plugin_module module, if (g_platform_curr_abi_version != data->platform_abi_version) continue; - if (data->backend_min_abi_version <= PLUGIN_ABI_VERSION_UNKNOWN || - data->backend_min_abi_version >= PLUGIN_ABI_VERSION_END) { + if (data->backend_min_abi_version <= SYSCOMMON_PLUGIN_ABI_VERSION_UNKNOWN || + data->backend_min_abi_version >= SYSCOMMON_PLUGIN_ABI_VERSION_END) { _E("%s: abi_versions[%d].backend_min_abi_version(%d) is invalid\n", info->module_name, i, data->backend_min_abi_version); ret = -EINVAL; @@ -565,12 +565,12 @@ int plugin_common_check_backend_abi_version(enum plugin_module module, _E("%s: \'%s\' doesn't support \'%s\'\n", info->module_name, - plugin_abi_version_str[g_platform_curr_abi_version], - plugin_abi_version_str[abi_version]); + syscommon_plugin_abi_version_str[g_platform_curr_abi_version], + syscommon_plugin_abi_version_str[abi_version]); _E("%s: Must use ABI versions from \'%s\' to \'%s\'\n", info->module_name, - plugin_abi_version_str[data->backend_min_abi_version], - plugin_abi_version_str[data->platform_abi_version]); + syscommon_plugin_abi_version_str[data->backend_min_abi_version], + syscommon_plugin_abi_version_str[data->platform_abi_version]); } ret = -EINVAL; @@ -580,32 +580,32 @@ out: } EXPORT -unsigned int plugin_common_get_backend_abi_version(enum plugin_module module) +unsigned int syscommon_plugin_common_get_backend_abi_version(enum syscommon_plugin_module module) { unsigned int abi_version; int ret; ret = __get_backend_data(module, &abi_version, NULL, 0, NULL, 0); if (ret < 0) - return PLUGIN_ABI_VERSION_UNKNOWN; + return SYSCOMMON_PLUGIN_ABI_VERSION_UNKNOWN; return abi_version; } EXPORT -int plugin_common_get_backend_name(enum plugin_module module, char *name, int size) +int syscommon_plugin_common_get_backend_name(enum syscommon_plugin_module module, char *name, int size) { return __get_backend_data(module, NULL, name, size, NULL, 0); } EXPORT -int plugin_common_get_backend_vendor(enum plugin_module module, char *vendor, int size) +int syscommon_plugin_common_get_backend_vendor(enum syscommon_plugin_module module, char *vendor, int size) { return __get_backend_data(module, NULL, NULL, 0, vendor, size); } -static int __get_backend_library_data(enum plugin_module module, +static int __get_backend_library_data(enum syscommon_plugin_module module, char **lib_names, int lib_count, int lib_name_size) @@ -616,16 +616,16 @@ static int __get_backend_library_data(enum plugin_module module, char *backend_module_name = NULL; int count, i, ret; #if defined(__aarch64__) || defined(__x86_64__) - const char plugin_backend_path[] = "/usr/lib64/plugin"; + const char plugin_backend_path[] = "/usr/lib64/system/plugin"; #else - const char plugin_backend_path[] = "/usr/lib/plugin"; + const char plugin_backend_path[] = "/usr/lib/system/plugin"; #endif /* Check if lib_names and lib_count are valid */ assert(!(lib_names == NULL && lib_count != 0)); /* Check parameter whether is valid or not */ - if (module <= PLUGIN_MODULE_UNKNOWN || module >= PLUGIN_MODULE_END) { + if (module <= SYSCOMMON_PLUGIN_MODULE_UNKNOWN || module >= SYSCOMMON_PLUGIN_MODULE_END) { _E("Invalid parameter of PLUGIN module (%d)\n", module); return -EINVAL; } @@ -646,7 +646,7 @@ static int __get_backend_library_data(enum plugin_module module, ret = -EINVAL; goto err; } - backend_module_name = g_strdup_printf("libplugin-backend-%s", + backend_module_name = g_strdup_printf("libplugin-%s", info->backend_module_name); if (!backend_module_name) { _E("Failed to allocate the backend_module_name of PLUGIN module(%s)\n", @@ -707,13 +707,14 @@ err: } EXPORT -int plugin_common_get_backend_count(enum plugin_module module) +int syscommon_plugin_common_get_backend_count(enum syscommon_plugin_module module) { return __get_backend_library_data(module, NULL, 0, 0); } EXPORT -int plugin_common_get_backend_library_names(enum plugin_module module, +int syscommon_plugin_common_get_backend_library_names( + enum syscommon_plugin_module module, char **library_names, int library_count, int library_name_size) diff --git a/src/plugin-api/common/src/plugin-api-conf.c b/src/plugin-api/common/src/syscommon-plugin-api-conf.c similarity index 86% rename from src/plugin-api/common/src/plugin-api-conf.c rename to src/plugin-api/common/src/syscommon-plugin-api-conf.c index bb560a2..19daa1a 100644 --- a/src/plugin-api/common/src/plugin-api-conf.c +++ b/src/plugin-api/common/src/syscommon-plugin-api-conf.c @@ -27,12 +27,12 @@ #include #include -#include "plugin-common.h" -#include "plugin-common-interface.h" +#include "syscommon-plugin-common.h" +#include "syscommon-plugin-common-interface.h" #include "common.h" -#include "plugin-api-conf.h" -#include "plugin-api-list.h" +#include "syscommon-plugin-api-conf.h" +#include "syscommon-plugin-api-list.h" #ifndef EXPORT #define EXPORT __attribute__ ((visibility("default"))) @@ -57,13 +57,14 @@ void _destroy_module_info(gpointer data) } } -static struct __plugin_module_info* _get_module_info(enum plugin_module module) +static struct __plugin_module_info* _get_module_info(enum syscommon_plugin_module module) { return &g_plugin_module_info[module]; } -static struct __plugin_module_info* _get_module_info_with_library_name(enum plugin_module module, - const char *library_name) +static struct __plugin_module_info* _get_module_info_with_library_name( + enum syscommon_plugin_module module, + const char *library_name) { struct __plugin_module_info *info = NULL, *new_info = NULL, *tmp_info = NULL; char *library_name_prefix = NULL; @@ -82,7 +83,7 @@ static struct __plugin_module_info* _get_module_info_with_library_name(enum plug tmp_info->module_name); return NULL; } - library_name_prefix = g_strdup_printf("libplugin-backend-%s", + library_name_prefix = g_strdup_printf("libplugin-%s", tmp_info->backend_module_name); if (!library_name_prefix) { _E("Failed to allocate library_name_prefix of PLUGIN module(%s)\n", @@ -120,9 +121,9 @@ static struct __plugin_module_info* _get_module_info_with_library_name(enum plug new_info->license = info->license; new_info->module_name = g_strdup(info->module_name); #if defined(__aarch64__) || defined(__x86_64__) - new_info->library_name_64bit = g_strdup_printf("/usr/lib64/plugin/%s", library_name); + new_info->library_name_64bit = g_strdup_printf("/usr/lib64/system/plugin/%s", library_name); #else - new_info->library_name = g_strdup_printf("/usr/lib/plugin/%s", library_name); + new_info->library_name = g_strdup_printf("/usr/lib/system/plugin/%s", library_name); #endif new_info->symbol_name = g_strdup(info->symbol_name); new_info->num_abi_versions = info->num_abi_versions; @@ -137,7 +138,7 @@ out: } EXPORT -struct __plugin_module_info* _plugin_api_conf_get_module_info(enum plugin_module module, +struct __plugin_module_info* _plugin_api_conf_get_module_info(enum syscommon_plugin_module module, const char *library_name) { if (!_module_hash) @@ -150,7 +151,7 @@ struct __plugin_module_info* _plugin_api_conf_get_module_info(enum plugin_module } -enum plugin_abi_version _plugin_api_conf_get_platform_abi_version(void) +enum syscommon_plugin_abi_version _plugin_api_conf_get_platform_abi_version(void) { return g_platform_curr_abi_version; } diff --git a/src/plugin-api/common/src/plugin-api-conf.h b/src/plugin-api/common/src/syscommon-plugin-api-conf.h similarity index 78% rename from src/plugin-api/common/src/plugin-api-conf.h rename to src/plugin-api/common/src/syscommon-plugin-api-conf.h index 2d59713..20e8b32 100644 --- a/src/plugin-api/common/src/plugin-api-conf.h +++ b/src/plugin-api/common/src/syscommon-plugin-api-conf.h @@ -22,13 +22,13 @@ * THE SOFTWARE. */ -#ifndef __PLUGIN_API_CONF__ -#define __PLUGIN_API_CONF__ +#ifndef __SYSCOMMON_PLUGIN_API_CONF__ +#define __SYSCOMMON_PLUGIN_API_CONF__ #include #include -#include "plugin-common-interface.h" +#include "syscommon-plugin-common-interface.h" #ifdef __cplusplus extern "C" { @@ -37,12 +37,13 @@ extern "C" { int _plugin_api_conf_init(void); void _plugin_api_conf_exit(void); -struct __plugin_module_info *_plugin_api_conf_get_module_info(enum plugin_module module, - const char *library_name); +struct __plugin_module_info *_plugin_api_conf_get_module_info( + enum syscommon_plugin_module module, + const char *library_name); -enum plugin_abi_version _plugin_api_conf_get_platform_abi_version(void); +enum syscommon_plugin_abi_version _plugin_api_conf_get_platform_abi_version(void); #ifdef __cplusplus } #endif /* __cplusplus */ -#endif /* __PLUGIN_API_CONF__ */ +#endif /* __SYSCOMMON_PLUGIN_API_CONF__ */ diff --git a/src/plugin-api/common/src/plugin-api-list.h b/src/plugin-api/common/src/syscommon-plugin-api-list.h similarity index 56% rename from src/plugin-api/common/src/plugin-api-list.h rename to src/plugin-api/common/src/syscommon-plugin-api-list.h index 79439fb..e7b0ee6 100644 --- a/src/plugin-api/common/src/plugin-api-list.h +++ b/src/plugin-api/common/src/syscommon-plugin-api-list.h @@ -22,38 +22,39 @@ * THE SOFTWARE. */ -#ifndef __PLUGIN_API_LIST_H__ -#define __PLUGIN_API_LIST_H__ +#ifndef __SYSCOMMON_PLUGIN_API_LIST_H__ +#define __SYSCOMMON_PLUGIN_API_LIST_H__ -#include "plugin-common.h" +#include "syscommon-plugin-common.h" #include "common.h" #define PLUGIN_ABI_VERSION_MAX 10 -enum plugin_abi_version g_platform_curr_abi_version = PLUGIN_ABI_VERSION_TIZEN_7_5; +enum syscommon_plugin_abi_version g_platform_curr_abi_version = + SYSCOMMON_PLUGIN_ABI_VERSION_TIZEN_7_5; -static struct plugin_abi_version_match abi_version_match_data[PLUGIN_MODULE_END][PLUGIN_ABI_VERSION_MAX] = { - [PLUGIN_MODULE_RESOURCED_MEMORY_LMK] = { +static struct plugin_abi_version_match abi_version_match_data[SYSCOMMON_PLUGIN_MODULE_END][PLUGIN_ABI_VERSION_MAX] = { + [SYSCOMMON_PLUGIN_MODULE_RESOURCED_MEMORY_LMK] = { [0] = { - .platform_abi_version = PLUGIN_ABI_VERSION_TIZEN_7_5, - .backend_min_abi_version = PLUGIN_ABI_VERSION_TIZEN_7_5, + .platform_abi_version = SYSCOMMON_PLUGIN_ABI_VERSION_TIZEN_7_5, + .backend_min_abi_version = SYSCOMMON_PLUGIN_ABI_VERSION_TIZEN_7_5, }, }, }; static struct __plugin_module_info g_plugin_module_info[] = { - [PLUGIN_MODULE_RESOURCED_MEMORY_LMK] = { + [SYSCOMMON_PLUGIN_MODULE_RESOURCED_MEMORY_LMK] = { .group = PLUGIN_GROUP_RESOURCED, - .module = PLUGIN_MODULE_RESOURCED_MEMORY_LMK, + .module = SYSCOMMON_PLUGIN_MODULE_RESOURCED_MEMORY_LMK, .license = PLUGIN_LICENSE_APACHE_2_0, - .module_name = "PLUGIN_MODULE_RESOURCED_MEMORY_LMK", + .module_name = "SYSCOMMON_PLUGIN_MODULE_RESOURCED_MEMORY_LMK", .backend_module_name = "resourced-memory-lmk", - .library_name = "/usr/lib/plugin/libplugin-backend-resourced-memory-lmk.so", - .library_name_64bit = "/usr/lib64/plugin/libplugin-backend-resourced-memory-lmk.so", - .symbol_name = "plugin_backend_resourced_memory_lmk_data", - .num_abi_versions = ARRAY_SIZE(abi_version_match_data[PLUGIN_MODULE_RESOURCED_MEMORY_LMK]), - .abi_versions = abi_version_match_data[PLUGIN_MODULE_RESOURCED_MEMORY_LMK], + .library_name = "/usr/lib/system/plugin/libplugin-resourced-memory-lmk.so", + .library_name_64bit = "/usr/lib64/system/plugin/libplugin-resourced-memory-lmk.so", + .symbol_name = "system_plugin_backend_resourced_memory_lmk_data", + .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], }, }; diff --git a/src/plugin-api/deviced/CMakeLists.txt b/src/plugin-api/deviced/CMakeLists.txt index 89ed42d..78af80a 100644 --- a/src/plugin-api/deviced/CMakeLists.txt +++ b/src/plugin-api/deviced/CMakeLists.txt @@ -1,15 +1,15 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT(plugin-api-deviced) +PROJECT(syscommon-plugin-api-deviced) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(EXEC_PREFIX "${PREFIX}/bin") SET(LIBDIR ${LIB_INSTALL_DIR}) -SET(INCLUDEDIR "${PREFIX}/include/plugin") +SET(INCLUDEDIR "${PREFIX}/include/system") SET(VERSION ${PLUGIN_API_DEVICED_VERSION}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) -# Including below should be removed if the repository of plugin-api-common is -# separated. +# Including below should be removed if the repository of +# syscommon-plugin-api-common is separated. INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../common/include) if (${PLUGIN_API_DEVICED_ENABLE_DLOG}) @@ -17,7 +17,7 @@ if (${PLUGIN_API_DEVICED_ENABLE_DLOG}) glib-2.0 dlog) ADD_DEFINITIONS("-DENABLE_DLOG") - ADD_DEFINITIONS("-DLOG_TAG=\"PLUGIN_API_DEVICED\"") + ADD_DEFINITIONS("-DLOG_TAG=\"SYSTEM_PLUGIN_API_DEVICED\"") else() SET(PKG_MODULES glib-2.0) @@ -35,12 +35,13 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall -lrt") SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl") SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") -# plugin-api-common.c and plugin-api-conf.c are unnecessary if the repository of -# plugin-api-common is separated. -# Please remove them from SRCS and add 'plugin-api-common' to PKG_MODULES. -SET(SRCS src/plugin-deviced-display.c - ../common/src/plugin-api-common.c - ../common/src/plugin-api-conf.c) +# syscommon-plugin-api-common.c and syscommon-plugin-api-conf.c are unnecessary +# if the repository of syscommon-plugin-api-common is separated. +# Please remove them from SRCS and add 'syscommon-plugin-api-common' +# to PKG_MODULES. +SET(SRCS src/syscommon-plugin-deviced-display.c + ../common/src/syscommon-plugin-api-common.c + ../common/src/syscommon-plugin-api-conf.c) ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} @@ -62,5 +63,6 @@ ENDFOREACH(include_dirs) FOREACH(libraries ${pkgs_LIBRARIES}) SET(PLUGIN_DEVICED_LIBS "${PLUGIN_DEVICED_LIBS} -l${libraries}") ENDFOREACH(libraries) -CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) -INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) +SET(PACKAGE_CONFIG_FILE "lib${PROJECT_NAME}.pc") +CONFIGURE_FILE(${PACKAGE_CONFIG_FILE}.in ${PACKAGE_CONFIG_FILE} @ONLY) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_CONFIG_FILE} DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) diff --git a/src/plugin-api/deviced/include/plugin-deviced-display-interface.h b/src/plugin-api/deviced/include/syscommon-plugin-deviced-display-interface.h similarity index 87% rename from src/plugin-api/deviced/include/plugin-deviced-display-interface.h rename to src/plugin-api/deviced/include/syscommon-plugin-deviced-display-interface.h index 2a0c909..6b094a3 100644 --- a/src/plugin-api/deviced/include/plugin-deviced-display-interface.h +++ b/src/plugin-api/deviced/include/syscommon-plugin-deviced-display-interface.h @@ -22,8 +22,8 @@ * THE SOFTWARE. */ -#ifndef __PLUGIN_DEVICED_DISPLAY_INTERFACE_H__ -#define __PLUGIN_DEVICED_DISPLAY_INTERFACE_H__ +#ifndef __SYSCOMMON_PLUGIN_DEVICED_DISPLAY_INTERFACE_H__ +#define __SYSCOMMON_PLUGIN_DEVICED_DISPLAY_INTERFACE_H__ #ifdef __cplusplus extern "C" { @@ -33,4 +33,4 @@ extern "C" { } #endif -#endif //__PLUGIN_DEVICED_DISPLAY_INTERFACE_H__ +#endif //__SYSCOMMON_PLUGIN_DEVICED_DISPLAY_INTERFACE_H__ diff --git a/src/plugin-api/deviced/include/plugin-deviced-display.h b/src/plugin-api/deviced/include/syscommon-plugin-deviced-display.h similarity index 89% rename from src/plugin-api/deviced/include/plugin-deviced-display.h rename to src/plugin-api/deviced/include/syscommon-plugin-deviced-display.h index 14e5c6c..c0267c3 100644 --- a/src/plugin-api/deviced/include/plugin-deviced-display.h +++ b/src/plugin-api/deviced/include/syscommon-plugin-deviced-display.h @@ -22,8 +22,8 @@ * THE SOFTWARE. */ -#ifndef __PLUGIN_DEVICED_DISPLAY_H__ -#define __PLUGIN_DEVICED_DISPLAY_H__ +#ifndef __SYSCOMMON_PLUGIN_DEVICED_DISPLAY_H__ +#define __SYSCOMMON_PLUGIN_DEVICED_DISPLAY_H__ #ifdef __cplusplus extern "C" { @@ -33,4 +33,4 @@ extern "C" { } #endif -#endif //__PLUGIN_DEVICED_DISPLAY_H__ +#endif //__SYSCOMMON_PLUGIN_DEVICED_DISPLAY_H__ diff --git a/src/plugin-api/deviced/plugin-api-deviced.pc.in b/src/plugin-api/deviced/libsyscommon-plugin-api-deviced.pc.in similarity index 56% rename from src/plugin-api/deviced/plugin-api-deviced.pc.in rename to src/plugin-api/deviced/libsyscommon-plugin-api-deviced.pc.in index a328de4..100d572 100644 --- a/src/plugin-api/deviced/plugin-api-deviced.pc.in +++ b/src/plugin-api/deviced/libsyscommon-plugin-api-deviced.pc.in @@ -9,9 +9,9 @@ exec_prefix=@EXEC_PREFIX@ libdir=@LIBDIR@ includedir=@INCLUDEDIR@ -Name: plugin-api-deviced -Description: Plugin APIs for the deviced +Name: libsyscommon-plugin-api-deviced +Description: System plugin APIs for the deviced Version: @VERSION@ -Requires.private: plugin-api-common +Requires.private: libsyscommon-plugin-api-common Cflags: -I${includedir} @PLUGIN_DEVICED_INCLUDEDIR@ -Libs: -L${libdir} -lplugin-api-deviced @PLUGIN_DEVICED_LIBS@ +Libs: -L${libdir} -lsyscommon-plugin-api-deviced @PLUGIN_DEVICED_LIBS@ diff --git a/src/plugin-api/deviced/src/plugin-deviced-display.c b/src/plugin-api/deviced/src/syscommon-plugin-deviced-display.c similarity index 100% rename from src/plugin-api/deviced/src/plugin-deviced-display.c rename to src/plugin-api/deviced/src/syscommon-plugin-deviced-display.c diff --git a/src/plugin-api/resourced/CMakeLists.txt b/src/plugin-api/resourced/CMakeLists.txt index 114cbcb..9060f8e 100644 --- a/src/plugin-api/resourced/CMakeLists.txt +++ b/src/plugin-api/resourced/CMakeLists.txt @@ -1,16 +1,16 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT(plugin-api-resourced) +PROJECT(syscommon-plugin-api-resourced) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(EXEC_PREFIX "${PREFIX}/bin") SET(LIBDIR ${LIB_INSTALL_DIR}) -SET(INCLUDEDIR "${PREFIX}/include/plugin") +SET(INCLUDEDIR "${PREFIX}/include/system") SET(VERSION ${PLUGIN_API_RESOURCED_VERSION}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) -# Including below should be removed if the repository of plugin-api-common is -# separated. +# Including below should be removed if the repository of +# syscommon-plugin-api-common is separated. INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../common/include) if (${PLUGIN_API_RESOURCED_ENABLE_DLOG}) @@ -18,7 +18,7 @@ if (${PLUGIN_API_RESOURCED_ENABLE_DLOG}) glib-2.0 dlog) ADD_DEFINITIONS("-DENABLE_DLOG") - ADD_DEFINITIONS("-DLOG_TAG=\"PLUGIN_API_RESOURCED\"") + ADD_DEFINITIONS("-DLOG_TAG=\"SYSTEM_PLUGIN_API_RESOURCED\"") else() SET(PKG_MODULES glib-2.0) @@ -36,12 +36,13 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall -lrt") SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl") SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") -# plugin-api-common.c and plugin-api-conf.c are unnecessary if the repository of -# plugin-api-common is separated. -# Please remove them from SRCS and add 'plugin-api-common' to PKG_MODULES. -SET(SRCS src/plugin-resourced-memory-lmk.c - ../common/src/plugin-api-common.c - ../common/src/plugin-api-conf.c) +# syscommon-plugin-api-common.c and syscommon-plugin-api-conf.c are unnecessary +# if the repository of syscommon-plugin-api-common is separated. +# Please remove them from SRCS and add 'syscommon-plugin-api-common' +# to PKG_MODULES. +SET(SRCS src/syscommon-plugin-resourced-memory-lmk.c + ../common/src/syscommon-plugin-api-common.c + ../common/src/syscommon-plugin-api-conf.c) ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${${PROJECT_NAME}_LDFLAGS} @@ -63,5 +64,6 @@ ENDFOREACH(include_dirs) FOREACH(libraries ${${PROJECT_NAME}_LIBRARIES}) SET(PLUGIN_RESOURCED_LIBS "${PLUGIN_RESOURCED_LIBS} -l${libraries}") ENDFOREACH(libraries) -CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) -INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) +SET(PACKAGE_CONFIG_FILE "lib${PROJECT_NAME}.pc") +CONFIGURE_FILE(${PACKAGE_CONFIG_FILE}.in ${PACKAGE_CONFIG_FILE} @ONLY) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_CONFIG_FILE} DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) diff --git a/src/plugin-api/resourced/include/plugin-resourced-memory-lmk-interface.h b/src/plugin-api/resourced/include/syscommon-plugin-resourced-memory-lmk-interface.h similarity index 81% rename from src/plugin-api/resourced/include/plugin-resourced-memory-lmk-interface.h rename to src/plugin-api/resourced/include/syscommon-plugin-resourced-memory-lmk-interface.h index e936fc0..9bfc4ac 100644 --- a/src/plugin-api/resourced/include/plugin-resourced-memory-lmk-interface.h +++ b/src/plugin-api/resourced/include/syscommon-plugin-resourced-memory-lmk-interface.h @@ -22,8 +22,8 @@ * THE SOFTWARE. */ -#ifndef __PLUGIN_RESOURCED_MEMORY_LMK_INTERFACE_H__ -#define __PLUGIN_RESOURCED_MEMORY_LMK_INTERFACE_H__ +#ifndef __SYSCOMMON_PLUGIN_RESOURCED_MEMORY_LMK_INTERFACE_H__ +#define __SYSCOMMON_PLUGIN_RESOURCED_MEMORY_LMK_INTERFACE_H__ #include @@ -31,16 +31,16 @@ extern "C" { #endif -typedef struct _plugin_backend_resourced_memory_lmk_funcs { +typedef struct _syscommon_plugin_backend_resourced_memory_lmk_funcs { int (*get_kill_candidates)(GArray *candidates, GArray *task_info_app_array, GArray *task_info_proc_array, unsigned long totalram_kb); -} plugin_backend_resourced_memory_lmk_funcs; +} syscommon_plugin_backend_resourced_memory_lmk_funcs; #ifdef __cplusplus } #endif -#endif /* __PLUGIN_RESOURCED_MEMORY_LMK_INTERFACE_H__ */ +#endif /* __SYSCOMMON_PLUGIN_RESOURCED_MEMORY_LMK_INTERFACE_H__ */ diff --git a/src/plugin-api/resourced/include/plugin-resourced-memory-lmk.h b/src/plugin-api/resourced/include/syscommon-plugin-resourced-memory-lmk.h similarity index 88% rename from src/plugin-api/resourced/include/plugin-resourced-memory-lmk.h rename to src/plugin-api/resourced/include/syscommon-plugin-resourced-memory-lmk.h index 9d58ca5..49f257b 100644 --- a/src/plugin-api/resourced/include/plugin-resourced-memory-lmk.h +++ b/src/plugin-api/resourced/include/syscommon-plugin-resourced-memory-lmk.h @@ -22,8 +22,8 @@ * THE SOFTWARE. */ -#ifndef __PLUGIN_RESOURCED_MEMORY_LMK_H__ -#define __PLUGIN_RESOURCED_MEMORY_LMK_H__ +#ifndef __SYSCOMMON_PLUGIN_RESOURCED_MEMORY_LMK_H__ +#define __SYSCOMMON_PLUGIN_RESOURCED_MEMORY_LMK_H__ #include #include @@ -65,13 +65,13 @@ struct task_info { * @brief Get the backend data of resourced-memory-lmk module * @return @c 0 on success, otherwise a negative error value */ -int plugin_resourced_memory_lmk_get_backend(void); +int syscommon_plugin_resourced_memory_lmk_get_backend(void); /** * @brief Put the backend data of resourced-memory-lmk module * @return @c 0 on success, otherwise a negative error value */ -int plugin_resourced_memory_lmk_put_backend(void); +int syscommon_plugin_resourced_memory_lmk_put_backend(void); /** * @brief Call the get_kill_candidates function of resourced-memory-lmk module @@ -82,7 +82,8 @@ int plugin_resourced_memory_lmk_put_backend(void); * @return @c the number of kill candidates on success, * otherwise a negative error value */ -int plugin_resourced_memory_lmk_get_kill_candidates(GArray *candidates, +int syscommon_plugin_resourced_memory_lmk_get_kill_candidates( + GArray *candidates, GArray *task_info_app_array, GArray *task_info_proc_array, unsigned long totalram_kb); @@ -91,4 +92,4 @@ int plugin_resourced_memory_lmk_get_kill_candidates(GArray *candidates, } #endif -#endif /* __PLUGIN_RESOURCED_MEMORY_LMK_H__ */ +#endif /* __SYSCOMMON_PLUGIN_RESOURCED_MEMORY_LMK_H__ */ diff --git a/src/plugin-api/resourced/plugin-api-resourced.pc.in b/src/plugin-api/resourced/libsyscommon-plugin-api-resourced.pc.in similarity index 55% rename from src/plugin-api/resourced/plugin-api-resourced.pc.in rename to src/plugin-api/resourced/libsyscommon-plugin-api-resourced.pc.in index 6b406aa..d1292b6 100644 --- a/src/plugin-api/resourced/plugin-api-resourced.pc.in +++ b/src/plugin-api/resourced/libsyscommon-plugin-api-resourced.pc.in @@ -9,9 +9,9 @@ exec_prefix=@EXEC_PREFIX@ libdir=@LIBDIR@ includedir=@INCLUDEDIR@ -Name: plugin-api-resourced -Description: Plugin APIs for the resourced +Name: libsyscommon-plugin-api-resourced +Description: System plugin APIs for the resourced Version: @VERSION@ -Requires.private: plugin-api-common +Requires.private: libsyscommon-plugin-api-common Cflags: -I${includedir} @PLUGIN_RESOURCED_INCLUDEDIR@ -Libs: -L${libdir} -lplugin-api-resourced @PLUGIN_RESOURCED_LIBS@ +Libs: -L${libdir} -lsyscommon-plugin-api-resourced @PLUGIN_RESOURCED_LIBS@ diff --git a/src/plugin-api/resourced/src/plugin-resourced-memory-lmk.c b/src/plugin-api/resourced/src/syscommon-plugin-resourced-memory-lmk.c similarity index 74% rename from src/plugin-api/resourced/src/plugin-resourced-memory-lmk.c rename to src/plugin-api/resourced/src/syscommon-plugin-resourced-memory-lmk.c index f1aed5b..c79eeb0 100644 --- a/src/plugin-api/resourced/src/plugin-resourced-memory-lmk.c +++ b/src/plugin-api/resourced/src/syscommon-plugin-resourced-memory-lmk.c @@ -24,28 +24,29 @@ #include -#include "plugin-common.h" +#include "syscommon-plugin-common.h" #include "common.h" -#include "plugin-resourced-memory-lmk.h" -#include "plugin-resourced-memory-lmk-interface.h" +#include "syscommon-plugin-resourced-memory-lmk.h" +#include "syscommon-plugin-resourced-memory-lmk-interface.h" #ifndef EXPORT #define EXPORT __attribute__((visibility("default"))) #endif -static plugin_backend_resourced_memory_lmk_funcs *funcs = NULL; +static syscommon_plugin_backend_resourced_memory_lmk_funcs *funcs = NULL; EXPORT -int plugin_resourced_memory_lmk_get_backend(void) +int syscommon_plugin_resourced_memory_lmk_get_backend(void) { int ret = 0; if (funcs) return 0; - ret = plugin_common_get_backend( - PLUGIN_MODULE_RESOURCED_MEMORY_LMK, (void **)&funcs); + ret = syscommon_plugin_common_get_backend( + SYSCOMMON_PLUGIN_MODULE_RESOURCED_MEMORY_LMK, + (void **)&funcs); if (ret < 0) { _E("Failed to get resourced_memory_lmk backend: %d", ret); return ret; @@ -57,15 +58,16 @@ int plugin_resourced_memory_lmk_get_backend(void) } EXPORT -int plugin_resourced_memory_lmk_put_backend(void) +int syscommon_plugin_resourced_memory_lmk_put_backend(void) { int ret = 0; if (!funcs) return 0; - ret = plugin_common_put_backend( - PLUGIN_MODULE_RESOURCED_MEMORY_LMK, (void *)funcs); + ret = syscommon_plugin_common_put_backend( + SYSCOMMON_PLUGIN_MODULE_RESOURCED_MEMORY_LMK, + (void *)funcs); if (ret < 0) { _E("Failed to put resourced_memory_lmk backend: %d", ret); return ret; @@ -78,7 +80,8 @@ int plugin_resourced_memory_lmk_put_backend(void) } EXPORT -int plugin_resourced_memory_lmk_get_kill_candidates(GArray *candidates, +int syscommon_plugin_resourced_memory_lmk_get_kill_candidates( + GArray *candidates, GArray *task_info_app_array, GArray *task_info_proc_array, unsigned long totalram_kb) @@ -86,7 +89,7 @@ int plugin_resourced_memory_lmk_get_kill_candidates(GArray *candidates, int ret = 0; if (!funcs) { - ret = plugin_resourced_memory_lmk_get_backend(); + ret = syscommon_plugin_resourced_memory_lmk_get_backend(); if (ret < 0) return ret; } -- 2.7.4 From ff97a0e967849a01e4f8b5cd1418536eb41dbea1 Mon Sep 17 00:00:00 2001 From: SangYoun Kwak Date: Fri, 28 Apr 2023 13:55:10 +0900 Subject: [PATCH 07/16] plugin-api: Add manifest to plugin-api packages Previously, the smack label("_") was added by 'chsmack' command. By adding '%manifest' in the '%file' section, smack label can be applied to files without using chsmack in the '%post' section. Change-Id: Icd91b04e46d0eeb4182454aada7705ff0952c8fb Signed-off-by: SangYoun Kwak --- packaging/libsyscommon.spec | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packaging/libsyscommon.spec b/packaging/libsyscommon.spec index 0ce2272..79901c6 100644 --- a/packaging/libsyscommon.spec +++ b/packaging/libsyscommon.spec @@ -150,17 +150,16 @@ Common system plugin APIs to load another APIs from backend. %files -n libsyscommon-plugin-api-common %defattr(-,root,root,-) +%manifest %{name}.manifest %license LICENSE.MIT %{_libdir}/libsyscommon-plugin-api-common.so.* %post -n libsyscommon-plugin-api-common -pushd %{_libdir} -chsmack -a "_" libsyscommon-plugin-api-common.so.%{libsyscommon_plugin_api_common_version} -popd /sbin/ldconfig %files -n libsyscommon-plugin-api-common-devel %defattr(-,root,root,-) +%manifest %{name}.manifest %license LICENSE.MIT %{_includedir}/system/syscommon-plugin-common*.h %{_libdir}/pkgconfig/libsyscommon-plugin-api-common.pc @@ -168,17 +167,16 @@ popd %files -n libsyscommon-plugin-api-resourced %defattr(-,root,root,-) +%manifest %{name}.manifest %license LICENSE.MIT %{_libdir}/libsyscommon-plugin-api-resourced.so.* %post -n libsyscommon-plugin-api-resourced -pushd %{_libdir} -chsmack -a "_" libsyscommon-plugin-api-resourced.so.%{libsyscommon_plugin_api_resourced_version} -popd /sbin/ldconfig %files -n libsyscommon-plugin-api-resourced-devel %defattr(-,root,root,-) +%manifest %{name}.manifest %license LICENSE.MIT %{_includedir}/system/syscommon-plugin-resourced*.h %{_libdir}/pkgconfig/libsyscommon-plugin-api-resourced.pc @@ -186,11 +184,13 @@ popd %files -n libsyscommon-plugin-api-deviced %defattr(-,root,root,-) +%manifest %{name}.manifest %license LICENSE.MIT %{_libdir}/libsyscommon-plugin-api-deviced.so.* %files -n libsyscommon-plugin-api-deviced-devel %defattr(-,root,root,-) +%manifest %{name}.manifest %license LICENSE.MIT %{_includedir}/system/syscommon-plugin-deviced*.h %{_libdir}/pkgconfig/libsyscommon-plugin-api-deviced.pc -- 2.7.4 From d2ef1c9fccfb0dbd172135956eb060f6422b8d99 Mon Sep 17 00:00:00 2001 From: SangYoun Kwak Date: Thu, 8 Jun 2023 11:10:22 +0900 Subject: [PATCH 08/16] plugin-api: Fix the name of backend .so files The name for plugin backend .so files changed: libplugin-resourced-memory-lmk.so -> libplugin-backend-resourced-memory-lmk.so Since there are other packages start with "system-plugin", it is necessary to show that it is a backend for system-plugin. Change-Id: I5b11cfc6c1cdf39a3b60758d8bc2c075ac348ce9 Signed-off-by: SangYoun Kwak --- src/plugin-api/common/src/syscommon-plugin-api-list.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 e7b0ee6..477c6da 100644 --- a/src/plugin-api/common/src/syscommon-plugin-api-list.h +++ b/src/plugin-api/common/src/syscommon-plugin-api-list.h @@ -50,8 +50,8 @@ static struct __plugin_module_info g_plugin_module_info[] = { .license = PLUGIN_LICENSE_APACHE_2_0, .module_name = "SYSCOMMON_PLUGIN_MODULE_RESOURCED_MEMORY_LMK", .backend_module_name = "resourced-memory-lmk", - .library_name = "/usr/lib/system/plugin/libplugin-resourced-memory-lmk.so", - .library_name_64bit = "/usr/lib64/system/plugin/libplugin-resourced-memory-lmk.so", + .library_name = "/usr/lib/system/plugin/libplugin-backend-resourced-memory-lmk.so", + .library_name_64bit = "/usr/lib64/system/plugin/libplugin-backend-resourced-memory-lmk.so", .symbol_name = "system_plugin_backend_resourced_memory_lmk_data", .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], -- 2.7.4 From 870bb280426a0c2a5c758ac33da91aee89a5bd40 Mon Sep 17 00:00:00 2001 From: wchang kim Date: Thu, 4 May 2023 17:35:13 +0900 Subject: [PATCH 09/16] Remove the unnecessary dependencies and fix pc file If it have to make the dependency with specific packages at install time of rpm package , 'Requires' keyword should be used. But, development packages are only used when building the packages and they are not needed to be included in the image like rootfs.img. In result, remove the unnecessary dependencies and fix pc file from platform image. Change-Id: Ic14f2ab2bbe5134bedd948618c1aeee1e6d2d0fb Signed-off-by: wchang kim [cw00.choi: Update patch title and add description] Signed-off-by: Chanwoo Choi --- libsyscommon.pc.in | 2 +- packaging/libsyscommon.spec | 13 ------------- .../resourced/libsyscommon-plugin-api-resourced.pc.in | 2 +- 3 files changed, 2 insertions(+), 15 deletions(-) diff --git a/libsyscommon.pc.in b/libsyscommon.pc.in index 8dda939..7f29eb3 100644 --- a/libsyscommon.pc.in +++ b/libsyscommon.pc.in @@ -12,6 +12,6 @@ includedir=@INCLUDEDIR@ Name: libsyscommon Description: system common library Version: @VERSION@ -Requires.private: libsyscommon +Requires.private: gio-2.0 gio-unix-2.0 dlog json-c capi-system-info Cflags: -I${includedir} @SYSCOMMON_INCLUDEDIR@ Libs: -L${libdir} -lsyscommon @SYSCOMMON_LIBS@ diff --git a/packaging/libsyscommon.spec b/packaging/libsyscommon.spec index 79901c6..e7d9c82 100644 --- a/packaging/libsyscommon.spec +++ b/packaging/libsyscommon.spec @@ -32,11 +32,6 @@ System common utility libraries. Summary: Header files for system common library License: MIT Requires: libsyscommon = %{version} -Requires: pkgconfig(gio-2.0) -Requires: pkgconfig(gio-unix-2.0) -Requires: pkgconfig(dlog) -Requires: pkgconfig(json-c) -Requires: pkgconfig(capi-system-info) %description -n libsyscommon-devel Development header files for system common library. @@ -46,15 +41,11 @@ Development header files for system common library. Summary: Common system plugin APIs Version: %{libsyscommon_plugin_api_common_version} License: MIT -Requires: pkgconfig(gio-2.0) -Requires: pkgconfig(dlog) %package -n libsyscommon-plugin-api-common-devel Summary: Header files for common system plugin APIs Version: %{libsyscommon_plugin_api_common_version} License: MIT -Requires: pkgconfig(gio-2.0) -Requires: pkgconfig(dlog) %description -n libsyscommon-plugin-api-common-devel Development header files for common system plugin APIs. @@ -63,8 +54,6 @@ Development header files for common system plugin APIs. Summary: System plugin APIs for the resourced Version: %{libsyscommon_plugin_api_resourced_version} License: MIT -Requires: pkgconfig(gio-2.0) -Requires: pkgconfig(dlog) %description -n libsyscommon-plugin-api-resourced System plugin APIs for the resourced. @@ -73,8 +62,6 @@ System plugin APIs for the resourced. Summary: Header files for system plugin APIs for the resourced Version: %{libsyscommon_plugin_api_resourced_version} License: MIT -Requires: pkgconfig(gio-2.0) -Requires: pkgconfig(dlog) %description -n libsyscommon-plugin-api-resourced-devel Development header files for system plugin APIs for the resourced. diff --git a/src/plugin-api/resourced/libsyscommon-plugin-api-resourced.pc.in b/src/plugin-api/resourced/libsyscommon-plugin-api-resourced.pc.in index d1292b6..8887722 100644 --- a/src/plugin-api/resourced/libsyscommon-plugin-api-resourced.pc.in +++ b/src/plugin-api/resourced/libsyscommon-plugin-api-resourced.pc.in @@ -12,6 +12,6 @@ includedir=@INCLUDEDIR@ Name: libsyscommon-plugin-api-resourced Description: System plugin APIs for the resourced Version: @VERSION@ -Requires.private: libsyscommon-plugin-api-common +Requires.private: libsyscommon-plugin-api-common dlog gio-2.0 Cflags: -I${includedir} @PLUGIN_RESOURCED_INCLUDEDIR@ Libs: -L${libdir} -lsyscommon-plugin-api-resourced @PLUGIN_RESOURCED_LIBS@ -- 2.7.4 From 81ca03541a0b4c72570b65875ce03c6be86e753b Mon Sep 17 00:00:00 2001 From: Mateusz Moscicki Date: Tue, 20 Jun 2023 13:15:22 +0200 Subject: [PATCH 10/16] Allow to change the default connection type to private This is used to ensure that applications launched by launchpad get their own connection with the appropriate label, rather than using the connection that was established before the label change. Change-Id: Id1a6c80638c762f3de8856410b562df653dd70b5 --- src/libgdbus/libgdbus.c | 45 ++++++++++++++++++++++++++++++++++++++++++--- src/libgdbus/libgdbus.h | 2 ++ 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/libgdbus/libgdbus.c b/src/libgdbus/libgdbus.c index 32c15ed..3046ab1 100644 --- a/src/libgdbus/libgdbus.c +++ b/src/libgdbus/libgdbus.c @@ -34,6 +34,7 @@ #define DBUS_REPLY_TIMEOUT (10000) static GBusType g_default_bus_type = G_BUS_TYPE_SYSTEM; +static gboolean g_default_priv = false; pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER; void gdbus_set_default_bus_type(GBusType bus_type) @@ -93,9 +94,13 @@ typedef struct { static dbus_handle_s g_dh[2]; static dbus_handle_s *_gdbus_get_connection(GBusType bus_type); +static dbus_handle_s *_gdbus_get_connection_private(GBusType bus_type); dbus_handle_s * _gdbus_get_default_connection(void) { + if (g_default_priv) + return _gdbus_get_connection_private(gdbus_get_default_bus_type()); + return _gdbus_get_connection(gdbus_get_default_bus_type()); } @@ -559,7 +564,7 @@ char **gdbus_get_owner_list(dbus_handle_h handle, const char *bus_name) return strv; } -int gdbus_free_connection(dbus_handle_h handle) +int _gdbus_free_connection(dbus_handle_h handle, gboolean close_any_connection) { dcl_gdbus(); dbus_handle_s *pdh = NULL; @@ -643,8 +648,8 @@ int gdbus_free_connection(dbus_handle_h handle) } /* close connection */ - if (pdh->priv) { - _E("close private connection\n"); + if (pdh->priv || close_any_connection) { + _E("close connection\n"); if (!g_dbus_connection_close_sync(pdh->conn, NULL, &err)) { _E("Error closing connection %s\n", err->message); @@ -669,6 +674,12 @@ int gdbus_free_connection(dbus_handle_h handle) // todo: signal ? } +int gdbus_free_connection(dbus_handle_h handle) +{ + return _gdbus_free_connection(handle, false); +} + + #define buf_cal_free_space(size, nwrite) ((size - nwrite - 1) > 0 ? (size - nwrite - 1) : 0) #define buf_block_size 8192 @@ -2882,3 +2893,31 @@ GVariant *gdbus_make_simple_array(const char *sig, int *param) g_variant_builder_unref(builder); return var; } + +int gdbus_switch_to_private_connection(void) +{ + // This function is called by launchpad during the application preparation + // process. Launchpad is running with high privileges (label User). If a call + // to dbus is made before the process privileges are changed to lower (wich is + // what happens now), any method call sent with this connection will be + // visible as a call from a privileged process. + // + // From outside glib we can't effectively close the current connection so as + // to receive a new one (with application label), so this function forces to + // use of a private connection. + + // Close current connection so that it can not be used. + dbus_handle_s *connection = _gdbus_get_connection(gdbus_get_default_bus_type()); + int ret; + if ((ret = _gdbus_free_connection(connection, true)) != 0) + return ret; + + // Switch to a private connection. + pthread_mutex_lock(&g_mutex); + g_default_priv = true; + pthread_mutex_unlock(&g_mutex); + + _I("Switched to private connection."); + + return 0; +} diff --git a/src/libgdbus/libgdbus.h b/src/libgdbus/libgdbus.h index 659b2e4..8313715 100644 --- a/src/libgdbus/libgdbus.h +++ b/src/libgdbus/libgdbus.h @@ -278,6 +278,8 @@ GVariant *gdbus_make_simple_array (const char *sig, int check_systemd_active (void); +int gdbus_switch_to_private_connection (void); + #ifdef __cplusplus } #endif -- 2.7.4 From 7916aa8b6d7953afea4d42afbe54436702e176da Mon Sep 17 00:00:00 2001 From: Mateusz Moscicki Date: Wed, 28 Jun 2023 15:59:03 +0200 Subject: [PATCH 11/16] Revert "Allow to change the default connection type to private" This reverts commit 81ca03541a0b4c72570b65875ce03c6be86e753b. Change-Id: I871cf09f17724070d7e4c437d4638e87c33a5eae --- src/libgdbus/libgdbus.c | 45 +++------------------------------------------ src/libgdbus/libgdbus.h | 2 -- 2 files changed, 3 insertions(+), 44 deletions(-) diff --git a/src/libgdbus/libgdbus.c b/src/libgdbus/libgdbus.c index 3046ab1..32c15ed 100644 --- a/src/libgdbus/libgdbus.c +++ b/src/libgdbus/libgdbus.c @@ -34,7 +34,6 @@ #define DBUS_REPLY_TIMEOUT (10000) static GBusType g_default_bus_type = G_BUS_TYPE_SYSTEM; -static gboolean g_default_priv = false; pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER; void gdbus_set_default_bus_type(GBusType bus_type) @@ -94,13 +93,9 @@ typedef struct { static dbus_handle_s g_dh[2]; static dbus_handle_s *_gdbus_get_connection(GBusType bus_type); -static dbus_handle_s *_gdbus_get_connection_private(GBusType bus_type); dbus_handle_s * _gdbus_get_default_connection(void) { - if (g_default_priv) - return _gdbus_get_connection_private(gdbus_get_default_bus_type()); - return _gdbus_get_connection(gdbus_get_default_bus_type()); } @@ -564,7 +559,7 @@ char **gdbus_get_owner_list(dbus_handle_h handle, const char *bus_name) return strv; } -int _gdbus_free_connection(dbus_handle_h handle, gboolean close_any_connection) +int gdbus_free_connection(dbus_handle_h handle) { dcl_gdbus(); dbus_handle_s *pdh = NULL; @@ -648,8 +643,8 @@ int _gdbus_free_connection(dbus_handle_h handle, gboolean close_any_connection) } /* close connection */ - if (pdh->priv || close_any_connection) { - _E("close connection\n"); + if (pdh->priv) { + _E("close private connection\n"); if (!g_dbus_connection_close_sync(pdh->conn, NULL, &err)) { _E("Error closing connection %s\n", err->message); @@ -674,12 +669,6 @@ int _gdbus_free_connection(dbus_handle_h handle, gboolean close_any_connection) // todo: signal ? } -int gdbus_free_connection(dbus_handle_h handle) -{ - return _gdbus_free_connection(handle, false); -} - - #define buf_cal_free_space(size, nwrite) ((size - nwrite - 1) > 0 ? (size - nwrite - 1) : 0) #define buf_block_size 8192 @@ -2893,31 +2882,3 @@ GVariant *gdbus_make_simple_array(const char *sig, int *param) g_variant_builder_unref(builder); return var; } - -int gdbus_switch_to_private_connection(void) -{ - // This function is called by launchpad during the application preparation - // process. Launchpad is running with high privileges (label User). If a call - // to dbus is made before the process privileges are changed to lower (wich is - // what happens now), any method call sent with this connection will be - // visible as a call from a privileged process. - // - // From outside glib we can't effectively close the current connection so as - // to receive a new one (with application label), so this function forces to - // use of a private connection. - - // Close current connection so that it can not be used. - dbus_handle_s *connection = _gdbus_get_connection(gdbus_get_default_bus_type()); - int ret; - if ((ret = _gdbus_free_connection(connection, true)) != 0) - return ret; - - // Switch to a private connection. - pthread_mutex_lock(&g_mutex); - g_default_priv = true; - pthread_mutex_unlock(&g_mutex); - - _I("Switched to private connection."); - - return 0; -} diff --git a/src/libgdbus/libgdbus.h b/src/libgdbus/libgdbus.h index 8313715..659b2e4 100644 --- a/src/libgdbus/libgdbus.h +++ b/src/libgdbus/libgdbus.h @@ -278,8 +278,6 @@ GVariant *gdbus_make_simple_array (const char *sig, int check_systemd_active (void); -int gdbus_switch_to_private_connection (void); - #ifdef __cplusplus } #endif -- 2.7.4 From 2b794736a23ff141b160862adc18f49b3c604b7e Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Wed, 12 Jul 2023 19:05:44 +0900 Subject: [PATCH 12/16] libcommon: Introduce bitmap These have come from the deviced. Change-Id: I8d5eb95703d32d8fd17054c4446378adb4db97b2 Signed-off-by: Youngjae Cho --- src/libcommon/bitmap.c | 199 ++++++++++++++++++++++++++++++++++++++++++ src/libcommon/bitmap.h | 40 +++++++++ tests/libcommon/test-common.c | 84 ++++++++++++++++++ 3 files changed, 323 insertions(+) create mode 100644 src/libcommon/bitmap.c create mode 100644 src/libcommon/bitmap.h diff --git a/src/libcommon/bitmap.c b/src/libcommon/bitmap.c new file mode 100644 index 0000000..07a7117 --- /dev/null +++ b/src/libcommon/bitmap.c @@ -0,0 +1,199 @@ +/* MIT License + * + * Copyright (c) 2022 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 +#include + +#include "bitmap.h" +#include "shared/log.h" + +/** + * Align bits by size of long, and convert it to long, + * for example, if long is 64bit then, + * ROUNDUP_BITS_TO_LONGS(0) -> 0 + * ROUNDUP_BITS_TO_LONGS(1) -> 1 + * ROUNDUP_BITS_TO_LONGS(64) -> 1 + * ROUNDUP_BITS_TO_LONGS(65) -> 2 + * ROUNDUP_BITS_TO_LONGS(128) -> 2 + * ROUNDUP_BITS_TO_LONGS(129) -> 3 + * ... + */ +#define BYTES_PER_LONG (sizeof(unsigned long)) +#define BITS_PER_LONG (BYTES_PER_LONG * 8) +#define ROUNDUP(n, d) ((((n) + (d) - 1) / (d)) * (d)) +#define ROUNDUP_BITS_TO_LONGS(nbits) (ROUNDUP(nbits, BITS_PER_LONG) / BITS_PER_LONG) + +#define BIT_WORD(nr) ((nr) / BITS_PER_LONG) +#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG)) +#define BITMAP_MARGIN (BYTES_PER_LONG * 2) /* trailing margin for safety, bytes */ + +struct syscommon_bitmap { + /* bitmap */ + unsigned long *b; + + /* number of bits, not the maximum bit. + * maximum bit is size - 1 */ + unsigned long size; +}; + +static void bitmap_alloc_size(struct syscommon_bitmap *bm, unsigned int nbits) +{ + unsigned int bytes = ROUNDUP_BITS_TO_LONGS(nbits) * BYTES_PER_LONG; + + bytes += BITMAP_MARGIN; + + bm->b = (unsigned long *) malloc(bytes); + if (!bm->b) + return; + + bm->size = nbits; +} + +void syscommon_bitmap_set_all_bits(struct syscommon_bitmap *bm) +{ + unsigned long complete_longs; + unsigned long complete_bytes; + unsigned long residue_bits; + + if (!bm) + return; + + complete_longs = bm->size / BITS_PER_LONG; + complete_bytes = complete_longs * BYTES_PER_LONG; + residue_bits = bm->size % BITS_PER_LONG; + + /* set all bits of the long element except the last long element */ + memset(bm->b, ~0, complete_bytes); + + /* set residue bits in the last long element */ + if (residue_bits) + bm->b[complete_longs] = (1UL << residue_bits) - 1; +} + +void syscommon_bitmap_clear_all_bits(struct syscommon_bitmap *bm) +{ + unsigned int bytes; + + if (!bm) + return; + + bytes = ROUNDUP_BITS_TO_LONGS(bm->size) * BYTES_PER_LONG; + + memset(bm->b, 0, bytes); +} + +void syscommon_bitmap_set_bit(struct syscommon_bitmap *bm, unsigned long nr) +{ + if (!bm) + return; + + if (nr >= bm->size) { + _E("Requested nr=%lu exceeds max bit=%lu", nr, bm->size - 1); + return; + } + + bm->b[BIT_WORD(nr)] |= BIT_MASK(nr); +} + +void syscommon_bitmap_clear_bit(struct syscommon_bitmap *bm, unsigned long nr) +{ + if (!bm) + return; + + if (nr >= bm->size) { + _E("Requested nr=%lu exceeds max bit=%lu", nr, bm->size - 1); + return; + } + + bm->b[BIT_WORD(nr)] &= ~BIT_MASK(nr); +} + +bool syscommon_bitmap_test_bit(struct syscommon_bitmap *bm, unsigned long nr) +{ + if (!bm) + return false; + + if (nr >= bm->size) { + _E("Requested nr=%lu exceeds max bit=%lu", nr, bm->size - 1); + return false; + } + + return bm->b[BIT_WORD(nr)] & BIT_MASK(nr); +} + +int syscommon_bitmap_count_set_bit(struct syscommon_bitmap *bm) +{ + int i; + int count = 0; + + if (!bm) + return -1; + + for (i = 0; i < ROUNDUP_BITS_TO_LONGS(bm->size); ++i) + count += __builtin_popcountl(bm->b[i]); + + return count; +} + +int syscommon_bitmap_count_unset_bit(struct syscommon_bitmap *bm) +{ + if (!bm) + return -1; + + return bm->size - syscommon_bitmap_count_set_bit(bm); +} + +struct syscommon_bitmap* syscommon_bitmap_init_bitmap(unsigned int nbits) +{ + struct syscommon_bitmap *bm = NULL; + + if (nbits == 0) + return NULL; + + bm = (struct syscommon_bitmap *) malloc(sizeof(struct syscommon_bitmap)); + if (!bm) + return NULL; + + bm->b = NULL; + bm->size = 0; + + bitmap_alloc_size(bm, nbits); + if (!bm->b) { + free(bm); + return NULL; + } + + syscommon_bitmap_clear_all_bits(bm); + bm->size = nbits; + + return bm; +} + +void syscommon_bitmap_deinit_bitmap(struct syscommon_bitmap *bm) +{ + if (!bm) + return; + + free(bm->b); + free(bm); +} diff --git a/src/libcommon/bitmap.h b/src/libcommon/bitmap.h new file mode 100644 index 0000000..75ff7c5 --- /dev/null +++ b/src/libcommon/bitmap.h @@ -0,0 +1,40 @@ +/* MIT License + * + * Copyright (c) 2022 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_BITMAP_H__ +#define __SYSCOMMON_BITMAP_H__ + +#include + +struct syscommon_bitmap; + +void syscommon_bitmap_set_bit(struct syscommon_bitmap *b, unsigned long nr); +void syscommon_bitmap_clear_bit(struct syscommon_bitmap *b, unsigned long nr); +bool syscommon_bitmap_test_bit(struct syscommon_bitmap *b, unsigned long nr); +void syscommon_bitmap_set_all_bits(struct syscommon_bitmap *b); +void syscommon_bitmap_clear_all_bits(struct syscommon_bitmap *b); +int syscommon_bitmap_count_set_bit(struct syscommon_bitmap *b); +int syscommon_bitmap_count_unset_bit(struct syscommon_bitmap *b); +struct syscommon_bitmap* syscommon_bitmap_init_bitmap(unsigned int nbits); +void syscommon_bitmap_deinit_bitmap(struct syscommon_bitmap *b); + +#endif diff --git a/tests/libcommon/test-common.c b/tests/libcommon/test-common.c index 392830a..3b988f9 100644 --- a/tests/libcommon/test-common.c +++ b/tests/libcommon/test-common.c @@ -9,6 +9,7 @@ #include "libcommon/file.h" #include "libcommon/list.h" #include "libcommon/ini-parser.h" +#include "libcommon/bitmap.h" #include "../test-main.h" #include "../test-mock.h" @@ -193,6 +194,85 @@ static void test_config_parse_p(void **state) assert_false(garbage); } +static void test_init_bitmap_p(void **state) +{ + struct syscommon_bitmap *bm; + + bm = syscommon_bitmap_init_bitmap(10); + assert_non_null(bm); + + syscommon_bitmap_deinit_bitmap(bm); +} + +static void test_init_bitmap_n(void **state) +{ + struct syscommon_bitmap *bm = NULL; + + bm = syscommon_bitmap_init_bitmap(0); + assert_null(bm); +} + +static void test_test_bit(void **state) +{ + struct syscommon_bitmap *bm; + const int bmsize = 37; + bool bit; + int i, nbit; + + bm = syscommon_bitmap_init_bitmap(bmsize); + assert_non_null(bm); + + for (i = 0; i < bmsize; ++i) { + bit = syscommon_bitmap_test_bit(bm, i); + assert_false(bit); + } + + /* count bit by setting one by one */ + for (i = 0; i < bmsize; ++i) { + syscommon_bitmap_set_bit(bm, i); + nbit = syscommon_bitmap_count_set_bit(bm); + assert_int_equal(nbit, i + 1); + } + + /* test the marginal bit */ + bit = syscommon_bitmap_test_bit(bm, 0); + assert_true(bit); + bit = syscommon_bitmap_test_bit(bm, bmsize - 1); + assert_true(bit); + bit = syscommon_bitmap_test_bit(bm, bmsize); + assert_false(bit); + + + /* count bit by clearing one by one */ + for (i = 0; i < bmsize; ++i) { + syscommon_bitmap_clear_bit(bm, i); + nbit = syscommon_bitmap_count_set_bit(bm); + assert_int_equal(nbit, bmsize - i - 1); + } + + syscommon_bitmap_deinit_bitmap(bm); +} + +static void test_all_bit(void **state) +{ + struct syscommon_bitmap *bm; + const int bmsize = 37; + int nbit; + + bm = syscommon_bitmap_init_bitmap(bmsize); + assert_non_null(bm); + + syscommon_bitmap_set_all_bits(bm); + nbit = syscommon_bitmap_count_set_bit(bm); + assert_int_equal(nbit, bmsize); + + syscommon_bitmap_clear_all_bits(bm); + nbit = syscommon_bitmap_count_set_bit(bm); + assert_int_equal(nbit, 0); + + syscommon_bitmap_deinit_bitmap(bm); +} + int run_test_suite(void) { const struct CMUnitTest testsuite[] = { @@ -202,6 +282,10 @@ int run_test_suite(void) cmocka_unit_test(test_list_append_p), cmocka_unit_test(test_list_prepend_p), cmocka_unit_test(test_config_parse_p), + cmocka_unit_test(test_init_bitmap_p), + cmocka_unit_test(test_init_bitmap_n), + cmocka_unit_test(test_test_bit), + cmocka_unit_test(test_all_bit), }; return cmocka_run_group_tests(testsuite, NULL, NULL); -- 2.7.4 From 4e087d5b9256880dfccffde7f99470e7498fa3c1 Mon Sep 17 00:00:00 2001 From: Mateusz Moscicki Date: Mon, 10 Jul 2023 16:34:25 +0200 Subject: [PATCH 13/16] Add functions that use a private connection. At the moment only the functions that libstorage uses are prepared. Currently only functoins are added that are called by libstorage during the dotnet-launcher preparation. Change-Id: Idd7f145d1fef057cb5ba42039d006b491f5d7166 --- src/libgdbus/libgdbus.c | 42 ++++++++++++++++++++++++++++++++++-------- src/libgdbus/libgdbus.h | 10 ++++++++++ 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/src/libgdbus/libgdbus.c b/src/libgdbus/libgdbus.c index 32c15ed..248bb67 100644 --- a/src/libgdbus/libgdbus.c +++ b/src/libgdbus/libgdbus.c @@ -248,6 +248,7 @@ static dbus_handle_s *_gdbus_get_connection_private(GBusType bus_type) if (!dh->conn) { dh->conn = _get_bus_private(bus_type); + dh->priv = TRUE; dh->bus_type = bus_type; if (!dh->conn) goto err; @@ -2056,7 +2057,8 @@ int gdbus_flush_sync(dbus_handle_h handle) return ret; } -int gdbus_call_sync_with_reply(const char *dest, +int gdbus_priv_call_sync_with_reply(dbus_handle_h handle, + const char *dest, const char *path, const char *iface, const char *method, @@ -2066,21 +2068,20 @@ int gdbus_call_sync_with_reply(const char *dest, GError *err = NULL; GVariant *reply = NULL; int ret = 0; - dbus_handle_s *dh = NULL; + dcl_gdbus(); - if (!dest || !path || !iface || !method) { - _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); + if (!dh) { + _E("dbus handle is NULL"); if (param) g_variant_unref(param); return -EINVAL; } - dh = _gdbus_get_default_connection(); - if (!dh) { - _E("failed to get default connection, bustype:%d", (int)gdbus_get_default_bus_type()); + if (!dest || !path || !iface || !method) { + _E("wrong parameters dest(%s) path(%s) iface(%s) method(%s)", dest, path, iface, method); if (param) g_variant_unref(param); - return -ECOMM; + return -EINVAL; } reply = g_dbus_connection_call_sync(dh->conn, @@ -2113,6 +2114,30 @@ int gdbus_call_sync_with_reply(const char *dest, return ret; } +int gdbus_call_sync_with_reply(const char *dest, + const char *path, + const char *iface, + const char *method, + GVariant *param, + GVariant **out_reply) +{ + dbus_handle_s *dh = _gdbus_get_default_connection(); + if (!dh) { + _E("failed to get default connection, bustype:%d", (int)gdbus_get_default_bus_type()); + if (param) + g_variant_unref(param); + return -ECOMM; + } + + return gdbus_priv_call_sync_with_reply(dh, + dest, + path, + iface, + method, + param, + out_reply); +} + int gdbus_call_sync_with_reply_timeout(const char *dest, const char *path, const char *iface, const char *method, GVariant *param, GVariant **out_reply, int timeout) { @@ -2527,6 +2552,7 @@ err: if (param) g_variant_unref(param); return ret; + } int gdbus_call_pairs_async_with_reply(const char *dest, diff --git a/src/libgdbus/libgdbus.h b/src/libgdbus/libgdbus.h index 659b2e4..87d5c81 100644 --- a/src/libgdbus/libgdbus.h +++ b/src/libgdbus/libgdbus.h @@ -90,6 +90,8 @@ typedef struct { dbus_handle_h gdbus_get_connection (GBusType bus_type, gboolean priv); +int gdbus_free_connection(dbus_handle_h handle); + int gdbus_request_name (dbus_handle_h handle, const char *bus_name, GBusNameAcquiredCallback acquired_handler, @@ -148,6 +150,14 @@ int gdbus_call_sync_with_reply (const char *dest, GVariant *param, GVariant **out_reply); +int gdbus_priv_call_sync_with_reply (dbus_handle_h handle, + const char *dest, + const char *path, + const char *iface, + const char *method, + GVariant *param, + GVariant **out_reply); + int gdbus_call_sync_with_reply_timeout (const char *dest, const char *path, const char *iface, -- 2.7.4 From 838f0c2aad7e7e31938797c62926b68ab078e793 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 17 Jul 2023 10:22:12 +0900 Subject: [PATCH 14/16] libcommon: Add missing source/header for CMake Change-Id: Ifc3d782a610cd6dfddcdc66037ea680ca9aca8da Signed-off-by: Youngjae Cho --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index d28713b..a06a977 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,7 @@ SET(libsyscommon_SRCS src/libcommon/ini-parser.c src/libcommon/file.c src/libcommon/common.c + src/libcommon/bitmap.c src/resource-manager/resource-manager.c src/resource-manager/resource-device.c src/resource-manager/resource-listener-epoll.c @@ -31,6 +32,7 @@ SET(HEADERS src/libcommon/list.h src/libcommon/ini-parser.h src/libcommon/file.h + src/libcommon/bitmap.h src/libcommon/common.h src/resource-manager/resource-manager.h src/resource-manager/resource-type.h -- 2.7.4 From 33e3a51a433d042e845531e86afed1dde62e3fc0 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 17 Jul 2023 11:13:49 +0900 Subject: [PATCH 15/16] Add include directory to collect header file It is collected and installed automatically just by creating header file in include directory. Change-Id: Ia411edd7101afbb49097229986965eff5b175519 Signed-off-by: Youngjae Cho --- CMakeLists.txt | 19 ++----------------- {src/libcommon => include/libsyscommon}/bitmap.h | 0 {src/libcommon => include/libsyscommon}/common.h | 0 .../libsyscommon}/dbus-iface-system.h | 0 {src/libcommon => include/libsyscommon}/file.h | 0 {src/libcommon => include/libsyscommon}/ini-parser.h | 0 {src/libgdbus => include/libsyscommon}/libgdbus.h | 0 {src/libsystemd => include/libsyscommon}/libsystemd.h | 0 {src/libcommon => include/libsyscommon}/list.h | 0 .../libsyscommon}/resource-device.h | 0 .../libsyscommon}/resource-listener.h | 0 .../libsyscommon}/resource-manager.h | 0 .../libsyscommon}/resource-type.h | 0 src/libcommon/bitmap.c | 2 +- src/libcommon/common.c | 2 +- src/libcommon/file.c | 2 +- src/libcommon/ini-parser.c | 2 +- src/libgdbus/libgdbus.c | 2 +- src/libsystemd/libsystemd.c | 2 +- src/resource-manager/resource-device.c | 2 +- src/resource-manager/resource-listener-epoll.c | 4 ++-- src/resource-manager/resource-manager.c | 4 ++-- tests/libcommon/test-common.c | 8 ++++---- 23 files changed, 17 insertions(+), 32 deletions(-) rename {src/libcommon => include/libsyscommon}/bitmap.h (100%) rename {src/libcommon => include/libsyscommon}/common.h (100%) rename {src/libgdbus => include/libsyscommon}/dbus-iface-system.h (100%) rename {src/libcommon => include/libsyscommon}/file.h (100%) rename {src/libcommon => include/libsyscommon}/ini-parser.h (100%) rename {src/libgdbus => include/libsyscommon}/libgdbus.h (100%) rename {src/libsystemd => include/libsyscommon}/libsystemd.h (100%) rename {src/libcommon => include/libsyscommon}/list.h (100%) rename {src/resource-manager => include/libsyscommon}/resource-device.h (100%) rename {src/resource-manager => include/libsyscommon}/resource-listener.h (100%) rename {src/resource-manager => include/libsyscommon}/resource-manager.h (100%) rename {src/resource-manager => include/libsyscommon}/resource-type.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index a06a977..7d0a82d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,7 @@ PROJECT(libsyscommon C) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src/shared) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) ADD_SUBDIRECTORY(src/plugin-api/common) ADD_SUBDIRECTORY(src/plugin-api/resourced) ADD_SUBDIRECTORY(src/plugin-api/deviced) @@ -25,20 +26,6 @@ SET(libsyscommon_SRCS src/resource-manager/resource-device.c src/resource-manager/resource-listener-epoll.c ) -SET(HEADERS - src/libgdbus/libgdbus.h - src/libgdbus/dbus-iface-system.h - src/libsystemd/libsystemd.h - src/libcommon/list.h - src/libcommon/ini-parser.h - src/libcommon/file.h - src/libcommon/bitmap.h - src/libcommon/common.h - src/resource-manager/resource-manager.h - src/resource-manager/resource-type.h - src/resource-manager/resource-device.h - src/resource-manager/resource-listener.h -) # CHECK PKG INCLUDE(FindPkgConfig) @@ -79,8 +66,6 @@ CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) # HEADER -FOREACH(hfile ${HEADERS}) - INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${hfile} DESTINATION include/${PROJECT_NAME}) -ENDFOREACH(hfile) +INSTALL(DIRECTORY include/libsyscommon DESTINATION include) ADD_SUBDIRECTORY(tests) diff --git a/src/libcommon/bitmap.h b/include/libsyscommon/bitmap.h similarity index 100% rename from src/libcommon/bitmap.h rename to include/libsyscommon/bitmap.h diff --git a/src/libcommon/common.h b/include/libsyscommon/common.h similarity index 100% rename from src/libcommon/common.h rename to include/libsyscommon/common.h diff --git a/src/libgdbus/dbus-iface-system.h b/include/libsyscommon/dbus-iface-system.h similarity index 100% rename from src/libgdbus/dbus-iface-system.h rename to include/libsyscommon/dbus-iface-system.h diff --git a/src/libcommon/file.h b/include/libsyscommon/file.h similarity index 100% rename from src/libcommon/file.h rename to include/libsyscommon/file.h diff --git a/src/libcommon/ini-parser.h b/include/libsyscommon/ini-parser.h similarity index 100% rename from src/libcommon/ini-parser.h rename to include/libsyscommon/ini-parser.h diff --git a/src/libgdbus/libgdbus.h b/include/libsyscommon/libgdbus.h similarity index 100% rename from src/libgdbus/libgdbus.h rename to include/libsyscommon/libgdbus.h diff --git a/src/libsystemd/libsystemd.h b/include/libsyscommon/libsystemd.h similarity index 100% rename from src/libsystemd/libsystemd.h rename to include/libsyscommon/libsystemd.h diff --git a/src/libcommon/list.h b/include/libsyscommon/list.h similarity index 100% rename from src/libcommon/list.h rename to include/libsyscommon/list.h diff --git a/src/resource-manager/resource-device.h b/include/libsyscommon/resource-device.h similarity index 100% rename from src/resource-manager/resource-device.h rename to include/libsyscommon/resource-device.h diff --git a/src/resource-manager/resource-listener.h b/include/libsyscommon/resource-listener.h similarity index 100% rename from src/resource-manager/resource-listener.h rename to include/libsyscommon/resource-listener.h diff --git a/src/resource-manager/resource-manager.h b/include/libsyscommon/resource-manager.h similarity index 100% rename from src/resource-manager/resource-manager.h rename to include/libsyscommon/resource-manager.h diff --git a/src/resource-manager/resource-type.h b/include/libsyscommon/resource-type.h similarity index 100% rename from src/resource-manager/resource-type.h rename to include/libsyscommon/resource-type.h diff --git a/src/libcommon/bitmap.c b/src/libcommon/bitmap.c index 07a7117..849ca15 100644 --- a/src/libcommon/bitmap.c +++ b/src/libcommon/bitmap.c @@ -24,7 +24,7 @@ #include #include -#include "bitmap.h" +#include "libsyscommon/bitmap.h" #include "shared/log.h" /** diff --git a/src/libcommon/common.c b/src/libcommon/common.c index 50cdee6..051f8bb 100644 --- a/src/libcommon/common.c +++ b/src/libcommon/common.c @@ -26,7 +26,7 @@ #include #include #include "shared/log.h" -#include "common.h" +#include "libsyscommon/common.h" #define FEATURE_MODEL_NAME "http://tizen.org/system/model_name" #define FEATURE_MODEL_NAME_EMULATOR "Emulator" diff --git a/src/libcommon/file.c b/src/libcommon/file.c index e0a3b29..c2f579d 100644 --- a/src/libcommon/file.c +++ b/src/libcommon/file.c @@ -27,7 +27,7 @@ #include #include -#include "file.h" +#include "libsyscommon/file.h" #define SHARED_H_BUF_MAX 255 diff --git a/src/libcommon/ini-parser.c b/src/libcommon/ini-parser.c index e8e2bce..19355d2 100644 --- a/src/libcommon/ini-parser.c +++ b/src/libcommon/ini-parser.c @@ -23,7 +23,7 @@ #include #include #include -#include "ini-parser.h" +#include "libsyscommon/ini-parser.h" #include "shared/log.h" diff --git a/src/libgdbus/libgdbus.c b/src/libgdbus/libgdbus.c index 248bb67..d206064 100644 --- a/src/libgdbus/libgdbus.c +++ b/src/libgdbus/libgdbus.c @@ -28,7 +28,7 @@ #include #include "shared/log.h" -#include "libgdbus.h" +#include "libsyscommon/libgdbus.h" /* 10 seconds */ #define DBUS_REPLY_TIMEOUT (10000) diff --git a/src/libsystemd/libsystemd.c b/src/libsystemd/libsystemd.c index 3d2fbc2..0e9725b 100644 --- a/src/libsystemd/libsystemd.c +++ b/src/libsystemd/libsystemd.c @@ -25,7 +25,7 @@ #include #include #include -#include +#include "libsyscommon/libgdbus.h" #include "shared/log.h" diff --git a/src/resource-manager/resource-device.c b/src/resource-manager/resource-device.c index a716593..2520946 100644 --- a/src/resource-manager/resource-device.c +++ b/src/resource-manager/resource-device.c @@ -23,7 +23,7 @@ #include #include -#include "resource-device.h" +#include "libsyscommon/resource-device.h" static GList *g_resource_device_head; diff --git a/src/resource-manager/resource-listener-epoll.c b/src/resource-manager/resource-listener-epoll.c index 615c3de..ce74e8c 100644 --- a/src/resource-manager/resource-listener-epoll.c +++ b/src/resource-manager/resource-listener-epoll.c @@ -25,8 +25,8 @@ #include #include -#include "resource-manager.h" -#include "resource-listener.h" +#include "libsyscommon/resource-manager.h" +#include "libsyscommon/resource-listener.h" /* listener common */ struct listener_handle { diff --git a/src/resource-manager/resource-manager.c b/src/resource-manager/resource-manager.c index 6fd1f5e..25817ce 100644 --- a/src/resource-manager/resource-manager.c +++ b/src/resource-manager/resource-manager.c @@ -27,8 +27,8 @@ #include #include -#include "resource-manager.h" -#include "resource-type.h" +#include "libsyscommon/resource-manager.h" +#include "libsyscommon/resource-type.h" #define BIT64_INDEX(id) (63 - __builtin_clzll(id)) #define RESOURCE_ATTR_INDEX(id) BIT64_INDEX(id) diff --git a/tests/libcommon/test-common.c b/tests/libcommon/test-common.c index 3b988f9..9df8e61 100644 --- a/tests/libcommon/test-common.c +++ b/tests/libcommon/test-common.c @@ -6,10 +6,10 @@ #include #include -#include "libcommon/file.h" -#include "libcommon/list.h" -#include "libcommon/ini-parser.h" -#include "libcommon/bitmap.h" +#include "libsyscommon/file.h" +#include "libsyscommon/list.h" +#include "libsyscommon/ini-parser.h" +#include "libsyscommon/bitmap.h" #include "../test-main.h" #include "../test-mock.h" -- 2.7.4 From 928f87047a86a7f0f4cf02b92e85094543829e89 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 17 Jul 2023 15:18:40 +0900 Subject: [PATCH 16/16] proc: Add proc operation These have come from the deviced. - int syscommon_proc_get_comm(pid_t pid, char *buf, int len); - int syscommon_proc_get_cmdline(pid_t pid, char *buf, int len); - int syscommon_proc_get_attr_current(pid_t pid, char *buf, int len); - int syscommon_proc_is_app(pid_t pid); Change-Id: I89b668ed045db9c666e1921bceaf8a70c112af78 Signed-off-by: Youngjae Cho --- CMakeLists.txt | 1 + include/libsyscommon/proc.h | 33 ++++++++++++++ src/libcommon/proc.c | 103 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 include/libsyscommon/proc.h create mode 100644 src/libcommon/proc.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d0a82d..9094e74 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,7 @@ SET(libsyscommon_SRCS src/libcommon/file.c src/libcommon/common.c src/libcommon/bitmap.c + src/libcommon/proc.c src/resource-manager/resource-manager.c src/resource-manager/resource-device.c src/resource-manager/resource-listener-epoll.c diff --git a/include/libsyscommon/proc.h b/include/libsyscommon/proc.h new file mode 100644 index 0000000..e6d2f3a --- /dev/null +++ b/include/libsyscommon/proc.h @@ -0,0 +1,33 @@ +/* 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_PROC_H__ +#define __SYSCOMMON_PROC_H__ + +#include + +int syscommon_proc_get_comm(pid_t pid, char *buf, int len); +int syscommon_proc_get_cmdline(pid_t pid, char *buf, int len); +int syscommon_proc_get_attr_current(pid_t pid, char *buf, int len); +int syscommon_proc_is_app(pid_t pid); + +#endif /*__SYSCOMMON_PROC_H__ */ diff --git a/src/libcommon/proc.c b/src/libcommon/proc.c new file mode 100644 index 0000000..16c439f --- /dev/null +++ b/src/libcommon/proc.c @@ -0,0 +1,103 @@ +#include +#include +#include +#include +#include + +#include "shared/log.h" +#include "libsyscommon/proc.h" + +#define PATH_MAX 128 +#define NAME_MAX 64 +#define FORMAT_MAX 16 + +static int proc_get_string(char *buf, int len, const char *pathfmt, ...) +{ + FILE *fp = NULL; + char path[PATH_MAX] = { 0 , }; + char scanfmt[FORMAT_MAX] = { 0, }; + va_list ap; + int ret = 0; + + if (!buf || len < 0) + return -EINVAL; + + va_start(ap, pathfmt); + ret = vsnprintf(path, PATH_MAX, pathfmt, ap); + va_end(ap); + + if (ret < 0) + return -EIO; + + if (ret >= PATH_MAX) + return -ENAMETOOLONG; + + fp = fopen(path, "r"); + if (!fp) { + _E("Failed to open %s, %m", path); + return -errno; + } + + ret = snprintf(scanfmt, FORMAT_MAX, "%%%ds", len - 1); + if (ret < 0) { + fclose(fp); + return -EIO; + } + + if (ret >= FORMAT_MAX) { /* impossible */ + fclose(fp); + return -ERANGE; + } + + errno = 0; + ret = fscanf(fp, scanfmt, buf); + if (ret != 1) { + fclose(fp); + return errno ? -errno : -EIO; + } + + fclose(fp); + + return 0; +} + +int syscommon_proc_get_comm(pid_t pid, char *buf, int len) +{ + return proc_get_string(buf, len, "/proc/%d/comm", pid); +} + +int syscommon_proc_get_cmdline(pid_t pid, char *buf, int len) +{ + return proc_get_string(buf, len, "/proc/%d/cmdline", pid); +} + +int syscommon_proc_get_attr_current(pid_t pid, char *buf, int len) +{ + return proc_get_string(buf, len, "/proc/%d/attr/current", pid); +} + +int syscommon_proc_is_app(pid_t pid) +{ + char attr[NAME_MAX] = { 0 ,}; + size_t len = 0; + int ret = 0; + + ret = syscommon_proc_get_attr_current(pid, attr, sizeof(attr)); + if (ret != 0) { + _E("Failed to read privilege, %d", ret); + return -1; + } + + len = strlen(attr) + 1; + + if (!strncmp("System", attr, len)) + return 0; + + if (!strncmp("User", attr, len)) + return 0; + + if (!strncmp("System::Privileged", attr, len)) + return 0; + + return 1; +} -- 2.7.4