From: Jaehyun Kim Date: Fri, 23 Feb 2018 08:27:23 +0000 (+0900) Subject: Added CAPIs for C# thread handling X-Git-Tag: accepted/tizen/unified/20180227.062948^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=67587ba4d830b7906db5e20f516b5b4b79604d48;p=platform%2Fcore%2Fapi%2Fconnection.git Added CAPIs for C# thread handling It is not guaranteed that the GC in C# will call connection_destroy on the thread that called connection_create. So I added thread-independent CAPIs for init/deinit. Change-Id: Ia70fdc543b06c34611643a702aa43377ad144365 Signed-off-by: Jaehyun Kim --- diff --git a/include/connection_extension.h b/include/connection_extension.h index 0a8cd15..9ad8ef6 100755 --- a/include/connection_extension.h +++ b/include/connection_extension.h @@ -65,6 +65,36 @@ int connection_profile_stop_tcpdump(connection_h connection); */ int connection_profile_get_tcpdump_state(connection_h connection, gboolean *tcpdump_state); +/** + * @brief Creates a handle for managing data connections in C# API. + * @since_tizen 5.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/network.get + * @remarks You must release @a handle using connection_destroy_cs(). + * @param[in] tid TID in C# + * @param[out] connection The connection handle + * @return @c 0 on success, + * otherwise a negative error value + * @retval #CONNECTION_ERROR_NONE Successful + * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONNECTION_ERROR_OUT_OF_MEMORY Out of memory + * @retval #CONNECTION_ERROR_PERMISSION_DENIED Permission denied + * @see connection_destroy_cs() + */ +int connection_create_cs(int tid, connection_h *connection); + +/** + * @brief Destroys the connection handle in C# API. + * @since_tizen 5.0 + * @param[in] tid TID in C# + * @param[in] connection The connection handle + * @return @c 0 on success, + * otherwise a negative error value + * @retval #CONNECTION_ERROR_NONE Successful + * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter + * @see connection_create_cs() + */ +int connection_destroy_cs(int tid, connection_h connection); typedef enum { CONNECTION_MPTCP_DISABLE = 0, diff --git a/include/net_connection_private.h b/include/net_connection_private.h index 3f3f4ba..2c60aaa 100755 --- a/include/net_connection_private.h +++ b/include/net_connection_private.h @@ -125,6 +125,8 @@ bool _connection_is_created(void); int _connection_libnet_init(void); bool _connection_libnet_deinit(void); +void _connection_set_cs_tid(int tid); +void _connection_unset_cs_tid(int tid); int _connection_libnet_get_metered_state(bool* is_metered); int _connection_libnet_get_wifi_state(connection_wifi_state_e *state); int _connection_libnet_get_ethernet_state(connection_ethernet_state_e *state); diff --git a/packaging/capi-network-connection.spec b/packaging/capi-network-connection.spec index 8244508..4bb9ac4 100755 --- a/packaging/capi-network-connection.spec +++ b/packaging/capi-network-connection.spec @@ -1,6 +1,6 @@ Name: capi-network-connection Summary: Network Connection library in TIZEN C API -Version: 1.0.109 +Version: 1.0.110 Release: 1 Group: System/Network License: Apache-2.0 diff --git a/src/connection.c b/src/connection.c index 76147ab..4ae5640 100755 --- a/src/connection.c +++ b/src/connection.c @@ -424,6 +424,28 @@ EXPORT_API int connection_destroy(connection_h connection) return CONNECTION_ERROR_NONE; } +EXPORT_API int connection_create_cs(int tid, connection_h *connection) +{ + int rv; + + rv = connection_create(connection); + + if (rv == CONNECTION_ERROR_NONE) + _connection_set_cs_tid(tid); + + return rv; +} + +EXPORT_API int connection_destroy_cs(int tid, connection_h connection) +{ + int rv; + + _connection_unset_cs_tid(tid); + rv = connection_destroy(connection); + + return rv; +} + EXPORT_API int connection_get_type(connection_h connection, connection_type_e* type) { int rv = 0; diff --git a/src/libnetwork.c b/src/libnetwork.c index 64ef839..c5d2433 100755 --- a/src/libnetwork.c +++ b/src/libnetwork.c @@ -615,6 +615,16 @@ bool _connection_libnet_deinit(void) return true; } +void _connection_set_cs_tid(int tid) +{ + net_set_cs_tid(tid); +} + +void _connection_unset_cs_tid(int tid) +{ + net_unset_cs_tid(tid); +} + bool _connection_libnet_check_profile_validity(connection_profile_h profile) { GSList *list; diff --git a/test/connection_test.c b/test/connection_test.c index 2abebf0..350bae9 100755 --- a/test/connection_test.c +++ b/test/connection_test.c @@ -1029,6 +1029,65 @@ int test_deregister_client(void) return 1; } +int test_register_client_cs(void) +{ + int tid = 0; + test_get_user_int("Input a TID in C# API :", &tid); + + int err = connection_create_cs(tid, &connection); + + if (CONNECTION_ERROR_NONE == err) { + connection_set_type_changed_cb(connection, test_type_changed_callback, NULL); + connection_set_ip_address_changed_cb(connection, test_ip_changed_callback, NULL); + connection_set_proxy_address_changed_cb(connection, test_proxy_changed_callback, NULL); + connection_set_ethernet_cable_state_chaged_cb(connection, + test_get_ethernet_cable_state_callback, NULL); + } else { + printf("Client registration failed [%s]\n", test_print_error(err)); + return -1; + } + + printf("Client registration success\n"); + return 1; +} + +int test_deregister_client_cs(void) +{ + int rv = 0; + GSList *list; + connection_profile_h profile; + int tid = 0; + + test_get_user_int("Input a TID in C# API :", &tid); + + if (connection != NULL) + rv = connection_destroy_cs(tid, connection); + else { + printf("Cannot deregister : Handle is NULL\n"); + rv = CONNECTION_ERROR_INVALID_OPERATION; + } + + if (rv != CONNECTION_ERROR_NONE) { + printf("Client deregistration fail [%s]\n", test_print_error(rv)); + return -1; + } + + if (state_cb_list) { + for (list = state_cb_list; list; list = list->next) { + profile = list->data; + connection_profile_destroy(profile); + } + + g_slist_free(state_cb_list); + state_cb_list = NULL; + } + + connection = NULL; + printf("Client deregistration success\n"); + + return 1; +} + int test_get_network_state(void) { int rv = 0; @@ -2398,6 +2457,8 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) printf("N - Get MPTCP Path Manager (internal)\n"); printf("O - Set MPTCP Scheduler (internal)\n"); printf("P - Get MPTCP Scheduler (internal)\n"); + printf(LOG_GREEN "Q - Create Handle and set callbacks in C# API\n" LOG_END); + printf("R - Destroy Handle(unset callbacks automatically in C# API)\n"); printf(LOG_RED "0 - Exit \n" LOG_END); printf("ENTER - Show options menu.......\n"); } @@ -2549,6 +2610,12 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) case 'P': rv = test_mptcp_get_scheduler(); break; + case 'Q': + rv = test_register_client_cs(); + break; + case 'R': + rv = test_deregister_client_cs(); + break; }