newbie want to compile example
Gloria Saripah Patara
glowz.saripah at gmail.com
Tue Jun 27 21:16:40 PDT 2006
hello, i'm glowz. a newbie here. i want to ask something to you all about dbus.
i've tried the first example program like inside the tutorial. i can
compile the program without warning and error message. i compile it
with this command:
gcc -ldbus-1 -ldbus-glib-1 -lglib-2.0 -I/usr/local/include/dbus-1.0
-I/usr/local/lib/dbus-1.0/include -I/usr/include/glib-2.0
-I/usr/lib/glib-2.0/include -o coba coba1.c
-DDBUS_API_SUBJECT_TO_CHANGE
And then, i attempt to run it. however, it goes to give me an error
that i can't understand, like this:
Failed to open connection to bus: Unable to determine the address of
the message bus (try 'man dbus-launch' and 'man dbus-daemon' for help)
Here's the code :
----------------------------------------------------------------------------------------------------
#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
int main (int argc, char **argv)
{
DBusGConnection *connection;
GError *error;
DBusGProxy *proxy;
char **name_list;
char **name_list_ptr;
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.freedesktop.DBus") */
proxy = dbus_g_proxy_new_for_name (connection,
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS);
/* Call ListNames method, wait for reply */
error = NULL;
if (!dbus_g_proxy_call (proxy, "ListNames", &error, G_TYPE_INVALID,
G_TYPE_STRV, &name_list, G_TYPE_INVALID)){
/* Just do demonstrate remote exceptions versus regular GError */
if (error->domain == DBUS_GERROR && error->code ==
DBUS_GERROR_REMOTE_EXCEPTION)
g_printerr ("Caught remote method exception %s:
%s",dbus_g_error_get_name (error),error->message);
else
g_printerr ("Error: %s\n", error->message);
g_error_free (error);
exit (1);
}
/* Print the results */
g_print ("Names on the message bus:\n");
for (name_list_ptr = name_list; *name_list_ptr; name_list_ptr++){
g_print (" %s\n", *name_list_ptr);
}
g_strfreev (name_list);
g_object_unref (proxy);
return 0;
}
------------------------------------------------------------------------------------------------------
Your considerations will help me.
------------------------
Thanks in advance!
More information about the dbus
mailing list