static Eina_Bool _props_getall(Eldbus_Service_Interface *iface, Eina_Iterator *iterator, Eldbus_Message_Iter *dict, const Eldbus_Message *input_msg, Eldbus_Message **error_reply) { Property *prop; EINA_ITERATOR_FOREACH(iterator, prop) { Eldbus_Message_Iter *entry, *var; Eina_Bool ret; Eldbus_Property_Get_Cb getter = NULL; if (prop->property->get_func) getter = prop->property->get_func; else if (iface->get_func) getter = iface->get_func; if (!getter || prop->is_invalidate) continue; if (!eldbus_message_iter_arguments_append(dict, "{sv}", &entry)) continue; eldbus_message_iter_basic_append(entry, 's', prop->property->name); var = eldbus_message_iter_container_new(entry, 'v', prop->property->type); ret = getter(iface, prop->property->name, var, input_msg, error_reply); if (!ret) return EINA_FALSE; eldbus_message_iter_container_close(entry, var); eldbus_message_iter_container_close(dict, entry); }
static void _elm_sys_notify_marshal_dict_string(Eldbus_Message_Iter *array, const char *key, const char *value) { Eldbus_Message_Iter *var, *entry; eldbus_message_iter_arguments_append(array, "{sv}", &entry); eldbus_message_iter_basic_append(entry, 's', key); var = eldbus_message_iter_container_new(entry, 'v', "s"); eldbus_message_iter_basic_append(var, 's', value); eldbus_message_iter_container_close(entry, var); eldbus_message_iter_container_close(array, entry); }
static void _efl_net_control_technology_property_set(Eo *o, Efl_Net_Control_Technology_Data *pd, const char *name, const char *signature, ...) { Eldbus_Message *msg; Eldbus_Message_Iter *msg_itr, *var; Eldbus_Pending *p; va_list ap; msg = eldbus_proxy_method_call_new(pd->proxy, "SetProperty"); EINA_SAFETY_ON_NULL_RETURN(msg); msg_itr = eldbus_message_iter_get(msg); EINA_SAFETY_ON_NULL_GOTO(msg_itr, error_send); eldbus_message_iter_basic_append(msg_itr, 's', name); var = eldbus_message_iter_container_new(msg_itr, 'v', signature); va_start(ap, signature); eldbus_message_iter_arguments_vappend(var, signature, ap); va_end(ap); eldbus_message_iter_container_close(msg_itr, var); p = eldbus_proxy_send(pd->proxy, msg, _efl_net_control_technology_property_set_cb, o, DEFAULT_TIMEOUT); EINA_SAFETY_ON_NULL_GOTO(p, error_send); pd->pending = eina_list_append(pd->pending, p); DBG("Setting property %s", name); return; error_send: eldbus_message_unref(msg); }
void wkb_ibus_iter_append_text(Eldbus_Message_Iter *iter, struct wkb_ibus_text *text) { Eldbus_Message_Iter *txt_iter = NULL; /* TODO */ txt_iter = eldbus_message_iter_container_new(iter, 'v', "sa{sv}sv"); eldbus_message_iter_container_close(iter, txt_iter); }
static Eldbus_Message * _cb_property_get(const Eldbus_Service_Interface *piface, const Eldbus_Message *msg) { const char *propname, *iface_name; Eldbus_Service_Object *obj = piface->obj; Eldbus_Service_Interface *iface; Property *prop; Eldbus_Message *reply, *error_reply = NULL; Eldbus_Message_Iter *main_iter, *variant; Eina_Bool ret; Eldbus_Property_Get_Cb getter = NULL; if (!eldbus_message_arguments_get(msg, "ss", &iface_name, &propname)) return NULL; iface = eina_hash_find(obj->interfaces, iface_name); if (!iface) return eldbus_message_error_new(msg, DBUS_ERROR_UNKNOWN_INTERFACE, "Interface not found."); prop = eina_hash_find(iface->properties, propname); if (!prop || prop->is_invalidate) goto not_found; if (prop->property->get_func) getter = prop->property->get_func; else if (iface->get_func) getter = iface->get_func; if (!getter) goto not_found; reply = eldbus_message_method_return_new(msg); EINA_SAFETY_ON_NULL_RETURN_VAL(reply, NULL); main_iter = eldbus_message_iter_get(reply); variant = eldbus_message_iter_container_new(main_iter, 'v', prop->property->type); ret = getter(iface, propname, variant, msg, &error_reply); if (ret) { eldbus_message_iter_container_close(main_iter, variant); return reply; } eldbus_message_unref(reply); return error_reply; not_found: return eldbus_message_error_new(msg, DBUS_ERROR_UNKNOWN_PROPERTY, "Property not found."); }
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; }
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; }