Merge "Add test program" into tizen
authorJiung Yu <jiung.yu@samsung.com>
Sun, 30 Aug 2020 23:01:15 +0000 (23:01 +0000)
committerGerrit Code Review <gerrit@review>
Sun, 30 Aug 2020 23:01:15 +0000 (23:01 +0000)
1  2 
src/uwb.c

diff --combined src/uwb.c
+++ b/src/uwb.c
@@@ -37,7 -37,7 +37,7 @@@ static struct _uwb_ctx 
        void *message_received_user_data;
        uwb_position_changed_cb position_changed_cb;
        void *position_changed_user_data;
-       uwb_network_get_finished_cb network_get_finished_cb;
+       uwb_get_network_finished_cb get_network_finished_cb;
        uwb_network_foreach_remote_node_cb foreach_remote_node_cb;
  } uwb_ctx = {NULL,};
  
@@@ -80,15 -80,10 +80,15 @@@ static void __message_received(GObject 
        unsigned char *buf = NULL;
        int size = 0;
  
 +      buf = (unsigned char *)malloc(sizeof(unsigned char) * size + 1);
 +      if (buf == NULL) {
 +              _ERR("buf is NULL");
 +              return;
 +      }
 +
        g_variant_get(message, "a(y)", &iter);
        size = g_variant_iter_n_children(iter);
  
 -      buf = (unsigned char *)malloc(sizeof(unsigned char) * size + 1);
        for (int i = 0; g_variant_iter_loop(iter, "(y)", &element); i++)
        {
                buf[i] = element;
@@@ -112,7 -107,7 +112,7 @@@ static void __position_changed(GObject 
                uwb_ctx.position_changed_cb(node_id, x, y, z, uwb_ctx.position_changed_user_data);
  }
  
- static int manager_proxy_init()
+ static int manager_proxy_init(void)
  {
        GError *error = NULL;
  
        return UWB_ERROR_NONE;
  }
  
- static void manager_proxy_deinit()
+ static void manager_proxy_deinit(void)
  {
        g_object_unref(uwb_ctx.manager_proxy);
        uwb_ctx.manager_proxy = NULL;
  }
  
- EXPORT_API int uwb_initialize()
+ EXPORT_API int uwb_initialize(void)
  {
        int ret = UWB_ERROR_NONE;
  
        return ret;
  }
  
- EXPORT_API int uwb_deinitialize()
+ EXPORT_API int uwb_deinitialize(void)
  {
        int ret = UWB_ERROR_NONE;
  
        return ret;
  }
  
- EXPORT_API int uwb_reset()
+ EXPORT_API int uwb_reset(void)
  {
        int ret = UWB_ERROR_NONE;
        GError *error = NULL;
        return ret;
  }
  
- EXPORT_API int uwb_factory_reset()
+ EXPORT_API int uwb_factory_reset(void)
  {
        int ret = UWB_ERROR_NONE;
        GError *error = NULL;
@@@ -252,7 -247,7 +252,7 @@@ EXPORT_API int uwb_set_position_changed
        return ret;
  }
  
- EXPORT_API int uwb_unset_message_received_cb()
+ EXPORT_API int uwb_unset_message_received_cb(void)
  {
        int ret = UWB_ERROR_NONE;
  
        return ret;
  }
  
- EXPORT_API int uwb_unset_position_changed_cb()
+ EXPORT_API int uwb_unset_position_changed_cb(void)
  {
        int ret = UWB_ERROR_NONE;
  
@@@ -304,7 -299,7 +304,7 @@@ EXPORT_API int uwb_get_own_node(uwb_nod
        }
  
        if (ret == UWB_ERROR_NONE && own_node_va != NULL)
-               *_own_node = uwb_get_node_from_variant(own_node_va);
+               *_own_node = uwb_util_get_node_from_variant(own_node_va);
        else
                *_own_node = NULL;
  
@@@ -330,8 -325,8 +330,8 @@@ static void __network_get_cb(GObject *s
                        _ERR("manager_call_get_network_info_finish failed : %s", error->message);
                        __handle_error(error, &ret);
  
-                       if (uwb_ctx.network_get_finished_cb != NULL) {
-                               uwb_ctx.network_get_finished_cb(ret, NULL, user_data);
+                       if (uwb_ctx.get_network_finished_cb != NULL) {
+                               uwb_ctx.get_network_finished_cb(ret, NULL, user_data);
                        }
  
                        return;
                        while ((nodes_va = g_variant_iter_next_value(iter)) != NULL) {
                                uwb_node_s *node;
  
-                               node = uwb_get_node_from_variant(nodes_va);
+                               node = uwb_util_get_node_from_variant(nodes_va);
                                node->is_remote = true;
  
                                _DBG("(%d, %d, %d)", node->x, node->y, node->z);
                g_variant_unref(remote_node_list_va);
        }
  
-       if (uwb_ctx.network_get_finished_cb != NULL) {
-               uwb_ctx.network_get_finished_cb(ret, (uwb_network_h)network_s, user_data);
+       if (uwb_ctx.get_network_finished_cb != NULL) {
+               uwb_ctx.get_network_finished_cb(ret, (uwb_network_h)network_s, user_data);
        }
  }
  
- EXPORT_API int uwb_network_get(uwb_network_get_finished_cb finished_cb, void *user_data)
+ EXPORT_API int uwb_network_get(uwb_get_network_finished_cb finished_cb, void *user_data)
  {
        int ret = UWB_ERROR_NONE;
  
  
        uwb_check_null_ret_error("finished_cb", finished_cb, UWB_ERROR_INVALID_PARAMETER);
  
-       uwb_ctx.network_get_finished_cb = finished_cb;
+       uwb_ctx.get_network_finished_cb = finished_cb;
  
        manager_call_get_network_info(uwb_ctx.manager_proxy, NULL, __network_get_cb, user_data);
  
        return ret;
  }
  
+ static gpointer __copy_node(gconstpointer src, gpointer data)
+ {
+       if (!src)
+               return NULL;
+       uwb_node_s *src_ptr = (uwb_node_s *)src;
+       uwb_node_s *dst_ptr = (uwb_node_s *)malloc(sizeof(uwb_node_s));
+       if (!dst_ptr)
+               return NULL;
+       dst_ptr->node_id = src_ptr->node_id;
+       dst_ptr->pan_id = src_ptr->pan_id;
+       dst_ptr->is_remote = src_ptr->is_remote;
+       dst_ptr->distance = src_ptr->distance;
+       dst_ptr->x = src_ptr->x;
+       dst_ptr->y = src_ptr->y;
+       dst_ptr->z = src_ptr->z;
+       return (gpointer)dst_ptr;
+ }
  EXPORT_API int uwb_network_clone(uwb_network_h source, uwb_network_h *target)
  {
+       uwb_network_s *result_network = NULL;
+       uwb_network_s *src_network = (uwb_network_s *)source;
+       GSList *remote_node_list = NULL;
        int ret = UWB_ERROR_NONE;
  
        CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
  
        _BEGIN();
  
+       uwb_check_null_ret_error("source", source, UWB_ERROR_INVALID_PARAMETER);
+       result_network = (uwb_network_s *)malloc(sizeof(uwb_network_s));
+       if (result_network == NULL) {
+               _ERR("malloc failed");
+               return UWB_ERROR_OPERATION_FAILED;
+       }
+       result_network->pan_id = src_network->pan_id;
+       result_network->remote_node_count = src_network->remote_node_count;
+       remote_node_list = src_network->remote_node_list;
+       result_network->remote_node_list = g_slist_copy_deep(remote_node_list,
+                       __copy_node,
+                       NULL);
        _END();
  
+       *target = result_network;
        return ret;
  }
  
@@@ -414,7 -450,7 +455,7 @@@ EXPORT_API int uwb_network_destroy(uwb_
  
        uwb_check_null_ret_error("network", network, UWB_ERROR_INVALID_PARAMETER);
  
-       uwb_network_clean(network);
+       uwb_util_destroy_network(network);
  
        _END();