/*
 * Testing emitting a DBus signal with signature xad
 *
 * gcc $(pkg-config gio-2.0 --cflags --libs) -o test-dbus-xad test-dbus-xad.c
 */

#include <gio/gio.h>

int
main (void)
{
  GDBusConnection *conn;
  GError *error = NULL;
  GDBusMessage *message;
  GVariantBuilder builder;
  gchar *string;

  conn = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
  g_assert_no_error (error);

  g_variant_builder_init (&builder, G_VARIANT_TYPE ("ad"));
  g_variant_builder_add (&builder, "d", (gdouble)0.0);
  g_variant_builder_add (&builder, "d", (gdouble)8.0);
  g_variant_builder_add (&builder, "d", (gdouble)22.0);
  g_variant_builder_add (&builder, "d", (gdouble)0.0);

  message = g_dbus_message_new_signal ("/path", "org.iface.Test", "MySignal");
  g_dbus_message_set_body (message,
                           g_variant_new ("(@ad)",
                                          g_variant_builder_end (&builder)));

  g_dbus_connection_send_message (conn, message, 0, NULL, &error);
  g_assert_no_error (error);

  string = g_variant_print (g_dbus_message_get_body (message), TRUE);
  g_printerr ("sent: %s %s.%s %s\n",
              g_dbus_message_get_path (message),
              g_dbus_message_get_interface (message),
              g_dbus_message_get_member (message),
              string);
  g_free (string);

  g_object_unref (message);

  while (TRUE)
    g_main_context_iteration (NULL, TRUE);
  g_assert_not_reached ();
  return 1;
}
