Changes

Jump to: navigation, search

D-Bus and other Linux desktop integration improvements

1,907 bytes added, 14:35, 15 December 2006
DBUS Tutorial and info
You will need to include the libdbus libraries in your project or make files. They are not in the default path.
 
#include <stdio.h>
#include "glib.h"
#ifndef DBUS_API_SUBJECT_TO_CHANGE
#define DBUS_API_SUBJECT_TO_CHANGE
#include <dbus/dbus.h>
#endif
int main()
{
DBusConnection *conn;
DBusError error;
dbus_error_init(&error);
conn = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
if(conn == NULL)
{
fprintf(stderr, "Failed to open connection to bus: %s\n",error.message);
dbus_error_free(&error);
exit(1);
}
else printf("Connected to System Bus\n");
dbus_uint32_t serial = 0;// unique number to associate replies with requests
DBusMessage* msg;
DBusMessageIter args;
const char* sigvalue = "Hello World";
printf("Attempting to create a new Signal.\n");
msg = dbus_message_new_signal("/com/halcyoncomplex/test", // object name of the signal
"com.halcyoncomplex.test", // interface name of the signal
"test"); // name of the signal
if (NULL == msg)
{
fprintf(stderr, "Message Null\n");
exit(1);
}
else printf("Signal Created.\n");
printf("Attempting to add arguments to signal.\n");
dbus_message_iter_init_append(msg, &args);
if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &sigvalue))
{
fprintf(stderr, "Out Of Memory!\n");
exit(1);
}
else printf("Added argument of type(String) with value(Hello World)\n");
printf("Attempting to send signal.\n");
// send the message and flush the connection
if (!dbus_connection_send(conn, msg, &serial))
{
fprintf(stderr, "Out Of Memory!\n");
exit(1);
}
else printf("Signal Sent. =)\n");
printf("Serial value for my signal is: %u\n",&serial);
//printf("Flushing connection.\n");
dbus_connection_flush(conn);
printf("Unreferencing message object.\n");
// free the message
dbus_message_unref(msg);
////////////////////////////////////////////////////////////////////////////
printf("Closing connection.\n");
dbus_connection_close(conn);
}
== Suggestions & Ideas ==
1
edit

Navigation menu