{
GVariantIter *peer = NULL;
GVariantIter *property = NULL;
+ gchar *key = NULL;
GVariant *val = NULL;
gsize len = 0;
GVariant *child;
g_variant_get(variant, "(a(oa{sv}))", &peer);
while ((child = g_variant_iter_next_value(peer))) {
- GVariantDict *dict = NULL;
- GVariant *tmp = NULL;
mesh_network_info_s *joined_info = NULL;
+ gboolean valid_state = TRUE;
MESH_LOGD(" Child : [%s]", g_variant_get_type_string(child));
var_string = g_variant_print(child, FALSE);
MESH_LOGD(" %s", var_string);
g_free(var_string);
- g_variant_get(child, "(oa{sv})", &obj_path, &dict);
+ g_variant_get(child, "(oa{sv})", &obj_path, &property);
+ MESH_LOGD(" Object: [%s]", obj_path);
if (NULL == obj_path) {
MESH_LOGE("Null object");
continue;
}
- tmp = g_variant_dict_lookup_value(dict, "State", G_VARIANT_TYPE_STRING);
- if (NULL == tmp) continue;
- buf = g_variant_get_string(tmp, &len);
- MESH_LOGD(" Object: [%s]", obj_path);
- MESH_LOGD(" State : [%s]", buf);
-
- /* Skip ignorable state */
- if (g_strcmp0(buf, "idle") == 0
- && g_strcmp0(buf, "disconnect") == 0
- && g_strcmp0(buf, "failure") == 0)
- continue;
-
/* Create an information structure for joined network */
joined_info = g_try_new0(mesh_network_info_s, 1);
if (NULL == joined_info) {
return;
}
- tmp = g_variant_dict_lookup_value(dict, "Name", G_VARIANT_TYPE_STRING);
- if (NULL == tmp) continue;
- buf = g_variant_get_string(tmp, &len);
- joined_info->mesh_id = g_strdup(buf);
- MESH_LOGD(" Mesh ID : %s", joined_info->mesh_id);
+ while (g_variant_iter_loop(property, "{sv}", &key, &val)) {
+ if (strcasecmp(key, "Name") == 0) {
+ buf = g_variant_get_string(val, &len);
+ joined_info->mesh_id = g_strdup(buf);
+ }
+ else if (strcasecmp(key, "Address") == 0) {
+ buf = g_variant_get_string(val, &len);
+ joined_info->bssid = g_strdup(buf);
+ }
+ else if (strcasecmp(key, "State") == 0) {
+ buf = g_variant_get_string(val, &len);
+ MESH_LOGD(" State : %s", buf);
+
+ /* Skip ignorable state */
+ if (g_strcmp0(buf, "idle") == 0
+ || g_strcmp0(buf, "disconnect") == 0
+ || g_strcmp0(buf, "failure") == 0) {
+ valid_state = FALSE;
+ break;
+ }
+ }
+ else if (strcasecmp(key, "Frequency") == 0) {
+ joined_info->channel = __frequency_to_channel(g_variant_get_uint16(val));
+ }
+ }
- tmp = g_variant_dict_lookup_value(dict, "Address", G_VARIANT_TYPE_STRING);
- if (NULL == tmp) continue;
- buf = g_variant_get_string(tmp, &len);
- joined_info->bssid = g_strdup(buf);
- MESH_LOGD(" BSSID : %s", joined_info->bssid);
+ /* Skip ignorable state */
+ if (FALSE == valid_state) {
+ g_free(joined_info->mesh_id);
+ g_free(joined_info->bssid);
+ continue;
+ }
- tmp = g_variant_dict_lookup_value(dict, "Frequency", G_VARIANT_TYPE_UINT16);
- joined_info->channel = __frequency_to_channel(g_variant_get_uint16(val));
+ MESH_LOGD(" Mesh ID : %s", joined_info->mesh_id);
+ MESH_LOGD(" BSSID : %s", joined_info->bssid);
MESH_LOGD(" Channel : %d", joined_info->channel);
-
service->joined_network = joined_info;
g_variant_iter_free(property);
g_variant_get(child, "(oa{sv})", &obj_path, &property);
if (NULL == obj_path) {
MESH_LOGE("Null object");
+ g_free(scan_info);
continue;
}
MESH_LOGD(" Obj path : [%s]", obj_path);
else if (strcasecmp(key, "Strength") == 0) {
scan_info->rssi = (gint)g_variant_get_byte(val);
MESH_LOGD(" RSSI : %d", scan_info->rssi);
-
- /* Last element */
- service->scanned_mesh_network =
- g_list_prepend(service->scanned_mesh_network, scan_info);
}
}
+ /* Last element */
+ service->scanned_mesh_network =
+ g_list_prepend(service->scanned_mesh_network, scan_info);
+
g_variant_iter_free(property);
}
g_variant_iter_free(peer);