From: Youngjae Cho Date: Wed, 5 Jun 2024 07:08:15 +0000 (+0900) Subject: plugin-api: deviced: Add interface for detecting setting value change X-Git-Tag: accepted/tizen/unified/20240618.060027~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1804a1fff4b31c832b07c90d5547d54b7447fd68;p=platform%2Fcore%2Fsystem%2Flibsyscommon.git plugin-api: deviced: Add interface for detecting setting value change The function has been added as display plugin operation : on_changed_setting_value(int key, int value) It is invoked when setting app changes display setting such as screen timeout or brightness. The parameters are saying that which 'key' has changed to what 'value'. Change-Id: Id904488c3fb393a648618d4fd30df2d283dfa6ef Signed-off-by: Youngjae Cho --- diff --git a/src/plugin-api/deviced/include/system/syscommon-plugin-deviced-display-interface.h b/src/plugin-api/deviced/include/system/syscommon-plugin-deviced-display-interface.h index caf5414..5b5d266 100644 --- a/src/plugin-api/deviced/include/system/syscommon-plugin-deviced-display-interface.h +++ b/src/plugin-api/deviced/include/system/syscommon-plugin-deviced-display-interface.h @@ -140,6 +140,7 @@ enum syscommon_deviced_display_capability { typedef struct _syscommon_plugin_backend_deviced_display_funcs { int (*load_display_config) (struct syscommon_deviced_display_config **); + int (*on_changed_setting_value) (int, int); } syscommon_plugin_backend_deviced_display_funcs; #ifdef __cplusplus diff --git a/src/plugin-api/deviced/include/system/syscommon-plugin-deviced-display.h b/src/plugin-api/deviced/include/system/syscommon-plugin-deviced-display.h index a999c95..67b003a 100644 --- a/src/plugin-api/deviced/include/system/syscommon-plugin-deviced-display.h +++ b/src/plugin-api/deviced/include/system/syscommon-plugin-deviced-display.h @@ -45,11 +45,20 @@ int syscommon_plugin_deviced_display_get_backend(void); int syscommon_plugin_deviced_display_put_backend(void); /** - * @brief Load the backend config of deviced-displaymodule + * @brief Load the backend config of deviced-display module * @return @c 0 on success, otherwise a negative error value */ int syscommon_plugin_deviced_display_load_config(struct syscommon_deviced_display_config **); +/** + * @brief Let plugin know about setting value change + * @param[in] key Key of which setting value has changed + * @param[in] value Value that a key has changed to + * @return @c 0 on success, otherwise a negative error value + */ + +int syscommon_plugin_deviced_display_notify_setting_value_changed(int key, int value); + #ifdef __cplusplus } #endif diff --git a/src/plugin-api/deviced/src/syscommon-plugin-deviced-display.c b/src/plugin-api/deviced/src/syscommon-plugin-deviced-display.c index 57495fb..0f49ec5 100644 --- a/src/plugin-api/deviced/src/syscommon-plugin-deviced-display.c +++ b/src/plugin-api/deviced/src/syscommon-plugin-deviced-display.c @@ -22,6 +22,7 @@ * THE SOFTWARE. */ #include +#include #include @@ -95,3 +96,22 @@ int syscommon_plugin_deviced_display_load_config(struct syscommon_deviced_displa return g_display_funcs->load_display_config(data); } + +EXPORT +int syscommon_plugin_deviced_display_notify_setting_value_changed(int key, int value) +{ + int ret = 0; + + if (!g_display_funcs) { + ret = syscommon_plugin_deviced_display_get_backend(); + if (ret < 0) + return ret; + } + + assert(g_display_funcs); + + if (!g_display_funcs->on_changed_setting_value) + return -EOPNOTSUPP; + + return g_display_funcs->on_changed_setting_value(key, value); +} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ae480bf..e53ee04 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,6 +1,8 @@ SET(TEST_DRIVER "test-driver") INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/plugin-api/common/include) +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/plugin-api/deviced/include) FILE(GLOB TEST_DRIVER_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/*.c") FILE(GLOB LIBCOMMON_SRCS @@ -9,14 +11,25 @@ FILE(GLOB LIBCOMMON_SRCS FILE(GLOB RESOURCE_MANAGER_SRCS "${CMAKE_SOURCE_DIR}/tests/resource-manager/*.c" "${CMAKE_SOURCE_DIR}/src/resource-manager/*.c") +FILE(GLOB PLUGIN_API_COMMON_SRCS + "${CMAKE_SOURCE_DIR}/src/plugin-api/common/src/*.c") +FILE(GLOB PLUGIN_API_DEVICED_SRCS + "${CMAKE_SOURCE_DIR}/tests/plugin-api/deviced/*.c" + "${CMAKE_SOURCE_DIR}/src/plugin-api/deviced/src/*.c") SET(SRCS ${TEST_DRIVER_SRCS} ${LIBCOMMON_SRCS} - ${RESOURCE_MANAGER_SRCS}) + ${RESOURCE_MANAGER_SRCS} + ${PLUGIN_API_COMMON_SRCS} + ${PLUGIN_API_DEVICED_SRCS}) SET(WRAP_FLAGS "${WRAP_FLAGS} -Wl,--wrap=open") SET(WRAP_FLAGS "${WRAP_FLAGS} -Wl,--wrap=open64") +SET(WRAP_FLAGS "${WRAP_FLAGS} -Wl,--wrap=dlopen") +SET(WRAP_FLAGS "${WRAP_FLAGS} -Wl,--wrap=dlclose") +SET(WRAP_FLAGS "${WRAP_FLAGS} -Wl,--wrap=dlsym") +SET(WRAP_FLAGS "${WRAP_FLAGS} -Wl,--wrap=access") INCLUDE(FindPkgConfig) PKG_CHECK_MODULES(REQUIRED_PKGS REQUIRED @@ -26,7 +39,7 @@ PKG_CHECK_MODULES(REQUIRED_PKGS REQUIRED cmocka) ADD_EXECUTABLE(${TEST_DRIVER} ${SRCS}) -TARGET_LINK_LIBRARIES(${TEST_DRIVER} ${REQUIRED_PKGS_LDFLAGS}) +TARGET_LINK_LIBRARIES(${TEST_DRIVER} "${REQUIRED_PKGS_LDFLAGS} -ldl") # Suppress implicit declaration warning for __real functions. SET_TARGET_PROPERTIES(${TEST_DRIVER} PROPERTIES COMPILE_FLAGS "-Wno-implicit-function-declaration") SET_TARGET_PROPERTIES(${TEST_DRIVER} PROPERTIES LINK_FLAGS "${WRAP_FLAGS} -Wl,--export-dynamic") diff --git a/tests/plugin-api/deviced/test-plugin-display.c b/tests/plugin-api/deviced/test-plugin-display.c new file mode 100644 index 0000000..4af264f --- /dev/null +++ b/tests/plugin-api/deviced/test-plugin-display.c @@ -0,0 +1,65 @@ +#include +#include +#include +#include + +#include "../../test-main.h" + +#define EXPORT __attribute__ ((visibility("default"))) + +static struct syscommon_deviced_display_config configurations = { + 0, /* define plugin own configurations */ }; + +static int load_display_config(struct syscommon_deviced_display_config **data) +{ + if (!data) + return -EINVAL; + + *data = &configurations; + + return 0; +} + +static int on_changed_setting_value(int key, int value) +{ + check_expected(key); + + switch (key) { + case 1: + check_expected(value); + // do something + break; + case 2: + check_expected(value); + // do something + break; + default: + break; + } + + return 0; +} + +static syscommon_plugin_backend_deviced_display_funcs g_display_funcs = { + .load_display_config = load_display_config, + .on_changed_setting_value = on_changed_setting_value, +}; + +static int deviced_display_init(void **data) +{ + *data = (void *)&g_display_funcs; + + return 0; +} + +static int deviced_display_exit(void *data) +{ + return 0; +} + +syscommon_plugin_backend EXPORT system_plugin_backend_deviced_display_data = { + .name = "test-deviced-display", + .vendor = "Samsung", + .init = deviced_display_init, + .exit = deviced_display_exit, +}; diff --git a/tests/plugin-api/deviced/test.c b/tests/plugin-api/deviced/test.c new file mode 100644 index 0000000..112d998 --- /dev/null +++ b/tests/plugin-api/deviced/test.c @@ -0,0 +1,48 @@ +#include +#include +#include +#include + +#include "../../test-main.h" +#include "../../test-mock.h" + +#include + +extern syscommon_plugin_backend system_plugin_backend_deviced_display_data; + +static int setup_plugin_deviced(void **state) +{ + int ret; + + mock_set_plugin_funcs(&system_plugin_backend_deviced_display_data); + + ret = syscommon_plugin_deviced_display_get_backend(); + assert_int_equal(ret, 0); + + return 0; +} + +static int teardown_plugin_deviced(void **state) +{ + syscommon_plugin_deviced_display_put_backend(); + + mock_unset_plugin_funcs(); + + return 0; +} + +static void test_notify_setting_value_changed(void **state) +{ + int ret; + + expect_value(on_changed_setting_value, key, 1); + expect_value(on_changed_setting_value, value, 1); + + ret = syscommon_plugin_deviced_display_notify_setting_value_changed(1, 1); + assert_int_equal(ret, 0); +} + +static const struct CMUnitTest testsuite_plugin_api_deviced[] = { + cmocka_unit_test(test_notify_setting_value_changed), +}; +TESTSUITE_FIXTURE(testsuite_plugin_api_deviced, setup_plugin_deviced, teardown_plugin_deviced) diff --git a/tests/test-mock.c b/tests/test-mock.c index 5dffc7c..84e60fa 100644 --- a/tests/test-mock.c +++ b/tests/test-mock.c @@ -1,6 +1,8 @@ #include +#include #include #include +#include #include #include "test-main.h" @@ -8,6 +10,13 @@ //static FILE *__fp = NULL; +static void *plugin_funcs = NULL; + +int __wrap_access(const char *pathname, int mode) +{ + return 0; +} + int __wrap_open(const char *pathname, int flags) { const char *mock_pathname; @@ -35,6 +44,43 @@ void mock_open(const char *pathname, int flags) will_return(__wrap_open, flags); } +void mock_set_plugin_funcs(void *funcs) +{ + plugin_funcs = funcs; +} + +void mock_unset_plugin_funcs(void) +{ + plugin_funcs = NULL; +} + +extern void* __real_dlopen(const char *filename, int flags); +void *__wrap_dlopen(const char *filename, int flags) +{ + if (plugin_funcs) + return (void *)(intptr_t) 1; + + return __real_dlopen(filename, flags); +} + +extern int __real_dlclose(void *handle); +int __wrap_dlclose(void *handle) +{ + if (plugin_funcs) + return 0; + + return __real_dlclose(handle); +} + +extern void* __real_dlsym(void *handle, const char *symbol); +void *__wrap_dlsym(void *handle, const char *symbol) +{ + if (plugin_funcs) + return plugin_funcs; + + return __real_dlsym(handle, symbol); +} + /* FILE *__wrap_fopen(const char *pathname, const char *mode) { diff --git a/tests/test-mock.h b/tests/test-mock.h index 22c7196..a384aa1 100644 --- a/tests/test-mock.h +++ b/tests/test-mock.h @@ -5,4 +5,7 @@ void mock_open(const char *pathname, int flags); +void mock_set_plugin_funcs(void *funcs); +void mock_unset_plugin_funcs(void); + #endif //__TEST_MOCK_H__