Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7181811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:38:08+00:00 2026-05-28T17:38:08+00:00

I’m currently building a program which needs to interface with the d-bus. I’m using

  • 0

I’m currently building a program which needs to interface with the d-bus. I’m using the glib dbus library. I have a method that returns a dbus dictionary type, like this:

array [
  dict entry(
     string "Metadata"
     variant             array [
           dict entry(
              string "mpris:artUrl"
              variant                      string "http://open.spotify.com/thumb/05e9ad92c22953e6c778536613605b67faa5a095"
           )
           dict entry(
              string "mpris:length"
              variant                      uint64 238000000
           )

My question is, how on earth do I get this in my C program? I’ve tried the usual `dbus_g_proxy_connect_signal´ with a registered marshaller without much luck!

Edit: I’ve added some sample code (Which is not working, but does compile)

#include <string.h>
#include <glib.h>
#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>

#define DBUS_SERVICE      "com.spotify.qt"
#define DBUS_PATH         "/"
#define DBUS_INTERFACE    "org.freedesktop.MediaPlayer2"

#define DBUS_TYPE_G_STRING_VALUE_HASHTABLE (dbus_g_type_get_map ("GHashTable",     G_TYPE_STRING, G_TYPE_VALUE))
//Global bus connection
DBusGConnection *bus;
DBusGProxy *proxy;
//Main gloop
GMainLoop *loop = NULL;

//Callback function. 
static void callbackfunc(DBusGProxy *player_proxy, GHashTable *table){
GValue *value;
/* fetch values from hash table */
value = (GValue *) g_hash_table_lookup(table, "artist");
if (value != NULL && G_VALUE_HOLDS_STRING(value)) {
    g_print("\nArtist: %s\n",g_value_get_string(value));
}
value = (GValue *) g_hash_table_lookup(table, "album");
if (value != NULL && G_VALUE_HOLDS_STRING(value)) {
  g_print("\nAlbum: %s\n",g_value_get_string(value));
}
value = (GValue *) g_hash_table_lookup(table, "title");
if (value != NULL && G_VALUE_HOLDS_STRING(value)) {
  g_print("\nTitle: %s\n",g_value_get_string(value));
}
}

int main (int argc, char **argv){
GError *error = NULL;
g_type_init ();

/* Get (on) the bus :p */
bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
if (bus == NULL) {
    g_printerr("Failed to open connection to bus: %s", error->message);
    g_error_free(error);
    return -1;
}

/* Create a proxy object for the bus driver */
proxy = dbus_g_proxy_new_for_name (bus,
                                   DBUS_SERVICE,
                                   DBUS_PATH,
                                   DBUS_INTERFACE);

if (!proxy) {
    g_printerr("Couldn't connect: %s", error->message);
    g_error_free(error);
    return -1;
}

/* Create the main loop instance */
loop = g_main_loop_new (NULL, FALSE);

dbus_g_proxy_add_signal(proxy, "GetMetadata",
        DBUS_TYPE_G_STRING_VALUE_HASHTABLE, G_TYPE_INVALID);

dbus_g_proxy_connect_signal(proxy, "GetMetadata",
                                G_CALLBACK(callbackfunc), NULL, NULL);

g_print("Going into main function\n");
/* Main loop */
g_main_loop_run (loop);

return 0;
} 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T17:38:09+00:00Added an answer on May 28, 2026 at 5:38 pm

    I’m going to port my code to use GIO rather than glib-dbus, I did how ever manage to get it working with glib-dbus using this:

    if (dbus_g_proxy_call(p_proxy_md, "GetMetadata", NULL, G_TYPE_INVALID,   DBUS_TYPE_G_STRING_VALUE_HASHTABLE, &table, G_TYPE_INVALID)) {
    value = (GValue *) g_hash_table_lookup(table, "xesam:title");
    sprintf(currentTrack.trackname,"%s",g_value_get_string(value));
    value = (GValue *) g_hash_table_lookup(table, "xesam:album");
    sprintf(currentTrack.album,"%s",g_value_get_string(value));
    tmp = g_hash_table_lookup(table, "xesam:artist");
    if (tmp != NULL)
      {
        GStrv strv = g_value_get_boxed(g_hash_table_lookup(table, "xesam:artist"));
        sprintf(currentTrack.artist,"%s",*strv);
    
      }
    }  
    sprintf(notifybody,"By %s on %s",currentTrack.artist,currentTrack.album);
    music_noti = notify_notification_new(currentTrack.trackname,notifybody, NULL);
    notify_notification_set_timeout(music_noti,1500);
    notify_notification_set_icon_from_pixbuf(music_noti, notifyicon);
    notify_notification_show(music_noti, NULL);
    notify_uninit();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.