dbus-glib on debian lenny.
Fujitaka Daidouji
fujitaka.daidouji at gmail.com
Tue Apr 14 18:43:01 PDT 2009
I have been tring to awhile now to figure this out. Tring to recieve track
information from banshee-1. The field type is Dict of {String, variant}
CurrentTrack. <-- So far I have not been successful on get information from
it. This is what I tried. The for outputs the keys from the hashtable, but
not values beside it. All the values are things like @ < ( symbols.
#include <stdio.h>
#include <dbus/dbus-glib.h>
#include <string.h>
banshee_hash_str(GHashTable *table, const char *key, char *dest)
{
GValue* value = (GValue*) g_hash_table_lookup(table, key);
//if (value != NULL && G_VALUE_HOLDS_STRING(value)) {
strncpy(dest, g_value_get_string(value),
strlen(g_value_get_string(value)));
//}
}
static void print_hash_value (gpointer key, gpointer val, gpointer data)
{
printf ("%s -> %s\n", (char *) key, (char *) val);
}
int main (int argc, char **argv)
{
DBusGConnection *connection;
GError *error;
DBusGProxy *proxy;
GHashTable* table;
struct TrackInfo {
char *album;
};
struct TrackInfo ti;
g_type_init ();
error = NULL;
connection = dbus_g_bus_get (DBUS_BUS_SESSION,
&error);
if (connection == NULL)
{
g_printerr ("Failed to open connection to bus: %s\n",
error->message);
g_error_free (error);
exit (1);
}
/* Create a proxy object for the "bus driver" (name
"org.bansheeproject.Banshee") */
proxy = dbus_g_proxy_new_for_name (connection,
"org.bansheeproject.Banshee",
"/org/bansheeproject/Banshee/PlayerEngine",
"org.bansheeproject.Banshee.PlayerEngine");
/* Call GetCurrentTrack method, wait for reply */
error = NULL;
if (!dbus_g_proxy_call (proxy, "GetCurrentTrack", &error, G_TYPE_INVALID,
dbus_g_type_get_map("GHashTable", G_TYPE_STRING,
G_TYPE_VALUE), &table,
G_TYPE_INVALID))
{
g_printerr ("Error: %s\n", error->message);
g_error_free (error);
exit (1);
}
/* Print the results */
g_hash_table_foreach (table, print_hash_value, NULL);
//banshee_hash_str(table, "album", ti->album);
g_object_unref (proxy);
return 0;
}
Using to compile it:
gcc `pkg-config --libs --cflags glib-2.0 dbus-glib-1` spammer.c
Maby someone can help me on this. Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freedesktop.org/archives/dbus/attachments/20090414/50356e99/attachment.htm
More information about the dbus
mailing list