forked from enlightenment/efl
edbus: Add example for reading str array inside a variant using eina_value
Patch by: José Roberto de Souza <zehortigoza@profusion.mobi> SVN revision: 80700
This commit is contained in:
parent
3a4cbf1e4c
commit
2391dcf481
|
@ -147,6 +147,35 @@ on_plus_one(void *data, const EDBus_Message *msg, EDBus_Pending *pending)
|
|||
eina_value_free(v);
|
||||
}
|
||||
|
||||
static void
|
||||
receive_variant_cb(void *data, const EDBus_Message *msg, EDBus_Pending *pending)
|
||||
{
|
||||
Eina_Value *v, variant, array;
|
||||
unsigned i;
|
||||
|
||||
printf("4 - receive a variant with an array of strings\n");
|
||||
if (edbus_message_error_get(msg, NULL, NULL))
|
||||
{
|
||||
printf("Message error\n\n");
|
||||
return;
|
||||
}
|
||||
|
||||
v = edbus_message_to_eina_value(msg);
|
||||
|
||||
eina_value_struct_value_get(v, "arg0", &variant);
|
||||
eina_value_struct_value_get(&variant, "arg0", &array);
|
||||
for (i = 0; i < eina_value_array_count(&array); i++)
|
||||
{
|
||||
const char *txt;
|
||||
eina_value_array_get(&array, i, &txt);
|
||||
printf("\t%s\n", txt);
|
||||
}
|
||||
|
||||
eina_value_flush(&array);
|
||||
eina_value_flush(&variant);
|
||||
eina_value_free(v);
|
||||
}
|
||||
|
||||
static void
|
||||
_property_removed(void *data, EDBus_Proxy *proxy, void *event_info)
|
||||
{
|
||||
|
@ -280,6 +309,8 @@ main(void)
|
|||
edbus_proxy_properties_monitor(proxy, EINA_TRUE);
|
||||
ecore_timer_add(10, _read_cache, proxy);
|
||||
|
||||
edbus_proxy_call(proxy, "ReceiveVariantData", receive_variant_cb, NULL, -1, "");
|
||||
|
||||
ecore_main_loop_begin();
|
||||
|
||||
edbus_proxy_event_callback_del(proxy, EDBUS_PROXY_EVENT_PROPERTY_CHANGED,
|
||||
|
|
|
@ -63,6 +63,26 @@ _receive_array_of_string_int_with_size(const EDBus_Service_Interface *iface, con
|
|||
return reply;
|
||||
}
|
||||
|
||||
static EDBus_Message *
|
||||
_receive_variant(const EDBus_Service_Interface *iface, const EDBus_Message *msg)
|
||||
{
|
||||
EDBus_Message *reply = edbus_message_method_return_new(msg);
|
||||
EDBus_Message_Iter *var, *array, *main_iter;
|
||||
|
||||
main_iter = edbus_message_iter_get(reply);
|
||||
var = edbus_message_iter_container_new(main_iter, 'v', "as");
|
||||
edbus_message_iter_arguments_set(var, "as", &array);
|
||||
|
||||
edbus_message_iter_arguments_set(array, "s", "item1");
|
||||
edbus_message_iter_arguments_set(array, "s", "item2");
|
||||
edbus_message_iter_arguments_set(array, "s", "item3");
|
||||
|
||||
edbus_message_iter_container_close(var, array);
|
||||
edbus_message_iter_container_close(main_iter, var);
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
||||
static EDBus_Message *
|
||||
_send_variant(const EDBus_Service_Interface *iface, const EDBus_Message *msg)
|
||||
{
|
||||
|
@ -262,6 +282,10 @@ static const EDBus_Method methods[] = {
|
|||
"SendVariantData", EDBUS_ARGS({"v", "variant_data"}),
|
||||
NULL, _send_variant
|
||||
},
|
||||
{
|
||||
"ReceiveVariantData", NULL, EDBUS_ARGS({"v", "variant_data"}),
|
||||
_receive_variant
|
||||
},
|
||||
{
|
||||
"SendArrayInt", NULL,
|
||||
EDBUS_ARGS({"ai", "array_of_int"}), _send_array_int, 0
|
||||
|
|
Loading…
Reference in New Issue