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); } }
/** * @brief Convert result to a string * @param res Result * @return Stringshared result */ const char * esql_res_to_string(const Esql_Res *res) { const Esql_Row *row; const Eina_Value_Struct_Member *member; Eina_Value tmp, conv; EINA_SAFETY_ON_NULL_RETURN_VAL(res, NULL); EINA_SAFETY_ON_TRUE_RETURN_VAL(res->row_count > 1, NULL); if (!res->row_count) return NULL; row = EINA_INLIST_CONTAINER_GET(res->rows, Esql_Row); member = row->res->desc->members; if (!eina_value_struct_value_get(&(row->value), member->name, &tmp)) return NULL; conv.type = EINA_VALUE_TYPE_STRINGSHARE; if (!eina_value_convert(&tmp, &conv)) goto error_convert; eina_value_flush(&tmp); return conv.value.ptr; /* no flush, ptr is a stringshared string! */ error_convert: eina_value_flush(&tmp); return NULL; }
/** * @brief Convert result to an unsigned long int * @param res Result * @return Unsigned long int */ unsigned long int esql_res_to_ulong(const Esql_Res *res) { const Esql_Row *row; const Eina_Value_Struct_Member *member; Eina_Value tmp, conv; unsigned long int ret; EINA_SAFETY_ON_NULL_RETURN_VAL(res, 0); EINA_SAFETY_ON_TRUE_RETURN_VAL(res->row_count > 1, 0); if (!res->row_count) return 0; row = EINA_INLIST_CONTAINER_GET(res->rows, Esql_Row); member = row->res->desc->members; if (!eina_value_struct_value_get(&(row->value), member->name, &tmp)) return 0; conv.type = EINA_VALUE_TYPE_ULONG; if (!eina_value_convert(&tmp, &conv)) goto error_convert; eina_value_flush(&tmp); if (!eina_value_pget(&conv, &ret)) return 0; return ret; error_convert: eina_value_flush(&tmp); return 0; }
static void cb_mpris_media_player2_supported_uri_schemes(void *data, const Eldbus_Message *msg, Eldbus_Pending *pending) { void *user_data = eldbus_pending_data_del(pending, "__user_data"); const char *error, *error_msg; Eldbus_Codegen_Property_Complex_Get_Cb cb = data; Eldbus_Proxy *proxy = eldbus_pending_data_del(pending, "__proxy"); Eldbus_Message_Iter *variant; Eina_Value *v, stack_value; if (eldbus_message_error_get(msg, &error, &error_msg)) { Eldbus_Error_Info error_info = {error, error_msg}; cb(user_data, pending, "SupportedUriSchemes", proxy, &error_info, NULL); return; } if (!eldbus_message_arguments_get(msg, "v", &variant)) { Eldbus_Error_Info error_info = {"", ""}; cb(user_data, pending, "SupportedUriSchemes", proxy, &error_info, NULL); return; } v = eldbus_message_iter_struct_like_to_eina_value(variant); eina_value_struct_value_get(v, "arg0", &stack_value); cb(user_data, pending, "SupportedUriSchemes", proxy, NULL, &stack_value); eina_value_flush(&stack_value); eina_value_free(v); }
static cJSON * azy_value_serialize_struct_json(const Eina_Value *val) { Eina_Value_Struct st; cJSON *object; unsigned int x; eina_value_pget(val, &st); object = cJSON_CreateObject(); for (x = 0; x < st.desc->member_count; x++) { Eina_Value m; eina_value_struct_value_get(val, st.desc->members[x].name, &m); cJSON_AddItemToObject(object, st.desc->members[x].name, azy_value_serialize_json(&m)); eina_value_flush(&m); } return object; }
/** * @brief Convert result to a binary blob * @param res Result * @return Allocated binary blob (must be freed) */ unsigned char * esql_res_to_blob(const Esql_Res *res, unsigned int *size) { const Esql_Row *row; const Eina_Value_Struct_Member *member; Eina_Value tmp, conv; Eina_Value_Blob blob; unsigned char *ret = NULL; if (size) *size = 0; EINA_SAFETY_ON_NULL_RETURN_VAL(res, NULL); EINA_SAFETY_ON_TRUE_RETURN_VAL(res->row_count > 1, NULL); if (!res->row_count) return NULL; row = EINA_INLIST_CONTAINER_GET(res->rows, Esql_Row); member = row->res->desc->members; if (!eina_value_struct_value_get(&(row->value), member->name, &tmp)) return NULL; if (!eina_value_setup(&conv, EINA_VALUE_TYPE_BLOB)) goto error_setup; if (!eina_value_convert(&tmp, &conv)) goto error; if (!eina_value_pget(&conv, &blob)) goto error; ret = malloc(blob.size); EINA_SAFETY_ON_NULL_GOTO(ret, error); memcpy(ret, blob.memory, blob.size); if (size) *size = blob.size; error: eina_value_flush(&conv); error_setup: eina_value_flush(&tmp); return ret; }
Eina_Bool _message_iter_from_eina_value_struct(const char *signature, Eldbus_Message_Iter *iter, const Eina_Value *value) { unsigned i; DBusSignatureIter signature_iter; Eina_Bool r = EINA_TRUE; char *type; Eina_Value_Struct st; EINA_SAFETY_ON_FALSE_RETURN_VAL( eina_value_type_get(value) == EINA_VALUE_TYPE_STRUCT, EINA_FALSE); EINA_SAFETY_ON_FALSE_RETURN_VAL( eina_value_pget(value, &st), EINA_FALSE); dbus_signature_iter_init(&signature_iter, signature); i = 0; while ((type = dbus_signature_iter_get_signature(&signature_iter))) { DBG("type: %s", type); if (type[0] != 'v' && !type[1]) r = _basic_append(type[0], value, st.desc, i, iter); else if (type[0] == 'a') { Eina_Value value_array; EINA_SAFETY_ON_FALSE_RETURN_VAL( _compatible_type(type[0], st.desc->members[i].type), EINA_FALSE); eina_value_struct_value_get(value, st.desc->members[i].name, &value_array); r = _array_append(type, &value_array, iter); eina_value_flush(&value_array); } else if (type[0] == '(') { Eina_Value inner_st; Eldbus_Message_Iter *sub_iter; char *sub_sig; unsigned len = strlen(type+1) -1; sub_sig = alloca(sizeof(char) * len); memcpy(sub_sig, type+1, len); sub_sig[len-1] = 0; EINA_SAFETY_ON_FALSE_RETURN_VAL( _compatible_type(type[0], st.desc->members[i].type), EINA_FALSE); eina_value_struct_value_get(value, st.desc->members[i].name, &inner_st); eldbus_message_iter_arguments_append(iter, type, &sub_iter); r = _message_iter_from_eina_value_struct(sub_sig, sub_iter, &inner_st); eldbus_message_iter_container_close(iter, sub_iter); } else if (type[0] == 'v') { ERR("Variant not supported"); r = EINA_FALSE; } else { ERR("Unknown type %c", type[0]); r = EINA_FALSE; } i++; dbus_free(type); if (!r || !dbus_signature_iter_next(&signature_iter)) break; } return r; }