From: Cheoleun Moon Date: Tue, 22 Jun 2021 07:57:56 +0000 (+0900) Subject: Allow to set event loop type with api X-Git-Tag: submit/tizen/20210628.025645~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9ed09763be6378447a6993c6ed07c20c5425b2c9;p=platform%2Fcore%2Fapi%2Fvine.git Allow to set event loop type with api Change-Id: Ib33d2e130f0cc939272d496605a64a768188335c Signed-off-by: Cheoleun Moon --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 964c045..85a4fb8 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,12 +50,11 @@ IF(TIZEN_OS) ENDIF(TIZEN_OS) IF(USE_EVENT_LOOP_EPOLL) - ADD_DEFINITIONS("-DVINE_EVENT_LOOP_EPOLL") + ADD_DEFINITIONS("-DUSE_VINE_EVENT_LOOP_EPOLL") ENDIF(USE_EVENT_LOOP_EPOLL) IF(USE_EVENT_LOOP_EXTERNAL_GLIB) - REMOVE_DEFINITIONS("-DVINE_EVENT_LOOP_EPOLL") - ADD_DEFINITIONS("-DVINE_EVENT_LOOP_EXTERNAL_GLIB") + ADD_DEFINITIONS("-DUSE_VINE_EVENT_LOOP_EXTERNAL_GLIB") STRING(CONCAT DEPS ${DEPS} " glib-2.0 gio-2.0") ENDIF(USE_EVENT_LOOP_EXTERNAL_GLIB) diff --git a/include/vine.h b/include/vine.h index 97cfa95..cdb4096 100755 --- a/include/vine.h +++ b/include/vine.h @@ -290,6 +290,22 @@ typedef enum { VINE_ADDRESS_FAMILY_IPV6, } vine_address_family_e; +/** + * @brief Enumeration for event loop + * @since_tizen 6.5 + */ +typedef enum { + /** + * App uses event fd from vine + */ + VINE_EVENT_LOOP_DEFAULT = 0, + + /** + * External glib event loop + */ + VINE_EVENT_LOOP_EXTERNAL_GLIB, +} vine_event_loop_e; + /** * @brief Initializes Vine. * @since_tizen 6.5 @@ -326,6 +342,18 @@ int vine_deinitialize(); */ int vine_get_capabilities(vine_capability_type_e type, int *capabilities); +/** + * @brief Sets event loop. + * @since_tizen 6.5 + * @param[in] loop The event loop + * @return 0 on success, otherwise a negative error value + * @retval #VINE_ERROR_NONE Successful + * @retval #VINE_ERROR_NOT_INITIALIZED Not initialized + * @retval #VINE_ERROR_NOT_SUPPORTED Not supported + * @see vine_initialize() + */ +int vine_set_event_loop(vine_event_loop_e loop); + /** * @brief Gets event file discriptor for monitoring Vine events. * @since_tizen 6.5 diff --git a/packaging/capi-network-vine.spec b/packaging/capi-network-vine.spec index bedbdf8..2411059 100755 --- a/packaging/capi-network-vine.spec +++ b/packaging/capi-network-vine.spec @@ -3,7 +3,7 @@ %bcond_without use_glib_event_loop Name: capi-network-vine Summary: An service discovery framework -Version: 1.0.8 +Version: 1.0.9 Release: 0 Group: Network & Connectivity/API License: Apache-2.0 @@ -90,12 +90,11 @@ export LDFLAGS+=" -lgcov" -DLIB_DIR:PATH=%{_libdir} \ -DBIN_DIR:PATH=%{_bindir} \ -DINCLUDE_DIR:PATH=%{_includedir} \ + -DUSE_EVENT_LOOP_EPOLL=ON \ %if %{with use_glib_event_loop} -DUSE_EVENT_LOOP_EXTERNAL_GLIB=ON \ - -DUSE_EVENT_LOOP_EPOLL=OFF \ %else - -DUSE_EVENT_LOOP_EXTERNAL_GLIB=OF \ - -DUSE_EVENT_LOOP_EPOLL=ON \ + -DUSE_EVENT_LOOP_EXTERNAL_GLIB=OFF \ %endif %if %{with lws_static} -DUSE_LIBWEBSOCKETS_STATIC=ON \ diff --git a/src/include/vine-event-loop.h b/src/include/vine-event-loop.h index f2a09d9..48ab5b6 100755 --- a/src/include/vine-event-loop.h +++ b/src/include/vine-event-loop.h @@ -20,6 +20,8 @@ #include #include +#include "vine.h" + typedef void *vine_event_queue_h; typedef void (*vine_poll_handler)(int fd, int events, void *user_data); @@ -35,6 +37,8 @@ enum { VINE_POLLHUP = EPOLLHUP, }; +int vine_event_loop_set(vine_event_loop_e loop); + int vine_event_loop_init(); void vine_event_loop_deinit(); int vine_event_loop_start(); diff --git a/src/include/vine-private.h b/src/include/vine-private.h index 53ad15c..a972914 100755 --- a/src/include/vine-private.h +++ b/src/include/vine-private.h @@ -20,5 +20,6 @@ int _vine_init(); int _vine_deinit(); int _vine_get_capabilities(int type, int *capabilities); +int _vine_set_event_loop(vine_event_loop_e loop); #endif diff --git a/src/vine-event-loop-glib.cpp b/src/vine-event-loop-glib.cpp index 4f252f9..eafea33 100755 --- a/src/vine-event-loop-glib.cpp +++ b/src/vine-event-loop-glib.cpp @@ -15,7 +15,7 @@ * */ -#if defined VINE_EVENT_LOOP_EXTERNAL_GLIB +#if defined USE_VINE_EVENT_LOOP_EXTERNAL_GLIB #include #include #include @@ -221,4 +221,4 @@ vine_event_loop_fn vine_event_loop_glib = { .add_event = vine_event_loop_glib_add_event, }; -#endif // VINE_EVENT_LOOP_EXTERNAL_GLIB \ No newline at end of file +#endif // USE_VINE_EVENT_LOOP_EXTERNAL_GLIB \ No newline at end of file diff --git a/src/vine-event-loop.cpp b/src/vine-event-loop.cpp index e31be40..b1dacf5 100755 --- a/src/vine-event-loop.cpp +++ b/src/vine-event-loop.cpp @@ -24,70 +24,92 @@ #include "vine-log.h" #include "vine-utils.h" -static vine_event_loop_fn __event_loop; -#if defined VINE_EVENT_LOOP_EPOLL +#if defined USE_VINE_EVENT_LOOP_EPOLL extern vine_event_loop_fn vine_event_loop_epoll; #endif -#if defined VINE_EVENT_LOOP_EXTERNAL_GLIB +#if defined USE_VINE_EVENT_LOOP_EXTERNAL_GLIB extern vine_event_loop_fn vine_event_loop_glib; #endif -int vine_event_loop_init() +static vine_event_loop_fn __event_loop[] = { +#if defined USE_VINE_EVENT_LOOP_EPOLL + [VINE_EVENT_LOOP_DEFAULT] = vine_event_loop_epoll, +#endif +#if defined USE_VINE_EVENT_LOOP_EXTERNAL_GLIB + [VINE_EVENT_LOOP_EXTERNAL_GLIB] = vine_event_loop_glib, +#endif +}; + +static int __event_loop_type = 0; + +int vine_event_loop_set(vine_event_loop_e loop) { -#if defined VINE_EVENT_LOOP_EPOLL - __event_loop = vine_event_loop_epoll; -#elif defined VINE_EVENT_LOOP_EXTERNAL_GLIB - __event_loop = vine_event_loop_glib; + RET_VAL_IF(loop < VINE_EVENT_LOOP_DEFAULT || loop > VINE_EVENT_LOOP_EXTERNAL_GLIB, + VINE_ERROR_INVALID_PARAMETER, "Invalid parameter"); + +#ifndef USE_VINE_EVENT_LOOP_EPOLL + RET_VAL_IF(loop == VINE_EVENT_LOOP_DEFAULT, VINE_ERROR_INVALID_PARAMETER, + "External glib event loop is not supported"); #endif +#ifndef USE_VINE_EVENT_LOOP_EXTERNAL_GLIB + RET_VAL_IF(loop == VINE_EVENT_LOOP_EXTERNAL_GLIB, VINE_ERROR_INVALID_PARAMETER, + "External glib event loop is not supported"); +#endif + + __event_loop_type = (int)loop; + return VINE_ERROR_NONE; +} - return __event_loop.init(); +int vine_event_loop_init() +{ + return __event_loop[__event_loop_type].init(); } void vine_event_loop_deinit() { - __event_loop.deinit(); + __event_loop[__event_loop_type].deinit(); } int vine_event_loop_start() { - return __event_loop.start();; + return __event_loop[__event_loop_type].start();; } void vine_event_loop_stop() { - __event_loop.stop();; + __event_loop[__event_loop_type].stop();; } int vine_event_queue_create(vine_event_queue_h *event_queue) { - return __event_loop.event_queue_create(event_queue);; + return __event_loop[__event_loop_type].event_queue_create(event_queue);; } void vine_event_queue_destroy(vine_event_queue_h event_queue) { - __event_loop.event_queue_destroy(event_queue); + __event_loop[__event_loop_type].event_queue_destroy(event_queue); } void vine_event_loop_get_eventfd(vine_event_queue_h event_queue, int *eventfd) { - __event_loop.get_eventfd(event_queue, eventfd); + __event_loop[__event_loop_type].get_eventfd(event_queue, eventfd); } int vine_event_loop_add_io_handler( int fd, int events, vine_poll_handler handler, void *user_data) { - return __event_loop.add_io_handler(fd, events, handler, user_data); + return __event_loop[__event_loop_type].add_io_handler(fd, events, handler, user_data); } int vine_event_loop_mod_io_handler( int fd, int events, vine_poll_handler handler, void *user_data) { - return __event_loop.mod_io_handler(fd, events, handler, user_data); + return __event_loop[__event_loop_type].mod_io_handler(fd, events, handler, user_data); } int vine_event_loop_del_io_handler(int fd) { - return __event_loop.del_io_handler(fd); + return __event_loop[__event_loop_type].del_io_handler(fd); } // Register an event handler which is called in vine_event_loop_process() @@ -96,10 +118,10 @@ int vine_event_loop_add_event(vine_event_queue_h event_queue, void *event_data, vine_event_handler handler, vine_event_free_handler free_func, void *user_data) { - return __event_loop.add_event(event_queue, event_data, handler, free_func, user_data); + return __event_loop[__event_loop_type].add_event(event_queue, event_data, handler, free_func, user_data); } int vine_event_loop_process(vine_event_queue_h event_queue) { - return __event_loop.process(event_queue); + return __event_loop[__event_loop_type].process(event_queue); } diff --git a/src/vine-private.cpp b/src/vine-private.cpp index 80a322a..c2561f4 100755 --- a/src/vine-private.cpp +++ b/src/vine-private.cpp @@ -125,3 +125,14 @@ int _vine_get_capabilities(int type, int *capabilities) return VINE_ERROR_NONE; } + +int _vine_set_event_loop(vine_event_loop_e loop) +{ + VINE_LOCK(&__vine_mutex); + if (__vine_is_initialized()) { + VINE_UNLOCK(&__vine_mutex); + return VINE_ERROR_INVALID_OPERATION; + } + VINE_UNLOCK(&__vine_mutex); + return vine_event_loop_set(loop); +} \ No newline at end of file diff --git a/src/vine.cpp b/src/vine.cpp index 9c72307..f5fb50a 100755 --- a/src/vine.cpp +++ b/src/vine.cpp @@ -52,6 +52,14 @@ API int vine_get_capabilities(vine_capability_type_e type, int *capabilities) return _vine_get_capabilities(type, capabilities); } +int vine_set_event_loop(vine_event_loop_e loop) +{ + __VINE_FUNC_ENTER__; + CHECK_FEATURE_SUPPORTED; + + return _vine_set_event_loop(loop); +} + API int vine_session_get_event_fd(vine_session_h session, int *fd) { __VINE_FUNC_ENTER__; diff --git a/tests/vine-test/vine-test-glib.cpp b/tests/vine-test/vine-test-glib.cpp index 36aade2..af09216 100755 --- a/tests/vine-test/vine-test-glib.cpp +++ b/tests/vine-test/vine-test-glib.cpp @@ -96,6 +96,7 @@ static void __start_event_loop() static void __init() { PRINT_IF_ERROR(vine_initialize(), "vine_initialize()"); + PRINT_IF_ERROR(vine_set_event_loop(VINE_EVENT_LOOP_EXTERNAL_GLIB), "vine_set_event_loop"); } static void __registered_cb(vine_session_h session,