add NOWARN_SIZEOF_POINTER_MEMACCESS
[AROS.git] / rom / dbus / test / dbus-ping.c
blobc155448830b38805513b485eb54179b9fefe965e
1 /*
2 * Based on examples from "Connect desktop apps using D-BUS -- Helping
3 * applications talk to one another", developerWorks 27 Jul 2004,
4 */
6 #define DBUS_API_SUBJECT_TO_CHANGE
7 #include <proto/dbus.h>
8 #include <proto/dos.h>
9 #include <proto/exec.h>
11 #include <stdio.h>
13 #include "dbus-amiga.h"
15 struct Library* DBUSBase;
17 static int run();
18 static void send_ping(DBusConnection *bus);
20 int main() {
21 int rc = 0;
23 DBUSBase = OpenLibrary("dbus.library", 1);
25 if (DBUSBase != NULL) {
26 rc = run();
27 CloseLibrary(DBUSBase);
29 else {
30 rc = 20;
31 fprintf (stderr, "Unable to open dbus.library version 1\n");
34 return rc;
37 static int run() {
38 void* ac;
39 DBusError error;
40 DBusConnection* bus;
42 /* Get a connection to the session bus */
43 dbus_error_init (&error);
44 bus = dbus_bus_get (DBUS_BUS_SESSION, &error);
46 if (!bus) {
47 fprintf(stderr, "Failed to connect to the D-BUS daemon: %s", error.message);
48 dbus_error_free(&error);
49 return 10;
52 /* Set up this connection to work in an Amiga thread */
53 if (dbus_a_setup_connection(bus)) {
54 while ((SetSignal(0, 0) & SIGBREAKF_CTRL_C) == 0) {
55 send_ping(bus);
56 Delay(50);
58 dbus_a_cleanup_connection(bus);
61 dbus_error_free(&error);
62 return 0;
65 static void send_ping(DBusConnection *bus)
67 DBusMessage *message;
69 /* Create a new signal "Ping" on the "com.burtonini.dbus.Signal" interface,
70 * from the object "/com/burtonini/dbus/ping". */
71 message = dbus_message_new_signal ("/com/burtonini/dbus/ping",
72 "com.burtonini.dbus.Signal", "Ping");
73 /* Append the string "Ping!" to the signal */
74 dbus_message_append_args (message,
75 DBUS_TYPE_STRING, "Ping!",
76 DBUS_TYPE_INVALID);
77 /* Send the signal */
78 dbus_connection_send (bus, message, NULL);
79 /* Free the signal now we have finished with it */
80 dbus_message_unref (message);
81 /* Tell the user we send a signal */
82 printf("Ping!\n");