Add elisp interface
[emacs-jabber-tox.git] / main.c
blobd42be8a46543b4a8ee0c37b504f2cfd9bdeee5e1
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 if (!dbus_g_proxy_call(bus_proxy, "RequestName", &error,
43 G_TYPE_STRING, "net.sourceforge.emacs-jabber.Tox",
44 G_TYPE_UINT,
45 /* these settings are good for debugging. we
46 should listen for the NameLost signal, though. */
47 DBUS_NAME_FLAG_ALLOW_REPLACEMENT
48 | DBUS_NAME_FLAG_REPLACE_EXISTING
49 | DBUS_NAME_FLAG_DO_NOT_QUEUE,
50 G_TYPE_INVALID,
51 G_TYPE_UINT, &x,
52 G_TYPE_INVALID)) {
53 g_printerr("Couldn't acquire name: %s\n", error->message);
54 exit(1);
56 else if (x != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
57 g_printerr("Couldn't acquire name: RequestName returned %u\n", x);
58 exit(1);
61 obj = g_object_new(TOX_TYPE_OBJECT, "dbus-connection", connection, NULL);
62 dbus_g_connection_register_g_object(connection, "/net/sourceforge/emacs_jabber/Tox", G_OBJECT(obj));
64 loop = g_main_loop_new(NULL, FALSE);
66 g_main_loop_run(loop);
67 return 0;