Mercurial > pidgin
comparison src/dbus-server.c @ 11055:df0241eb602c
[gaim-migrate @ 12996]
Added preliminary DBUS support to gaim, the details are described in
README.dbus.
committer: Tailor Script <tailor@pidgin.im>
| author | Piotr Zielinski <zielaj> |
|---|---|
| date | Sun, 03 Jul 2005 21:48:56 +0000 |
| parents | |
| children | 2eca9ed49469 |
comparison
equal
deleted
inserted
replaced
| 11054:bc700cc98b82 | 11055:df0241eb602c |
|---|---|
| 1 /* | |
| 2 * gaim | |
| 3 * | |
| 4 * Gaim is the legal property of its developers, whose names are too numerous | |
| 5 * to list here. Please refer to the COPYRIGHT file distributed with this | |
| 6 * source distribution. | |
| 7 * | |
| 8 * This program is free software; you can redistribute it and/or modify | |
| 9 * it under the terms of the GNU General Public License as published by | |
| 10 * the Free Software Foundation; either version 2 of the License, or | |
| 11 * (at your option) any later version. | |
| 12 * | |
| 13 * This program is distributed in the hope that it will be useful, | |
| 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 * GNU General Public License for more details. | |
| 17 * | |
| 18 * You should have received a copy of the GNU General Public License | |
| 19 * along with this program; if not, write to the Free Software | |
| 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 21 * | |
| 22 */ | |
| 23 | |
| 24 #include <dbus/dbus-glib.h> | |
| 25 #include <dbus/dbus-glib-bindings.h> | |
| 26 #include <stdio.h> | |
| 27 #include <stdlib.h> | |
| 28 #include <string.h> | |
| 29 #include <glib/gi18n.h> | |
| 30 #include <glib-object.h> | |
| 31 #include <glib/gquark.h> | |
| 32 | |
| 33 #include "account.h" | |
| 34 #include "dbus-gaim.h" | |
| 35 #include "dbus-server.h" | |
| 36 #include "debug.h" | |
| 37 #include "core.h" | |
| 38 | |
| 39 /* GaimObject, basic definitions*/ | |
| 40 | |
| 41 typedef struct GaimObject GaimObject; | |
| 42 typedef struct GaimObjectClass GaimObjectClass; | |
| 43 | |
| 44 GType gaim_object_get_type(void); | |
| 45 | |
| 46 struct GaimObject { | |
| 47 GObject parent; | |
| 48 }; | |
| 49 | |
| 50 struct GaimObjectClass { | |
| 51 GObjectClass parent; | |
| 52 }; | |
| 53 | |
| 54 #define GAIM_TYPE_OBJECT (gaim_object_get_type ()) | |
| 55 #define GAIM_OBJECT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GAIM_TYPE_OBJECT, GaimObject)) | |
| 56 #define GAIM_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAIM_TYPE_OBJECT, GaimObjectClass)) | |
| 57 #define GAIM_IS_OBJECT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GAIM_TYPE_OBJECT)) | |
| 58 #define GAIM_IS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAIM_TYPE_OBJECT)) | |
| 59 #define GAIM_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAIM_TYPE_OBJECT, GaimObjectClass)) | |
| 60 | |
| 61 G_DEFINE_TYPE(GaimObject, gaim_object, G_TYPE_OBJECT) | |
| 62 | |
| 63 | |
| 64 static void | |
| 65 gaim_object_init(GaimObject *obj) | |
| 66 { | |
| 67 } | |
| 68 | |
| 69 static void | |
| 70 gaim_object_class_init(GaimObjectClass *mobject_class) | |
| 71 { | |
| 72 } | |
| 73 | |
| 74 static GObject *gaim_object; | |
| 75 | |
| 76 | |
| 77 /* Implementations of remote DBUS calls */ | |
| 78 | |
| 79 | |
| 80 static gboolean | |
| 81 gaim_object_ping(GaimObject *obj, GError **error) | |
| 82 { | |
| 83 return TRUE; | |
| 84 } | |
| 85 | |
| 86 static gboolean | |
| 87 gaim_object_quit(GaimObject *obj, GError **error) | |
| 88 { | |
| 89 g_timeout_add(0, gaim_core_quit_cb, NULL); | |
| 90 return TRUE; | |
| 91 } | |
| 92 | |
| 93 static gboolean | |
| 94 gaim_object_connect_all(GaimObject *obj, GError **error) | |
| 95 { | |
| 96 GList *cur; | |
| 97 | |
| 98 for (cur = gaim_accounts_get_all(); cur != NULL; cur = cur->next) | |
| 99 gaim_account_connect((GaimAccount*) cur->data); | |
| 100 | |
| 101 return TRUE; | |
| 102 } | |
| 103 | |
| 104 #include "dbus-server-bindings.c" | |
| 105 | |
| 106 | |
| 107 gboolean | |
| 108 dbus_server_init(void) | |
| 109 { | |
| 110 DBusGConnection *connection; | |
| 111 GError *error; | |
| 112 DBusGProxy *driver_proxy; | |
| 113 guint32 request_name_ret; | |
| 114 | |
| 115 gaim_debug_misc("dbus", "launching dbus server\n"); | |
| 116 | |
| 117 /* Connect to the bus */ | |
| 118 | |
| 119 error = NULL; | |
| 120 connection = dbus_g_bus_get(DBUS_BUS_STARTER, &error); | |
| 121 | |
| 122 if (connection == NULL) { | |
| 123 g_assert(error); | |
| 124 gaim_debug_error("dbus", "Failed to open connection to bus: %s\n", | |
| 125 error->message); | |
| 126 g_error_free (error); | |
| 127 return FALSE; | |
| 128 } | |
| 129 | |
| 130 | |
| 131 /* Instantiate the gaim dbus object and register it */ | |
| 132 | |
| 133 gaim_object = g_object_new (GAIM_TYPE_OBJECT, NULL); | |
| 134 | |
| 135 dbus_g_object_type_install_info (GAIM_TYPE_OBJECT, | |
| 136 &dbus_glib_gaim_object_object_info); | |
| 137 | |
| 138 dbus_g_connection_register_g_object (connection, DBUS_PATH_GAIM, | |
| 139 gaim_object); | |
| 140 | |
| 141 | |
| 142 /* Obtain a proxy for the DBus object */ | |
| 143 | |
| 144 driver_proxy = dbus_g_proxy_new_for_name (connection, | |
| 145 DBUS_SERVICE_DBUS, | |
| 146 DBUS_PATH_DBUS, | |
| 147 DBUS_INTERFACE_DBUS); | |
| 148 | |
| 149 | |
| 150 /* Test whether the registration was successful */ | |
| 151 | |
| 152 org_freedesktop_DBus_request_name(driver_proxy, DBUS_SERVICE_GAIM, | |
| 153 0, &request_name_ret, &error); | |
| 154 | |
| 155 if (error) { | |
| 156 gaim_debug_error("dbus", "Failed to get name: %s\n", error->message); | |
| 157 g_error_free (error); | |
| 158 return FALSE; | |
| 159 } | |
| 160 | |
| 161 if (request_name_ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) | |
| 162 { | |
| 163 gaim_debug_error ("dbus", "Got result code %u from requesting name\n", | |
| 164 request_name_ret); | |
| 165 return FALSE; | |
| 166 } | |
| 167 | |
| 168 gaim_debug_misc ("dbus", "GLib test service has name '%s'\n", | |
| 169 DBUS_SERVICE_GAIM); | |
| 170 gaim_debug_misc ("dbus", "GLib test service entering main loop\n"); | |
| 171 | |
| 172 return TRUE; | |
| 173 } |
