comparison plugins/mono/loader/mono.c @ 11952:565d2e437c04

[gaim-migrate @ 14243] Another patch attached to sf #1285501, from Eoin Coffey "the loader will now attempt to catch exceptions, so hopefully this will resolve some of the issues we were having." This looked fairly innocuous. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Wed, 02 Nov 2005 05:23:00 +0000
parents 2c8216659a84
children 67fbd2ff4c4e
comparison
equal deleted inserted replaced
11951:b6fa01513d76 11952:565d2e437c04
16 #include "version.h" 16 #include "version.h"
17 #include "mono-helper.h" 17 #include "mono-helper.h"
18 18
19 #define MONO_PLUGIN_ID "core-mono" 19 #define MONO_PLUGIN_ID "core-mono"
20 20
21 /* This is where our code executes */
22 static MonoDomain *domain = NULL;
23
24 /****************************************************************************** 21 /******************************************************************************
25 * Loader Stuff 22 * Loader Stuff
26 *****************************************************************************/ 23 *****************************************************************************/
27 /* probes the given plugin to determine if its a plugin */ 24 /* probes the given plugin to determine if its a plugin */
28 static gboolean probe_mono_plugin(GaimPlugin *plugin) 25 static gboolean probe_mono_plugin(GaimPlugin *plugin)
37 GaimPluginInfo *info; 34 GaimPluginInfo *info;
38 GaimMonoPlugin *mplug; 35 GaimMonoPlugin *mplug;
39 36
40 char *file = plugin->path; 37 char *file = plugin->path;
41 38
42 assm = mono_domain_assembly_open(domain, file); 39 assm = mono_domain_assembly_open(mono_loader_get_domain(), file);
43 40
44 if (!assm) { 41 if (!assm) {
45 return FALSE; 42 return FALSE;
46 } 43 }
47 44
61 if (!mplug->klass) { 58 if (!mplug->klass) {
62 gaim_debug(GAIM_DEBUG_ERROR, "mono", "no plugin class in \'%s\'\n", file); 59 gaim_debug(GAIM_DEBUG_ERROR, "mono", "no plugin class in \'%s\'\n", file);
63 return FALSE; 60 return FALSE;
64 } 61 }
65 62
66 mplug->obj = mono_object_new(domain, mplug->klass); 63 mplug->obj = mono_object_new(mono_loader_get_domain(), mplug->klass);
67 if (!mplug->obj) { 64 if (!mplug->obj) {
68 gaim_debug(GAIM_DEBUG_ERROR, "mono", "obj not valid\n"); 65 gaim_debug(GAIM_DEBUG_ERROR, "mono", "obj not valid\n");
69 return FALSE; 66 return FALSE;
70 } 67 }
71 68
90 if (!(found_load && found_unload && found_destroy && found_info)) { 87 if (!(found_load && found_unload && found_destroy && found_info)) {
91 gaim_debug(GAIM_DEBUG_ERROR, "mono", "did not find the required methods\n"); 88 gaim_debug(GAIM_DEBUG_ERROR, "mono", "did not find the required methods\n");
92 return FALSE; 89 return FALSE;
93 } 90 }
94 91
95 plugin_info = mono_runtime_invoke(info_method, mplug->obj, NULL, NULL); 92 plugin_info = mono_loader_invoke(info_method, mplug->obj, NULL);
96 93
97 /* now that the methods are filled out we can populate 94 /* now that the methods are filled out we can populate
98 the info struct with all the needed info */ 95 the info struct with all the needed info */
99 96
100 info->name = mono_loader_get_prop_string(plugin_info, "Name"); 97 info->name = mono_loader_get_prop_string(plugin_info, "Name");
128 125
129 gaim_debug(GAIM_DEBUG_INFO, "mono", "Loading plugin\n"); 126 gaim_debug(GAIM_DEBUG_INFO, "mono", "Loading plugin\n");
130 127
131 mplug = (GaimMonoPlugin*)plugin->info->extra_info; 128 mplug = (GaimMonoPlugin*)plugin->info->extra_info;
132 129
133 mono_runtime_invoke(mplug->load, mplug->obj, NULL, NULL); 130 mono_loader_invoke(mplug->load, mplug->obj, NULL);
134 131
135 return TRUE; 132 return TRUE;
136 } 133 }
137 134
138 /* Unloads a Mono Plugin by calling 'unload' in the class */ 135 /* Unloads a Mono Plugin by calling 'unload' in the class */
144 141
145 mplug = (GaimMonoPlugin*)plugin->info->extra_info; 142 mplug = (GaimMonoPlugin*)plugin->info->extra_info;
146 143
147 gaim_signals_disconnect_by_handle((gpointer)mplug->klass); 144 gaim_signals_disconnect_by_handle((gpointer)mplug->klass);
148 145
149 mono_runtime_invoke(mplug->unload, mplug->obj, NULL, NULL); 146 mono_loader_invoke(mplug->unload, mplug->obj, NULL);
150 147
151 return TRUE; 148 return TRUE;
152 } 149 }
153 150
154 /* Destroys a Mono Plugin by calling 'destroy' in the class,
155 and cleaning up all the malloced memory */
156 static void destroy_mono_plugin(GaimPlugin *plugin) 151 static void destroy_mono_plugin(GaimPlugin *plugin)
157 { 152 {
158 GaimMonoPlugin *mplug; 153 GaimMonoPlugin *mplug;
159 154
160 gaim_debug(GAIM_DEBUG_INFO, "mono", "Destroying plugin\n"); 155 gaim_debug(GAIM_DEBUG_INFO, "mono", "Destroying plugin\n");
161 156
162 mplug = (GaimMonoPlugin*)plugin->info->extra_info; 157 mplug = (GaimMonoPlugin*)plugin->info->extra_info;
163 158
164 mono_runtime_invoke(mplug->destroy, mplug->obj, NULL, NULL); 159 mono_loader_invoke(mplug->destroy, mplug->obj, NULL);
165 160
166 if (plugin->info) { 161 if (plugin->info) {
167 g_free(plugin->info->name); 162 g_free(plugin->info->name);
168 g_free(plugin->info->version); 163 g_free(plugin->info->version);
169 g_free(plugin->info->summary); 164 g_free(plugin->info->summary);
185 /****************************************************************************** 180 /******************************************************************************
186 * Plugin Stuff 181 * Plugin Stuff
187 *****************************************************************************/ 182 *****************************************************************************/
188 static void plugin_destroy(GaimPlugin *plugin) 183 static void plugin_destroy(GaimPlugin *plugin)
189 { 184 {
190 mono_jit_cleanup(domain); 185 mono_jit_cleanup(mono_loader_get_domain());
191 } 186 }
192 187
193 static GaimPluginLoaderInfo loader_info = 188 static GaimPluginLoaderInfo loader_info =
194 { 189 {
195 NULL, 190 NULL,
223 &loader_info, 218 &loader_info,
224 NULL, 219 NULL,
225 NULL 220 NULL
226 }; 221 };
227 222
228 /* Creates the domain to execute in, and setups our CS Gaim API (note:
229 in the future the 'mono_add_internal_call' will be spread through out
230 the source to whatever module is exposing the API; this function will
231 simply call helper functions to do so) */
232 static void init_plugin(GaimPlugin *plugin) 223 static void init_plugin(GaimPlugin *plugin)
233 { 224 {
234 domain = mono_jit_init("gaim"); 225 MonoDomain *domain = mono_jit_init("gaim");
235 226
236 mono_loader_set_domain(domain); 227 mono_loader_set_domain(domain);
237 228
238 mono_loader_init_internal_calls(); 229 mono_loader_init_internal_calls();
239 230