debug messages about D-Bus name acquisition
[emacs-jabber-tox.git] / main.c
blob39909f37d0d4e3509a9c28b8fa068de0c204f75d
1 #include <farsight/farsight.h>
2 #include <dbus/dbus-glib.h>
3 #include <glib/gprintf.h>
4 #include <string.h>
5 #include "tox.h"
7 int
8 main(int argc, char *argv[])
10 GMainLoop *loop;
11 DBusGConnection *connection;
12 DBusGProxy *bus_proxy;
13 GError *error = NULL;
14 ToxObject *obj;
15 guint32 x;
17 g_type_init();
18 gst_init(&argc, &argv);
21 GLogLevelFlags fatal_mask;
23 fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
24 /* not aborting on warnings because of:
25 farsight-rtp-WARNING **: Not enough information in rtp caps
27 fatal_mask |= /*G_LOG_LEVEL_WARNING | */ G_LOG_LEVEL_CRITICAL;
28 g_log_set_always_fatal (fatal_mask);
31 connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
32 if (connection == NULL) {
33 g_printerr("Failed to open connection to bus: %s\n",
34 error->message);
35 exit(1);
38 bus_proxy = dbus_g_proxy_new_for_name(connection, "org.freedesktop.DBus",
39 "/org/freedesktop/DBus",
40 "org.freedesktop.DBus");
42 g_debug("About to request D-Bus name...\n");
43 if (!dbus_g_proxy_call(bus_proxy, "RequestName", &error,
44 G_TYPE_STRING, "net.sourceforge.emacs-jabber.Tox",
45 G_TYPE_UINT,
46 /* these settings are good for debugging. we
47 should listen for the NameLost signal, though. */
48 DBUS_NAME_FLAG_ALLOW_REPLACEMENT
49 | DBUS_NAME_FLAG_REPLACE_EXISTING
50 | DBUS_NAME_FLAG_DO_NOT_QUEUE,
51 G_TYPE_INVALID,
52 G_TYPE_UINT, &x,
53 G_TYPE_INVALID)) {
54 g_printerr("Couldn't acquire name: %s\n", error->message);
55 exit(1);
57 else if (x != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
58 g_printerr("Couldn't acquire name: RequestName returned %u\n", x);
59 exit(1);
61 g_debug("D-Bus name acquired\n");
63 obj = g_object_new(TOX_TYPE_OBJECT, "dbus-connection", connection, NULL);
64 dbus_g_connection_register_g_object(connection, "/net/sourceforge/emacs_jabber/Tox", G_OBJECT(obj));
66 loop = g_main_loop_new(NULL, FALSE);
68 g_main_loop_run(loop);
69 return 0;