static void parse_metadata(E_Music_Control_Module_Context *ctxt, Eina_Value *array) { unsigned i; E_FREE_FUNC(ctxt->meta_title, eina_stringshare_del); E_FREE_FUNC(ctxt->meta_album, eina_stringshare_del); E_FREE_FUNC(ctxt->meta_artist, eina_stringshare_del); E_FREE_FUNC(ctxt->meta_cover, eina_stringshare_del); // DBG("Metadata: %s", eina_value_to_string(array)); for (i = 0; i < eina_value_array_count(array); i++) { const char *key, *str_val; Eina_Value st, subst; Efreet_Uri *uri; eina_value_array_value_get(array, i, &st); eina_value_struct_get(&st, "arg0", &key); if (!strcmp(key, "xesam:title")) { eina_value_struct_value_get(&st, "arg1", &subst); eina_value_struct_get(&subst, "arg0", &str_val); ctxt->meta_title = eina_stringshare_add(str_val); eina_value_flush(&subst); } else if (!strcmp(key, "xesam:album")) { eina_value_struct_value_get(&st, "arg1", &subst); eina_value_struct_get(&subst, "arg0", &str_val); ctxt->meta_album = eina_stringshare_add(str_val); eina_value_flush(&subst); } else if (!strcmp(key, "xesam:artist")) { Eina_Value arr; eina_value_struct_value_get(&st, "arg1", &subst); eina_value_struct_value_get(&subst, "arg0", &arr); eina_value_array_get(&arr, 0, &str_val); ctxt->meta_artist = eina_stringshare_add(str_val); eina_value_flush(&arr); eina_value_flush(&subst); } else if (!strcmp(key, "mpris:artUrl")) { eina_value_struct_value_get(&st, "arg1", &subst); eina_value_struct_get(&subst, "arg0", &str_val); uri = efreet_uri_decode(str_val); if (uri && !strncmp(uri->protocol, "file", 4)) ctxt->meta_cover = eina_stringshare_add(uri->path); E_FREE_FUNC(uri, efreet_uri_free); eina_value_flush(&subst); } eina_value_flush(&st); } }
static cJSON * azy_value_serialize_array_json(const Eina_Value *val) { unsigned int x, total; cJSON *object; total = eina_value_array_count(val); object = cJSON_CreateArray(); for (x = 0; x < total; x++) { Eina_Value m; eina_value_array_value_get(val, x, &m); cJSON_AddItemToArray(object, azy_value_serialize_json(&m)); eina_value_flush(&m); } return object; }
static Eina_Bool _array_append(const char *type, const Eina_Value *value_array, Eldbus_Message_Iter *iter) { Eldbus_Message_Iter *array; Eina_Bool ok = eldbus_message_iter_arguments_append(iter, type, &array); EINA_SAFETY_ON_FALSE_RETURN_VAL(ok, EINA_FALSE); DBG("array of type %c", type[1]); switch (type[1]) { case '{': case '(': { unsigned i = strlen(type+2);//remove 'a()' of len a(sv) char *entry_sig = malloc(sizeof(char) * i); memcpy(entry_sig, type+2, i); entry_sig[i-1] = 0; for (i = 0; i < eina_value_array_count(value_array); i++) { Eina_Value st; Eldbus_Message_Iter *entry; eina_value_array_value_get(value_array, i, &st); eldbus_message_iter_arguments_append(array, type+1, &entry); _message_iter_from_eina_value_struct(entry_sig, entry, &st); eldbus_message_iter_container_close(array, entry); eina_value_flush(&st); } free(entry_sig); break; } case 'a': { unsigned i; for (i = 0; i < eina_value_array_count(value_array); i++) { Eina_Value inner_array; Eldbus_Message_Iter *sub_array; eina_value_array_value_get(value_array, i, &inner_array); eldbus_message_iter_arguments_append(array, type+1, &sub_array); _array_append(type+1, &inner_array, sub_array); eldbus_message_iter_container_close(array, sub_array); eina_value_flush(&inner_array); } break; } case 'v': { ERR("Variant not supported."); return EINA_FALSE; } case 'i': case 'h'://fd { int32_t z; unsigned i; for (i = 0; i < eina_value_array_count(value_array); i++) { eina_value_array_get(value_array, i, &z); eldbus_message_iter_basic_append(array, type[1], z); } break; } case 's': case 'o'://object path case 'g'://signature { const char *txt; unsigned i; for (i = 0; i < eina_value_array_count(value_array); i++) { eina_value_array_get(value_array, i, &txt); eldbus_message_iter_basic_append(array, type[1], txt); } break; } case 'b'://boolean case 'y'://byte { unsigned char z; unsigned i; for (i = 0; i < eina_value_array_count(value_array); i++) { eina_value_array_get(value_array, i, &z); eldbus_message_iter_basic_append(array, type[1], z); } break; } case 'n'://int16 { int16_t z; unsigned i; for (i = 0; i < eina_value_array_count(value_array); i++) { eina_value_array_get(value_array, i, &z); eldbus_message_iter_basic_append(array, type[1], z); } break; } case 'q'://uint16 { uint16_t z; unsigned i; for (i = 0; i < eina_value_array_count(value_array); i++) { eina_value_array_get(value_array, i, &z); eldbus_message_iter_basic_append(array, type[1], z); } break; } case 'u'://uint32 { uint32_t z; unsigned i; for (i = 0; i < eina_value_array_count(value_array); i++) { eina_value_array_get(value_array, i, &z); eldbus_message_iter_basic_append(array, type[1], z); } break; } case 'x'://int64 { int64_t z; unsigned i; for (i = 0; i < eina_value_array_count(value_array); i++) { eina_value_array_get(value_array, i, &z); eldbus_message_iter_basic_append(array, type[1], z); } break; } case 't'://uint64 { uint64_t z; unsigned i; for (i = 0; i < eina_value_array_count(value_array); i++) { eina_value_array_get(value_array, i, &z); eldbus_message_iter_basic_append(array, type[1], z); } break; } case 'd'://double { double z; unsigned i; for (i = 0; i < eina_value_array_count(value_array); i++) { eina_value_array_get(value_array, i, &z); eldbus_message_iter_basic_append(array, type[1], z); } break; } default: { ERR("Unknown type %c", type[1]); return EINA_FALSE; } } eldbus_message_iter_container_close(iter, array); return EINA_TRUE; }