annotate plugins/mono/loader/signal-glue.c @ 11723:9537977703bb

[gaim-migrate @ 14014] SF Patch #1335123 from sadrul "Hi. This patch enable images in the `Get Info' dialog." Yeah, I'm pretty pumped about this being such an easy fix. committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Sat, 22 Oct 2005 22:13:19 +0000
parents a3302d271199
children 565d2e437c04
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
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
30 array = mono_array_new(mono_loader_get_domain(), mono_get_object_class(), num_vals);
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);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35 obj = mono_loader_object_from_gaim_subtype(gaim_value_get_subtype(sig_data->values[i]), gaim_obj);
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);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39 obj = mono_loader_object_from_gaim_type(gaim_value_get_type(sig_data->values[i]), gaim_obj);
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
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
48 return mono_runtime_delegate_invoke(sig_data->func, meth_args, NULL);
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 {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
53 dispatch_callback((SignalData*)data, ((SignalData*)data)->num_vals, arg1);
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 }
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
56
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
57 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
58 {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59 char *sig;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
60 void **instance = NULL;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
61 SignalData *sig_data;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
62
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
63 sig = mono_string_to_utf8(signal);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
64 gaim_debug(GAIM_DEBUG_INFO, "mono", "connecting signal: %s\n", sig);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
65
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
66 instance = (void*)mono_object_unbox(h);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
67
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
68 sig_data = g_new0(SignalData, 1);
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_data->func = func;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
71 sig_data->signal = 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 gaim_signal_get_values(*instance, sig, &sig_data->ret_value, &sig_data->num_vals, &sig_data->values);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
74
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
75 return gaim_signal_connect(*instance, sig, (gpointer)mono_object_get_class(plugin), get_callback(sig_data), (gpointer)sig_data);
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
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
78 static int determine_index(GaimType type)
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 switch (type) {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
81 case GAIM_TYPE_SUBTYPE:
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
82 case GAIM_TYPE_STRING:
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
83 case GAIM_TYPE_OBJECT:
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
84 case GAIM_TYPE_POINTER:
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
85 case GAIM_TYPE_BOXED:
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
86 return 1;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
87 break;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
88 default:
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
89 return type;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
90 break;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
91 }
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
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
94 static gpointer callbacks[]= {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
95 NULL,
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
96 cb_void__pointer,
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
97 };
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
98
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
99 static int callbacks_array_size = sizeof(callbacks) / sizeof(GaimCallback);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
100
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
101
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
102 static GaimCallback get_callback(SignalData *sig_data)
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
103 {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
104 int i, index = 0;
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 if (sig_data->ret_value == NULL)
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
107 index = 0;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
108 else
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
109 index = gaim_value_get_type(sig_data->ret_value);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
110
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
111 for (i = 0; i < sig_data->num_vals; i++) {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
112 index += determine_index(gaim_value_get_type(sig_data->values[i]));
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
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
115 if (index >= callbacks_array_size || callbacks[index] == NULL) {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
116 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
117 return NULL;
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
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
120 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
121 return GAIM_CALLBACK(callbacks[index]);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
122 }