From: saerome.kim Date: Tue, 14 Mar 2017 04:34:59 +0000 (+0900) Subject: Implement get_mpath_info API X-Git-Tag: submit/tizen/20170828.225740~47 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a0ddb16015404b6101526e06cebe6925d000267c;p=platform%2Fcore%2Fapi%2Fwifi-mesh.git Implement get_mpath_info API Signed-off-by: saerome.kim --- diff --git a/include/mesh.h b/include/mesh.h index 82e6b19..4fc6668 100644 --- a/include/mesh.h +++ b/include/mesh.h @@ -169,7 +169,7 @@ typedef void* mesh_station_info_h; * @brief The mesh path information handle. * @since_tizen 4.0 */ -typedef void* mesh_path_info_h; +typedef void* mesh_mpath_info_h; /** @@ -959,7 +959,8 @@ typedef void (*mesh_found_station_cb)(mesh_station_info_h station, void* user_da * @since_tizen 4.0 * * @param[in] handle The mesh handle - * @param[out] station The mesh station information handle + * @param[in] cb The callback function to receive station information + * @param[in] user_data User data * * * @return 0 on success, otherwise a negative error value. @@ -972,6 +973,21 @@ typedef void (*mesh_found_station_cb)(mesh_station_info_h station, void* user_da */ int mesh_get_stations_info(mesh_h handle, mesh_found_station_cb cb, void *user_data); +/** + * @brief Called after mesh_get_stations_info() + * @details This function can receive joined station information from mesh network. + * + * @since_tizen 4.0 + * + * @param[out] path mesh path information handle + * @param[out] user_data user data pointer + * + * @pre The callback must be registered with mesh_foreach_found_mesh_netwrok() + * + * @see mesh_foreach_found_mesh_netwrok() + */ +typedef void (*mesh_found_mpath_cb)(mesh_mpath_info_h path, void* user_data); + /** * @brief Get information of all mesh paths. * @details Get information about all mesh paths present in the currently connected mesh network. @@ -979,7 +995,8 @@ int mesh_get_stations_info(mesh_h handle, mesh_found_station_cb cb, void *user_d * @since_tizen 4.0 * * @param[in] handle The mesh handle - * @param[out] path The mesh path information handle + * @param[in] cb The callback function to receive mesh path information + * @param[in] user_data User data * * * @return 0 on success, otherwise a negative error value. @@ -990,7 +1007,7 @@ int mesh_get_stations_info(mesh_h handle, mesh_found_station_cb cb, void *user_d * @see mesh_get_stations_info() * */ -int mesh_get_path_info(mesh_h handle, mesh_path_info_h path); +int mesh_get_mpath_info(mesh_h handle, mesh_found_mpath_cb cb, void *user_data); /** * @brief Sets network device interface name. diff --git a/include/mesh_dbus.h b/include/mesh_dbus.h index e4bf3b4..b6078dd 100644 --- a/include/mesh_dbus.h +++ b/include/mesh_dbus.h @@ -59,8 +59,8 @@ int _mesh_foreach_saved_mesh_netwrok(mesh_h handle, int _mesh_select_network(mesh_h handle, mesh_network_h _network); int _mesh_remove_network(mesh_h handle, mesh_network_h _network); int _mesh_set_interface(mesh_h handle, const char *mesh, const char *gate, const char *softap); -int _mesh_get_station_info(mesh_h handle, void *station); -int _mesh_get_path_info(mesh_h handle, void *mpath_data); +int _mesh_get_stations_info(mesh_h handle, mesh_found_station_cb cb, void *user_data); +int _mesh_get_mpath_info(mesh_h handle, mesh_found_mpath_cb cb, void *user_data); int _mesh_set_interfaces(mesh_h handle, const char *mesh, const char *gate, const char *softap); #ifdef __cplusplus diff --git a/src/mesh.c b/src/mesh.c index a1dbc6d..428895f 100644 --- a/src/mesh.c +++ b/src/mesh.c @@ -635,14 +635,14 @@ EXPORT_API int mesh_get_stations_info(mesh_h handle, mesh_found_station_cb cb, v return MESH_ERROR_NONE; } -EXPORT_API int mesh_get_path_info(mesh_h handle, mesh_path_info_h path) +EXPORT_API int mesh_get_mpath_info(mesh_h handle, mesh_found_mpath_cb cb, void *user_data) { int rv = 0; CHECK_FEATURE_SUPPORTED(MESH_FEATURE); RETV_IF(NULL == handle, MESH_ERROR_INVALID_PARAMETER); - rv = _mesh_get_path_info(handle, path); + rv = _mesh_get_mpath_info(handle, cb, user_data); if (rv == MESH_ITNL_ERR_IO_ERROR) { return MESH_ERROR_IO_ERROR; } diff --git a/src/mesh_dbus.c b/src/mesh_dbus.c index 11033e7..4be5395 100644 --- a/src/mesh_dbus.c +++ b/src/mesh_dbus.c @@ -1015,25 +1015,18 @@ int _mesh_get_stations_info(mesh_h handle, mesh_found_station_cb cb, void *user_ RETV_IF(NULL == h->dbus_connection, MESH_ITNL_ERR_IO_ERROR); RETV_IF(NULL == _gproxy_mesh_service, MESH_ITNL_ERR_IO_ERROR); - LOGE("-1"); - variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "get_station_info", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); - LOGE("0"); if (variant) { /* handle station list here */ g_variant_get(variant, "(aa{sv}u)", &iter, &result); - LOGE("1"); while (g_variant_iter_next(iter, "a{sv}", &iter_row)) { struct mesh_station_info_s station; memset(&station, 0, sizeof(struct mesh_station_info_s)); - LOGE("2"); - while (g_variant_iter_loop(iter_row, "{sv}", &key, &val)) { - LOGE("3"); if (strcasecmp(key, "bssid") == 0) { const char *buf = g_variant_get_string(val, &len); memcpy(station.bssid, buf, len); @@ -1131,7 +1124,7 @@ int _mesh_get_stations_info(mesh_h handle, mesh_found_station_cb cb, void *user_ } else if (strcasecmp(key, "connected_time") == 0) { station.connected_time = g_variant_get_uint32(val); LOGE("connected_time = %d", station.connected_time); - + /* Let users know what stations joined */ if (cb) cb(&station, user_data); } } @@ -1149,7 +1142,7 @@ int _mesh_get_stations_info(mesh_h handle, mesh_found_station_cb cb, void *user_ return MESH_ITNL_ERR_NONE; } -int _mesh_get_path_info(mesh_h handle, void* mpath_data) +int _mesh_get_mpath_info(mesh_h handle, mesh_found_mpath_cb cb, void *user_data) { GVariant *variant = NULL; unsigned int result; @@ -1166,14 +1159,11 @@ int _mesh_get_path_info(mesh_h handle, void* mpath_data) RETV_IF(NULL == h->dbus_connection, MESH_ITNL_ERR_IO_ERROR); RETV_IF(NULL == _gproxy_mesh_service, MESH_ITNL_ERR_IO_ERROR); - LOGE("-1"); - variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "get_mpath_info", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); - LOGE("0"); if (variant) { /* handle station list here */ _mesh_remove_mpath(); @@ -1183,9 +1173,7 @@ int _mesh_get_path_info(mesh_h handle, void* mpath_data) LOGE("1"); while (g_variant_iter_next(iter, "a{sv}", &iter_row)) { struct mesh_mpath_dump_s *mpath = g_malloc0(sizeof(struct mesh_mpath_dump_s)); - LOGE("2"); while (g_variant_iter_loop(iter_row, "{sv}", &key, &val)) { - LOGE("3"); if (strcasecmp(key, "DEST_ADDR") == 0) { const char *buf = g_variant_get_string(val, &len); memcpy(mpath->dest_addr, buf, len); @@ -1220,7 +1208,12 @@ int _mesh_get_path_info(mesh_h handle, void* mpath_data) mpath->flags = g_variant_get_byte(val); LOGE("flags= %d", mpath->flags); + /* Add temporal mesh path buffer */ _mesh_add_mpath((gpointer)mpath); + + if (cb) { + cb(mpath, user_data); + } } } g_variant_iter_free(iter_row); diff --git a/test/mesh_network.c b/test/mesh_network.c index 4728741..2916542 100644 --- a/test/mesh_network.c +++ b/test/mesh_network.c @@ -104,6 +104,11 @@ static void found_station_cb(mesh_station_info_h station, void* user_data) msg("Station Inforation Received: %p", station); } +static void found_mpath_cb(mesh_mpath_info_h mpath, void* user_data) +{ + msg("Station Inforation Received: %p", mpath); +} + static gboolean _mesh_lookup_by_id(gpointer key, gpointer value, gpointer user_data) { int k = (int)key; @@ -115,7 +120,7 @@ static gboolean _mesh_lookup_by_id(gpointer key, gpointer value, gpointer user_d return FALSE; } -static int run_show_saved_network(void) +static int run_show_saved_network(MManager *mm, struct menu_data *menu) { int i = 0; char *_meshid = NULL; @@ -145,7 +150,7 @@ static int run_show_saved_network(void) return RET_SUCCESS; } -static int run_show_scanned_network(void) +static int run_show_scanned_network(MManager *mm, struct menu_data *menu) { int i = 0; char *_meshid = NULL; @@ -431,8 +436,6 @@ static int run_add_network(MManager *mm, struct menu_data *menu) mesh_network_h net = NULL; msg("Add a Network Configuration among scan results"); - run_show_scanned_network(); - if (strlen(network_idx)) idx = (unsigned short)strtol(network_idx, NULL, 10); @@ -484,8 +487,6 @@ static int run_select_network(MManager *mm, struct menu_data *menu) mesh_network_h net = NULL; msg("Select Saved Network Configuration"); - run_show_saved_network(); - if (strlen(network_idx)) idx = (unsigned short)strtol(network_idx, NULL, 10); @@ -514,8 +515,6 @@ static int run_remove_network(MManager *mm, struct menu_data *menu) mesh_network_h net = NULL; msg("Remove Saved Network Configuration"); - run_show_saved_network(); - if (strlen(network_idx)) idx = (unsigned short)strtol(network_idx, NULL, 10); @@ -554,7 +553,16 @@ static int run_get_station_information(MManager *mm, struct menu_data *menu) static int run_get_mpath_information(MManager *mm, struct menu_data *menu) { + int ret; msg("Get Mesh Path Information"); + + ret = mesh_get_mpath_info(mesh, found_mpath_cb, NULL); + if (ret != 0) { + msg("Failed to mesh_get_mpath_info: [%s(0x%X)]", + mesh_error_to_string(ret), ret); + return RET_FAILURE; + } + return RET_SUCCESS; } static struct menu_data menu_specific_scan[] = { @@ -584,6 +592,7 @@ static struct menu_data menu_softap_option[] = { }; static struct menu_data menu_add_network[] = { + { "0", "show scanned networks", NULL, run_show_scanned_network, NULL }, { "1", "index", NULL, NULL, network_idx }, { "2", "run", NULL, run_add_network, NULL }, { NULL, NULL, }, @@ -597,12 +606,14 @@ static struct menu_data menu_add_new_network[] = { }; static struct menu_data menu_select_network[] = { + { "0", "show saved networks", NULL, run_show_saved_network, NULL }, { "1", "index", NULL, NULL, network_idx }, { "2", "run", NULL, run_select_network, NULL }, { NULL, NULL, }, }; static struct menu_data menu_remove_network[] = { + { "0", "show saved networks", NULL, run_show_saved_network, NULL }, { "1", "index", NULL, NULL, network_idx }, { "2", "run", NULL, run_remove_network, NULL }, { NULL, NULL, },