Mercurial > pidgin
annotate plugins/mono/loader/mono.c @ 11980:67fbd2ff4c4e
[gaim-migrate @ 14273]
Mono cleanup patch from Eoin Coffey
First, I changed mono_loader_ to ml_, since I was
getting sick of typing mono_loader_ :-D
Moved the mono runtime init and deinit code out of
mono.c into ml_init and ml_uninit in mono-helper.c
Added api/Status.cs and loader/status-glue.c so the
.net api now knows very little (as in the 'id') of
statuses.
committer: Tailor Script <tailor@pidgin.im>
| author | Gary Kramlich <grim@reaperworld.com> |
|---|---|
| date | Sat, 05 Nov 2005 02:09:30 +0000 |
| parents | 565d2e437c04 |
| children | ecd33ffb0b0a |
| rev | line source |
|---|---|
| 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 | |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
10 # include <config.h> |
| 11660 | 11 #endif |
| 12 | |
| 13 #include "internal.h" | |
| 14 #include "debug.h" | |
| 15 #include "plugin.h" | |
| 16 #include "version.h" | |
| 17 #include "mono-helper.h" | |
| 18 | |
| 19 #define MONO_PLUGIN_ID "core-mono" | |
| 20 | |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
21 /****************************************************************************** |
|
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
22 * Loader Stuff |
|
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
23 *****************************************************************************/ |
| 11660 | 24 /* probes the given plugin to determine if its a plugin */ |
| 25 static gboolean probe_mono_plugin(GaimPlugin *plugin) | |
| 26 { | |
| 27 MonoAssembly *assm; | |
| 28 MonoMethod *m = NULL; | |
| 29 MonoMethod *info_method = NULL; | |
| 30 MonoObject *plugin_info; | |
| 31 gboolean found_load = FALSE, found_unload = FALSE, found_destroy = FALSE, found_info = FALSE; | |
| 32 gpointer iter = NULL; | |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
33 |
| 11660 | 34 GaimPluginInfo *info; |
| 35 GaimMonoPlugin *mplug; | |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
36 |
| 11660 | 37 char *file = plugin->path; |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
38 |
|
11980
67fbd2ff4c4e
[gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents:
11952
diff
changeset
|
39 assm = mono_domain_assembly_open(ml_get_domain(), file); |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
40 |
| 11660 | 41 if (!assm) { |
| 42 return FALSE; | |
| 43 } | |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
44 |
| 11660 | 45 gaim_debug(GAIM_DEBUG_INFO, "mono", "Probing plugin\n"); |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
46 |
|
11980
67fbd2ff4c4e
[gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents:
11952
diff
changeset
|
47 if (ml_is_api_dll(mono_assembly_get_image(assm))) { |
| 11660 | 48 gaim_debug(GAIM_DEBUG_INFO, "mono", "Found our GaimAPI.dll\n"); |
| 49 return FALSE; | |
| 50 } | |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
51 |
| 11660 | 52 info = g_new0(GaimPluginInfo, 1); |
| 53 mplug = g_new0(GaimMonoPlugin, 1); | |
|
11980
67fbd2ff4c4e
[gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents:
11952
diff
changeset
|
54 |
|
67fbd2ff4c4e
[gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents:
11952
diff
changeset
|
55 mplug->signal_data = NULL; |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
56 |
| 11660 | 57 mplug->assm = assm; |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
58 |
|
11980
67fbd2ff4c4e
[gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents:
11952
diff
changeset
|
59 mplug->klass = ml_find_plugin_class(mono_assembly_get_image(mplug->assm)); |
| 11660 | 60 if (!mplug->klass) { |
| 61 gaim_debug(GAIM_DEBUG_ERROR, "mono", "no plugin class in \'%s\'\n", file); | |
| 62 return FALSE; | |
| 63 } | |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
64 |
|
11980
67fbd2ff4c4e
[gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents:
11952
diff
changeset
|
65 mplug->obj = mono_object_new(ml_get_domain(), mplug->klass); |
| 11660 | 66 if (!mplug->obj) { |
| 67 gaim_debug(GAIM_DEBUG_ERROR, "mono", "obj not valid\n"); | |
| 68 return FALSE; | |
| 69 } | |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
70 |
| 11660 | 71 mono_runtime_object_init(mplug->obj); |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
72 |
| 11660 | 73 while ((m = mono_class_get_methods(mplug->klass, &iter))) { |
| 74 if (strcmp(mono_method_get_name(m), "Load") == 0) { | |
| 75 mplug->load = m; | |
| 76 found_load = TRUE; | |
| 77 } else if (strcmp(mono_method_get_name(m), "Unload") == 0) { | |
| 78 mplug->unload = m; | |
| 79 found_unload = TRUE; | |
| 80 } else if (strcmp(mono_method_get_name(m), "Destroy") == 0) { | |
| 81 mplug->destroy = m; | |
| 82 found_destroy = TRUE; | |
| 83 } else if (strcmp(mono_method_get_name(m), "Info") == 0) { | |
| 84 info_method = m; | |
| 85 found_info = TRUE; | |
| 86 } | |
| 87 } | |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
88 |
| 11660 | 89 if (!(found_load && found_unload && found_destroy && found_info)) { |
| 90 gaim_debug(GAIM_DEBUG_ERROR, "mono", "did not find the required methods\n"); | |
| 91 return FALSE; | |
| 92 } | |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
93 |
|
11980
67fbd2ff4c4e
[gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents:
11952
diff
changeset
|
94 plugin_info = ml_invoke(info_method, mplug->obj, NULL); |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
95 |
| 11660 | 96 /* now that the methods are filled out we can populate |
| 97 the info struct with all the needed info */ | |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
98 |
|
11980
67fbd2ff4c4e
[gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents:
11952
diff
changeset
|
99 info->name = ml_get_prop_string(plugin_info, "Name"); |
|
67fbd2ff4c4e
[gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents:
11952
diff
changeset
|
100 info->version = ml_get_prop_string(plugin_info, "Version"); |
|
67fbd2ff4c4e
[gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents:
11952
diff
changeset
|
101 info->summary = ml_get_prop_string(plugin_info, "Summary"); |
|
67fbd2ff4c4e
[gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents:
11952
diff
changeset
|
102 info->description = ml_get_prop_string(plugin_info, "Description"); |
|
67fbd2ff4c4e
[gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents:
11952
diff
changeset
|
103 info->author = ml_get_prop_string(plugin_info, "Author"); |
|
67fbd2ff4c4e
[gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents:
11952
diff
changeset
|
104 info->homepage = ml_get_prop_string(plugin_info, "Homepage"); |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
105 |
| 11660 | 106 info->magic = GAIM_PLUGIN_MAGIC; |
| 107 info->major_version = GAIM_MAJOR_VERSION; | |
| 108 info->minor_version = GAIM_MINOR_VERSION; | |
| 109 info->type = GAIM_PLUGIN_STANDARD; | |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
110 |
| 11660 | 111 /* this plugin depends on us; duh */ |
| 112 info->dependencies = g_list_append(info->dependencies, MONO_PLUGIN_ID); | |
| 113 mplug->plugin = plugin; | |
| 114 | |
| 115 plugin->info = info; | |
| 116 info->extra_info = mplug; | |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
117 |
|
11980
67fbd2ff4c4e
[gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents:
11952
diff
changeset
|
118 ml_add_plugin(mplug); |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
119 |
| 11660 | 120 return gaim_plugin_register(plugin); |
| 121 } | |
| 122 | |
| 123 /* Loads a Mono Plugin by calling 'load' in the class */ | |
| 124 static gboolean load_mono_plugin(GaimPlugin *plugin) | |
| 125 { | |
| 126 GaimMonoPlugin *mplug; | |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
127 |
| 11660 | 128 gaim_debug(GAIM_DEBUG_INFO, "mono", "Loading plugin\n"); |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
129 |
| 11660 | 130 mplug = (GaimMonoPlugin*)plugin->info->extra_info; |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
131 |
|
11980
67fbd2ff4c4e
[gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents:
11952
diff
changeset
|
132 ml_invoke(mplug->load, mplug->obj, NULL); |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
133 |
| 11660 | 134 return TRUE; |
| 135 } | |
| 136 | |
| 137 /* Unloads a Mono Plugin by calling 'unload' in the class */ | |
| 138 static gboolean unload_mono_plugin(GaimPlugin *plugin) | |
| 139 { | |
| 140 GaimMonoPlugin *mplug; | |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
141 |
| 11660 | 142 gaim_debug(GAIM_DEBUG_INFO, "mono", "Unloading plugin\n"); |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
143 |
| 11660 | 144 mplug = (GaimMonoPlugin*)plugin->info->extra_info; |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
145 |
| 11660 | 146 gaim_signals_disconnect_by_handle((gpointer)mplug->klass); |
|
11980
67fbd2ff4c4e
[gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents:
11952
diff
changeset
|
147 g_list_free(mplug->signal_data); |
|
67fbd2ff4c4e
[gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents:
11952
diff
changeset
|
148 mplug->signal_data = NULL; |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
149 |
|
11980
67fbd2ff4c4e
[gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents:
11952
diff
changeset
|
150 ml_invoke(mplug->unload, mplug->obj, NULL); |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
151 |
| 11660 | 152 return TRUE; |
| 153 } | |
| 154 | |
|
11679
f05542391cd2
[gaim-migrate @ 13965]
Gary Kramlich <grim@reaperworld.com>
parents:
11660
diff
changeset
|
155 static void destroy_mono_plugin(GaimPlugin *plugin) |
| 11660 | 156 { |
| 157 GaimMonoPlugin *mplug; | |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
158 |
| 11660 | 159 gaim_debug(GAIM_DEBUG_INFO, "mono", "Destroying plugin\n"); |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
160 |
| 11660 | 161 mplug = (GaimMonoPlugin*)plugin->info->extra_info; |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
162 |
|
11980
67fbd2ff4c4e
[gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents:
11952
diff
changeset
|
163 ml_invoke(mplug->destroy, mplug->obj, NULL); |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
164 |
| 11660 | 165 if (plugin->info) { |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
166 g_free(plugin->info->name); |
|
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
167 g_free(plugin->info->version); |
|
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
168 g_free(plugin->info->summary); |
|
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
169 g_free(plugin->info->description); |
|
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
170 g_free(plugin->info->author); |
|
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
171 g_free(plugin->info->homepage); |
| 11660 | 172 } |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
173 |
| 11660 | 174 if (mplug) { |
| 175 if (mplug->assm) { | |
| 176 mono_assembly_close(mplug->assm); | |
| 177 } | |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
178 |
| 11660 | 179 g_free(mplug); |
| 180 mplug = NULL; | |
| 181 } | |
| 182 } | |
| 183 | |
|
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
184 /****************************************************************************** |
|
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
185 * Plugin Stuff |
|
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11679
diff
changeset
|
186 *****************************************************************************/ |
|
11679
f05542391cd2
[gaim-migrate @ 13965]
Gary Kramlich <grim@reaperworld.com>
parents:
11660
diff
changeset
|
187 static void plugin_destroy(GaimPlugin *plugin) |
| 11660 | 188 { |
|
11980
67fbd2ff4c4e
[gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents:
11952
diff
changeset
|
189 ml_uninit(); |
| 11660 | 190 } |
| 191 | |
| 192 static GaimPluginLoaderInfo loader_info = | |
| 193 { | |
| 194 NULL, | |
| 195 probe_mono_plugin, | |
| 196 load_mono_plugin, | |
| 197 unload_mono_plugin, | |
| 198 destroy_mono_plugin | |
| 199 }; | |
| 200 | |
| 201 static GaimPluginInfo info = | |
| 202 { | |
| 203 GAIM_PLUGIN_MAGIC, | |
| 204 GAIM_MAJOR_VERSION, | |
| 205 GAIM_MINOR_VERSION, | |
| 206 GAIM_PLUGIN_LOADER, | |
| 207 NULL, | |
| 208 0, | |
| 209 NULL, | |
| 210 GAIM_PRIORITY_DEFAULT, | |
| 211 MONO_PLUGIN_ID, | |
| 212 N_("Mono Plugin Loader"), | |
| 213 VERSION, | |
| 214 N_("Loads .NET plugins with Mono."), | |
| 215 N_("Loads .NET plugins with Mono."), | |
| 216 "Eoin Coffey <ecoffey@simla.colostate.edu>", | |
| 217 GAIM_WEBSITE, | |
| 218 NULL, | |
| 219 NULL, | |
| 220 plugin_destroy, | |
| 221 NULL, | |
| 222 &loader_info, | |
| 223 NULL, | |
| 224 NULL | |
| 225 }; | |
| 226 | |
| 227 static void init_plugin(GaimPlugin *plugin) | |
| 228 { | |
|
11980
67fbd2ff4c4e
[gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents:
11952
diff
changeset
|
229 ml_init(); |
|
67fbd2ff4c4e
[gaim-migrate @ 14273]
Gary Kramlich <grim@reaperworld.com>
parents:
11952
diff
changeset
|
230 |
| 11660 | 231 loader_info.exts = g_list_append(loader_info.exts, "dll"); |
| 232 } | |
| 233 | |
| 234 GAIM_INIT_PLUGIN(mono, init_plugin, info) |
