From: Chanwoo Choi Date: Wed, 5 Mar 2025 12:08:23 +0000 (+0900) Subject: plugin-api: common: Add new SYSCOMMON_PLUGIN_MODULE_SESSIOND plugin X-Git-Tag: accepted/tizen/9.0/unified/20250415.165856~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2350823edf285402a7871e29becb4afb4d768fff;p=platform%2Fcore%2Fsystem%2Flibsyscommon.git plugin-api: common: Add new SYSCOMMON_PLUGIN_MODULE_SESSIOND plugin Add new SYSCOMMON_PLUGIN_MODULE_SESSIOND for sessiond.service plugin to support the specific multi-user feature of GBM/profile/product. Change-Id: I25499ecc449b7a99b2805ee4f76a13b1c7f7da12 Signed-off-by: Chanwoo Choi --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 5412f1c..51f115b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,7 @@ ADD_SUBDIRECTORY(src/plugin-api/common) ADD_SUBDIRECTORY(src/plugin-api/resourced) ADD_SUBDIRECTORY(src/plugin-api/deviced) ADD_SUBDIRECTORY(src/plugin-api/update-control) +ADD_SUBDIRECTORY(src/plugin-api/sessiond) # ADD_SUBDIRECTORY(src/libgdbus) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) diff --git a/packaging/libsyscommon.spec b/packaging/libsyscommon.spec index 561bf64..8f81229 100644 --- a/packaging/libsyscommon.spec +++ b/packaging/libsyscommon.spec @@ -3,6 +3,7 @@ %define libsyscommon_plugin_api_resourced_version 0.1.0 %define libsyscommon_plugin_api_deviced_version 0.1.0 %define libsyscommon_plugin_api_update_control_version 0.1.0 +%define libsyscommon_plugin_api_sessiond_version 0.1.0 Name: libsyscommon Summary: System Libraries @@ -101,6 +102,23 @@ License: MIT Development header files for system plugin API for update-control. +%package -n libsyscommon-plugin-api-sessiond +Summary: System plugin API for the sessiond +Version: %{libsyscommon_plugin_api_sessiond_version} +License: MIT + +%description -n libsyscommon-plugin-api-sessiond +System plugin API for sessiond. + +%package -n libsyscommon-plugin-api-sessiond-devel +Summary: Header files for system plugin API for sessiond +Version: %{libsyscommon_plugin_api_sessiond_version} +License: MIT + +%description -n libsyscommon-plugin-api-sessiond-devel +Development header files for system plugin API for sessiond. + + ###### @@ -113,6 +131,7 @@ PLUGIN_API_COMMON_MAJORVER=$(echo %{libsyscommon_plugin_api_common_version} | cu 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) PLUGIN_API_UPDATE_CONTROL_MAJORVER=$(echo %{libsyscommon_plugin_api_update_control_version} | cut -d'.' -f1) +PLUGIN_API_SESSIOND_MAJORVER=$(echo %{libsyscommon_plugin_api_sessiond_version} | cut -d'.' -f1) %cmake . -DFULLVER=%{libsyscommon_version} \ -DPLUGIN_API_COMMON_VERSION=%{libsyscommon_plugin_api_common_version} \ -DPLUGIN_API_COMMON_MAJORVER=${PLUGIN_API_COMMON_MAJORVER} \ @@ -122,10 +141,13 @@ PLUGIN_API_UPDATE_CONTROL_MAJORVER=$(echo %{libsyscommon_plugin_api_update_contr -DPLUGIN_API_DEVICED_MAJORVER=${PLUGIN_API_DEVICED_MAJORVER} \ -DPLUGIN_API_UPDATE_CONTROL_VERSION=%{libsyscommon_plugin_api_update_control_version} \ -DPLUGIN_API_UPDATE_CONTROL_MAJORVER=${PLUGIN_API_UPDATE_CONTROL_MAJORVER} \ + -DPLUGIN_API_SESSIOND_VERSION=%{libsyscommon_plugin_api_sessiond_version} \ + -DPLUGIN_API_SESSIOND_MAJORVER=${PLUGIN_API_SESSIOND_MAJORVER} \ -DPLUGIN_API_COMMON_ENABLE_DLOG=1 \ -DPLUGIN_API_RESOURCED_ENABLE_DLOG=1 \ -DPLUGIN_API_DEVICED_ENABLE_DLOG=1 \ - -DPLUGIN_API_UPDATE_CONTROL_ENABLE_DLOG=1 + -DPLUGIN_API_UPDATE_CONTROL_ENABLE_DLOG=1 \ + -DPLUGIN_API_SESSIOND_ENABLE_DLOG=1 make %{?_smp_mflags} %install @@ -218,3 +240,18 @@ Common system plugin APIs to load another APIs from backend. %{_includedir}/system/syscommon-plugin-update-control*.h %{_libdir}/pkgconfig/libsyscommon-plugin-api-update-control.pc %{_libdir}/libsyscommon-plugin-api-update-control.so + +%files -n libsyscommon-plugin-api-sessiond +%defattr(-,root,root,-) +%manifest %{name}.manifest +%license LICENSE.MIT +%{_libdir}/libsyscommon-plugin-api-sessiond.so.* + +%files -n libsyscommon-plugin-api-sessiond-devel +%defattr(-,root,root,-) +%manifest %{name}.manifest +%license LICENSE.MIT +%{_includedir}/system/syscommon-plugin-sessiond*.h +%{_includedir}/system/syscommon-internal-sessiond.h +%{_libdir}/pkgconfig/libsyscommon-plugin-api-sessiond.pc +%{_libdir}/libsyscommon-plugin-api-sessiond.so diff --git a/src/plugin-api/common/include/system/syscommon-plugin-common.h b/src/plugin-api/common/include/system/syscommon-plugin-common.h index 7993c08..4cdd6b9 100644 --- a/src/plugin-api/common/include/system/syscommon-plugin-common.h +++ b/src/plugin-api/common/include/system/syscommon-plugin-common.h @@ -39,6 +39,7 @@ enum syscommon_plugin_module { SYSCOMMON_PLUGIN_MODULE_DEVICED_DISPLAY, SYSCOMMON_PLUGIN_MODULE_RESOURCED_CPU_BOOSTING, SYSCOMMON_PLUGIN_MODULE_UPDATE_CONTROL, + SYSCOMMON_PLUGIN_MODULE_SESSIOND, SYSCOMMON_PLUGIN_MODULE_END, }; diff --git a/src/plugin-api/common/src/common.h b/src/plugin-api/common/src/common.h index d6a370d..4960585 100644 --- a/src/plugin-api/common/src/common.h +++ b/src/plugin-api/common/src/common.h @@ -48,6 +48,7 @@ enum plugin_group { PLUGIN_GROUP_RESOURCED, PLUGIN_GROUP_DEVICED, PLUGIN_GROUP_UPDATE_CONTROL, + PLUGIN_GROUP_SESSIOND, PLUGIN_GROUP_END, }; diff --git a/src/plugin-api/common/src/syscommon-plugin-api-list.h b/src/plugin-api/common/src/syscommon-plugin-api-list.h index 8161a31..41d8474 100644 --- a/src/plugin-api/common/src/syscommon-plugin-api-list.h +++ b/src/plugin-api/common/src/syscommon-plugin-api-list.h @@ -90,6 +90,16 @@ static struct __plugin_module_info g_plugin_module_info[] = { .library_name_64bit = "/usr/lib64/system/plugin/libplugin-backend-update-control.so", .symbol_name = "system_plugin_backend_update_control_data", }, + [SYSCOMMON_PLUGIN_MODULE_SESSIOND] = { + .group = PLUGIN_GROUP_SESSIOND, + .module = SYSCOMMON_PLUGIN_MODULE_SESSIOND, + .license = PLUGIN_LICENSE_APACHE_2_0, + .module_name = "SYSCOMMON_PLUGIN_MODULE_SESSIOND", + .backend_module_name = "sessiond", + .library_name = "/usr/lib/system/plugin/libplugin-backend-sessiond.so", + .library_name_64bit = "/usr/lib64/system/plugin/libplugin-backend-sessiond.so", + .symbol_name = "system_plugin_backend_sessiond_data", + }, }; #endif /* __PLUGIN_API_LIST_H__ */ diff --git a/src/plugin-api/sessiond/CMakeLists.txt b/src/plugin-api/sessiond/CMakeLists.txt new file mode 100644 index 0000000..a6f6886 --- /dev/null +++ b/src/plugin-api/sessiond/CMakeLists.txt @@ -0,0 +1,68 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(syscommon-plugin-api-sessiond) + +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(EXEC_PREFIX "${PREFIX}/bin") +SET(LIBDIR ${LIB_INSTALL_DIR}) +SET(INCLUDEDIR "${PREFIX}/include/system") +SET(VERSION ${PLUGIN_API_SESSIOND_VERSION}) + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) +# 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}) + SET(PKG_MODULES + glib-2.0 + dlog) + ADD_DEFINITIONS("-DENABLE_DLOG") + ADD_DEFINITIONS("-DLOG_TAG=\"SYSTEM_PLUGIN_API_SESSIOND\"") +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") + +# 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-sessiond.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} + -ldl -Wl,-z,nodelete,--no-undefined) + +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${PLUGIN_API_SESSIOND_VERSION}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${PLUGIN_API_SESSIOND_MAJORVER}) + +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}) +INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/system/ + DESTINATION ${INCLUDEDIR} + FILES_MATCHING PATTERN "*.h" +) + +# CONFIGURE .pc FILE +FOREACH(include_dirs ${pkgs_INCLUDE_DIRS}) + SET(PLUGIN_SESSIOND_INCLUDEDIR "${PLUGIN_SESSIOND_INCLUDEDIR} -I${include_dirs}") +ENDFOREACH(include_dirs) +FOREACH(libraries ${pkgs_LIBRARIES}) + SET(PLUGIN_SESSIOND_LIBS "${PLUGIN_SESSIOND_LIBS} -l${libraries}") +ENDFOREACH(libraries) +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/sessiond/include/system/syscommon-internal-sessiond.h b/src/plugin-api/sessiond/include/system/syscommon-internal-sessiond.h new file mode 100644 index 0000000..3e8c3dd --- /dev/null +++ b/src/plugin-api/sessiond/include/system/syscommon-internal-sessiond.h @@ -0,0 +1,74 @@ +/** + * MIT License + * + * Copyright (c) 2025 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_INTERNAL_SESSIOND_H__ +#define __SYSCOMMON_INTERNAL_SESSIOND_H__ + +#ifdef __cplusplus +extern "C" { +#endif + + +/* These functions are to be called by the plugin, and let it access sessiond + * directly. There is no routing via libsyscommon, the header is here mostly + * because otherwise there would be a cyclical sessiond/plugin dependency. */ + +/** + * @brief Add a subsession (called from plugin) + * @param uid user ID to add the subsession to + * @param subsession Subsession name to add + * @return @c 0 on success, otherwise a negative error value + */ +int sessiond_internal_add_subsession(int uid, const char *subsession); + +/** + * @brief Add a subsession (called from plugin) + * @param uid user ID to add the subsession to + * @param subsession Subsession name to add + * @param size_kB Size limit of the subsession in kilobytes + * @return @c 0 on success, otherwise a negative error value + */ +int sessiond_internal_add_subsession_fixed_size(int uid, const char *subsession, unsigned size_kB); + +/** + * @brief Remove a subsession (called from plugin) + * @param uid user ID to remove the subsession from + * @param subsession Subsession name to remove + * @return @c 0 on success, otherwise a negative error value + */ +int sessiond_internal_remove_subsession(int uid, const char *subsession); + +/** + * @brief Switch subsession (called from plugin) + * @param uid user ID whose subsession to switch + * @param subsession Subsession name to switch to + * @return @c 0 on success, otherwise a negative error value + */ +int sessiond_internal_switch_subsession(int uid, const char *subsession); + +#ifdef __cplusplus +} +#endif + +#endif // __SYSCOMMON_INTERNAL_SESSIOND_H__ diff --git a/src/plugin-api/sessiond/include/system/syscommon-plugin-sessiond-interface.h b/src/plugin-api/sessiond/include/system/syscommon-plugin-sessiond-interface.h new file mode 100644 index 0000000..40bee76 --- /dev/null +++ b/src/plugin-api/sessiond/include/system/syscommon-plugin-sessiond-interface.h @@ -0,0 +1,53 @@ +/** + * MIT License + * + * Copyright (c) 2025 Samsung Electronics Co., Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef __SYSCOMMON_PLUGIN_SESSIOND_INTERFACE_H__ +#define __SYSCOMMON_PLUGIN_SESSIOND_INTERFACE_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct _syscommon_plugin_backend_sessiond_funcs { + int (*sessiond_initialize) (void); + + /* The functions below return an `int` mostly for consistency with + * other libcommon interfaces, but sessiond ignores it. Only initialize's + * return value is actually used. */ + + int (*sessiond_deinitialize) (void); + int (*sessiond_subsession_changed)(int uid, const char *subsession_from, const char *subsession_to); + int (*sessiond_subsession_added)(int uid, const char *subsession); + int (*sessiond_subsession_removed)(int uid, const char *subsession); +} syscommon_plugin_backend_sessiond_funcs; + + +#ifdef __cplusplus +} +#endif + +#endif //__SYSCOMMON_PLUGIN_SESSIOND_INTERFACE_H__ diff --git a/src/plugin-api/sessiond/include/system/syscommon-plugin-sessiond.h b/src/plugin-api/sessiond/include/system/syscommon-plugin-sessiond.h new file mode 100644 index 0000000..d31de23 --- /dev/null +++ b/src/plugin-api/sessiond/include/system/syscommon-plugin-sessiond.h @@ -0,0 +1,93 @@ +/** + * MIT License + * + * Copyright (c) 2025 Samsung Electronics Co., Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is furnished + * to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef __SYSCOMMON_PLUGIN_SESSIOND_H__ +#define __SYSCOMMON_PLUGIN_SESSIOND_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + + +/* These functions are called by sessiond, and let it access plugin functions + * by routing via usual libsyscommon patterns. */ + + +/** + * @brief Get the backend data of sessiond-plugin module + * @return @c 0 on success, otherwise a negative error value + */ +int syscommon_plugin_sessiond_get_backend(int *backend_exists); + +/** + * @brief Put the backend data of sessiond-plugin module + * @return @c 0 on success, otherwise a negative error value + */ +int syscommon_plugin_sessiond_put_backend(void); + +/** + * @brief Call the sessiond_initialize function of sessiond-plugin module + * @return @c 0 on success, otherwise a negative error value + */ +int syscommon_plugin_sessiond_initialize(); + +/** + * @brief Call the sessiond_deinitialize function of sessiond-plugin module + * Call this before calling syscommon_plugin_SESSIOND_put_backend() + */ +int syscommon_plugin_sessiond_deinitialize(void); + +/** + * @brief Call the sessiond_subsession_changed function of sessiond-plugin module + * @param uid user ID whose subsession changed + * @param from Subsession name that is being switched away from + * @param to Subsession name that is being switched into + * @return @c 0 on success, otherwise a negative error value + */ +int syscommon_plugin_sessiond_subsession_changed(int uid, const char *from, const char *to); + +/** + * @brief Call the sessiond_subsession_added function of sessiond-plugin module + * @param uid user ID to whom a subsession is being added + * @param subsession Subsession name that is being added + * @return @c 0 on success, otherwise a negative error value + */ +int syscommon_plugin_sessiond_subsession_added(int uid, const char *subsession); + +/** + * @brief Call the sessiond_subsession_removed function of sessiond-plugin module + * @param uid user ID whose subsession is being removed + * @param subsession Subsession name that is being removed + * @return @c 0 on success, otherwise a negative error value + */ +int syscommon_plugin_sessiond_subsession_removed(int uid, const char *subsession); + + +#ifdef __cplusplus +} +#endif + +#endif //__SYSCOMMON_PLUGIN_SESSIOND_H__ diff --git a/src/plugin-api/sessiond/libsyscommon-plugin-api-sessiond.pc.in b/src/plugin-api/sessiond/libsyscommon-plugin-api-sessiond.pc.in new file mode 100644 index 0000000..6590c27 --- /dev/null +++ b/src/plugin-api/sessiond/libsyscommon-plugin-api-sessiond.pc.in @@ -0,0 +1,17 @@ +# Package Information for pkg-config +# +# Copyright (c) 2025 Samsung Electronics Co., Ltd. +# All rights reserved. +# + +prefix=@PREFIX@ +exec_prefix=@EXEC_PREFIX@ +libdir=@LIBDIR@ +includedir=@INCLUDEDIR@ + +Name: libsyscommon-plugin-api-sessiond +Description: System plugin API for sessiond +Version: @VERSION@ +Requires.private: libsyscommon-plugin-api-common +Cflags: -I${includedir} @PLUGIN_SESSIOND_INCLUDEDIR@ +Libs: -L${libdir} -lsyscommon-plugin-api-sessiond @PLUGIN_SESSIOND_LIBS@ diff --git a/src/plugin-api/sessiond/src/syscommon-plugin-sessiond.c b/src/plugin-api/sessiond/src/syscommon-plugin-sessiond.c new file mode 100644 index 0000000..04f2c19 --- /dev/null +++ b/src/plugin-api/sessiond/src/syscommon-plugin-sessiond.c @@ -0,0 +1,131 @@ +/** + * MIT License + * + * Copyright (c) 2025 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 + +#ifndef EXPORT +#define EXPORT __attribute__((visibility("default"))) +#endif + +static syscommon_plugin_backend_sessiond_funcs *funcs = NULL; + +EXPORT +int syscommon_plugin_sessiond_get_backend(int *backend_exists) +{ + if (funcs) + goto get_backend_success; + + int ret = syscommon_plugin_common_get_backend( + SYSCOMMON_PLUGIN_MODULE_SESSIOND, + (void **)&funcs); + + if (ret < 0) { + if (ret == -ENOENT) { + _I("sessiond backend was not found"); + if (backend_exists) + *backend_exists = 0; + return 0; + } + + _E("Failed to get sessiond backend: %d", ret); + return ret; + } + + _I("Success to get sessiond backend: %d", ret); + +get_backend_success: + if (backend_exists) + *backend_exists = 1; + + return 0; +} + +EXPORT +int syscommon_plugin_sessiond_put_backend(void) +{ + if (!funcs) + return 0; + + int ret = syscommon_plugin_common_put_backend( + SYSCOMMON_PLUGIN_MODULE_SESSIOND, + (void *)funcs); + if (ret < 0) { + _E("Failed to put sessiond backend: %d", ret); + return ret; + } + funcs = NULL; + + _I("Success to put sessiond backend: %d", ret); + + return 0; +} + +#define RUN_CHECKED_FUNCTION(name, ...) \ + if (!funcs) { \ + _E("No backend"); \ + return -EINVAL; \ + } \ + if (!funcs->name) { \ + static bool message_sent = false; \ + if (!message_sent) { \ + _I("No " #name " function"); \ + message_sent = true; \ + } \ + return -ENOTSUP; \ + } \ + return funcs->name(__VA_ARGS__); + + +EXPORT +int syscommon_plugin_sessiond_initialize() +{ + RUN_CHECKED_FUNCTION(sessiond_initialize); +} + +EXPORT +int syscommon_plugin_sessiond_deinitialize(void) +{ + RUN_CHECKED_FUNCTION(sessiond_deinitialize); +} + +EXPORT +int syscommon_plugin_sessiond_subsession_changed(int uid, const char *from, const char *to) +{ + RUN_CHECKED_FUNCTION(sessiond_subsession_changed, uid, from, to); +} + +EXPORT +int syscommon_plugin_sessiond_subsession_added(int uid, const char *subsession) +{ + RUN_CHECKED_FUNCTION(sessiond_subsession_added, uid, subsession); +} + +EXPORT +int syscommon_plugin_sessiond_subsession_removed(int uid, const char *subsession) +{ + RUN_CHECKED_FUNCTION(sessiond_subsession_removed, uid, subsession); +}