Mercurial > pidgin
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 11979:717cbb3115bc | 11980:67fbd2ff4c4e |
|---|---|
| 34 GaimPluginInfo *info; | 34 GaimPluginInfo *info; |
| 35 GaimMonoPlugin *mplug; | 35 GaimMonoPlugin *mplug; |
| 36 | 36 |
| 37 char *file = plugin->path; | 37 char *file = plugin->path; |
| 38 | 38 |
| 39 assm = mono_domain_assembly_open(mono_loader_get_domain(), file); | 39 assm = mono_domain_assembly_open(ml_get_domain(), file); |
| 40 | 40 |
| 41 if (!assm) { | 41 if (!assm) { |
| 42 return FALSE; | 42 return FALSE; |
| 43 } | 43 } |
| 44 | 44 |
| 45 gaim_debug(GAIM_DEBUG_INFO, "mono", "Probing plugin\n"); | 45 gaim_debug(GAIM_DEBUG_INFO, "mono", "Probing plugin\n"); |
| 46 | 46 |
| 47 if (mono_loader_is_api_dll(mono_assembly_get_image(assm))) { | 47 if (ml_is_api_dll(mono_assembly_get_image(assm))) { |
| 48 gaim_debug(GAIM_DEBUG_INFO, "mono", "Found our GaimAPI.dll\n"); | 48 gaim_debug(GAIM_DEBUG_INFO, "mono", "Found our GaimAPI.dll\n"); |
| 49 return FALSE; | 49 return FALSE; |
| 50 } | 50 } |
| 51 | 51 |
| 52 info = g_new0(GaimPluginInfo, 1); | 52 info = g_new0(GaimPluginInfo, 1); |
| 53 mplug = g_new0(GaimMonoPlugin, 1); | 53 mplug = g_new0(GaimMonoPlugin, 1); |
| 54 | |
| 55 mplug->signal_data = NULL; | |
| 54 | 56 |
| 55 mplug->assm = assm; | 57 mplug->assm = assm; |
| 56 | 58 |
| 57 mplug->klass = mono_loader_find_plugin_class(mono_assembly_get_image(mplug->assm)); | 59 mplug->klass = ml_find_plugin_class(mono_assembly_get_image(mplug->assm)); |
| 58 if (!mplug->klass) { | 60 if (!mplug->klass) { |
| 59 gaim_debug(GAIM_DEBUG_ERROR, "mono", "no plugin class in \'%s\'\n", file); | 61 gaim_debug(GAIM_DEBUG_ERROR, "mono", "no plugin class in \'%s\'\n", file); |
| 60 return FALSE; | 62 return FALSE; |
| 61 } | 63 } |
| 62 | 64 |
| 63 mplug->obj = mono_object_new(mono_loader_get_domain(), mplug->klass); | 65 mplug->obj = mono_object_new(ml_get_domain(), mplug->klass); |
| 64 if (!mplug->obj) { | 66 if (!mplug->obj) { |
| 65 gaim_debug(GAIM_DEBUG_ERROR, "mono", "obj not valid\n"); | 67 gaim_debug(GAIM_DEBUG_ERROR, "mono", "obj not valid\n"); |
| 66 return FALSE; | 68 return FALSE; |
| 67 } | 69 } |
| 68 | 70 |
| 87 if (!(found_load && found_unload && found_destroy && found_info)) { | 89 if (!(found_load && found_unload && found_destroy && found_info)) { |
| 88 gaim_debug(GAIM_DEBUG_ERROR, "mono", "did not find the required methods\n"); | 90 gaim_debug(GAIM_DEBUG_ERROR, "mono", "did not find the required methods\n"); |
| 89 return FALSE; | 91 return FALSE; |
| 90 } | 92 } |
| 91 | 93 |
| 92 plugin_info = mono_loader_invoke(info_method, mplug->obj, NULL); | 94 plugin_info = ml_invoke(info_method, mplug->obj, NULL); |
| 93 | 95 |
| 94 /* now that the methods are filled out we can populate | 96 /* now that the methods are filled out we can populate |
| 95 the info struct with all the needed info */ | 97 the info struct with all the needed info */ |
| 96 | 98 |
| 97 info->name = mono_loader_get_prop_string(plugin_info, "Name"); | 99 info->name = ml_get_prop_string(plugin_info, "Name"); |
| 98 info->version = mono_loader_get_prop_string(plugin_info, "Version"); | 100 info->version = ml_get_prop_string(plugin_info, "Version"); |
| 99 info->summary = mono_loader_get_prop_string(plugin_info, "Summary"); | 101 info->summary = ml_get_prop_string(plugin_info, "Summary"); |
| 100 info->description = mono_loader_get_prop_string(plugin_info, "Description"); | 102 info->description = ml_get_prop_string(plugin_info, "Description"); |
| 101 info->author = mono_loader_get_prop_string(plugin_info, "Author"); | 103 info->author = ml_get_prop_string(plugin_info, "Author"); |
| 102 info->homepage = mono_loader_get_prop_string(plugin_info, "Homepage"); | 104 info->homepage = ml_get_prop_string(plugin_info, "Homepage"); |
| 103 | 105 |
| 104 info->magic = GAIM_PLUGIN_MAGIC; | 106 info->magic = GAIM_PLUGIN_MAGIC; |
| 105 info->major_version = GAIM_MAJOR_VERSION; | 107 info->major_version = GAIM_MAJOR_VERSION; |
| 106 info->minor_version = GAIM_MINOR_VERSION; | 108 info->minor_version = GAIM_MINOR_VERSION; |
| 107 info->type = GAIM_PLUGIN_STANDARD; | 109 info->type = GAIM_PLUGIN_STANDARD; |
| 111 mplug->plugin = plugin; | 113 mplug->plugin = plugin; |
| 112 | 114 |
| 113 plugin->info = info; | 115 plugin->info = info; |
| 114 info->extra_info = mplug; | 116 info->extra_info = mplug; |
| 115 | 117 |
| 116 mono_loader_add_plugin(mplug); | 118 ml_add_plugin(mplug); |
| 117 | 119 |
| 118 return gaim_plugin_register(plugin); | 120 return gaim_plugin_register(plugin); |
| 119 } | 121 } |
| 120 | 122 |
| 121 /* Loads a Mono Plugin by calling 'load' in the class */ | 123 /* Loads a Mono Plugin by calling 'load' in the class */ |
| 125 | 127 |
| 126 gaim_debug(GAIM_DEBUG_INFO, "mono", "Loading plugin\n"); | 128 gaim_debug(GAIM_DEBUG_INFO, "mono", "Loading plugin\n"); |
| 127 | 129 |
| 128 mplug = (GaimMonoPlugin*)plugin->info->extra_info; | 130 mplug = (GaimMonoPlugin*)plugin->info->extra_info; |
| 129 | 131 |
| 130 mono_loader_invoke(mplug->load, mplug->obj, NULL); | 132 ml_invoke(mplug->load, mplug->obj, NULL); |
| 131 | 133 |
| 132 return TRUE; | 134 return TRUE; |
| 133 } | 135 } |
| 134 | 136 |
| 135 /* Unloads a Mono Plugin by calling 'unload' in the class */ | 137 /* Unloads a Mono Plugin by calling 'unload' in the class */ |
| 140 gaim_debug(GAIM_DEBUG_INFO, "mono", "Unloading plugin\n"); | 142 gaim_debug(GAIM_DEBUG_INFO, "mono", "Unloading plugin\n"); |
| 141 | 143 |
| 142 mplug = (GaimMonoPlugin*)plugin->info->extra_info; | 144 mplug = (GaimMonoPlugin*)plugin->info->extra_info; |
| 143 | 145 |
| 144 gaim_signals_disconnect_by_handle((gpointer)mplug->klass); | 146 gaim_signals_disconnect_by_handle((gpointer)mplug->klass); |
| 145 | 147 g_list_free(mplug->signal_data); |
| 146 mono_loader_invoke(mplug->unload, mplug->obj, NULL); | 148 mplug->signal_data = NULL; |
| 149 | |
| 150 ml_invoke(mplug->unload, mplug->obj, NULL); | |
| 147 | 151 |
| 148 return TRUE; | 152 return TRUE; |
| 149 } | 153 } |
| 150 | 154 |
| 151 static void destroy_mono_plugin(GaimPlugin *plugin) | 155 static void destroy_mono_plugin(GaimPlugin *plugin) |
| 154 | 158 |
| 155 gaim_debug(GAIM_DEBUG_INFO, "mono", "Destroying plugin\n"); | 159 gaim_debug(GAIM_DEBUG_INFO, "mono", "Destroying plugin\n"); |
| 156 | 160 |
| 157 mplug = (GaimMonoPlugin*)plugin->info->extra_info; | 161 mplug = (GaimMonoPlugin*)plugin->info->extra_info; |
| 158 | 162 |
| 159 mono_loader_invoke(mplug->destroy, mplug->obj, NULL); | 163 ml_invoke(mplug->destroy, mplug->obj, NULL); |
| 160 | 164 |
| 161 if (plugin->info) { | 165 if (plugin->info) { |
| 162 g_free(plugin->info->name); | 166 g_free(plugin->info->name); |
| 163 g_free(plugin->info->version); | 167 g_free(plugin->info->version); |
| 164 g_free(plugin->info->summary); | 168 g_free(plugin->info->summary); |
| 180 /****************************************************************************** | 184 /****************************************************************************** |
| 181 * Plugin Stuff | 185 * Plugin Stuff |
| 182 *****************************************************************************/ | 186 *****************************************************************************/ |
| 183 static void plugin_destroy(GaimPlugin *plugin) | 187 static void plugin_destroy(GaimPlugin *plugin) |
| 184 { | 188 { |
| 185 mono_jit_cleanup(mono_loader_get_domain()); | 189 ml_uninit(); |
| 186 } | 190 } |
| 187 | 191 |
| 188 static GaimPluginLoaderInfo loader_info = | 192 static GaimPluginLoaderInfo loader_info = |
| 189 { | 193 { |
| 190 NULL, | 194 NULL, |
| 220 NULL | 224 NULL |
| 221 }; | 225 }; |
| 222 | 226 |
| 223 static void init_plugin(GaimPlugin *plugin) | 227 static void init_plugin(GaimPlugin *plugin) |
| 224 { | 228 { |
| 225 MonoDomain *domain = mono_jit_init("gaim"); | 229 ml_init(); |
| 226 | 230 |
| 227 mono_loader_set_domain(domain); | |
| 228 | |
| 229 mono_loader_init_internal_calls(); | |
| 230 | |
| 231 loader_info.exts = g_list_append(loader_info.exts, "dll"); | 231 loader_info.exts = g_list_append(loader_info.exts, "dll"); |
| 232 } | 232 } |
| 233 | 233 |
| 234 GAIM_INIT_PLUGIN(mono, init_plugin, info) | 234 GAIM_INIT_PLUGIN(mono, init_plugin, info) |
