Added CAPIs for C# thread handling 76/171076/1 submit/tizen_4.0/20180226.110141
authorJaehyun Kim <jeik01.kim@samsung.com>
Mon, 26 Feb 2018 09:20:48 +0000 (18:20 +0900)
committerJaehyun Kim <jeik01.kim@samsung.com>
Mon, 26 Feb 2018 09:24:07 +0000 (18:24 +0900)
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: I9f85182b72278e06c4daef04b34180f664d79e02
Signed-off-by: Jaehyun Kim <jeik01.kim@samsung.com>
include/connection_extension.h [new file with mode: 0755]
include/net_connection_private.h
packaging/capi-network-connection.spec
src/connection.c
src/libnetwork.c
test/connection_test.c

diff --git a/include/connection_extension.h b/include/connection_extension.h
new file mode 100755 (executable)
index 0000000..f853b97
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __TIZEN_NETWORK_CONNECTION_EXTENSION_H__
+#define __TIZEN_NETWORK_CONNECTION_EXTENSION_H__
+
+#include "net_connection.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file connection_extension.h
+ */
+
+/**
+ * @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);
+
+/**
+* @}
+*/
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+
+#endif /* __TIZEN_NETWORK_CONNECTION_EXTENSION_H__ */
index 797893fbc5917ef6002bf4128ffc18df66a4a332..8fd51022c1b4efe6096c02dd942e2574839f1a4c 100755 (executable)
@@ -118,6 +118,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);
index 0e5f6915fba8659276f8807cc8c5283444f9ae9c..82445081f31f9ae91e69c1830d49d01988652fcf 100755 (executable)
@@ -1,6 +1,6 @@
 Name:          capi-network-connection
 Summary:       Network Connection library in TIZEN C API
-Version:       1.0.108
+Version:       1.0.109
 Release:       1
 Group:         System/Network
 License:       Apache-2.0
index 9c09e550a5d20315646b42d9abc71e156b65407c..9fcab100799de964cf45aeb83fe3c635a1b061d4 100755 (executable)
@@ -478,6 +478,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;
index 9e5b09a7fddb207b9289711043dab3e8b19b7beb..644c708c21c4593d45822ef248fae40e2e9891e3 100755 (executable)
@@ -572,6 +572,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;
index 815a9182b70b19af7a97a7a34242a4e1fdccea6c..a02efcdb5d044afc126b47a3d2bd5153102a99d4 100755 (executable)
@@ -1006,6 +1006,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;
@@ -2199,6 +2258,8 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
                printf("E   - Remove route entry\n");
                printf("F   - Get all IPv6 address\n");
                printf("G   - Get metered state\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");
        }
@@ -2321,6 +2382,13 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
        case 'G':
                rv = test_is_metered_network();
                break;
+       case 'Q':
+               rv = test_register_client_cs();
+               break;
+       case 'R':
+               rv = test_deregister_client_cs();
+               break;
+
        }
 
        if (rv == 1)