annotate src/dbus-server.c @ 11080:f54740547c95

[gaim-migrate @ 13092] All gaim signals are automatically relayed to dbus. committer: Tailor Script <tailor@pidgin.im>
author Piotr Zielinski <zielaj>
date Sun, 10 Jul 2005 02:29:52 +0000
parents 9bd0aac996f4
children 1c5398ccbeb0
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
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
24 #include <dbus/dbus-glib.h>
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
25 #include <dbus/dbus-glib-bindings.h>
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 #include <glib/gi18n.h>
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
30 #include <glib-object.h>
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
31 #include <glib/gquark.h>
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
32 #include <glib.h>
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
33
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
34 #include "account.h"
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
35 #include "blist.h"
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
36 #include "conversation.h"
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
37 #include "dbus-gaim.h"
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
38 #include "dbus-server.h"
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
39 #include "debug.h"
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
40 #include "core.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 static gint gaim_dbus_pointer_to_id(gpointer node);
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
44 static gpointer gaim_dbus_id_to_pointer(gint id, GaimDBusPointerType type);
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
45
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
46
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
47 /**************************************************************************/
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
48 /** @name Lots of GObject stuff I don't really understand */
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
49 /**************************************************************************/
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
50
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
51 GType gaim_object_get_type(void);
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
52
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
53 struct _GaimObject {
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
54 GObject parent;
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
55
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
56 int ping_signal_id;
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
57 };
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
58
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
59 typedef struct {
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
60 GObjectClass parent;
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
61 } GaimObjectClass;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
62
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
63
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
64
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
65 #define GAIM_DBUS_TYPE_OBJECT (gaim_object_get_type ())
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
66 #define GAIM_DBUS_OBJECT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GAIM_DBUS_TYPE_OBJECT, GaimObject))
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
67 #define GAIM_DBUS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAIM_DBUS_TYPE_OBJECT, GaimObjectClass))
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
68 #define GAIM_DBUS_IS_OBJECT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GAIM_DBUS_TYPE_OBJECT))
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
69 #define GAIM_DBUS_IS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAIM_DBUS_TYPE_OBJECT))
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
70 #define GAIM_DBUS_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAIM_DBUS_TYPE_OBJECT, GaimObjectClass))
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
71
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
72 G_DEFINE_TYPE(GaimObject, gaim_object, G_TYPE_OBJECT)
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
73
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
74 GaimObject *gaim_dbus_object;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
75 static GQuark gaim_object_error_quark;
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
76
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
77 static const char* null_to_empty(const char *s) {
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
78 if (s)
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
79 return s;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
80 else
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
81 return "";
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
82 }
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
83
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
84
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
85
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
86 static void gaim_object_class_init(GaimObjectClass *klass)
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
87 {
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
88 }
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
89
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
90
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
91
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
92 /**************************************************************************/
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
93 /** @name Signals */
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
94 /**************************************************************************/
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
95
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
96 /* used in #gaim_values_to_gvalues, undefined afterwards */
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
97 #define my_arg(type) (ptr != NULL ? * ((type *)ptr) : va_arg(data, type))
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
98
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
99 /**
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
100 Converts from a list of data into an GValue array.
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
101
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
102 @param gvalus Array of empty gvalues to be filled.
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
103 @param number The number of data items.
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
104 @param gaim_value Array of #number pointers to GaimValues.
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
105 The types of of these GaimValues determine the type
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
106 of data items. The values do not matter.
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
107 @param mainptr A pointer to a single data item. If this pointer is not #NULL,
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
108 then #number must be 1.
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
109 @param data A va_list containing data items. If
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
110
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
111 Exactly one of #mainptr and #data must be not #NULL. If #mainptr
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
112 is not #NULL, then there is a single piece of data at the address
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
113 pointed at by #mainptr. If #data is not #NULL, then there are
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
114 #number data items in the #va_list #data.
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
115 */
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
116 static void gaim_values_to_gvalues(GValue *gvalue, int number,
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
117 GaimValue **gaim_values, gpointer mainptr, va_list data)
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
118 {
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
119 int i;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
120 gpointer ptr;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
121
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
122 g_assert(mainptr == NULL || data == NULL);
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
123 g_assert(mainptr != NULL || data != NULL);
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
124 g_assert(number == 1 || data != NULL);
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
125
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
126 for(i=0; i<number; i++, gvalue++) {
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
127 ptr = mainptr;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
128 if (gaim_value_is_outgoing(gaim_values[i])) {
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
129 ptr = my_arg(gpointer);
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
130 g_assert(ptr);
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
131 }
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
132
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
133 switch(gaim_values[i]->type) {
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
134 case GAIM_TYPE_CHAR:
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
135 g_value_init(gvalue, G_TYPE_CHAR);
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
136 g_value_set_char(gvalue, (char) my_arg(int));
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
137 break;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
138 case GAIM_TYPE_INT:
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
139 g_value_init(gvalue, G_TYPE_INT);
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
140 g_value_set_int(gvalue, my_arg(gint));
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
141 break;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
142 case GAIM_TYPE_UINT:
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
143 g_value_init(gvalue, G_TYPE_UINT);
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
144 g_value_set_uint(gvalue, my_arg(guint));
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
145 break;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
146 case GAIM_TYPE_BOOLEAN:
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
147 g_value_init(gvalue, G_TYPE_BOOLEAN);
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
148 g_value_set_boolean(gvalue, my_arg(gboolean));
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
149 break;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
150 case GAIM_TYPE_STRING:
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
151 g_value_init(gvalue, G_TYPE_STRING);
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
152 g_value_set_string(gvalue, null_to_empty(my_arg(char*)));
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
153 break;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
154 case GAIM_TYPE_SUBTYPE: /* registered pointers only! */
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
155 g_value_init(gvalue, G_TYPE_INT);
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
156 g_value_set_int(gvalue,
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
157 gaim_dbus_pointer_to_id(my_arg(gpointer)));
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
158 break;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
159 case GAIM_TYPE_POINTER:
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
160 case GAIM_TYPE_OBJECT:
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
161 case GAIM_TYPE_BOXED:
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
162 my_arg(gpointer); /* cannot pass general pointers */
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
163 g_value_init(gvalue, G_TYPE_INT);
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
164 g_value_set_int(gvalue, 0);
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
165 break;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
166
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
167 default: /* no conversion implemented */
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
168 g_assert_not_reached();
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
169 }
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
170 }
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
171
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
172 if (data)
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
173 va_end(data);
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
174 }
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
175
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
176 #undef my_arg /* my_arg was only used in gaim_values_to_gvalues */
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
177
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
178
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
179
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
180 /**
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
181 Converts from GaimTypes to GTypes.
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
182
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
183 @param type A GaimType to be converted.
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
184 @result The result of the conversion (GType).
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
185 */
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
186 static GType gaim_type_to_g_type(GaimType type)
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
187 {
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
188 switch(type) {
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
189 case GAIM_TYPE_CHAR:
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
190 return G_TYPE_CHAR;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
191 case GAIM_TYPE_INT:
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
192 return G_TYPE_INT;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
193 case GAIM_TYPE_UINT:
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
194 return G_TYPE_UINT;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
195 case GAIM_TYPE_BOOLEAN:
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
196 return G_TYPE_BOOLEAN;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
197 case GAIM_TYPE_STRING:
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
198 return G_TYPE_STRING;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
199 case GAIM_TYPE_SUBTYPE: /* registered pointers only! */
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
200 return G_TYPE_INT;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
201 case GAIM_TYPE_POINTER:
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
202 case GAIM_TYPE_BOXED:
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
203 case GAIM_TYPE_OBJECT:
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
204 return G_TYPE_INT; /* always 0 */
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
205 default: /* no conversion implemented */
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
206 g_assert_not_reached();
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
207 }
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
208 }
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
209
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
210
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
211 static const char *gaim_dbus_convert_signal_name(const char *gaim_name)
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
212 {
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
213 int gaim_index, g_index;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
214 char *g_name = g_new(char, strlen(gaim_name)+1);
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
215 gboolean capitalize_next = TRUE;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
216
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
217 for(gaim_index = g_index = 0; gaim_name[gaim_index]; gaim_index++)
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
218 if (gaim_name[gaim_index] != '-' && gaim_name[gaim_index] != '_') {
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
219 if (capitalize_next)
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
220 g_name[g_index++] = g_ascii_toupper(gaim_name[gaim_index]);
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
221 else
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
222 g_name[g_index++] = gaim_name[gaim_index];
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
223 capitalize_next = FALSE;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
224 } else
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
225 capitalize_next = TRUE;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
226 g_name[g_index] = 0;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
227
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
228 return g_name;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
229 }
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
230
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
231 /* Public signal-related functions */
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
232
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
233
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
234 void gaim_dbus_invalid_marshaller(GClosure *closure,
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
235 GValue *return_value,
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
236 guint n_param_values,
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
237 const GValue *param_values,
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
238 gpointer invocation_hint,
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
239 gpointer marshal_data)
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
240 {
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
241 g_assert_not_reached();
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
242 }
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
243
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
244 int gaim_dbus_signal_register(GaimObject *object, const char *name,
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
245 GSignalCMarshaller marshaller,
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
246 int num_values, ...)
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
247 {
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
248 va_list args;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
249
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
250 va_start(args, num_values);
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
251
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
252 return g_signal_new_valist(name, G_OBJECT_TYPE(object),
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
253 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
254 NULL, NULL, NULL, marshaller,
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
255 G_TYPE_NONE, num_values, args);
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
256 }
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
257
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
258 void gaim_dbus_signal_emit(GaimObject *object, int dbus_id, ...) {
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
259 va_list args;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
260
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
261 va_start(args, dbus_id);
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
262
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
263 gaim_dbus_signal_emit_valist(object, dbus_id, args);
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
264 }
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
265
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
266 void gaim_dbus_signal_emit_valist(GaimObject *object, int dbus_id, va_list args) {
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
267 g_signal_emit_valist(object, dbus_id, 0, args);
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
268 }
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
269
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
270 int gaim_dbus_signal_register_gaim(GaimObject *object, const char *name,
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
271 GSignalCMarshaller marshaller,
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
272 int num_values, GaimValue **values)
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
273 {
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
274 int i;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
275 int dbus_id;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
276 GType *types;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
277
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
278 types = g_new0(GType, num_values);
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
279
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
280 for(i=0; i<num_values; i++)
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
281 types[i] = gaim_type_to_g_type(values[i]->type);
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
282
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
283 dbus_id =
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
284 g_signal_newv(gaim_dbus_convert_signal_name(name),
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
285 G_OBJECT_TYPE(object),
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
286 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
287 NULL, NULL, NULL, marshaller,
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
288 G_TYPE_NONE, num_values, types);
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
289
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
290 g_free(types);
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
291
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
292 return dbus_id;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
293 }
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
294
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
295
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
296 void gaim_dbus_signal_emit_gaim(GaimObject *object, int dbus_id, int num_values,
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
297 GaimValue **values, va_list vargs)
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
298 {
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
299 GValue *args;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
300 int i;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
301
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
302 g_return_if_fail(dbus_id);
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
303
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
304 args = g_new0(GValue, num_values + 1);
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
305
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
306 g_value_init(args + 0, G_OBJECT_TYPE(object));
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
307 g_value_set_object(args + 0, object);
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
308
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
309 gaim_values_to_gvalues(args + 1, num_values, values, NULL, vargs);
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
310
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
311 g_signal_emitv(args, dbus_id, 0, NULL);
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
312
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
313 for(i = 1; i <= num_values; i++)
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
314 g_value_unset(args + i);
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
315
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
316 g_free(args);
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
317 }
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
318
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
319
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
320 /**************************************************************************/
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
321 /** @name Utility functions */
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
322 /**************************************************************************/
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
323
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
324 #define error_unless_1(condition, str, parameter) \
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
325 if (!(condition)) { \
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
326 g_set_error(error, gaim_object_error_quark, \
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
327 DBUS_ERROR_NOT_FOUND, \
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
328 str, parameter); \
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
329 return FALSE; \
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
330 }
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
331
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
332 #define error_unless_2(condition, str, a,b) \
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
333 if (!(condition)) { \
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
334 g_set_error(error, gaim_object_error_quark, \
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
335 DBUS_ERROR_NOT_FOUND, \
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
336 str, a,b); \
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
337 return FALSE; \
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
338 }
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
339
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
340 typedef gboolean (*GaimNodeFilter)(GaimBlistNode *node, gpointer *user_data);
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
341
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
342 static gboolean
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
343 filter_is_buddy(GaimBlistNode *node, gpointer *user_data)
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
344 {
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
345 return GAIM_BLIST_NODE_IS_BUDDY(node);
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
346 }
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
347
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
348 static gboolean
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
349 filter_is_online_buddy(GaimBlistNode *node,
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
350 gpointer *user_data)
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
351 {
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
352 return GAIM_BLIST_NODE_IS_BUDDY(node) &&
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
353 GAIM_BUDDY_IS_ONLINE((GaimBuddy *)node);
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
354 }
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
355
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
356
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
357 static GList*
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
358 get_buddy_list (GList *created_list, /**< can be NULL */
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
359 GaimBlistNode *gaim_buddy_list, /**< can be NULL */
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
360 GaimNodeFilter filter,
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
361 gpointer user_data)
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
362 {
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
363 GaimBlistNode *node;
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
364
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
365 for(node = gaim_buddy_list; node; node = node->next)
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
366 {
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
367 if ((*filter)(node, user_data))
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
368 created_list = g_list_prepend(created_list, node);
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
369
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
370 created_list = get_buddy_list(created_list, node->child,
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
371 filter, user_data);
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
372 }
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
373
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
374 return created_list;
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
375 }
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
376
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
377
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
378
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
379 /**************************************************************************/
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
380 /** @name Implementations of remote DBUS calls */
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
381 /**************************************************************************/
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
382
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
383 static gboolean
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
384 gaim_object_ping(GaimObject *object, GError **error)
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
385 {
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
386 gaim_dbus_signal_emit(object, object->ping_signal_id, "Ping Pong!");
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
387 return TRUE;
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
388 }
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
389
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
390 static gboolean
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
391 gaim_object_quit(GaimObject *obj, GError **error)
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
392 {
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
393 g_timeout_add(0, gaim_core_quit_cb, NULL);
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
394 return TRUE;
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
395 }
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
396
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
397 static gboolean
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
398 gaim_object_connect_all(GaimObject *obj, GError **error)
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
399 {
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
400 GList *cur;
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
401
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
402 for (cur = gaim_accounts_get_all(); cur != NULL; cur = cur->next)
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
403 gaim_account_connect((GaimAccount*) cur->data);
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
404
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
405 return TRUE;
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
406 }
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
407
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
408
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
409
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
410 static gboolean
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
411 gaim_object_get_buddy_list (GaimObject *obj, GArray **out_buddy_ids,
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
412 GError **error)
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
413 {
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
414 GList *node;
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
415 GList *buddy_list = get_buddy_list(NULL, gaim_get_blist()->root,
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
416 &filter_is_buddy, NULL);
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
417 GArray *buddy_ids = g_array_new(FALSE, TRUE, sizeof(gint32));;
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
418
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
419 buddy_list = g_list_reverse(buddy_list);
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
420
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
421 for (node = buddy_list; node; node = node->next) {
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
422 gint32 id = gaim_dbus_pointer_to_id(node->data);
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
423 g_array_append_val(buddy_ids, id);
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
424 }
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
425
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
426 g_list_free(buddy_list);
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
427 *out_buddy_ids = buddy_ids;
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
428
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
429 return TRUE;
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
430 }
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
431
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
432
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
433
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
434
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
435
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
436 static gboolean
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
437 gaim_object_find_account(GaimObject *object,
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
438 const char *account_name, const char *protocol_name,
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
439 gint *account_id, GError **error)
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
440 {
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
441 GaimAccount *account = gaim_accounts_find(account_name, protocol_name);
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
442
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
443 error_unless_2(account, "Account '%s' with protocol '%s' not found",
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
444 account_name, protocol_name);
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
445
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
446 *account_id = gaim_dbus_pointer_to_id(account);
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
447 return TRUE;
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
448 }
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
449
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
450 static gboolean
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
451 gaim_object_find_buddy(GaimObject *object, gint account_id, const char *buddy_name,
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
452 gint *buddy_id, GError **error)
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
453 {
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
454 GaimAccount *account;
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
455 GaimBuddy *buddy;
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
456
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
457 account = gaim_dbus_id_to_pointer(account_id, DBUS_POINTER_ACCOUNT);
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
458 error_unless_1(account, "Invalid account id: %i", account_id);
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
459
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
460 buddy = gaim_find_buddy(account, buddy_name);
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
461 error_unless_1(account, "Buddy '%s' not found.", buddy_name);
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
462
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
463 *buddy_id = gaim_dbus_pointer_to_id(buddy);
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
464 return TRUE;
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
465 }
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
466
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
467 static gboolean
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
468 gaim_object_start_im_conversation (GaimObject *object, gint buddy_id, GError **error)
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
469 {
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
470 GaimBuddy *buddy = (GaimBuddy*) gaim_dbus_id_to_pointer(buddy_id,
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
471 DBUS_POINTER_BUDDY);
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
472
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
473 error_unless_1(buddy, "Invalid buddy id: %i", buddy_id);
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
474
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
475 gaim_conversation_new(GAIM_CONV_IM, buddy->account, buddy->name);
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
476
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
477 return TRUE;
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
478 }
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
479
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
480
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
481
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
482 /**************************************************************************/
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
483 /** @name Gaim DBUS property handling functions */
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
484 /**************************************************************************/
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
485
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
486
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
487 typedef struct _GaimDBusProperty {
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
488 char *name;
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
489 gint offset;
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
490 GaimType type;
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
491 } GaimDBusProperty;
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
492
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
493 /* change GAIM_TYPE into G_TYPE */
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
494
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
495 static gboolean
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
496 gaim_dbus_get_property(GaimDBusProperty *list, int list_len,
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
497 gpointer data, const char *name,
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
498 GValue *value, GError **error)
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
499 {
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
500 int i;
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
501
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
502 for(i=0; i<list_len; i++) {
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
503 if (!strcmp(list[i].name, name)) {
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
504 gpointer ptr;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
505 GaimValue gaim_value, *gaim_value_ptr;
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
506
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
507 ptr = G_STRUCT_MEMBER_P(data, list[i].offset);
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
508 gaim_value.type = list[i].type;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
509 gaim_value.flags = 0;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
510 gaim_value_ptr = &gaim_value;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
511
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
512 gaim_values_to_gvalues(value, 1, &gaim_value_ptr,
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
513 ptr, NULL);
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
514 return TRUE;
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
515 }
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
516 }
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
517
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
518 g_value_init(value, G_TYPE_INT);
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
519 g_value_set_int(value, 0);
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
520 error_unless_1(FALSE, "Invalid property '%s'", name);
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
521 }
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
522
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
523
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
524 #define DECLARE_PROPERTY(maintype, name, type) {#name, G_STRUCT_OFFSET(maintype, name), type}
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
525
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
526 GaimDBusProperty buddy_properties [] = {
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
527 DECLARE_PROPERTY(GaimBuddy, name, GAIM_TYPE_STRING),
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
528 DECLARE_PROPERTY(GaimBuddy, alias, GAIM_TYPE_STRING),
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
529 DECLARE_PROPERTY(GaimBuddy, server_alias, GAIM_TYPE_STRING),
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
530 DECLARE_PROPERTY(GaimBuddy, account, GAIM_TYPE_SUBTYPE)
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
531 };
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
532
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
533 GaimDBusProperty account_properties [] = {
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
534 DECLARE_PROPERTY(GaimAccount, username, GAIM_TYPE_STRING),
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
535 DECLARE_PROPERTY(GaimAccount, alias, GAIM_TYPE_STRING),
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
536 DECLARE_PROPERTY(GaimAccount, user_info, GAIM_TYPE_STRING),
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
537 DECLARE_PROPERTY(GaimAccount, protocol_id, GAIM_TYPE_STRING),
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
538 };
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
539
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
540 GaimDBusProperty contact_properties [] = {
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
541 DECLARE_PROPERTY(GaimContact, alias, GAIM_TYPE_STRING),
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
542 DECLARE_PROPERTY(GaimContact, totalsize, GAIM_TYPE_INT),
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
543 DECLARE_PROPERTY(GaimContact, currentsize, GAIM_TYPE_INT),
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
544 DECLARE_PROPERTY(GaimContact, online, GAIM_TYPE_INT),
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
545 DECLARE_PROPERTY(GaimContact, priority, GAIM_TYPE_SUBTYPE),
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
546 DECLARE_PROPERTY(GaimContact, priority_valid, GAIM_TYPE_BOOLEAN),
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
547 };
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
548
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
549 GaimDBusProperty group_properties [] = {
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
550 DECLARE_PROPERTY(GaimGroup, name, GAIM_TYPE_STRING),
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
551 DECLARE_PROPERTY(GaimGroup, totalsize, GAIM_TYPE_INT),
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
552 DECLARE_PROPERTY(GaimGroup, currentsize, GAIM_TYPE_INT),
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
553 DECLARE_PROPERTY(GaimGroup, online, GAIM_TYPE_INT),
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
554 };
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
555
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
556 GaimDBusProperty chat_properties [] = {
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
557 DECLARE_PROPERTY(GaimChat, alias, GAIM_TYPE_STRING),
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
558 DECLARE_PROPERTY(GaimChat, account, GAIM_TYPE_SUBTYPE),
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
559 };
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
560
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
561
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
562 #define DECLARE_PROPERTY_HANDLER(type, gaim_type) \
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
563 static gboolean \
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
564 gaim_object_get_##type##_property (GaimObject *object, \
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
565 gint id, const char *property_name, \
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
566 GValue *value, GError **error) \
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
567 { \
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
568 gpointer ptr = gaim_dbus_id_to_pointer(id, gaim_type); \
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
569 \
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
570 error_unless_1(ptr, "Invalid " #type " id: %i", id); \
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
571 \
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
572 return gaim_dbus_get_property(type##_properties, \
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
573 G_N_ELEMENTS(type##_properties), \
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
574 ptr, property_name, value, error); \
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
575 }
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
576
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
577 DECLARE_PROPERTY_HANDLER(buddy, DBUS_POINTER_BUDDY)
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
578 DECLARE_PROPERTY_HANDLER(account, DBUS_POINTER_ACCOUNT)
11068
9bd0aac996f4 [gaim-migrate @ 13049]
Piotr Zielinski <zielaj>
parents: 11067
diff changeset
579 DECLARE_PROPERTY_HANDLER(contact, DBUS_POINTER_CONTACT)
9bd0aac996f4 [gaim-migrate @ 13049]
Piotr Zielinski <zielaj>
parents: 11067
diff changeset
580 DECLARE_PROPERTY_HANDLER(group, DBUS_POINTER_GROUP)
9bd0aac996f4 [gaim-migrate @ 13049]
Piotr Zielinski <zielaj>
parents: 11067
diff changeset
581 DECLARE_PROPERTY_HANDLER(chat, DBUS_POINTER_CHAT)
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
582
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
583 #include "dbus-server-bindings.c"
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
584
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
585
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
586
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
587 /**************************************************************************/
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
588 /** @name Gaim DBUS pointer registration mechanism */
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
589 /**************************************************************************/
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
590
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
591 static GHashTable *map_id_node;
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
592 static GHashTable *map_id_type;
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
593 static GHashTable *map_node_id;
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
594
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
595 void gaim_dbus_init_ids(void) {
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
596
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
597
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
598 map_id_node = g_hash_table_new (g_direct_hash, g_direct_equal);
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
599 map_id_type = g_hash_table_new (g_direct_hash, g_direct_equal);
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
600 map_node_id = g_hash_table_new (g_direct_hash, g_direct_equal);
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
601 }
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
602
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
603 void gaim_dbus_register_pointer(gpointer node, GaimDBusPointerType type)
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
604 {
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
605 static gint last_id = 0;
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
606
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
607 g_assert(map_node_id);
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
608 g_assert(g_hash_table_lookup(map_node_id, node) == NULL);
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
609
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
610
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
611 last_id++;
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
612 g_hash_table_insert(map_node_id, node, GINT_TO_POINTER(last_id));
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
613 g_hash_table_insert(map_id_node, GINT_TO_POINTER(last_id), node);
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
614 g_hash_table_insert(map_id_type, GINT_TO_POINTER(last_id),
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
615 GINT_TO_POINTER(type));
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
616 }
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
617
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
618
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
619 void gaim_dbus_unregister_pointer(gpointer node) {
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
620 gpointer id = g_hash_table_lookup(map_node_id, node);
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
621
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
622 g_hash_table_remove(map_node_id, node);
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
623 g_hash_table_remove(map_id_node, GINT_TO_POINTER(id));
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
624 g_hash_table_remove(map_id_node, GINT_TO_POINTER(id));
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
625 }
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
626
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
627 static gint gaim_dbus_pointer_to_id(gpointer node) {
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
628 g_assert(map_node_id);
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
629
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
630 gint id = GPOINTER_TO_INT(g_hash_table_lookup(map_node_id, node));
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
631 g_return_val_if_fail(id, 0);
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
632 return id;
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
633 }
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
634
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
635 static gpointer gaim_dbus_id_to_pointer(gint id, GaimDBusPointerType type) {
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
636 if (type != GPOINTER_TO_INT(g_hash_table_lookup(map_id_type,
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
637 GINT_TO_POINTER(id))))
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
638 return NULL;
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
639 return g_hash_table_lookup(map_id_node, GINT_TO_POINTER(id));
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
640 }
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
641
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
642
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
643
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
644 /**************************************************************************/
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
645 /** @name Gaim DBUS init function */
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
646 /**************************************************************************/
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
647
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
648
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
649 gboolean gaim_dbus_connect(GaimObject *object)
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
650 {
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
651 DBusGConnection *connection;
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
652 GError *error = NULL;
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
653 DBusGProxy *driver_proxy;
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
654 guint32 request_name_ret;
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
655
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
656
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
657 gaim_debug_misc("dbus", "launching dbus server\n");
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
658
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
659 /* Connect to the bus */
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
660
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
661 error = NULL;
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
662 connection = dbus_g_bus_get(DBUS_BUS_STARTER, &error);
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
663
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
664 if (connection == NULL) {
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
665 g_assert(error);
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
666 gaim_debug_error("dbus", "Failed to open connection to bus: %s\n",
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
667 error->message);
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
668 g_error_free (error);
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
669 return FALSE;
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
670 }
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
671
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
672 /* Instantiate the gaim dbus object and register it */
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
673
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
674
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
675
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
676
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
677 dbus_g_object_type_install_info (GAIM_DBUS_TYPE_OBJECT,
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
678 &dbus_glib_gaim_object_object_info);
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
679
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
680 dbus_g_connection_register_g_object (connection, DBUS_PATH_GAIM,
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
681 (GObject*) object);
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
682
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
683
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
684 /* Obtain a proxy for the DBus object */
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
685
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
686 driver_proxy = dbus_g_proxy_new_for_name (connection,
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
687 DBUS_SERVICE_DBUS,
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
688 DBUS_PATH_DBUS,
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
689 DBUS_INTERFACE_DBUS);
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
690
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
691 g_assert(driver_proxy);
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
692
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
693 /* Test whether the registration was successful */
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
694
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
695 org_freedesktop_DBus_request_name(driver_proxy, DBUS_SERVICE_GAIM,
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
696 DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT, &request_name_ret, &error);
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
697
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
698 if (error) {
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
699 gaim_debug_error("dbus", "Failed to get name: %s\n", error->message);
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
700 g_error_free (error);
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
701 return FALSE;
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
702 }
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
703
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
704 if (request_name_ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
705 {
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
706 gaim_debug_error ("dbus", "Got result code %u from requesting name\n",
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
707 request_name_ret);
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
708 return FALSE;
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
709 }
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
710
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
711 gaim_debug_misc ("dbus", "GLib test service has name '%s'\n",
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
712 DBUS_SERVICE_GAIM);
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
713 gaim_debug_misc ("dbus", "GLib test service entering main loop\n");
11067
2eca9ed49469 [gaim-migrate @ 13048]
Piotr Zielinski <zielaj>
parents: 11055
diff changeset
714
11055
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
715 return TRUE;
df0241eb602c [gaim-migrate @ 12996]
Piotr Zielinski <zielaj>
parents:
diff changeset
716 }
11080
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
717
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
718
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
719 static void gaim_object_init(GaimObject *object)
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
720 {
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
721
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
722 object->ping_signal_id =
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
723 gaim_dbus_signal_register(object, "PingSignal",
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
724 g_cclosure_marshal_VOID__STRING,
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
725 1, G_TYPE_STRING);
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
726 }
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
727
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
728
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
729 gboolean gaim_dbus_init(void)
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
730 {
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
731 gaim_dbus_init_ids();
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
732 gaim_object_error_quark =
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
733 g_quark_from_static_string("org.gaim.GaimError");
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
734
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
735 gaim_dbus_object = GAIM_DBUS_OBJECT(g_object_new (GAIM_DBUS_TYPE_OBJECT, NULL));
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
736
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
737 return TRUE;
f54740547c95 [gaim-migrate @ 13092]
Piotr Zielinski <zielaj>
parents: 11068
diff changeset
738 }