Fix set/get configuration API 61/242561/1
authorYu <jiung.yu@samsung.com>
Fri, 28 Aug 2020 02:01:53 +0000 (11:01 +0900)
committerYu <jiung.yu@samsung.com>
Fri, 28 Aug 2020 02:02:06 +0000 (11:02 +0900)
Change-Id: I4fb0b0ccf154edc21067404fcce0e232edf3939f
Signed-off-by: Yu jiung <jiung.yu@samsung.com>
CMakeLists.txt
include/uwb.h
packaging/capi-network-uwb.spec
src/uwb.c
tests/capi-network-uwb-test.c

index 516c32f..b430e62 100644 (file)
@@ -39,3 +39,4 @@ ADD_DEFINITIONS("-DUSE_DLOG")
 ADD_SUBDIRECTORY(include)
 ADD_SUBDIRECTORY(pkgconfig)
 ADD_SUBDIRECTORY(src)
+ADD_SUBDIRECTORY(tests)
index e0edd16..3717eb8 100755 (executable)
@@ -59,6 +59,15 @@ int uwb_set_message_received_cb(uwb_message_received_cb message_received_cb, voi
 int uwb_set_position_changed_cb(uwb_position_changed_cb position_changed_cb, void *user_data);
 int uwb_unset_message_received_cb(void);
 int uwb_unset_position_changed_cb(void);
+int uwb_node_set_position(uwb_node_h node, int x, int y, int z);
+int uwb_node_send_message(const unsigned char *message, int len);
+int uwb_node_send_message_to(uwb_node_h node, const unsigned char *message, int len);
+int uwb_node_get_configuration_int32(uwb_node_h node, const char *key, int32_t *value);
+int uwb_node_set_configuration_int32(uwb_node_h node, const char *key, int32_t value);
+int uwb_node_get_configuration_int64(uwb_node_h node, const char *key, int64_t *value);
+int uwb_node_set_configuration_int64(uwb_node_h node, const char *key, int64_t value);
+int uwb_node_get_configuration_string(uwb_node_h node, const char *key, char **value);
+int uwb_node_set_configuration_string(uwb_node_h node, const char *key, const char *value);
 int uwb_get_own_node(uwb_node_h *own_node);
 int uwb_get_network(uwb_get_network_finished_cb finished_cb, void *user_data);
 int uwb_network_clone(uwb_network_h source, uwb_network_h *target);
@@ -73,15 +82,6 @@ int uwb_node_get_node_id(uwb_node_h node, uint64_t *node_id);
 int uwb_node_get_pan_id(uwb_node_h node, uint64_t *pan_id);
 int uwb_node_get_is_remote(uwb_node_h node, bool *is_remote);
 int uwb_node_get_position(uwb_node_h node, int *x, int *y, int *z);
-int uwb_node_set_position(uwb_node_h node, int x, int y, int z);
-int uwb_node_send_message(const unsigned char *message, int len);
-int uwb_node_send_message_to(uwb_node_h node, const unsigned char *message, int len);
-int uwb_node_get_configuration_int32(uwb_node_h node, char *key, int32_t *value);
-int uwb_node_set_configuration_int32(uwb_node_h node, char *key, int32_t value);
-int uwb_node_get_configuration_int64(uwb_node_h node, char *key, int64_t *value);
-int uwb_node_set_configuration_int64(uwb_node_h node, char *key, int64_t value);
-int uwb_node_get_configuration_string(uwb_node_h node, char *key, const char **value);
-int uwb_node_set_configuration_string(uwb_node_h node, char *key, const char *value);
 
 #ifdef __cplusplus
 }
index 48b5eee..25a9794 100644 (file)
@@ -116,7 +116,7 @@ genhtml %{name}.info -o out --legend --show-details
 %{_includedir}/*.h
 
 %files tests
-#%{_bindir}/%{name}-test
+%{_bindir}/%{name}-test
 #%{_bindir}/%{name}-gtest
 
 %if 0%{?gcov:1}
index 1be4838..50851e9 100755 (executable)
--- a/src/uwb.c
+++ b/src/uwb.c
@@ -308,219 +308,280 @@ EXPORT_API int uwb_get_own_node(uwb_node_h *own_node)
        return ret;
 }
 
-static void __network_get_cb(GObject *source_object, GAsyncResult *res, gpointer user_data)
+EXPORT_API int uwb_node_set_position(uwb_node_h node, int x, int y, int z)
 {
        int ret = UWB_ERROR_NONE;
-       uint16_t pan_id = 0;
-       GVariant *remote_node_list_va = NULL;
        GError *error = NULL;
-       uwb_network_s *network_s;
 
-       if (manager_call_get_network_info_finish(
-                       MANAGER(source_object),
-                       &pan_id,
-                       &remote_node_list_va,
-                       res,
-                       &error) == FALSE) {
-                       _ERR("manager_call_get_network_info_finish failed : %s", error->message);
-                       __handle_error(error, &ret);
+       CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
+       CHECK_NOT_INITIALIZED();
 
-                       if (uwb_ctx.get_network_finished_cb != NULL) {
-                               uwb_ctx.get_network_finished_cb(ret, NULL, user_data);
-                       }
+       _BEGIN();
 
-                       return;
+       uwb_check_null_ret_error("node", node, UWB_ERROR_INVALID_PARAMETER);
+
+       if (manager_call_set_position_sync(uwb_ctx.manager_proxy,
+               ((uwb_node_s *)node)->node_id, x, y, z, NULL, &error) == FALSE) {
+               _ERR("manager_call_set_position_sync failed : %s", error->message);
+               __handle_error(error, &ret);
        }
 
-       /* create network handle */
-       network_s = (uwb_network_s *)malloc(sizeof(uwb_network_s));
+       _END();
 
-       if (ret == UWB_ERROR_NONE) {
-               GSList *remote_node_list = NULL;
-               network_s->pan_id = pan_id;
-               network_s->remote_node_count = g_variant_n_children(remote_node_list_va);
+       return ret;
+}
 
-               if (network_s->remote_node_count > 0) {
-                       GVariantIter *iter = NULL;
-                       GVariant *nodes_va = NULL;
+static GVariant *__data_to_variant(const unsigned char *data, int length)
+{
+       GVariantBuilder builder;
 
-                       g_variant_get(remote_node_list_va, "aa{sv}", &iter);
-                       while ((nodes_va = g_variant_iter_next_value(iter)) != NULL) {
-                               uwb_node_s *node;
+       g_variant_builder_init(&builder, G_VARIANT_TYPE("a(y)"));
 
-                               node = uwb_util_get_node_from_variant(nodes_va);
-                               node->is_remote = true;
+       if (data && length > 0)
+       {
+               for(int i = 0; i < length; i++)
+                       g_variant_builder_add(&builder, "(y)", *(data + i));
+       }
 
-                               _DBG("(%d, %d, %d)", node->x, node->y, node->z);
-                               remote_node_list = g_slist_append(remote_node_list, node);
-                       }
-                       g_variant_iter_free(iter);
-               }
-               network_s->remote_node_list = remote_node_list;
+       return g_variant_builder_end(&builder);
+}
 
-               g_variant_unref(remote_node_list_va);
-       }
+EXPORT_API int uwb_node_send_message(const unsigned char *message, int len)
+{
+       int ret = UWB_ERROR_NONE;
+       GVariant *msg = NULL;
+       GError *error = NULL;
 
-       if (uwb_ctx.get_network_finished_cb != NULL) {
-               uwb_ctx.get_network_finished_cb(ret, (uwb_network_h)network_s, user_data);
+       CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
+       CHECK_NOT_INITIALIZED();
+
+       _BEGIN();
+
+       uwb_check_null_ret_error("message", message, UWB_ERROR_INVALID_PARAMETER);
+       cond_expr_ret(len <= 0, UWB_ERROR_INVALID_PARAMETER);
+
+       msg = __data_to_variant(message, len);
+
+       if (manager_call_send_message_sync(uwb_ctx.manager_proxy,
+               msg, len, NULL, &error) == FALSE) {
+               _ERR("manager_call_send_message_sync failed : %s", error->message);
+               __handle_error(error, &ret);
        }
+
+       _END();
+
+       return ret;
 }
 
-EXPORT_API int uwb_network_get(uwb_get_network_finished_cb finished_cb, void *user_data)
+EXPORT_API int uwb_node_send_message_to(uwb_node_h node, const unsigned char *message, int len)
 {
        int ret = UWB_ERROR_NONE;
+       GVariant *msg = NULL;
+       GError *error = NULL;
 
        CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
        CHECK_NOT_INITIALIZED();
 
        _BEGIN();
 
-       uwb_check_null_ret_error("finished_cb", finished_cb, UWB_ERROR_INVALID_PARAMETER);
+       uwb_check_null_ret_error("node", node, UWB_ERROR_INVALID_PARAMETER);
+       uwb_check_null_ret_error("message", message, UWB_ERROR_INVALID_PARAMETER);
+       cond_expr_ret(len <= 0, UWB_ERROR_INVALID_PARAMETER);
 
-       uwb_ctx.get_network_finished_cb = finished_cb;
+       msg = __data_to_variant(message, len);
 
-       manager_call_get_network_info(uwb_ctx.manager_proxy, NULL, __network_get_cb, user_data);
+       if (manager_call_send_message_to_sync(uwb_ctx.manager_proxy, ((uwb_node_s *)node)->node_id,
+               msg, len, NULL, &error) == FALSE) {
+               _ERR("manager_call_send_message_to_sync failed : %s", error->message);
+               __handle_error(error, &ret);
+       }
 
        _END();
 
        return ret;
 }
 
-
-static gpointer __copy_node(gconstpointer src, gpointer data)
+static int __get_configurations(uwb_node_h node, const char *key,
+       const GVariantType *va_type, GVariant **va_out)
 {
-       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;
+       int ret = UWB_ERROR_NONE;
+       GError *error = NULL;
+       GVariant *va = 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;
+       if (manager_call_get_configurations_sync(uwb_ctx.manager_proxy,
+               ((uwb_node_s *)node)->node_id, &va, NULL, &error) == FALSE) {
+               _ERR("__get_configurations failed : %s", error->message);
+               __handle_error(error, &ret);
+       } else {
+               *va_out = g_variant_lookup_value(va, key, va_type);
+       }
 
-       return (gpointer)dst_ptr;
+       return ret;
 }
 
-EXPORT_API int uwb_network_clone(uwb_network_h source, uwb_network_h *target)
+EXPORT_API int uwb_node_get_configuration_int32(uwb_node_h node, const char *key, int32_t *value)
 {
-       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;
+       GVariant *value_va = NULL;
 
        CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
+       CHECK_NOT_INITIALIZED();
 
        _BEGIN();
 
-       uwb_check_null_ret_error("source", source, UWB_ERROR_INVALID_PARAMETER);
+       uwb_check_null_ret_error("node", node, 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;
-       }
+       ret = __get_configurations(node, key, G_VARIANT_TYPE_INT32, &value_va);
 
-       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);
+       if (value_va != NULL)
+               *value = g_variant_get_int32(value_va);
+       else
+               *value = 0;
 
        _END();
 
-       *target = result_network;
        return ret;
 }
 
-EXPORT_API int uwb_network_destroy(uwb_network_h network)
+EXPORT_API int uwb_node_get_configuration_int64(uwb_node_h node, const char *key, int64_t *value)
 {
        int ret = UWB_ERROR_NONE;
+       GVariant *value_va = NULL;
 
        CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
+       CHECK_NOT_INITIALIZED();
 
        _BEGIN();
 
-       uwb_check_null_ret_error("network", network, UWB_ERROR_INVALID_PARAMETER);
+       uwb_check_null_ret_error("node", node, UWB_ERROR_INVALID_PARAMETER);
 
-       uwb_util_destroy_network(network);
+       ret = __get_configurations(node, key, G_VARIANT_TYPE_INT64, &value_va);
+
+       if (value_va != NULL)
+               *value = g_variant_get_int64(value_va);
+       else
+               *value = 0;
 
        _END();
 
        return ret;
 }
 
-EXPORT_API int uwb_network_get_pan_id(uwb_network_h network, uint64_t *pan_id)
+EXPORT_API int uwb_node_get_configuration_string(uwb_node_h node, const char *key, char **value)
 {
        int ret = UWB_ERROR_NONE;
+       GVariant *value_va = NULL;
+       const char *value_str = NULL;
 
        CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
+       CHECK_NOT_INITIALIZED();
 
        _BEGIN();
 
-       uwb_check_null_ret_error("network", network, UWB_ERROR_INVALID_PARAMETER);
-       uwb_check_null_ret_error("pan_id", pan_id, UWB_ERROR_INVALID_PARAMETER);
+       uwb_check_null_ret_error("node", node, UWB_ERROR_INVALID_PARAMETER);
 
-       *pan_id = ((uwb_network_s *)network)->pan_id;
+       ret = __get_configurations(node, key, G_VARIANT_TYPE_STRING, &value_va);
+
+       if (value_va != NULL)
+               value_str = g_variant_get_string(value_va, NULL);
+       else
+               value_str = NULL;
 
        _END();
 
+       if (value_str && strlen(value_str) != 0)
+               *value = strdup(value_str);
        return ret;
 }
 
-EXPORT_API int uwb_network_get_remote_node_count(uwb_network_h network, int *remote_node_count)
+static int __set_configuration(uwb_node_h node, GVariant *va)
+{
+       int ret = UWB_ERROR_NONE;
+       GError *error = NULL;
+
+       if (manager_call_set_configurations_sync(uwb_ctx.manager_proxy, ((uwb_node_s *)node)->node_id,
+               va, NULL, &error) == FALSE) {
+               _ERR("__set_configurations : %s", error->message);
+               __handle_error(error, &ret);
+       }
+
+       return ret;
+}
+
+static GVariant *__build_configuration(const char *key, GVariant *value)
+{
+       GVariant *va = NULL;
+       GVariantBuilder *builder;
+
+       builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+       g_variant_builder_add(builder, "{sv}", key, value);
+       va = g_variant_new("a{sv}", builder);
+       g_variant_builder_unref(builder);
+
+       return va;
+}
+
+EXPORT_API int uwb_node_set_configuration_int32(uwb_node_h node, const char *key, int32_t value)
 {
        int ret = UWB_ERROR_NONE;
+       GVariant *configuration = NULL;
 
        CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
+       CHECK_NOT_INITIALIZED();
 
        _BEGIN();
 
-       uwb_check_null_ret_error("network", network, UWB_ERROR_INVALID_PARAMETER);
-       uwb_check_null_ret_error("remote_node_count", remote_node_count, UWB_ERROR_INVALID_PARAMETER);
+       uwb_check_null_ret_error("node", node, UWB_ERROR_INVALID_PARAMETER);
+       uwb_check_null_ret_error("key", key, UWB_ERROR_INVALID_PARAMETER);
 
-       *remote_node_count = ((uwb_network_s *)network)->remote_node_count;
+       configuration = __build_configuration(key, g_variant_new_int32(value));
+
+       ret = __set_configuration(node, configuration);
 
        _END();
 
        return ret;
 }
 
-static void __foreach_node(gpointer data, gpointer user_data)
+EXPORT_API int uwb_node_set_configuration_int64(uwb_node_h node, const char *key, int64_t value)
 {
-       uwb_node_s *node = (uwb_node_s *)data;
-       _DBG("panid : 0x%X, nodeid : 0x%04"PRIX64", distance : %"PRId64"", node->pan_id, node->node_id, node->distance);
+       int ret = UWB_ERROR_NONE;
+       GVariant *configuration = NULL;
 
-       if (uwb_ctx.foreach_remote_node_cb != NULL)
-               uwb_ctx.foreach_remote_node_cb((uwb_node_h)node, user_data);
+       CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
+       CHECK_NOT_INITIALIZED();
+
+       _BEGIN();
+
+       uwb_check_null_ret_error("node", node, UWB_ERROR_INVALID_PARAMETER);
+       uwb_check_null_ret_error("key", key, UWB_ERROR_INVALID_PARAMETER);
+
+       configuration = __build_configuration(key, g_variant_new_int64(value));
+
+       ret = __set_configuration(node, configuration);
+
+       _END();
+
+       return ret;
 }
 
-EXPORT_API int uwb_network_foreach_remote_node(uwb_network_h network,
-       uwb_network_foreach_remote_node_cb node_cb, void *user_data)
+EXPORT_API int uwb_node_set_configuration_string(uwb_node_h node, const char *key, const char *value)
 {
        int ret = UWB_ERROR_NONE;
+       GVariant *configuration = NULL;
 
        CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
+       CHECK_NOT_INITIALIZED();
 
        _BEGIN();
 
-       uwb_check_null_ret_error("network", network, UWB_ERROR_INVALID_PARAMETER);
+       uwb_check_null_ret_error("node", node, UWB_ERROR_INVALID_PARAMETER);
+       uwb_check_null_ret_error("key", key, UWB_ERROR_INVALID_PARAMETER);
+       uwb_check_null_ret_error("value", value, UWB_ERROR_INVALID_PARAMETER);
 
-       uwb_network_s *network_s = (uwb_network_s *)network;
-       if (network_s->remote_node_count == 0) {
-               _DBG("remote_node_count  is 0");
-               return ret;
-       }
+       configuration = __build_configuration(key, g_variant_new_string(value));
 
-       uwb_ctx.foreach_remote_node_cb = node_cb;
-       g_slist_foreach(network_s->remote_node_list, __foreach_node, user_data);
+       ret = __set_configuration(node, configuration);
 
        _END();
 
@@ -666,278 +727,220 @@ EXPORT_API int uwb_node_get_position(uwb_node_h node, int *x, int *y, int *z)
        return ret;
 }
 
-EXPORT_API int uwb_node_set_position(uwb_node_h node, int x, int y, int z)
+static void __get_network_cb(GObject *source_object, GAsyncResult *res, gpointer user_data)
 {
        int ret = UWB_ERROR_NONE;
+       uint16_t pan_id = 0;
+       GVariant *remote_node_list_va = NULL;
        GError *error = NULL;
+       uwb_network_s *network_s;
 
-       CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
-       CHECK_NOT_INITIALIZED();
-
-       _BEGIN();
-
-       uwb_check_null_ret_error("node", node, UWB_ERROR_INVALID_PARAMETER);
-
-       if (manager_call_set_position_sync(uwb_ctx.manager_proxy,
-               ((uwb_node_s *)node)->node_id, x, y, z, NULL, &error) == FALSE) {
-               _ERR("manager_call_set_position_sync failed : %s", error->message);
-               __handle_error(error, &ret);
-       }
-
-       _END();
-
-       return ret;
-}
-
-static GVariant *__data_to_variant(const unsigned char *data, int length)
-{
-       GVariantBuilder builder;
+       if (manager_call_get_network_info_finish(
+                       MANAGER(source_object),
+                       &pan_id,
+                       &remote_node_list_va,
+                       res,
+                       &error) == FALSE) {
+                       _ERR("manager_call_get_network_info_finish failed : %s", error->message);
+                       __handle_error(error, &ret);
 
-       g_variant_builder_init(&builder, G_VARIANT_TYPE("a(y)"));
+                       if (uwb_ctx.get_network_finished_cb != NULL) {
+                               uwb_ctx.get_network_finished_cb(ret, NULL, user_data);
+                       }
 
-       if (data && length > 0)
-       {
-               for(int i = 0; i < length; i++)
-                       g_variant_builder_add(&builder, "(y)", *(data + i));
+                       return;
        }
 
-       return g_variant_builder_end(&builder);
-}
+       /* create network handle */
+       network_s = (uwb_network_s *)malloc(sizeof(uwb_network_s));
 
-EXPORT_API int uwb_node_send_message(const unsigned char *message, int len)
-{
-       int ret = UWB_ERROR_NONE;
-       GVariant *msg = NULL;
-       GError *error = NULL;
+       if (ret == UWB_ERROR_NONE) {
+               GSList *remote_node_list = NULL;
+               network_s->pan_id = pan_id;
+               network_s->remote_node_count = g_variant_n_children(remote_node_list_va);
 
-       CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
-       CHECK_NOT_INITIALIZED();
+               if (network_s->remote_node_count > 0) {
+                       GVariantIter *iter = NULL;
+                       GVariant *nodes_va = NULL;
 
-       _BEGIN();
+                       g_variant_get(remote_node_list_va, "aa{sv}", &iter);
+                       while ((nodes_va = g_variant_iter_next_value(iter)) != NULL) {
+                               uwb_node_s *node;
 
-       uwb_check_null_ret_error("message", message, UWB_ERROR_INVALID_PARAMETER);
-       cond_expr_ret(len <= 0, UWB_ERROR_INVALID_PARAMETER);
+                               node = uwb_util_get_node_from_variant(nodes_va);
+                               node->is_remote = true;
 
-       msg = __data_to_variant(message, len);
+                               _DBG("(%d, %d, %d)", node->x, node->y, node->z);
+                               remote_node_list = g_slist_append(remote_node_list, node);
+                       }
+                       g_variant_iter_free(iter);
+               }
+               network_s->remote_node_list = remote_node_list;
 
-       if (manager_call_send_message_sync(uwb_ctx.manager_proxy,
-               msg, len, NULL, &error) == FALSE) {
-               _ERR("manager_call_send_message_sync failed : %s", error->message);
-               __handle_error(error, &ret);
+               g_variant_unref(remote_node_list_va);
        }
 
-       _END();
-
-       return ret;
+       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_node_send_message_to(uwb_node_h node, const unsigned char *message, int len)
+EXPORT_API int uwb_get_network(uwb_get_network_finished_cb finished_cb, void *user_data)
 {
        int ret = UWB_ERROR_NONE;
-       GVariant *msg = NULL;
-       GError *error = NULL;
 
        CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
        CHECK_NOT_INITIALIZED();
 
        _BEGIN();
 
-       uwb_check_null_ret_error("node", node, UWB_ERROR_INVALID_PARAMETER);
-       uwb_check_null_ret_error("message", message, UWB_ERROR_INVALID_PARAMETER);
-       cond_expr_ret(len <= 0, UWB_ERROR_INVALID_PARAMETER);
+       uwb_check_null_ret_error("finished_cb", finished_cb, UWB_ERROR_INVALID_PARAMETER);
 
-       msg = __data_to_variant(message, len);
+       uwb_ctx.get_network_finished_cb = finished_cb;
 
-       if (manager_call_send_message_to_sync(uwb_ctx.manager_proxy, ((uwb_node_s *)node)->node_id,
-               msg, len, NULL, &error) == FALSE) {
-               _ERR("manager_call_send_message_to_sync failed : %s", error->message);
-               __handle_error(error, &ret);
-       }
+       manager_call_get_network_info(uwb_ctx.manager_proxy, NULL, __get_network_cb, user_data);
 
        _END();
 
        return ret;
 }
 
-static int __get_configurations(uwb_node_h node, char *key,
-       const GVariantType *va_type, GVariant **va_out)
+static gpointer __copy_node(gconstpointer src, gpointer data)
 {
-       int ret = UWB_ERROR_NONE;
-       GError *error = NULL;
-       GVariant *va = NULL;
+       if (!src)
+               return NULL;
 
-       if (manager_call_get_configurations_sync(uwb_ctx.manager_proxy,
-               ((uwb_node_s *)node)->node_id, &va, NULL, &error) == FALSE) {
-               _ERR("__get_configurations failed : %s", error->message);
-               __handle_error(error, &ret);
-       } else {
-               *va_out = g_variant_lookup_value(va, key, va_type);
-       }
+       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;
 
-       return ret;
+       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_node_get_configuration_int32(uwb_node_h node, char *key, int32_t *value)
+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;
-       GVariant *value_va = NULL;
 
        CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
-       CHECK_NOT_INITIALIZED();
 
        _BEGIN();
 
-       uwb_check_null_ret_error("node", node, UWB_ERROR_INVALID_PARAMETER);
+       uwb_check_null_ret_error("source", source, UWB_ERROR_INVALID_PARAMETER);
 
-       ret = __get_configurations(node, key, G_VARIANT_TYPE_INT32, &value_va);
+       result_network = (uwb_network_s *)malloc(sizeof(uwb_network_s));
+       if (result_network == NULL) {
+               _ERR("malloc failed");
+               return UWB_ERROR_OPERATION_FAILED;
+       }
 
-       if (value_va != NULL)
-               *value = g_variant_get_int32(value_va);
-       else
-               *value = 0;
+       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;
 }
 
-EXPORT_API int uwb_node_get_configuration_int64(uwb_node_h node, char *key, int64_t *value)
+EXPORT_API int uwb_network_destroy(uwb_network_h network)
 {
        int ret = UWB_ERROR_NONE;
-       GVariant *value_va = NULL;
 
        CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
-       CHECK_NOT_INITIALIZED();
 
        _BEGIN();
 
-       uwb_check_null_ret_error("node", node, UWB_ERROR_INVALID_PARAMETER);
-
-       ret = __get_configurations(node, key, G_VARIANT_TYPE_INT64, &value_va);
+       uwb_check_null_ret_error("network", network, UWB_ERROR_INVALID_PARAMETER);
 
-       if (value_va != NULL)
-               *value = g_variant_get_int64(value_va);
-       else
-               *value = 0;
+       uwb_util_destroy_network(network);
 
        _END();
 
        return ret;
 }
 
-EXPORT_API int uwb_node_get_configuration_string(uwb_node_h node, char *key, const char **value)
+EXPORT_API int uwb_network_get_pan_id(uwb_network_h network, uint64_t *pan_id)
 {
        int ret = UWB_ERROR_NONE;
-       GVariant *value_va = NULL;
 
        CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
-       CHECK_NOT_INITIALIZED();
 
        _BEGIN();
 
-       uwb_check_null_ret_error("node", node, UWB_ERROR_INVALID_PARAMETER);
-
-       ret = __get_configurations(node, key, G_VARIANT_TYPE_STRING, &value_va);
+       uwb_check_null_ret_error("network", network, UWB_ERROR_INVALID_PARAMETER);
+       uwb_check_null_ret_error("pan_id", pan_id, UWB_ERROR_INVALID_PARAMETER);
 
-       if (value_va != NULL)
-               *value = g_variant_get_string(value_va, NULL);
-       else
-               *value = 0;
+       *pan_id = ((uwb_network_s *)network)->pan_id;
 
        _END();
 
        return ret;
 }
 
-static int __set_configuration(uwb_node_h node, char *key, GVariant *va)
-{
-       int ret = UWB_ERROR_NONE;
-       GError *error = NULL;
-
-       if (manager_call_set_configurations_sync(uwb_ctx.manager_proxy, ((uwb_node_s *)node)->node_id,
-               va, NULL, &error) == FALSE) {
-               _ERR("__set_configurations : %s", error->message);
-               __handle_error(error, &ret);
-       }
-
-       return ret;
-}
-
-static GVariant *__build_configuration(char *key, GVariant *value)
-{
-       GVariant *va = NULL;
-       GVariantBuilder *builder;
-
-       builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
-       g_variant_builder_open(builder, G_VARIANT_TYPE_VARDICT);
-       g_variant_builder_add(builder, "{sv}", key, value);
-       g_variant_builder_close(builder);
-       va = g_variant_builder_end(builder);
-       g_variant_builder_unref(builder);
-
-       return va;
-}
-
-EXPORT_API int uwb_node_set_configuration_int32(uwb_node_h node, char *key, int32_t value)
+EXPORT_API int uwb_network_get_remote_node_count(uwb_network_h network, int *remote_node_count)
 {
        int ret = UWB_ERROR_NONE;
-       GVariant *configuration = NULL;
 
        CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
-       CHECK_NOT_INITIALIZED();
 
        _BEGIN();
 
-       uwb_check_null_ret_error("node", node, UWB_ERROR_INVALID_PARAMETER);
-
-       configuration = __build_configuration(key, g_variant_new_int32(value));
+       uwb_check_null_ret_error("network", network, UWB_ERROR_INVALID_PARAMETER);
+       uwb_check_null_ret_error("remote_node_count", remote_node_count, UWB_ERROR_INVALID_PARAMETER);
 
-       ret = __set_configuration(node, key, configuration);
+       *remote_node_count = ((uwb_network_s *)network)->remote_node_count;
 
        _END();
 
        return ret;
 }
 
-EXPORT_API int uwb_node_set_configuration_int64(uwb_node_h node, char *key, int64_t value)
+static void __foreach_node(gpointer data, gpointer user_data)
 {
-       int ret = UWB_ERROR_NONE;
-       GVariant *configuration = NULL;
-
-       CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
-       CHECK_NOT_INITIALIZED();
-
-       _BEGIN();
-
-       uwb_check_null_ret_error("node", node, UWB_ERROR_INVALID_PARAMETER);
-
-       configuration = __build_configuration(key, g_variant_new_int64(value));
-
-       ret = __set_configuration(node, key, configuration);
-
-       _END();
+       uwb_node_s *node = (uwb_node_s *)data;
+       _DBG("panid : 0x%X, nodeid : 0x%04"PRIX64", distance : %"PRId64"", node->pan_id, node->node_id, node->distance);
 
-       return ret;
+       if (uwb_ctx.foreach_remote_node_cb != NULL)
+               uwb_ctx.foreach_remote_node_cb((uwb_node_h)node, user_data);
 }
 
-EXPORT_API int uwb_node_set_configuration_string(uwb_node_h node, char *key, const char *value)
+EXPORT_API int uwb_network_foreach_remote_node(uwb_network_h network,
+       uwb_network_foreach_remote_node_cb node_cb, void *user_data)
 {
        int ret = UWB_ERROR_NONE;
-       GVariant *configuration = NULL;
 
        CHECK_FEATURE_SUPPORTED(UWB_FEATURE);
-       CHECK_NOT_INITIALIZED();
 
        _BEGIN();
 
-       uwb_check_null_ret_error("node", node, UWB_ERROR_INVALID_PARAMETER);
+       uwb_check_null_ret_error("network", network, UWB_ERROR_INVALID_PARAMETER);
 
-       configuration = __build_configuration(key, g_variant_new_string(value));
+       uwb_network_s *network_s = (uwb_network_s *)network;
+       if (network_s->remote_node_count == 0) {
+               _DBG("remote_node_count  is 0");
+               return ret;
+       }
 
-       ret = __set_configuration(node, key, configuration);
+       uwb_ctx.foreach_remote_node_cb = node_cb;
+       g_slist_foreach(network_s->remote_node_list, __foreach_node, user_data);
 
        _END();
 
        return ret;
 }
-
index fad84f8..7fbd64d 100644 (file)
@@ -430,12 +430,16 @@ void test_get_configuration(void)
        if (data_type == 0) {
                ret = uwb_node_get_configuration_int32(own_node, key, &int32_data);
                __print_result(ret, "uwb_node_get_configuration_int32");
+               printf("Value [%d]\n", int32_data);
        } else if (data_type == 1) {
                ret = uwb_node_get_configuration_int64(own_node, key, &int64_data);
                __print_result(ret, "uwb_node_get_configuration_int64");
+               printf("Value [%lld]\n", int64_data);
        } else if (data_type == 2) {
                ret = uwb_node_get_configuration_string(own_node, key, &string_data);
                __print_result(ret, "uwb_node_get_configuration_string");
+               if (string_data)
+                       printf("Value [%s]\n", string_data);
        }
 
 out:
@@ -451,8 +455,8 @@ void test_set_configuration(void)
        uwb_node_h own_node = NULL;
        int data_type = 0;
        char *key;
-       int32_t int32_data;
-       int64_t int64_data;
+       int32_t int32_data = 2020;
+       int64_t int64_data = 2020;
        char *string_data = NULL;
        int ret = 0;
 
@@ -575,6 +579,16 @@ static gboolean __test_terminal_read_std_input(GIOChannel * source,
        return TRUE;
 }
 
+static void __glib_log(
+               const gchar *log_domain,
+               GLogLevelFlags log_level,
+               const gchar *msg,
+               gpointer user_data)
+{
+       printf("[GLib Err] %s-0x%2.2X: %s\n",
+                       log_domain, log_level, msg);
+}
+
 int main(int argc, char **argv)
 {
 
@@ -582,6 +596,7 @@ int main(int argc, char **argv)
        g_type_init();
 #endif
 
+       g_log_set_default_handler(__glib_log, NULL);
        g_main_loop_p = g_main_loop_new(NULL, FALSE);
 
        int std_input_fd = 0;