Thu, 24 Oct 2013 03:37:02 +0530
Merged default branch
| 11660 | 1 | /* |
| 2 | * Mono Plugin Loader | |
| 3 | * | |
| 4 | * -- Thanks to the perl plugin loader for all the great tips ;-) | |
| 5 | * | |
| 6 | * Eoin Coffey | |
| 7 | */ | |
| 8 | ||
| 9 | #ifdef HAVE_CONFIG_H | |
| 10 | #include <config.h> | |
| 11 | #endif | |
| 12 | ||
| 13 | #include <glib.h> | |
| 14 | #include <string.h> | |
| 15 | #include "mono-helper.h" | |
| 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 | 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 | 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 | 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 | 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 | 79 | { |
| 80 | MonoClass *klass, *pklass = NULL; | |
| 81 | int i, total; | |
| 82 | ||
| 83 | total = mono_image_get_table_rows (image, MONO_TABLE_TYPEDEF); | |
| 84 | for (i = 1; i <= total; ++i) { | |
| 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 | 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 | 91 | return klass; |
|
15938
1b037158411e
SF Patch #1686400 from Eoin Coffey ("ecoffey")
Richard Laager <rlaager@pidgin.im>
parents:
15884
diff
changeset
|
92 | } |
| 11660 | 93 | } |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15938
diff
changeset
|
94 | |
| 11660 | 95 | return NULL; |
| 96 | } | |
| 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 | 99 | { |
| 100 | MonoClass *klass; | |
| 101 | MonoProperty *prop; | |
| 102 | MonoString *str; | |
| 103 | gpointer args[1]; | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15938
diff
changeset
|
104 | |
| 11660 | 105 | klass = mono_object_get_class(obj); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15938
diff
changeset
|
106 | |
| 11660 | 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 | 111 | args[0] = str; |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15938
diff
changeset
|
112 | |
| 11660 | 113 | mono_property_set_value(prop, obj, args, NULL); |
| 114 | } | |
| 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 | 117 | { |
| 118 | MonoClass *klass; | |
| 119 | MonoProperty *prop; | |
| 120 | MonoString *str; | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15938
diff
changeset
|
121 | |
| 11660 | 122 | klass = mono_object_get_class(obj); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15938
diff
changeset
|
123 | |
| 11660 | 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 | 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 | 128 | return mono_string_to_utf8(str); |
| 129 | } | |
| 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 | 145 | MonoClass *klass; |
| 146 | int i, total; | |
| 147 | ||
| 148 | total = mono_image_get_table_rows (image, MONO_TABLE_TYPEDEF); | |
| 149 | for (i = 1; i <= total; ++i) { | |
| 150 | klass = mono_class_get (image, MONO_TOKEN_TYPE_DEF | i); | |
| 151 | if (strcmp(mono_class_get_name(klass), "Debug") == 0) | |
| 15884 | 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 | 154 | return TRUE; |
| 155 | } | |
| 156 | } | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
15938
diff
changeset
|
157 | |
| 11660 | 158 | return FALSE; |
| 159 | } | |
| 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 | 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 | 176 | return obj; |
| 177 | } | |
| 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 | 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 | 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 | 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 | 202 | |
|
11980
fe5c2c58508c
[gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
11952
diff
changeset
|
203 | MonoDomain* ml_get_domain(void) |
| 11660 | 204 | { |
| 205 | return _domain; | |
| 206 | } | |
| 207 | ||
|
11980
fe5c2c58508c
[gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
11952
diff
changeset
|
208 | void ml_set_domain(MonoDomain *d) |
| 11660 | 209 | { |
| 210 | _domain = d; | |
| 211 | } | |
| 212 | ||
| 213 | static MonoImage *_api_image = NULL; | |
| 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 | 216 | { |
| 217 | _api_image = image; | |
| 218 | } | |
| 219 | ||
|
11980
fe5c2c58508c
[gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
11952
diff
changeset
|
220 | MonoImage* ml_get_api_image() |
| 11660 | 221 | { |
| 222 | return _api_image; | |
| 223 | } | |
| 224 | ||
|
11980
fe5c2c58508c
[gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
11952
diff
changeset
|
225 | void ml_init_internal_calls(void) |
| 11660 | 226 | { |
| 15884 | 227 | mono_add_internal_call("Purple.Debug::_debug", purple_debug_glue); |
| 228 | mono_add_internal_call("Purple.Signal::_connect", purple_signal_connect_glue); | |
| 229 | mono_add_internal_call("Purple.BuddyList::_get_handle", purple_blist_get_handle_glue); | |
| 11660 | 230 | } |
| 231 | ||
| 232 | static GHashTable *plugins_hash = NULL; | |
| 233 | ||
| 15884 | 234 | void ml_add_plugin(PurpleMonoPlugin *plugin) |
| 11660 | 235 | { |
| 236 | if (!plugins_hash) | |
| 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 | 239 | g_hash_table_insert(plugins_hash, plugin->klass, plugin); |
| 240 | } | |
| 241 | ||
| 15884 | 242 | gboolean ml_remove_plugin(PurpleMonoPlugin *plugin) |
| 11660 | 243 | { |
| 244 | return g_hash_table_remove(plugins_hash, plugin->klass); | |
| 245 | } | |
| 246 | ||
| 15884 | 247 | gpointer ml_find_plugin(PurpleMonoPlugin *plugin) |
| 11660 | 248 | { |
| 249 | return g_hash_table_lookup(plugins_hash, plugin->klass); | |
| 250 | } | |
| 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 | 253 | { |
| 254 | return g_hash_table_lookup(plugins_hash, klass); | |
| 255 | } | |
| 256 | ||
|
11980
fe5c2c58508c
[gaim-migrate @ 14273]
Eoin Coffey <ecoffey@soc.pidgin.im>
parents:
11952
diff
changeset
|
257 | GHashTable* ml_get_plugin_hash() |
| 11660 | 258 | { |
| 259 | return plugins_hash; | |
| 260 | } |