annotate plugins/mono/loader/signal-glue.c @ 12687:88ccc3603163

[gaim-migrate @ 15030] I'm a stickler for getting rid of these crazy little things. A stickler to the last. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Tue, 03 Jan 2006 01:19:32 +0000
parents 67fbd2ff4c4e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11660
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 #include "mono-glue.h"
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 #include "mono-helper.h"
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 #include "debug.h"
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 #include "blist.h"
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
5 #include "signals.h"
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
6 #include "value.h"
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
7
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 typedef struct {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
9 MonoObject *func;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
10 char *signal;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
11 GaimValue **values;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
12 GaimValue *ret_value;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 int num_vals;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
14 } SignalData;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
15
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
16 static GaimCallback get_callback(SignalData *sig_data);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
17
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
18 static gpointer dispatch_callback(SignalData *sig_data, int num_vals, ...)
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
19 {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
20 MonoArray *array;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21 MonoObject *obj;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
22 int i;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
23 gpointer meth_args[1];
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
24 gpointer gaim_obj;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
25
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
26 va_list args;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
27
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
28 va_start(args, num_vals);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
29
11980
67fbd2ff4c4e [gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents: 11952
diff changeset
30 array = mono_array_new(ml_get_domain(), mono_get_object_class(), num_vals);
11660
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
32 for (i = 0; i < num_vals; i++) {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33 if (gaim_value_get_type(sig_data->values[i]) == GAIM_TYPE_SUBTYPE) {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34 gaim_obj = va_arg(args, gpointer);
11980
67fbd2ff4c4e [gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents: 11952
diff changeset
35 obj = ml_object_from_gaim_subtype(gaim_value_get_subtype(sig_data->values[i]), gaim_obj);
11660
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36 mono_array_set(array, MonoObject*, i, obj);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37 } else {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38 gaim_obj = va_arg(args, gpointer);
11980
67fbd2ff4c4e [gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents: 11952
diff changeset
39 obj = ml_object_from_gaim_type(gaim_value_get_type(sig_data->values[i]), gaim_obj);
11660
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40 mono_array_set(array, MonoObject*, i, obj);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41 }
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
42 }
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
43
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
44 va_end(args);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
45
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
46 meth_args[0] = array;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
47
11980
67fbd2ff4c4e [gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents: 11952
diff changeset
48 return ml_delegate_invoke(sig_data->func, meth_args);
11660
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
49 }
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
50
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
51 static void cb_void__pointer(void *arg1, void *data)
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
52 {
11980
67fbd2ff4c4e [gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents: 11952
diff changeset
53 dispatch_callback((SignalData*)data, ((SignalData*)data)->num_vals, arg1);
11660
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
54 }
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
55
11980
67fbd2ff4c4e [gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents: 11952
diff changeset
56 static void cb_void__pointer_pointer_pointer(void *arg1, void *arg2, void *arg3, void *data)
67fbd2ff4c4e [gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents: 11952
diff changeset
57 {
67fbd2ff4c4e [gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents: 11952
diff changeset
58 dispatch_callback((SignalData*)data, ((SignalData*)data)->num_vals, arg1, arg2, arg3);
67fbd2ff4c4e [gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents: 11952
diff changeset
59 }
67fbd2ff4c4e [gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents: 11952
diff changeset
60
67fbd2ff4c4e [gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents: 11952
diff changeset
61
11660
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
62 int gaim_signal_connect_glue(MonoObject* h, MonoObject *plugin, MonoString *signal, MonoObject *func)
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
63 {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
64 char *sig;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
65 void **instance = NULL;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
66 SignalData *sig_data;
11980
67fbd2ff4c4e [gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents: 11952
diff changeset
67 GaimMonoPlugin *mplug;
67fbd2ff4c4e [gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents: 11952
diff changeset
68 MonoClass *klass;
11660
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
69
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
70 sig = mono_string_to_utf8(signal);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
71 gaim_debug(GAIM_DEBUG_INFO, "mono", "connecting signal: %s\n", sig);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
72
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
73 instance = (void*)mono_object_unbox(h);
11980
67fbd2ff4c4e [gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents: 11952
diff changeset
74
11660
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
75 sig_data = g_new0(SignalData, 1);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
76
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
77 sig_data->func = func;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
78 sig_data->signal = sig;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
79
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
80 gaim_signal_get_values(*instance, sig, &sig_data->ret_value, &sig_data->num_vals, &sig_data->values);
11980
67fbd2ff4c4e [gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents: 11952
diff changeset
81
67fbd2ff4c4e [gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents: 11952
diff changeset
82 klass = mono_object_get_class(plugin);
67fbd2ff4c4e [gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents: 11952
diff changeset
83
67fbd2ff4c4e [gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents: 11952
diff changeset
84 mplug = ml_find_plugin_by_class(klass);
67fbd2ff4c4e [gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents: 11952
diff changeset
85
67fbd2ff4c4e [gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents: 11952
diff changeset
86 mplug->signal_data = g_list_append(mplug->signal_data, (gpointer)sig_data);
11660
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
87
11980
67fbd2ff4c4e [gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents: 11952
diff changeset
88 return gaim_signal_connect(*instance, sig, (gpointer)klass, get_callback(sig_data), (gpointer)sig_data);
11660
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
89 }
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
90
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
91 static int determine_index(GaimType type)
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
92 {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
93 switch (type) {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
94 case GAIM_TYPE_SUBTYPE:
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
95 case GAIM_TYPE_STRING:
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
96 case GAIM_TYPE_OBJECT:
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
97 case GAIM_TYPE_POINTER:
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
98 case GAIM_TYPE_BOXED:
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
99 return 1;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
100 break;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
101 default:
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
102 return type;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
103 break;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
104 }
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
105 }
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
106
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
107 static gpointer callbacks[]= {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
108 NULL,
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
109 cb_void__pointer,
11980
67fbd2ff4c4e [gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents: 11952
diff changeset
110 NULL,
67fbd2ff4c4e [gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents: 11952
diff changeset
111 cb_void__pointer_pointer_pointer
11660
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
112 };
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
113
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
114 static int callbacks_array_size = sizeof(callbacks) / sizeof(GaimCallback);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
115
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
116
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
117 static GaimCallback get_callback(SignalData *sig_data)
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
118 {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
119 int i, index = 0;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
120
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
121 if (sig_data->ret_value == NULL)
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
122 index = 0;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
123 else
11980
67fbd2ff4c4e [gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents: 11952
diff changeset
124 index = determine_index(gaim_value_get_type(sig_data->ret_value));
11660
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
125
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
126 for (i = 0; i < sig_data->num_vals; i++) {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
127 index += determine_index(gaim_value_get_type(sig_data->values[i]));
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
128 }
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
129
11980
67fbd2ff4c4e [gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents: 11952
diff changeset
130 gaim_debug(GAIM_DEBUG_INFO, "mono", "get_callback index = %d\n", index);
67fbd2ff4c4e [gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents: 11952
diff changeset
131
11660
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
132 if (index >= callbacks_array_size || callbacks[index] == NULL) {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
133 gaim_debug(GAIM_DEBUG_ERROR, "mono", "couldn't find a callback function for signal: %s\n", sig_data->signal);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
134 return NULL;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
135 }
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
136
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
137 gaim_debug(GAIM_DEBUG_MISC, "mono", "using callback at index: %d\n", index);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
138 return GAIM_CALLBACK(callbacks[index]);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
139 }