annotate src/dbus-server.c @ 14123:f8ab496671fa

[gaim-migrate @ 16761] Show scrollbars in trees and textviews. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Tue, 15 Aug 2006 02:45:52 +0000
parents dabbcb9b013d
children 38270d4e29c6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
1 /*
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
2 * gaim
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
3 *
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
4 * Gaim is the legal property of its developers, whose names are too numerous
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
5 * to list here. Please refer to the COPYRIGHT file distributed with this
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
6 * source distribution.
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
7 *
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
11 * (at your option) any later version.
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
12 *
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
16 * GNU General Public License for more details.
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
17 *
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
21 *
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
22 */
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
23
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
24 #define DBUS_API_SUBJECT_TO_CHANGE
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
25
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
26 #include <stdio.h>
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
27 #include <stdlib.h>
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
28 #include <string.h>
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
29
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
30 #include "account.h"
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
31 #include "blist.h"
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
32 #include "conversation.h"
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
33 #include "dbus-gaim.h"
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
34 #include "dbus-server.h"
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
35 #include "dbus-useful.h"
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
36 #include "dbus-bindings.h"
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
37 #include "debug.h"
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
38 #include "core.h"
13955
2d6f7ac4b6f2 [gaim-migrate @ 16503]
Mark Doliner <mark@kingant.net>
parents: 13763
diff changeset
39 #include "internal.h"
13761
ec858948d292 [gaim-migrate @ 16173]
Richard Laager <rlaager@wiktel.com>
parents: 13759
diff changeset
40 #include "savedstatuses.h"
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
41 #include "value.h"
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
42
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
43
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
44 /**************************************************************************/
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
45 /** @name Gaim DBUS pointer registration mechanism */
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
46 /**************************************************************************/
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
47
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
48 /*
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
49 * Here we include the list of #GAIM_DBUS_DEFINE_TYPE statements for
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
50 * all structs defined in gaim. This file has been generated by the
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
51 * #dbus-analize-types.py script.
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
52 */
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
53
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
54 #include "dbus-types.c"
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
55
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
56 /*
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
57 * The following three hashtables map are used to translate between
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
58 * pointers (nodes) and the corresponding handles (ids).
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
59 */
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
60
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
61 static GHashTable *map_node_id;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
62 static GHashTable *map_id_node;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
63 static GHashTable *map_id_type;
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
64
13955
2d6f7ac4b6f2 [gaim-migrate @ 16503]
Mark Doliner <mark@kingant.net>
parents: 13763
diff changeset
65 static gchar *init_error;
2d6f7ac4b6f2 [gaim-migrate @ 16503]
Mark Doliner <mark@kingant.net>
parents: 13763
diff changeset
66
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
67 /**
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
68 * This function initializes the pointer-id traslation system. It
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
69 * creates the three above hashtables and defines parents of some types.
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
70 */
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
71 void
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
72 gaim_dbus_init_ids(void)
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
73 {
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
74 map_id_node = g_hash_table_new(g_direct_hash, g_direct_equal);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
75 map_id_type = g_hash_table_new(g_direct_hash, g_direct_equal);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
76 map_node_id = g_hash_table_new(g_direct_hash, g_direct_equal);
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
77
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
78 GAIM_DBUS_TYPE(GaimBuddy)->parent = GAIM_DBUS_TYPE(GaimBlistNode);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
79 GAIM_DBUS_TYPE(GaimContact)->parent = GAIM_DBUS_TYPE(GaimBlistNode);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
80 GAIM_DBUS_TYPE(GaimChat)->parent = GAIM_DBUS_TYPE(GaimBlistNode);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
81 GAIM_DBUS_TYPE(GaimGroup)->parent = GAIM_DBUS_TYPE(GaimBlistNode);
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
82 }
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
83
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
84 void
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
85 gaim_dbus_register_pointer(gpointer node, GaimDBusType *type)
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
86 {
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
87 static gint last_id = 0;
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
88
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
89 g_return_if_fail(map_node_id);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
90 g_return_if_fail(g_hash_table_lookup(map_node_id, node) == NULL);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
91
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
92 last_id++;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
93 g_hash_table_insert(map_node_id, node, GINT_TO_POINTER(last_id));
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
94 g_hash_table_insert(map_id_node, GINT_TO_POINTER(last_id), node);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
95 g_hash_table_insert(map_id_type, GINT_TO_POINTER(last_id), type);
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
96 }
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
97
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
98 void
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
99 gaim_dbus_unregister_pointer(gpointer node)
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
100 {
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
101 gpointer id = g_hash_table_lookup(map_node_id, node);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
102
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
103 g_hash_table_remove(map_node_id, node);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
104 g_hash_table_remove(map_id_node, GINT_TO_POINTER(id));
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
105 g_hash_table_remove(map_id_type, GINT_TO_POINTER(id));
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
106 }
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
107
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
108 gint
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
109 gaim_dbus_pointer_to_id(gpointer node)
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
110 {
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
111 gint id = GPOINTER_TO_INT(g_hash_table_lookup(map_node_id, node));
13759
a849cf259d00 [gaim-migrate @ 16170]
Mark Doliner <mark@kingant.net>
parents: 13220
diff changeset
112 if ((id == 0) && (node != NULL))
a849cf259d00 [gaim-migrate @ 16170]
Mark Doliner <mark@kingant.net>
parents: 13220
diff changeset
113 {
a849cf259d00 [gaim-migrate @ 16170]
Mark Doliner <mark@kingant.net>
parents: 13220
diff changeset
114 gaim_debug_warning("dbus",
a849cf259d00 [gaim-migrate @ 16170]
Mark Doliner <mark@kingant.net>
parents: 13220
diff changeset
115 "Need to register an object with the dbus subsystem.\n");
13763
fd708f52defd [gaim-migrate @ 16175]
Richard Laager <rlaager@wiktel.com>
parents: 13761
diff changeset
116 g_return_val_if_reached(0);
13759
a849cf259d00 [gaim-migrate @ 16170]
Mark Doliner <mark@kingant.net>
parents: 13220
diff changeset
117 }
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
118 return id;
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
119 }
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
120
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
121 gpointer
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
122 gaim_dbus_id_to_pointer(gint id, GaimDBusType *type)
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
123 {
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
124 GaimDBusType *objtype;
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
125
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
126 objtype = (GaimDBusType*)g_hash_table_lookup(map_id_type,
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
127 GINT_TO_POINTER(id));
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
128
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
129 while (objtype != type && objtype != NULL)
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
130 objtype = objtype->parent;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
131
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
132 if (objtype == type)
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
133 return g_hash_table_lookup(map_id_node, GINT_TO_POINTER(id));
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
134 else
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
135 return NULL;
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
136 }
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
137
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
138 gint
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
139 gaim_dbus_pointer_to_id_error(gpointer ptr, DBusError *error)
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
140 {
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
141 gint id = gaim_dbus_pointer_to_id(ptr);
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
142
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
143 if (ptr != NULL && id == 0)
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
144 dbus_set_error(error, "net.sf.gaim.ObjectNotFound",
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
145 "The return object is not mapped (this is a Gaim error)");
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
146
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
147 return id;
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
148 }
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
149
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
150 gpointer
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
151 gaim_dbus_id_to_pointer_error(gint id, GaimDBusType *type,
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
152 const char *typename, DBusError *error)
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
153 {
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
154 gpointer ptr = gaim_dbus_id_to_pointer(id, type);
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
155
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
156 if (ptr == NULL && id != 0)
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
157 dbus_set_error(error, "net.sf.gaim.InvalidHandle",
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
158 "%s object with ID = %i not found", typename, id);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
159
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
160 return ptr;
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
161 }
11187
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
162
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
163
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
164 /**************************************************************************/
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
165 /** @name Modified versions of some DBus functions */
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
166 /**************************************************************************/
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
167
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
168 dbus_bool_t
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
169 gaim_dbus_message_get_args(DBusMessage *message,
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
170 DBusError *error, int first_arg_type, ...)
11187
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
171 {
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
172 dbus_bool_t retval;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
173 va_list var_args;
11187
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
174
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
175 va_start(var_args, first_arg_type);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
176 retval = gaim_dbus_message_get_args_valist(message, error, first_arg_type, var_args);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
177 va_end(var_args);
11187
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
178
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
179 return retval;
11187
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
180 }
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
181
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
182 dbus_bool_t
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
183 gaim_dbus_message_get_args_valist(DBusMessage *message,
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
184 DBusError *error, int first_arg_type, va_list var_args)
11187
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
185 {
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
186 DBusMessageIter iter;
11187
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
187
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
188 dbus_message_iter_init(message, &iter);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
189 return gaim_dbus_message_iter_get_args_valist(&iter, error, first_arg_type, var_args);
11187
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
190 }
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
191
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
192 dbus_bool_t
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
193 gaim_dbus_message_iter_get_args(DBusMessageIter *iter,
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
194 DBusError *error, int first_arg_type, ...)
11187
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
195 {
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
196 dbus_bool_t retval;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
197 va_list var_args;
11187
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
198
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
199 va_start(var_args, first_arg_type);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
200 retval = gaim_dbus_message_iter_get_args_valist(iter, error, first_arg_type, var_args);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
201 va_end(var_args);
11187
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
202
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
203 return retval;
11187
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
204 }
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
205
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
206 #define TYPE_IS_CONTAINER(typecode) \
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
207 ((typecode) == DBUS_TYPE_STRUCT || \
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
208 (typecode) == DBUS_TYPE_DICT_ENTRY || \
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
209 (typecode) == DBUS_TYPE_VARIANT || \
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
210 (typecode) == DBUS_TYPE_ARRAY)
11187
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
211
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
212
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
213 dbus_bool_t
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
214 gaim_dbus_message_iter_get_args_valist(DBusMessageIter *iter,
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
215 DBusError *error, int first_arg_type, va_list var_args)
11187
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
216 {
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
217 int spec_type, msg_type, i;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
218
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
219 spec_type = first_arg_type;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
220
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
221 for (i = 0; spec_type != DBUS_TYPE_INVALID; i++)
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
222 {
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
223 msg_type = dbus_message_iter_get_arg_type(iter);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
224
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
225 if (msg_type != spec_type)
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
226 {
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
227 dbus_set_error(error, DBUS_ERROR_INVALID_ARGS,
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
228 "Argument %d is specified to be of type \"%i\", but "
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
229 "is actually of type \"%i\"\n", i,
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
230 spec_type, msg_type);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
231 return FALSE;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
232 }
11187
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
233
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
234 if (!TYPE_IS_CONTAINER(spec_type))
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
235 {
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
236 gpointer ptr;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
237 ptr = va_arg (var_args, gpointer);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
238 dbus_message_iter_get_basic(iter, ptr);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
239 }
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
240 else
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
241 {
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
242 DBusMessageIter *sub;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
243 sub = va_arg (var_args, DBusMessageIter*);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
244 dbus_message_iter_recurse(iter, sub);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
245 gaim_debug_info("dbus", "subiter %p:%p\n", sub, * (gpointer*) sub);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
246 break; /* for testing only! */
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
247 }
11187
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
248
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
249 spec_type = va_arg(var_args, int);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
250 if (!dbus_message_iter_next(iter) && spec_type != DBUS_TYPE_INVALID)
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
251 {
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
252 dbus_set_error (error, DBUS_ERROR_INVALID_ARGS,
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
253 "Message has only %d arguments, but more were expected", i);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
254 return FALSE;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
255 }
11187
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
256 }
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
257
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
258 return TRUE;
11187
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
259 }
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
260
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
261
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
262
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
263 /**************************************************************************/
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
264 /** @name Useful functions */
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
265 /**************************************************************************/
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
266
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
267 const char *empty_to_null(const char *str)
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
268 {
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
269 if (str == NULL || str[0] == 0)
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
270 return NULL;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
271 else
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
272 return str;
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
273 }
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
274
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
275 const char *
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
276 null_to_empty(const char *s)
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
277 {
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
278 if (s)
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
279 return s;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
280 else
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
281 return "";
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
282 }
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
283
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
284 dbus_int32_t *
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
285 gaim_dbusify_GList(GList *list, gboolean free_memory, dbus_int32_t *len)
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
286 {
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
287 dbus_int32_t *array;
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
288 int i;
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
289 GList *elem;
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
290
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
291 *len = g_list_length(list);
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
292 array = g_new0(dbus_int32_t, g_list_length(list));
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
293 for (i = 0, elem = list; elem != NULL; elem = elem->next, i++)
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
294 array[i] = gaim_dbus_pointer_to_id(elem->data);
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
295
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
296 if (free_memory)
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
297 g_list_free(list);
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
298
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
299 return array;
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
300 }
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
301
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
302 dbus_int32_t *
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
303 gaim_dbusify_GSList(GSList *list, gboolean free_memory, dbus_int32_t *len)
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
304 {
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
305 dbus_int32_t *array;
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
306 int i;
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
307 GSList *elem;
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
308
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
309 *len = g_slist_length(list);
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
310 array = g_new0(dbus_int32_t, g_slist_length(list));
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
311 for (i = 0, elem = list; elem != NULL; elem = elem->next, i++)
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
312 array[i] = gaim_dbus_pointer_to_id(elem->data);
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
313
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
314 if (free_memory)
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
315 g_slist_free(list);
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
316
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
317 return array;
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
318 }
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
319
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
320 gpointer *
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
321 gaim_GList_to_array(GList *list, gboolean free_memory, dbus_int32_t *len)
11187
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
322 {
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
323 gpointer *array;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
324 int i;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
325 GList *elem;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
326
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
327 *len = g_list_length(list);
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
328 array = g_new0(gpointer, g_list_length(list));
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
329 for (i = 0, elem = list; elem != NULL; elem = elem->next, i++)
11187
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
330 array[i] = elem->data;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
331
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
332 if (free_memory)
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
333 g_list_free(list);
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
334
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
335 return array;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
336 }
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
337
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
338 gpointer *
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
339 gaim_GSList_to_array(GSList *list, gboolean free_memory, dbus_int32_t *len)
11187
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
340 {
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
341 gpointer *array;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
342 int i;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
343 GSList *elem;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
344
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
345 *len = g_slist_length(list);
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
346 array = g_new0(gpointer, g_slist_length(list));
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
347 for (i = 0, elem = list; elem != NULL; elem = elem->next, i++)
11187
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
348 array[i] = elem->data;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
349
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
350 if (free_memory)
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
351 g_slist_free(list);
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
352
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
353 return array;
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
354 }
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
355
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
356 GHashTable *
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
357 gaim_dbus_iter_hash_table(DBusMessageIter *iter, DBusError *error)
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
358 {
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
359 GHashTable *hash;
11187
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
360
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
361 /* we do not need to destroy strings because they are part of the message */
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
362 hash = g_hash_table_new(g_str_hash, g_str_equal);
11187
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
363
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
364 do {
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
365 char *key, *value;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
366 DBusMessageIter subiter;
11187
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
367
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
368 if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_DICT_ENTRY)
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
369 goto error;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
370 /* With all due respect to Dijkstra,
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
371 * this goto is for exception
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
372 * handling, and it is ok because it
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
373 * avoids duplication of the code
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
374 * responsible for destroying the hash
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
375 * table. Exceptional instructions
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
376 * for exceptional situations.
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
377 */
11187
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
378
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
379 dbus_message_iter_recurse(iter, &subiter);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
380 if (!gaim_dbus_message_iter_get_args(&subiter, error,
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
381 DBUS_TYPE_STRING, &key,
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
382 DBUS_TYPE_STRING, &value,
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
383 DBUS_TYPE_INVALID))
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
384 goto error; /* same here */
11187
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
385
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
386 g_hash_table_insert(hash, key, value);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
387 } while (dbus_message_iter_next(iter));
11187
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
388
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
389 return hash;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
390
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
391 error:
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
392 g_hash_table_destroy(hash);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
393 return NULL;
11187
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
394 }
744c0708d11f [gaim-migrate @ 13303]
Piotr Zielinski <zielaj>
parents: 11175
diff changeset
395
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
396 /**************************************************************/
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
397 /* DBus bindings ... */
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
398 /**************************************************************/
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
399
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
400 static DBusConnection *gaim_dbus_connection;
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
401
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
402 DBusConnection *
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
403 gaim_dbus_get_connection(void)
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
404 {
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
405 return gaim_dbus_connection;
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
406 }
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
407
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
408 #include "dbus-bindings.c"
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
409
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
410 static gboolean
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
411 gaim_dbus_dispatch_cb(DBusConnection *connection,
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
412 DBusMessage *message, void *user_data)
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
413 {
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
414 const char *name;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
415 GaimDBusBinding *bindings;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
416 int i;
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
417
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
418 bindings = (GaimDBusBinding*) user_data;
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
419
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
420 if (!dbus_message_has_path(message, DBUS_PATH_GAIM))
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
421 return FALSE;
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
422
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
423 name = dbus_message_get_member(message);
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
424
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
425 if (name == NULL)
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
426 return FALSE;
11175
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
427
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
428 if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_METHOD_CALL)
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
429 return FALSE;
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
430
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
431 for (i = 0; bindings[i].name; i++)
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
432 if (!strcmp(name, bindings[i].name))
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
433 {
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
434 DBusMessage *reply;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
435 DBusError error;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
436
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
437 dbus_error_init(&error);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
438
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
439 reply = bindings[i].handler(message, &error);
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
440
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
441 if (reply == NULL && dbus_error_is_set(&error))
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
442 reply = dbus_message_new_error (message,
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
443 error.name, error.message);
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
444
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
445 if (reply != NULL)
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
446 {
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
447 dbus_connection_send(connection, reply, NULL);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
448 dbus_message_unref(reply);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
449 }
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
450
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
451 return TRUE; /* return reply! */
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
452 }
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
453
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
454 return FALSE;
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
455 }
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
456
11175
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
457
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
458 static const char *
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
459 dbus_gettext(const char **ptr)
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
460 {
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
461 const char *text = *ptr;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
462 *ptr += strlen(text) + 1;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
463 return text;
11175
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
464 }
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
465
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
466 static void
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
467 gaim_dbus_introspect_cb(GList **bindings_list, void *bindings)
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
468 {
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
469 *bindings_list = g_list_prepend(*bindings_list, bindings);
11175
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
470 }
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
471
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
472 static DBusMessage *gaim_dbus_introspect(DBusMessage *message)
11175
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
473 {
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
474 DBusMessage *reply;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
475 GString *str;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
476 GList *bindings_list, *node;
11175
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
477
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
478 str = g_string_sized_new(0x1000); /* TODO: why this size? */
11175
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
479
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
480 g_string_append(str, "<!DOCTYPE node PUBLIC '-//freedesktop//DTD D-BUS Object Introspection 1.0//EN' 'http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd'>\n");
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
481 g_string_append_printf(str, "<node name='%s'>\n", DBUS_PATH_GAIM);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
482 g_string_append_printf(str, "<interface name='%s'>\n", DBUS_INTERFACE_GAIM);
11175
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
483
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
484 bindings_list = NULL;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
485 gaim_signal_emit(gaim_dbus_get_handle(), "dbus-introspect", &bindings_list);
11175
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
486
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
487 for (node = bindings_list; node; node = node->next)
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
488 {
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
489 GaimDBusBinding *bindings;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
490 int i;
11175
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
491
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
492 bindings = (GaimDBusBinding*)node->data;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
493
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
494 for (i = 0; bindings[i].name; i++)
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
495 {
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
496 const char *text;
11175
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
497
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
498 g_string_append_printf(str, "<method name='%s'>\n", bindings[i].name);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
499
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
500 text = bindings[i].parameters;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
501 while (*text)
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
502 {
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
503 const char *name, *direction, *type;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
504
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
505 direction = dbus_gettext(&text);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
506 type = dbus_gettext(&text);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
507 name = dbus_gettext(&text);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
508
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
509 g_string_append_printf(str,
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
510 "<arg name='%s' type='%s' direction='%s'/>\n",
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
511 name, type, direction);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
512 }
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
513 g_string_append(str, "</method>\n");
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
514 }
11175
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
515 }
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
516
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
517 g_string_append(str, "</interface>\n</node>\n");
11175
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
518
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
519 reply = dbus_message_new_method_return(message);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
520 dbus_message_append_args(reply, DBUS_TYPE_STRING, &(str->str),
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
521 DBUS_TYPE_INVALID);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
522 g_string_free(str, TRUE);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
523 g_list_free(bindings_list);
11175
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
524
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
525 return reply;
11175
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
526 }
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
527
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
528 static DBusHandlerResult
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
529 gaim_dbus_dispatch(DBusConnection *connection,
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
530 DBusMessage *message, void *user_data)
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
531 {
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
532 if (gaim_signal_emit_return_1(gaim_dbus_get_handle(),
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
533 "dbus-method-called", connection, message))
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
534 return DBUS_HANDLER_RESULT_HANDLED;
11175
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
535
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
536 if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_METHOD_CALL &&
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
537 dbus_message_has_path(message, DBUS_PATH_GAIM) &&
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
538 dbus_message_has_interface(message, DBUS_INTERFACE_INTROSPECTABLE) &&
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
539 dbus_message_has_member(message, "Introspect"))
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
540 {
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
541 DBusMessage *reply;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
542 reply = gaim_dbus_introspect(message);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
543 dbus_connection_send (connection, reply, NULL);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
544 dbus_message_unref(reply);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
545 return DBUS_HANDLER_RESULT_HANDLED;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
546 }
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
547
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
548 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
549 }
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
550
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
551 void
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
552 gaim_dbus_register_bindings(void *handle, GaimDBusBinding *bindings)
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
553 {
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
554 gaim_signal_connect(gaim_dbus_get_handle(), "dbus-method-called",
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
555 handle,
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
556 GAIM_CALLBACK(gaim_dbus_dispatch_cb),
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
557 bindings);
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
558 gaim_signal_connect(gaim_dbus_get_handle(), "dbus-introspect",
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
559 handle,
11175
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
560 GAIM_CALLBACK(gaim_dbus_introspect_cb),
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
561 bindings);
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
562 }
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
563
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
564 static void
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
565 gaim_dbus_dispatch_init(void)
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
566 {
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
567 static DBusObjectPathVTable vtable = {NULL, &gaim_dbus_dispatch, NULL, NULL, NULL, NULL};
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
568 DBusError error;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
569 int result;
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
570
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
571 dbus_error_init(&error);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
572 gaim_dbus_connection = dbus_bus_get(DBUS_BUS_STARTER, &error);
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
573
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
574 if (gaim_dbus_connection == NULL)
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
575 {
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
576 init_error = g_strdup_printf(N_("Failed to get connection: %s"), error.message);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
577 dbus_error_free(&error);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
578 return;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
579 }
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
580
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
581 if (!dbus_connection_register_object_path(gaim_dbus_connection,
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
582 DBUS_PATH_GAIM, &vtable, NULL))
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
583 {
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
584 init_error = g_strdup_printf(N_("Failed to get name: %s"), error.name);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
585 dbus_error_free(&error);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
586 return;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
587 }
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
588
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
589 result = dbus_bus_request_name(gaim_dbus_connection,
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
590 DBUS_SERVICE_GAIM, 0, &error);
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
591
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
592 if (dbus_error_is_set(&error))
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
593 {
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
594 dbus_connection_unref(gaim_dbus_connection);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
595 dbus_error_free(&error);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
596 gaim_dbus_connection = NULL;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
597 init_error = g_strdup_printf(N_("Failed to get serv name: %s"), error.name);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
598 return;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
599 }
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
600
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
601 dbus_connection_setup_with_g_main(gaim_dbus_connection, NULL);
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
602
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
603 gaim_debug_misc("dbus", "okkk\n");
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
604
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
605 gaim_signal_register(gaim_dbus_get_handle(), "dbus-method-called",
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
606 gaim_marshal_BOOLEAN__POINTER_POINTER,
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
607 gaim_value_new(GAIM_TYPE_BOOLEAN), 2,
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
608 gaim_value_new(GAIM_TYPE_POINTER),
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
609 gaim_value_new(GAIM_TYPE_POINTER));
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
610
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
611 gaim_signal_register(gaim_dbus_get_handle(), "dbus-introspect",
11175
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
612 gaim_marshal_VOID__POINTER, NULL, 1,
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
613 gaim_value_new_outgoing(GAIM_TYPE_POINTER));
57af14280b5f [gaim-migrate @ 13280]
Piotr Zielinski <zielaj>
parents: 11171
diff changeset
614
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
615 GAIM_DBUS_REGISTER_BINDINGS(gaim_dbus_get_handle());
11171
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
616 }
ebb02ea3c789 [gaim-migrate @ 13272]
Piotr Zielinski <zielaj>
parents: 11146
diff changeset
617
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
618
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
619
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
620 /**************************************************************************/
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
621 /** @name Signals */
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
622 /**************************************************************************/
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
623
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
624
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
625
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
626 static char *
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
627 gaim_dbus_convert_signal_name(const char *gaim_name)
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
628 {
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
629 int gaim_index, g_index;
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
630 char *g_name = g_new(char, strlen(gaim_name) + 1);
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
631 gboolean capitalize_next = TRUE;
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
632
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
633 for (gaim_index = g_index = 0; gaim_name[gaim_index]; gaim_index++)
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
634 if (gaim_name[gaim_index] != '-' && gaim_name[gaim_index] != '_')
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
635 {
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
636 if (capitalize_next)
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
637 g_name[g_index++] = g_ascii_toupper(gaim_name[gaim_index]);
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
638 else
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
639 g_name[g_index++] = gaim_name[gaim_index];
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
640 capitalize_next = FALSE;
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
641 } else
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
642 capitalize_next = TRUE;
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
643
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
644 g_name[g_index] = 0;
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
645
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
646 return g_name;
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
647 }
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
648
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
649 #define my_arg(type) (ptr != NULL ? * ((type *)ptr) : va_arg(data, type))
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
650
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
651 static void
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
652 gaim_dbus_message_append_gaim_values(DBusMessageIter *iter,
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
653 int number, GaimValue **gaim_values, va_list data)
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
654 {
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
655 int i;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
656
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
657 for (i = 0; i < number; i++)
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
658 {
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
659 const char *str;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
660 int id;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
661 gint xint;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
662 guint xuint;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
663 gboolean xboolean;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
664 gpointer ptr = NULL;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
665
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
666 if (gaim_value_is_outgoing(gaim_values[i]))
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
667 {
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
668 ptr = my_arg(gpointer);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
669 g_return_if_fail(ptr);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
670 }
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
671
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
672 switch (gaim_values[i]->type)
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
673 {
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
674 case GAIM_TYPE_INT:
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
675 xint = my_arg(gint);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
676 dbus_message_iter_append_basic(iter, DBUS_TYPE_INT32, &xint);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
677 break;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
678 case GAIM_TYPE_UINT:
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
679 xuint = my_arg(guint);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
680 dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &xuint);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
681 break;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
682 case GAIM_TYPE_BOOLEAN:
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
683 xboolean = my_arg(gboolean);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
684 dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &xboolean);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
685 break;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
686 case GAIM_TYPE_STRING:
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
687 str = null_to_empty(my_arg(char*));
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
688 dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &str);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
689 break;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
690 case GAIM_TYPE_SUBTYPE: /* registered pointers only! */
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
691 case GAIM_TYPE_POINTER:
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
692 case GAIM_TYPE_OBJECT:
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
693 case GAIM_TYPE_BOXED:
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
694 id = gaim_dbus_pointer_to_id(my_arg(gpointer));
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
695 dbus_message_iter_append_basic(iter,
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
696 (sizeof(void *) == 4) ? DBUS_TYPE_UINT32 : DBUS_TYPE_UINT64, &id);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
697 break;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
698 default: /* no conversion implemented */
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
699 g_return_if_reached();
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
700 }
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
701 }
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
702 }
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
703
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
704 #undef my_arg
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
705
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
706 void
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
707 gaim_dbus_signal_emit_gaim(const char *name, int num_values,
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
708 GaimValue **values, va_list vargs)
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
709 {
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
710 DBusMessage *signal;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
711 DBusMessageIter iter;
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
712 char *newname;
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
713
11903
c9312177821a [gaim-migrate @ 14194]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11291
diff changeset
714 #if 0 /* this is noisy with no dbus connection */
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
715 g_return_if_fail(gaim_dbus_connection);
11903
c9312177821a [gaim-migrate @ 14194]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11291
diff changeset
716 #else
c9312177821a [gaim-migrate @ 14194]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11291
diff changeset
717 if (gaim_dbus_connection == NULL)
c9312177821a [gaim-migrate @ 14194]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11291
diff changeset
718 return;
c9312177821a [gaim-migrate @ 14194]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11291
diff changeset
719 #endif
c9312177821a [gaim-migrate @ 14194]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11291
diff changeset
720
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
721
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
722 /*
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
723 * The test below is a hack that prevents our "dbus-method-called"
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
724 * signal from being propagated to dbus. What we really need is a
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
725 * flag for each signal that states whether this signal is to be
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
726 * dbus-propagated or not.
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
727 */
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
728 if (!strcmp(name, "dbus-method-called"))
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
729 return;
11277
421a8523ad04 [gaim-migrate @ 13467]
Piotr Zielinski <zielaj>
parents: 11187
diff changeset
730
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
731 newname = gaim_dbus_convert_signal_name(name);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
732 signal = dbus_message_new_signal(DBUS_PATH_GAIM, DBUS_INTERFACE_GAIM, newname);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
733 dbus_message_iter_init_append(signal, &iter);
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
734
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
735 gaim_dbus_message_append_gaim_values(&iter, num_values, values, vargs);
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
736
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
737 dbus_connection_send(gaim_dbus_connection, signal, NULL);
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
738
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
739 g_free(newname);
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
740 dbus_message_unref(signal);
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
741 }
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
742
13955
2d6f7ac4b6f2 [gaim-migrate @ 16503]
Mark Doliner <mark@kingant.net>
parents: 13763
diff changeset
743 const char *
2d6f7ac4b6f2 [gaim-migrate @ 16503]
Mark Doliner <mark@kingant.net>
parents: 13763
diff changeset
744 gaim_dbus_get_init_error(void)
2d6f7ac4b6f2 [gaim-migrate @ 16503]
Mark Doliner <mark@kingant.net>
parents: 13763
diff changeset
745 {
2d6f7ac4b6f2 [gaim-migrate @ 16503]
Mark Doliner <mark@kingant.net>
parents: 13763
diff changeset
746 return init_error;
2d6f7ac4b6f2 [gaim-migrate @ 16503]
Mark Doliner <mark@kingant.net>
parents: 13763
diff changeset
747 }
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
748
13955
2d6f7ac4b6f2 [gaim-migrate @ 16503]
Mark Doliner <mark@kingant.net>
parents: 13763
diff changeset
749 void *
2d6f7ac4b6f2 [gaim-migrate @ 16503]
Mark Doliner <mark@kingant.net>
parents: 13763
diff changeset
750 gaim_dbus_get_handle(void)
2d6f7ac4b6f2 [gaim-migrate @ 16503]
Mark Doliner <mark@kingant.net>
parents: 13763
diff changeset
751 {
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
752 static int handle;
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
753
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
754 return &handle;
13955
2d6f7ac4b6f2 [gaim-migrate @ 16503]
Mark Doliner <mark@kingant.net>
parents: 13763
diff changeset
755 }
2d6f7ac4b6f2 [gaim-migrate @ 16503]
Mark Doliner <mark@kingant.net>
parents: 13763
diff changeset
756
2d6f7ac4b6f2 [gaim-migrate @ 16503]
Mark Doliner <mark@kingant.net>
parents: 13763
diff changeset
757 void
2d6f7ac4b6f2 [gaim-migrate @ 16503]
Mark Doliner <mark@kingant.net>
parents: 13763
diff changeset
758 gaim_dbus_init(void)
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
759 {
14122
dabbcb9b013d [gaim-migrate @ 16759]
Ethan Blanton <elb@pidgin.im>
parents: 13963
diff changeset
760 if (g_thread_supported())
dabbcb9b013d [gaim-migrate @ 16759]
Ethan Blanton <elb@pidgin.im>
parents: 13963
diff changeset
761 dbus_g_thread_init();
dabbcb9b013d [gaim-migrate @ 16759]
Ethan Blanton <elb@pidgin.im>
parents: 13963
diff changeset
762
13963
f7cfaee79982 [gaim-migrate @ 16517]
Mark Doliner <mark@kingant.net>
parents: 13955
diff changeset
763 gaim_dbus_init_ids();
13955
2d6f7ac4b6f2 [gaim-migrate @ 16503]
Mark Doliner <mark@kingant.net>
parents: 13763
diff changeset
764
2d6f7ac4b6f2 [gaim-migrate @ 16503]
Mark Doliner <mark@kingant.net>
parents: 13763
diff changeset
765 g_free(init_error);
2d6f7ac4b6f2 [gaim-migrate @ 16503]
Mark Doliner <mark@kingant.net>
parents: 13763
diff changeset
766 init_error = NULL;
2d6f7ac4b6f2 [gaim-migrate @ 16503]
Mark Doliner <mark@kingant.net>
parents: 13763
diff changeset
767 gaim_dbus_dispatch_init();
2d6f7ac4b6f2 [gaim-migrate @ 16503]
Mark Doliner <mark@kingant.net>
parents: 13763
diff changeset
768 if (init_error != NULL)
2d6f7ac4b6f2 [gaim-migrate @ 16503]
Mark Doliner <mark@kingant.net>
parents: 13763
diff changeset
769 gaim_debug_error("dbus", "%s\n", init_error);
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
770 }
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
771
13955
2d6f7ac4b6f2 [gaim-migrate @ 16503]
Mark Doliner <mark@kingant.net>
parents: 13763
diff changeset
772 void
2d6f7ac4b6f2 [gaim-migrate @ 16503]
Mark Doliner <mark@kingant.net>
parents: 13763
diff changeset
773 gaim_dbus_uninit(void)
2d6f7ac4b6f2 [gaim-migrate @ 16503]
Mark Doliner <mark@kingant.net>
parents: 13763
diff changeset
774 {
2d6f7ac4b6f2 [gaim-migrate @ 16503]
Mark Doliner <mark@kingant.net>
parents: 13763
diff changeset
775 /* Surely we must do SOME kind of uninitialization? */
11146
1c5398ccbeb0 [gaim-migrate @ 13217]
Piotr Zielinski <zielaj>
parents: 11080
diff changeset
776
13955
2d6f7ac4b6f2 [gaim-migrate @ 16503]
Mark Doliner <mark@kingant.net>
parents: 13763
diff changeset
777 g_free(init_error);
2d6f7ac4b6f2 [gaim-migrate @ 16503]
Mark Doliner <mark@kingant.net>
parents: 13763
diff changeset
778 init_error = NULL;
2d6f7ac4b6f2 [gaim-migrate @ 16503]
Mark Doliner <mark@kingant.net>
parents: 13763
diff changeset
779 }