**** no! @jaeezzy Here's an example, using the lovely DBus-GLib bindings, that gets the current state and prints it out: http://slexy.org/view/s287btiNxS As you can see, I'm not in the habit of commenting my code. I'll try and explain anything asked, but I'm no expert on D-Bus. When I've finished it, I'll post again with another sample that automatically prints out the state when it changes.
#include <dbus/dbus-glib.h> #include <dbus/dbus-glib-lowlevel.h> #include <glib.h> #include <stdio.h> #include <string.h> #include <mce/dbus-names.h> #include <mce/mode-names.h> #include <stdlib.h> typedef struct{ DBusGProxy *proxy; gchar *call_state; gchar *call_e_state; } PSSwitcherD; static void mce_call_state_changed(DBusGProxy*, const gchar*, const gchar*, gpointer); static void private_free(gpointer); static GStaticPrivate private_key = G_STATIC_PRIVATE_INIT; int main(int argc, char *argv[]){ DBusGConnection *dbus; GError *dbus_err = NULL; PSSwitcherD *switcher; switcher = g_new0(PSSwitcherD, 1); g_static_private_set(&private_key, switcher, private_free); dbus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &dbus_err); if (!dbus){ g_print("D-BUS Connection FAILED!!!\n"); g_clear_error(&dbus_err); return 1; } switcher->proxy = dbus_g_proxy_new_for_name(dbus, MCE_SERVICE, MCE_SIGNAL_PATH, MCE_SIGNAL_IF); dbus_g_proxy_add_signal(switcher->proxy, MCE_CALL_STATE_SIG, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); dbus_g_proxy_connect_signal(switcher->proxy, MCE_CALL_STATE_SIG, G_CALLBACK(mce_call_state_changed), NULL, NULL); g_print("Requesting current call state...\n"); dbus_g_proxy_call(switcher->proxy, MCE_CALL_STATE_GET, &dbus_err, G_TYPE_INVALID, G_TYPE_STRING, &switcher->call_state, G_TYPE_STRING, &switcher->call_e_state, G_TYPE_INVALID); if (dbus_err){ g_print("couldn't request current call state.\n"); g_clear_error(&dbus_err); }else{ g_print("Current state is %s.\n", switcher->call_state); } return 0; } static void mce_call_state_changed(DBusGProxy *proxy, const gchar *call_state, const gchar *call_e_state, gpointer user_data){ PSSwitcherD *switcher; switcher = g_static_private_get(&private_key); g_return_if_fail(switcher != NULL); g_print("Call state changed to %s\n", call_state); g_free(switcher->call_state); switcher->call_state = g_strdup(call_state); g_free(switcher->call_e_state); switcher->call_e_state = g_strdup(call_e_state); if (g_strcmp0(call_state, MCE_CALL_STATE_NONE)) g_print("DOING NOTHING\n"); else if (g_strcmp0(call_state, MCE_CALL_STATE_RINGING)) g_print("BLOODY RINGING\n"); } static void private_free(gpointer data){ PSSwitcherD *switcher; switcher = data; g_free(switcher->call_state); g_free(switcher->call_e_state); if (switcher->proxy) g_object_unref(switcher->proxy); g_free(switcher); }