From b76d4a057b713de15f8ec3f881fdf653ace9c7e5 Mon Sep 17 00:00:00 2001 From: Cheoleun Moon Date: Fri, 2 Jul 2021 11:16:19 +0900 Subject: [PATCH] Handle unsupported functions Change-Id: I9ae35dd453129acd27dc5d6e0713724256fdad24 Signed-off-by: Cheoleun Moon --- CMakeLists.txt | 10 ++++++++-- packaging/capi-network-vine.spec | 6 +++--- plugins/ble/ble-plugin.cpp | 4 ++++ src/include/vine-event-loop.h | 4 ++-- src/vine-disc.cpp | 2 ++ src/vine-event-loop-epoll.cpp | 3 ++- src/vine-event-loop-glib.cpp | 3 ++- src/vine-event-loop.cpp | 4 ++-- src/vine-session.cpp | 16 ++++++++++++---- tool/tool_config.cpp | 0 tool/tool_run.cpp | 4 ++++ 11 files changed, 41 insertions(+), 15 deletions(-) mode change 100644 => 100755 tool/tool_config.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e0109b..eae5055 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,6 +84,12 @@ IF(TIZEN_OS) ADD_DEFINITIONS("-DTIZEN_OS -DUSE_DLOG") ENDIF(TIZEN_OS) +SET(BT_SUPPORT OFF) +IF(TIZEN_OS AND USE_EVENT_LOOP_EXTERNAL_GLIB) + ADD_DEFINITIONS("-DBT_SUPPORT") + SET(BT_SUPPORT ON) +ENDIF(TIZEN_OS AND USE_EVENT_LOOP_EXTERNAL_GLIB) + IF(ENABLE_INSTRUMENTATION_MODE) SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -finstrument-functions -finstrument-functions-exclude-file-list=src/logger") ADD_DEFINITIONS("-DENABLE_INSTRUMENTATION_MODE") @@ -119,9 +125,9 @@ IF(USE_LIBWEBSOCKETS) ENDIF(USE_LIBWEBSOCKETS) ADD_SUBDIRECTORY(plugins/dns-sd) -IF(TIZEN_OS AND USE_EVENT_LOOP_EXTERNAL_GLIB) +IF(BT_SUPPORT) ADD_SUBDIRECTORY(plugins/ble) -ENDIF(TIZEN_OS AND USE_EVENT_LOOP_EXTERNAL_GLIB) +ENDIF(BT_SUPPORT) ADD_SUBDIRECTORY(include) ADD_SUBDIRECTORY(src/logger) diff --git a/packaging/capi-network-vine.spec b/packaging/capi-network-vine.spec index 2cfa80e..1aa666a 100755 --- a/packaging/capi-network-vine.spec +++ b/packaging/capi-network-vine.spec @@ -104,12 +104,12 @@ export LDFLAGS+=" -lgcov" -DUSE_LIBWEBSOCKETS_STATIC=OFF \ %endif %if %{with lws_static_prebuilt} - -DUSE_LIBWEBSOCKETS_STATIC_PREBUILT=ON \ + -DUSE_LIBWEBSOCKETS_STATIC_PREBUILT=ON \ %else - -DUSE_LIBWEBSOCKETS_STATIC_PREBUILT=OFF \ + -DUSE_LIBWEBSOCKETS_STATIC_PREBUILT=OFF \ %endif -DWITH_UNITTEST=ON \ - -DENABLE_DATAPATH_PLUGIN_DEBUG=ON \ + -DENABLE_DATAPATH_PLUGIN_DEBUG=ON \ -DWITH_VINE_TEST=ON make %{?jobs:-j%jobs} diff --git a/plugins/ble/ble-plugin.cpp b/plugins/ble/ble-plugin.cpp index 01de78c..33f057b 100755 --- a/plugins/ble/ble-plugin.cpp +++ b/plugins/ble/ble-plugin.cpp @@ -270,6 +270,8 @@ vine_disc_error ble_publish(void *plugin_handle, const char *service_type, vine_ble_s *ble_handle = (vine_ble_s *)plugin_handle; RET_VAL_IF(ble_handle->adv != NULL, VINE_DISC_ERROR_INVALID_PARAMETER, "Already published"); + VINE_LOGD("Publish a service. plugin_handle[%p]\n", plugin_handle); + int ret = bt_adapter_le_create_advertiser(&ble_handle->adv); RET_VAL_IF(ret != BT_ERROR_NONE, __convert_ble_error_to_vine_disc_error(ret), "bt_adapter_le_create_advertiser() fails"); @@ -377,6 +379,8 @@ vine_disc_error ble_subscribe(void *plugin_handle, vine_ble_s *ble_handle = (vine_ble_s *)plugin_handle; RET_VAL_IF(ble_handle->filter != NULL, VINE_DISC_ERROR_INVALID_PARAMETER, "Already subscribed"); + VINE_LOGD("Subscribe a service. plugin_handle[%p]", plugin_handle); + int ret = bt_adapter_le_scan_filter_create(&ble_handle->filter); RET_VAL_IF(ret != BT_ERROR_NONE, __convert_ble_error_to_vine_disc_error(ret), "bt_adapter_le_scan_filter_create() fails"); diff --git a/src/include/vine-event-loop.h b/src/include/vine-event-loop.h index 48ab5b6..05379c4 100755 --- a/src/include/vine-event-loop.h +++ b/src/include/vine-event-loop.h @@ -47,7 +47,7 @@ void vine_event_loop_stop(); int vine_event_queue_create(vine_event_queue_h *event_queue); void vine_event_queue_destroy(vine_event_queue_h event_queue); -void vine_event_loop_get_eventfd(vine_event_queue_h event_queue, int *eventfd); +int vine_event_loop_get_eventfd(vine_event_queue_h event_queue, int *eventfd); int vine_event_loop_process(vine_event_queue_h event_queue); int vine_event_loop_add_io_handler(int fd, int events, @@ -68,7 +68,7 @@ typedef struct { void (*stop)(); int (*event_queue_create)(vine_event_queue_h *event_queue); void (*event_queue_destroy)(vine_event_queue_h event_queue); - void (*get_eventfd)(vine_event_queue_h event_queue, int *eventfd); + int (*get_eventfd)(vine_event_queue_h event_queue, int *eventfd); int (*process)(vine_event_queue_h event_queue); int (*add_io_handler)(int fd, int events, vine_poll_handler handler, void *user_data); int (*mod_io_handler)(int fd, int events, vine_poll_handler handler, void *user_data); diff --git a/src/vine-disc.cpp b/src/vine-disc.cpp index f967c59..01aa202 100755 --- a/src/vine-disc.cpp +++ b/src/vine-disc.cpp @@ -31,7 +31,9 @@ static struct { const char *path; } __vine_disc_plugins_info[] = { [VINE_DISCOVERY_METHOD_DNS_SD] = {"DNS-SD", DNS_SD_PLUGIN_PATH}, +#ifdef BT_SUPPORT [VINE_DISCOVERY_METHOD_BLE] = {"BLE", BLE_PLUGIN_PATH}, +#endif {NULL, NULL}, }; diff --git a/src/vine-event-loop-epoll.cpp b/src/vine-event-loop-epoll.cpp index c3beefd..e8815dd 100755 --- a/src/vine-event-loop-epoll.cpp +++ b/src/vine-event-loop-epoll.cpp @@ -179,10 +179,11 @@ void vine_event_queue_epoll_destroy(vine_event_queue_h event_queue) delete event_queue_handle; } -void vine_event_loop_epoll_get_eventfd(vine_event_queue_h event_queue, int *eventfd) +int vine_event_loop_epoll_get_eventfd(vine_event_queue_h event_queue, int *eventfd) { vine_epoll_event_queue_s *event_queue_handle = (vine_epoll_event_queue_s *)event_queue; *eventfd = event_queue_handle->fd; + return VINE_ERROR_NONE; } static void _add_io_event_handler(int fd, vine_epoll_io_event_handler *h) diff --git a/src/vine-event-loop-glib.cpp b/src/vine-event-loop-glib.cpp index eafea33..390eb51 100755 --- a/src/vine-event-loop-glib.cpp +++ b/src/vine-event-loop-glib.cpp @@ -69,8 +69,9 @@ void vine_event_queue_glib_destroy(vine_event_queue_h event_queue) { } -void vine_event_loop_glib_get_eventfd(vine_event_queue_h event_queue, int *eventfd) +int vine_event_loop_glib_get_eventfd(vine_event_queue_h event_queue, int *eventfd) { + return VINE_ERROR_NOT_SUPPORTED; } static void _add_io_event_handler(int fd, vine_glib_io_event_handler *h) diff --git a/src/vine-event-loop.cpp b/src/vine-event-loop.cpp index 84dae68..950edf0 100755 --- a/src/vine-event-loop.cpp +++ b/src/vine-event-loop.cpp @@ -90,9 +90,9 @@ void vine_event_queue_destroy(vine_event_queue_h 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) +int vine_event_loop_get_eventfd(vine_event_queue_h event_queue, int *eventfd) { - __event_loop[__event_loop_type].get_eventfd(event_queue, eventfd); + return __event_loop[__event_loop_type].get_eventfd(event_queue, eventfd); } int vine_event_loop_add_io_handler( diff --git a/src/vine-session.cpp b/src/vine-session.cpp index 599a349..6ca5d53 100755 --- a/src/vine-session.cpp +++ b/src/vine-session.cpp @@ -166,8 +166,11 @@ int _vine_session_unset_discovered_cb(vine_session_h session) static bool __check_disc_method(vine_discovery_method_e method) { - return method >= VINE_DISCOVERY_METHOD_DNS_SD - && method <= VINE_DISCOVERY_METHOD_BLE; + bool ret = (method == VINE_DISCOVERY_METHOD_DNS_SD); +#ifdef BT_SUPPORT + ret = ret || (method == VINE_DISCOVERY_METHOD_BLE); +#endif + return ret; } int _vine_session_set_discovery_method(vine_session_h session, vine_discovery_method_e method) @@ -399,6 +402,8 @@ int _vine_session_set_ip_resolved_cb(vine_session_h session, int ret = VINE_ERROR_NONE; vine_session_s *s = (vine_session_s *)session; + RET_VAL_IF(s->disc_method == VINE_DISCOVERY_METHOD_BLE, VINE_ERROR_NOT_SUPPORTED, + "BLE discovery doesn't support vine_session_set_ip_resolved_cb()"); vine_disc_h disc_handle; ret = vine_disc_create(s->disc_method, &disc_handle); RET_VAL_IF(ret != VINE_ERROR_NONE, ret, "Fail to vine_disc_create"); @@ -425,6 +430,10 @@ int _vine_session_unset_ip_resolved_cb(vine_session_h session, VINE_LOGD("Cancel resolving IP address for a service[%p]. session[%p]", service, session); + vine_session_s *s = (vine_session_s *)session; + RET_VAL_IF(s->disc_method == VINE_DISCOVERY_METHOD_BLE, VINE_ERROR_NOT_SUPPORTED, + "BLE discovery doesn't support vine_session_unset_ip_resolved_cb()"); + int ret = VINE_ERROR_NONE; vine_disc_h disc_handle = NULL; ret = _vine_service_get_disc_handle(service, VINE_DISCOVERY_METHOD_DNS_SD, &disc_handle); @@ -452,8 +461,7 @@ int _vine_session_get_event_fd(vine_session_h session, int *fd) RET_VAL_IF(session == NULL, VINE_ERROR_INVALID_PARAMETER, "session is NULL"); vine_session_s *s = (vine_session_s *)session; - vine_event_loop_get_eventfd(s->event_queue, fd); - return VINE_ERROR_NONE; + return vine_event_loop_get_eventfd(s->event_queue, fd); } int _vine_session_process_event(vine_session_h session) diff --git a/tool/tool_config.cpp b/tool/tool_config.cpp old mode 100644 new mode 100755 diff --git a/tool/tool_run.cpp b/tool/tool_run.cpp index db3952a..c76cadd 100755 --- a/tool/tool_run.cpp +++ b/tool/tool_run.cpp @@ -610,6 +610,7 @@ static void _event_handler(vine_session_h session) vine_session_process_event(session); } +#ifdef BT_SUPPORT static void _run_glib_event_loop() { GMainLoop *main_loop = g_main_loop_new(NULL, FALSE); @@ -618,6 +619,7 @@ static void _run_glib_event_loop() g_main_loop_unref(main_loop); } +#endif static void _run_epoll_event_loop(vine_session_h session) { int fd; @@ -658,9 +660,11 @@ static void _run_epoll_event_loop(vine_session_h session) static void run_event_loop(vine_session_h session) { +#ifdef BT_SUPPORT if (vine_configs.with_ble) _run_glib_event_loop(); else +#endif _run_epoll_event_loop(session); } -- 2.7.4