Mercurial > pidgin
comparison src/signals.c @ 6564:800ef4a51096
[gaim-migrate @ 7086]
gaim_signal_register now takes a GaimValue return value and param types.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Thu, 21 Aug 2003 21:54:36 +0000 |
parents | 9e4fa4853cfe |
children | 7dba3e17cb21 |
comparison
equal
deleted
inserted
replaced
6563:122cb375be2d | 6564:800ef4a51096 |
---|---|
22 */ | 22 */ |
23 #include "internal.h" | 23 #include "internal.h" |
24 | 24 |
25 #include "debug.h" | 25 #include "debug.h" |
26 #include "signals.h" | 26 #include "signals.h" |
27 #include "value.h" | |
27 | 28 |
28 typedef struct | 29 typedef struct |
29 { | 30 { |
30 void *instance; | 31 void *instance; |
31 | 32 |
39 typedef struct | 40 typedef struct |
40 { | 41 { |
41 gulong id; | 42 gulong id; |
42 | 43 |
43 GaimSignalMarshalFunc marshal; | 44 GaimSignalMarshalFunc marshal; |
45 | |
46 int num_values; | |
47 GaimValue **values; | |
48 GaimValue *ret_value; | |
44 | 49 |
45 GList *handlers; | 50 GList *handlers; |
46 size_t handler_count; | 51 size_t handler_count; |
47 | 52 |
48 gulong next_handler_id; | 53 gulong next_handler_id; |
82 g_free(l->data); | 87 g_free(l->data); |
83 } | 88 } |
84 | 89 |
85 g_list_free(signal_data->handlers); | 90 g_list_free(signal_data->handlers); |
86 | 91 |
92 if (signal_data->values != NULL) | |
93 { | |
94 int i; | |
95 | |
96 for (i = 0; i < signal_data->num_values; i++) | |
97 gaim_value_destroy((GaimValue *)signal_data->values[i]); | |
98 | |
99 g_free(signal_data->values); | |
100 } | |
101 | |
87 g_free(signal_data); | 102 g_free(signal_data); |
88 } | 103 } |
89 | 104 |
90 gulong | 105 gulong |
91 gaim_signal_register(void *instance, const char *signal, | 106 gaim_signal_register(void *instance, const char *signal, |
92 GaimSignalMarshalFunc marshal) | 107 GaimSignalMarshalFunc marshal, |
108 GaimValue *ret_value, int num_values, ...) | |
93 { | 109 { |
94 GaimInstanceData *instance_data; | 110 GaimInstanceData *instance_data; |
95 GaimSignalData *signal_data; | 111 GaimSignalData *signal_data; |
112 va_list args; | |
96 | 113 |
97 g_return_val_if_fail(instance != NULL, 0); | 114 g_return_val_if_fail(instance != NULL, 0); |
98 g_return_val_if_fail(signal != NULL, 0); | 115 g_return_val_if_fail(signal != NULL, 0); |
99 g_return_val_if_fail(marshal != NULL, 0); | 116 g_return_val_if_fail(marshal != NULL, 0); |
100 | 117 |
117 | 134 |
118 signal_data = g_new0(GaimSignalData, 1); | 135 signal_data = g_new0(GaimSignalData, 1); |
119 signal_data->id = instance_data->next_signal_id; | 136 signal_data->id = instance_data->next_signal_id; |
120 signal_data->marshal = marshal; | 137 signal_data->marshal = marshal; |
121 signal_data->next_handler_id = 1; | 138 signal_data->next_handler_id = 1; |
139 signal_data->ret_value = ret_value; | |
140 signal_data->num_values = num_values; | |
141 | |
142 if (num_values > 0) | |
143 { | |
144 int i; | |
145 | |
146 signal_data->values = g_new0(GaimValue *, num_values); | |
147 | |
148 va_start(args, num_values); | |
149 | |
150 for (i = 0; i < num_values; i++) | |
151 signal_data->values[i] = va_arg(args, GaimValue *); | |
152 | |
153 va_end(args); | |
154 } | |
122 | 155 |
123 g_hash_table_insert(instance_data->signals, | 156 g_hash_table_insert(instance_data->signals, |
124 g_strdup(signal), signal_data); | 157 g_strdup(signal), signal_data); |
125 | 158 |
126 instance_data->next_signal_id++; | 159 instance_data->next_signal_id++; |
165 /* | 198 /* |
166 * Makes things easier (more annoying?) for developers who don't have | 199 * Makes things easier (more annoying?) for developers who don't have |
167 * things registering and unregistering in the right order :) | 200 * things registering and unregistering in the right order :) |
168 */ | 201 */ |
169 g_return_if_fail(found); | 202 g_return_if_fail(found); |
203 } | |
204 | |
205 void | |
206 gaim_signal_get_values(void *instance, const char *signal, | |
207 GaimValue **ret_value, | |
208 int *num_values, GaimValue ***values) | |
209 { | |
210 GaimInstanceData *instance_data; | |
211 GaimSignalData *signal_data; | |
212 | |
213 g_return_if_fail(instance != NULL); | |
214 g_return_if_fail(signal != NULL); | |
215 g_return_if_fail(num_values != NULL); | |
216 g_return_if_fail(values != NULL); | |
217 | |
218 /* Get the instance data */ | |
219 instance_data = | |
220 (GaimInstanceData *)g_hash_table_lookup(instance_table, instance); | |
221 | |
222 g_return_if_fail(instance_data != NULL); | |
223 | |
224 /* Get the signal data */ | |
225 signal_data = | |
226 (GaimSignalData *)g_hash_table_lookup(instance_data->signals, signal); | |
227 | |
228 g_return_if_fail(signal_data != NULL); | |
229 | |
230 *num_values = signal_data->num_values; | |
231 *values = signal_data->values; | |
232 | |
233 if (ret_value != NULL) | |
234 *ret_value = signal_data->ret_value; | |
170 } | 235 } |
171 | 236 |
172 static gulong | 237 static gulong |
173 signal_connect_common(void *instance, const char *signal, void *handle, | 238 signal_connect_common(void *instance, const char *signal, void *handle, |
174 GaimCallback func, void *data, gboolean use_vargs) | 239 GaimCallback func, void *data, gboolean use_vargs) |