src/lib/edbus_pending.h \
src/lib/edbus_proxy.h \
src/lib/edbus_service.h \
- src/lib/edbus_signal_handler.h
+ src/lib/edbus_signal_handler.h \
+ src/lib/edbus_message_helper.h
libedbus2_la_LIBADD = @ECORE_LIBS@ @DBUS_LIBS@
libedbus2_la_SOURCES = \
src/lib/edbus_pending.c \
src/lib/edbus_freedesktop.c \
src/lib/edbus_service.c \
- src/lib/edbus_signal_handler.c
+ src/lib/edbus_signal_handler.c \
+ src/lib/edbus_message_helper.c
if EFL_BUILD_EXAMPLES
noinst_PROGRAMS = \
}
static void
+iterate_dict(void *data, const void *key, EDBus_Message_Iter *var)
+{
+ const char *skey = key;
+
+ if (!strcmp(skey, "PlaylistCount"))
+ {
+ unsigned count;
+ if (!edbus_message_iter_arguments_get(var, "u", &count))
+ printf("error2\n");
+ printf("PlaylistCount=%d\n", count);
+ }
+ else if (!strcmp(skey, "Orderings"))
+ {
+ EDBus_Message_Iter *as;
+ const char *txt;
+ printf("- Orderings\n");
+ if (!edbus_message_iter_arguments_get(var, "as", &as))
+ printf("error1\n");
+ while (edbus_message_iter_get_and_next(as, 's', &txt))
+ printf("\t%s\n", txt);
+ }
+}
+
+static void
+playlist_get_all_cb(void *data, const EDBus_Message *msg, EDBus_Pending *pending)
+{
+ const char *errname, *errmsg;
+ EDBus_Message_Iter *array;
+
+ if (edbus_message_error_get(msg, &errname, &errmsg))
+ {
+ fprintf(stderr, "Error: %s %s\n", errname, errmsg);
+ return;
+ }
+ if (edbus_message_arguments_get(msg, "a{sv}", &array))
+ edbus_message_iter_dict_iterate(array, "sv", iterate_dict, NULL);
+}
+
+static void
on_introspect(void *data, const EDBus_Message *msg, EDBus_Pending *pending)
{
const char *errname, *errmsg, *string;
playlists = edbus_proxy_get(mediaplayer2_obj, "org.mpris.MediaPlayer2.Playlists");
+ edbus_proxy_property_get_all(playlists, playlist_get_all_cb, NULL);
+
pending = edbus_proxy_call(introspectable, "Introspect", on_introspect, NULL, -1, "");
if (!pending)
{
#include "edbus_proxy.h"
#include "edbus_freedesktop.h"
#include "edbus_service.h"
+#include "edbus_message_helper.h"
#ifdef __cplusplus
}
--- /dev/null
+#include "edbus_private.h"
+#include "edbus_private_types.h"
+
+EAPI void
+edbus_message_iter_dict_iterate(EDBus_Message_Iter *array, const char *signature, EDBus_Dict_Cb_Get cb, const void *data)
+{
+ EDBus_Message_Iter *entry;
+ char *iter_sig;
+ unsigned len;
+ EINA_SAFETY_ON_FALSE_RETURN(array);
+ EINA_SAFETY_ON_NULL_RETURN(signature);
+
+ iter_sig = edbus_message_iter_signature_get(array);
+ len = strlen(iter_sig + 1);
+ if (strncmp(signature, iter_sig + 1, len - 1))
+ {
+ ERR("Unexpected signature, expected is: %s", iter_sig);
+ free(iter_sig);
+ return;
+ }
+ free(iter_sig);
+
+ while (edbus_message_iter_get_and_next(array, 'e', &entry))
+ {
+ const void *key;
+ EDBus_Message_Iter *var;
+ if (!edbus_message_iter_arguments_get(entry, signature, &key, &var))
+ continue;
+ cb((void *)data, key, var);
+ }
+}
--- /dev/null
+typedef void (*EDBus_Dict_Cb_Get)(void *data, const void *key, EDBus_Message_Iter *var);
+
+/**
+ * Iterate over a dictionary.
+ *
+ * @param dict iterator with array of entry
+ * @param signature of entry, example: "sv"
+ * @param cb callback that will be called in each entry
+ * @param data context data
+ */
+EAPI void edbus_message_iter_dict_iterate(EDBus_Message_Iter *dict, const char *signature, EDBus_Dict_Cb_Get cb, const void *data);