libpurple/plugins/mono/loader/mono-helper.c

Thu, 24 Oct 2013 03:37:02 +0530

author
Ankit Vani <a@nevitus.org>
date
Thu, 24 Oct 2013 03:37:02 +0530
branch
soc.2013.gobjectification
changeset 35037
bcf94ea5b8e5
parent 35008
e3277f6c9c03
permissions
-rw-r--r--

Merged default branch

11660
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
1 /*
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
2 * Mono Plugin Loader
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
3 *
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
4 * -- Thanks to the perl plugin loader for all the great tips ;-)
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
5 *
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
6 * Eoin Coffey
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
7 */
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
8
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
9 #ifdef HAVE_CONFIG_H
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
10 #include <config.h>
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
11 #endif
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
12
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
13 #include <glib.h>
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
14 #include <string.h>
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
15 #include "mono-helper.h"
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
16 #include "mono-glue.h"
11952
9cefc8360bff [gaim-migrate @ 14243]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11786
diff changeset
17 #include "debug.h"
9cefc8360bff [gaim-migrate @ 14243]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11786
diff changeset
18
11980
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
19 static gboolean _runtime_active = FALSE;
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
20
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
21 gboolean ml_init()
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
22 {
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
23 MonoDomain *d;
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
24
11980
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
25 g_return_val_if_fail(_runtime_active == FALSE, TRUE);
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
26
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
27 d = mono_jit_init("purple");
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
28
11980
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
29 if (!d) {
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
30 ml_set_domain(NULL);
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
31 return FALSE;
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
32 }
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
33
11980
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
34 ml_set_domain(d);
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
35
11980
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
36 ml_init_internal_calls();
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
37
11980
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
38 _runtime_active = TRUE;
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
39
11980
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
40 return TRUE;
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
41 }
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
42
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
43 void ml_uninit()
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
44 {
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
45 g_return_if_fail(_runtime_active == TRUE);
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
46
11980
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
47 mono_jit_cleanup(ml_get_domain());
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
48
11980
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
49 ml_set_domain(NULL);
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
50
11980
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
51 _runtime_active = FALSE;
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
52 }
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
53
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
54 MonoObject* ml_delegate_invoke(MonoObject *method, void **params)
11952
9cefc8360bff [gaim-migrate @ 14243]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11786
diff changeset
55 {
9cefc8360bff [gaim-migrate @ 14243]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11786
diff changeset
56 MonoObject *ret, *exception;
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
57
11952
9cefc8360bff [gaim-migrate @ 14243]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11786
diff changeset
58 ret = mono_runtime_delegate_invoke(method, params, &exception);
9cefc8360bff [gaim-migrate @ 14243]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11786
diff changeset
59 if (exception) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
60 purple_debug(PURPLE_DEBUG_ERROR, "mono", "caught exception: %s\n", mono_class_get_name(mono_object_get_class(exception)));
11952
9cefc8360bff [gaim-migrate @ 14243]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11786
diff changeset
61 }
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
62
11952
9cefc8360bff [gaim-migrate @ 14243]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11786
diff changeset
63 return ret;
9cefc8360bff [gaim-migrate @ 14243]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11786
diff changeset
64 }
9cefc8360bff [gaim-migrate @ 14243]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11786
diff changeset
65
11980
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
66 MonoObject* ml_invoke(MonoMethod *method, void *obj, void **params)
11952
9cefc8360bff [gaim-migrate @ 14243]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11786
diff changeset
67 {
9cefc8360bff [gaim-migrate @ 14243]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11786
diff changeset
68 MonoObject *ret, *exception;
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
69
11952
9cefc8360bff [gaim-migrate @ 14243]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11786
diff changeset
70 ret = mono_runtime_invoke(method, obj, params, &exception);
9cefc8360bff [gaim-migrate @ 14243]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11786
diff changeset
71 if (exception) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
72 purple_debug(PURPLE_DEBUG_ERROR, "mono", "caught exception: %s\n", mono_class_get_name(mono_object_get_class(exception)));
11952
9cefc8360bff [gaim-migrate @ 14243]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11786
diff changeset
73 }
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
74
11952
9cefc8360bff [gaim-migrate @ 14243]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11786
diff changeset
75 return ret;
9cefc8360bff [gaim-migrate @ 14243]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11786
diff changeset
76 }
11660
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
77
11980
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
78 MonoClass* ml_find_plugin_class(MonoImage *image)
11660
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
79 {
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
80 MonoClass *klass, *pklass = NULL;
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
81 int i, total;
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
82
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
83 total = mono_image_get_table_rows (image, MONO_TABLE_TYPEDEF);
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
84 for (i = 1; i <= total; ++i) {
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
85 klass = mono_class_get (image, MONO_TOKEN_TYPE_DEF | i);
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
86
11660
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
87 pklass = mono_class_get_parent(klass);
15938
1b037158411e SF Patch #1686400 from Eoin Coffey ("ecoffey")
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
88 if (pklass) {
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
89
15938
1b037158411e SF Patch #1686400 from Eoin Coffey ("ecoffey")
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
90 if (strcmp("Plugin", mono_class_get_name(pklass)) == 0)
11660
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
91 return klass;
15938
1b037158411e SF Patch #1686400 from Eoin Coffey ("ecoffey")
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
92 }
11660
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
93 }
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
94
11660
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
95 return NULL;
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
96 }
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
97
11980
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
98 void ml_set_prop_string(MonoObject *obj, char *field, char *data)
11660
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
99 {
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
100 MonoClass *klass;
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
101 MonoProperty *prop;
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
102 MonoString *str;
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
103 gpointer args[1];
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
104
11660
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
105 klass = mono_object_get_class(obj);
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
106
11660
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
107 prop = mono_class_get_property_from_name(klass, field);
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
108
11980
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
109 str = mono_string_new(ml_get_domain(), data);
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
110
11660
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
111 args[0] = str;
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
112
11660
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
113 mono_property_set_value(prop, obj, args, NULL);
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
114 }
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
115
11980
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
116 gchar* ml_get_prop_string(MonoObject *obj, char *field)
11660
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
117 {
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
118 MonoClass *klass;
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
119 MonoProperty *prop;
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
120 MonoString *str;
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
121
11660
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
122 klass = mono_object_get_class(obj);
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
123
11660
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
124 prop = mono_class_get_property_from_name(klass, field);
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
125
11660
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
126 str = (MonoString*)mono_property_get_value(prop, obj, NULL, NULL);
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
127
11660
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
128 return mono_string_to_utf8(str);
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
129 }
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
130
15938
1b037158411e SF Patch #1686400 from Eoin Coffey ("ecoffey")
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
131 MonoObject* ml_get_info_prop(MonoObject *obj)
1b037158411e SF Patch #1686400 from Eoin Coffey ("ecoffey")
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
132 {
1b037158411e SF Patch #1686400 from Eoin Coffey ("ecoffey")
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
133 MonoClass *klass;
1b037158411e SF Patch #1686400 from Eoin Coffey ("ecoffey")
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
134 MonoProperty *prop;
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
135
15938
1b037158411e SF Patch #1686400 from Eoin Coffey ("ecoffey")
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
136 klass = mono_class_get_parent(mono_object_get_class(obj));
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
137
15938
1b037158411e SF Patch #1686400 from Eoin Coffey ("ecoffey")
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
138 prop = mono_class_get_property_from_name(klass, "Info");
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
139
15938
1b037158411e SF Patch #1686400 from Eoin Coffey ("ecoffey")
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
140 return mono_property_get_value(prop, obj, NULL, NULL);
1b037158411e SF Patch #1686400 from Eoin Coffey ("ecoffey")
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
141 }
1b037158411e SF Patch #1686400 from Eoin Coffey ("ecoffey")
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
142
11980
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
143 gboolean ml_is_api_dll(MonoImage *image)
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
144 {
11660
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
145 MonoClass *klass;
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
146 int i, total;
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
147
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
148 total = mono_image_get_table_rows (image, MONO_TABLE_TYPEDEF);
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
149 for (i = 1; i <= total; ++i) {
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
150 klass = mono_class_get (image, MONO_TOKEN_TYPE_DEF | i);
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
151 if (strcmp(mono_class_get_name(klass), "Debug") == 0)
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
152 if (strcmp(mono_class_get_namespace(klass), "Purple") == 0) {
11980
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
153 ml_set_api_image(image);
11660
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
154 return TRUE;
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
155 }
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
156 }
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
157
11660
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
158 return FALSE;
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
159 }
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
160
35008
e3277f6c9c03 Removed the use of PurpleValue/PurpleType from mono
Ankit Vani <a@nevitus.org>
parents: 34799
diff changeset
161 MonoObject* ml_object_from_purple_type(GType type, gpointer data)
11660
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
162 {
11776
58fd4b78788a [gaim-migrate @ 14067]
Gary Kramlich <grim@reaperworld.com>
parents: 11660
diff changeset
163 MonoObject *obj = NULL;
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
164
34799
f029b9598b8e Undo initial replacement of PurpleValue
Ankit Vani <a@nevitus.org>
parents: 34779
diff changeset
165 switch (type) {
35008
e3277f6c9c03 Removed the use of PurpleValue/PurpleType from mono
Ankit Vani <a@nevitus.org>
parents: 34799
diff changeset
166 case PURPLE_TYPE_BUDDY:
34799
f029b9598b8e Undo initial replacement of PurpleValue
Ankit Vani <a@nevitus.org>
parents: 34779
diff changeset
167 obj = purple_blist_build_buddy_object(data);
f029b9598b8e Undo initial replacement of PurpleValue
Ankit Vani <a@nevitus.org>
parents: 34779
diff changeset
168 break;
35008
e3277f6c9c03 Removed the use of PurpleValue/PurpleType from mono
Ankit Vani <a@nevitus.org>
parents: 34799
diff changeset
169 case PURPLE_TYPE_STATUS:
34799
f029b9598b8e Undo initial replacement of PurpleValue
Ankit Vani <a@nevitus.org>
parents: 34779
diff changeset
170 obj = purple_status_build_status_object(data);
f029b9598b8e Undo initial replacement of PurpleValue
Ankit Vani <a@nevitus.org>
parents: 34779
diff changeset
171 break;
f029b9598b8e Undo initial replacement of PurpleValue
Ankit Vani <a@nevitus.org>
parents: 34779
diff changeset
172 default:
f029b9598b8e Undo initial replacement of PurpleValue
Ankit Vani <a@nevitus.org>
parents: 34779
diff changeset
173 break;
f029b9598b8e Undo initial replacement of PurpleValue
Ankit Vani <a@nevitus.org>
parents: 34779
diff changeset
174 }
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
175
11660
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
176 return obj;
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
177 }
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
178
11996
858bd928831c [gaim-migrate @ 14289]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11980
diff changeset
179 MonoObject* ml_create_api_object(char *class_name)
858bd928831c [gaim-migrate @ 14289]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11980
diff changeset
180 {
858bd928831c [gaim-migrate @ 14289]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11980
diff changeset
181 MonoObject *obj = NULL;
858bd928831c [gaim-migrate @ 14289]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11980
diff changeset
182 MonoClass *klass = NULL;
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
183
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
184 klass = mono_class_from_name(ml_get_api_image(), "Purple", class_name);
11996
858bd928831c [gaim-migrate @ 14289]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11980
diff changeset
185 if (!klass) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
186 purple_debug(PURPLE_DEBUG_FATAL, "mono", "couldn't find the '%s' class\n", class_name);
11996
858bd928831c [gaim-migrate @ 14289]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11980
diff changeset
187 return NULL;
858bd928831c [gaim-migrate @ 14289]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11980
diff changeset
188 }
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
189
11996
858bd928831c [gaim-migrate @ 14289]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11980
diff changeset
190 obj = mono_object_new(ml_get_domain(), klass);
858bd928831c [gaim-migrate @ 14289]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11980
diff changeset
191 if (!obj) {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
192 purple_debug(PURPLE_DEBUG_FATAL, "mono", "couldn't create the object from class '%s'\n", class_name);
11996
858bd928831c [gaim-migrate @ 14289]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11980
diff changeset
193 return NULL;
858bd928831c [gaim-migrate @ 14289]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11980
diff changeset
194 }
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
195
11996
858bd928831c [gaim-migrate @ 14289]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11980
diff changeset
196 mono_runtime_object_init(obj);
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
197
11996
858bd928831c [gaim-migrate @ 14289]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11980
diff changeset
198 return obj;
858bd928831c [gaim-migrate @ 14289]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11980
diff changeset
199 }
858bd928831c [gaim-migrate @ 14289]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11980
diff changeset
200
11786
d0067c6e542a [gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents: 11776
diff changeset
201 static MonoDomain *_domain = NULL;
11660
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
202
11980
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
203 MonoDomain* ml_get_domain(void)
11660
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
204 {
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
205 return _domain;
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
206 }
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
207
11980
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
208 void ml_set_domain(MonoDomain *d)
11660
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
209 {
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
210 _domain = d;
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
211 }
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
212
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
213 static MonoImage *_api_image = NULL;
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
214
11980
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
215 void ml_set_api_image(MonoImage *image)
11660
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
216 {
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
217 _api_image = image;
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
218 }
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
219
11980
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
220 MonoImage* ml_get_api_image()
11660
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
221 {
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
222 return _api_image;
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
223 }
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
224
11980
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
225 void ml_init_internal_calls(void)
11660
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
226 {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
227 mono_add_internal_call("Purple.Debug::_debug", purple_debug_glue);
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
228 mono_add_internal_call("Purple.Signal::_connect", purple_signal_connect_glue);
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
229 mono_add_internal_call("Purple.BuddyList::_get_handle", purple_blist_get_handle_glue);
11660
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
230 }
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
231
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
232 static GHashTable *plugins_hash = NULL;
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
233
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
234 void ml_add_plugin(PurpleMonoPlugin *plugin)
11660
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
235 {
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
236 if (!plugins_hash)
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
237 plugins_hash = g_hash_table_new(NULL, NULL);
31294
73607ab89c6f Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents: 15938
diff changeset
238
11660
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
239 g_hash_table_insert(plugins_hash, plugin->klass, plugin);
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
240 }
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
241
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
242 gboolean ml_remove_plugin(PurpleMonoPlugin *plugin)
11660
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
243 {
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
244 return g_hash_table_remove(plugins_hash, plugin->klass);
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
245 }
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
246
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
247 gpointer ml_find_plugin(PurpleMonoPlugin *plugin)
11660
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
248 {
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
249 return g_hash_table_lookup(plugins_hash, plugin->klass);
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
250 }
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
251
11980
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
252 gpointer ml_find_plugin_by_class(MonoClass *klass)
11660
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
253 {
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
254 return g_hash_table_lookup(plugins_hash, klass);
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
255 }
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
256
11980
fe5c2c58508c [gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents: 11952
diff changeset
257 GHashTable* ml_get_plugin_hash()
11660
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
258 {
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
259 return plugins_hash;
a7cf8f7d43b3 [gaim-migrate @ 13945]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
diff changeset
260 }

mercurial