annotate plugins/mono/loader/mono.c @ 11660:a3302d271199

[gaim-migrate @ 13945] Thanks to the hard work of Eoin 'ecoffey' Coffey, here is the mono plugin loader. It needs a lot of api wrapping a bit more autotools loving, but with the basic API that is wrapped, it works quite well. committer: Tailor Script <tailor@pidgin.im>
author Gary Kramlich <grim@reaperworld.com>
date Fri, 14 Oct 2005 05:00:17 +0000
parents
children f05542391cd2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11660
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * Mono Plugin Loader
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 *
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 * -- Thanks to the perl plugin loader for all the great tips ;-)
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
5 *
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
6 * Eoin Coffey
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
7 */
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
9 #ifdef HAVE_CONFIG_H
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
10 #include <config.h>
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
11 #endif
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
12
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 #include "internal.h"
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
14 #include "debug.h"
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
15 #include "plugin.h"
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
16 #include "version.h"
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
17 #include "mono-helper.h"
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
18
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
19 #define MONO_PLUGIN_ID "core-mono"
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
20
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21 /* This is where our code executes */
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
22 static MonoDomain *domain;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
23
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
24 /* probes the given plugin to determine if its a plugin */
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
25 static gboolean probe_mono_plugin(GaimPlugin *plugin)
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
26 {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
27 MonoAssembly *assm;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
28 MonoMethod *m = NULL;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
29 MonoMethod *info_method = NULL;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
30 MonoObject *plugin_info;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31 gboolean found_load = FALSE, found_unload = FALSE, found_destroy = FALSE, found_info = FALSE;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
32 gpointer iter = NULL;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34 GaimPluginInfo *info;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35 GaimMonoPlugin *mplug;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37 char *file = plugin->path;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39 assm = mono_domain_assembly_open(domain, file);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41 if (!assm) {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
42 return FALSE;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
43 }
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
44
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
45 gaim_debug(GAIM_DEBUG_INFO, "mono", "Probing plugin\n");
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
46
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
47 if (mono_loader_is_api_dll(mono_assembly_get_image(assm))) {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
48 gaim_debug(GAIM_DEBUG_INFO, "mono", "Found our GaimAPI.dll\n");
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
49 return FALSE;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
50 }
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
51
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
52 info = g_new0(GaimPluginInfo, 1);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
53 mplug = g_new0(GaimMonoPlugin, 1);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
54
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
55 mplug->assm = assm;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
56
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
57 mplug->klass = mono_loader_find_plugin_class(mono_assembly_get_image(mplug->assm));
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
58 if (!mplug->klass) {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59 gaim_debug(GAIM_DEBUG_ERROR, "mono", "no plugin class in \'%s\'\n", file);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
60 return FALSE;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
61 }
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
62
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
63 mplug->obj = mono_object_new(domain, mplug->klass);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
64 if (!mplug->obj) {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
65 gaim_debug(GAIM_DEBUG_ERROR, "mono", "obj not valid\n");
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
66 return FALSE;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
67 }
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
68
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
69 mono_runtime_object_init(mplug->obj);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
70
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
71 while ((m = mono_class_get_methods(mplug->klass, &iter))) {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
72 if (strcmp(mono_method_get_name(m), "Load") == 0) {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
73 mplug->load = m;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
74 found_load = TRUE;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
75 } else if (strcmp(mono_method_get_name(m), "Unload") == 0) {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
76 mplug->unload = m;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
77 found_unload = TRUE;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
78 } else if (strcmp(mono_method_get_name(m), "Destroy") == 0) {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
79 mplug->destroy = m;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
80 found_destroy = TRUE;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
81 } else if (strcmp(mono_method_get_name(m), "Info") == 0) {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
82 info_method = m;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
83 found_info = TRUE;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
84 }
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
85 }
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
86
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
87 if (!(found_load && found_unload && found_destroy && found_info)) {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
88 gaim_debug(GAIM_DEBUG_ERROR, "mono", "did not find the required methods\n");
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
89 return FALSE;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
90 }
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
91
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
92 plugin_info = mono_runtime_invoke(info_method, mplug->obj, NULL, NULL);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
93
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
94 /* now that the methods are filled out we can populate
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
95 the info struct with all the needed info */
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
96
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
97 info->name = mono_loader_get_prop_string(plugin_info, "Name");
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
98 info->version = mono_loader_get_prop_string(plugin_info, "Version");
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
99 info->summary = mono_loader_get_prop_string(plugin_info, "Summary");
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
100 info->description = mono_loader_get_prop_string(plugin_info, "Description");
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
101 info->author = mono_loader_get_prop_string(plugin_info, "Author");
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
102 info->homepage = mono_loader_get_prop_string(plugin_info, "Homepage");
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
103
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
104 info->magic = GAIM_PLUGIN_MAGIC;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
105 info->major_version = GAIM_MAJOR_VERSION;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
106 info->minor_version = GAIM_MINOR_VERSION;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
107 info->type = GAIM_PLUGIN_STANDARD;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
108
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
109 /* this plugin depends on us; duh */
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
110 info->dependencies = g_list_append(info->dependencies, MONO_PLUGIN_ID);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
111 mplug->plugin = plugin;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
112
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
113 plugin->info = info;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
114 info->extra_info = mplug;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
115
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
116 mono_loader_add_plugin(mplug);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
117
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
118 return gaim_plugin_register(plugin);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
119 }
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
120
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
121 /* Loads a Mono Plugin by calling 'load' in the class */
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
122 static gboolean load_mono_plugin(GaimPlugin *plugin)
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
123 {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
124 GaimMonoPlugin *mplug;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
125
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
126 gaim_debug(GAIM_DEBUG_INFO, "mono", "Loading plugin\n");
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
127
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
128 mplug = (GaimMonoPlugin*)plugin->info->extra_info;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
129
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
130 mono_runtime_invoke(mplug->load, mplug->obj, NULL, NULL);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
131
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
132 return TRUE;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
133 }
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
134
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
135 /* Unloads a Mono Plugin by calling 'unload' in the class */
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
136 static gboolean unload_mono_plugin(GaimPlugin *plugin)
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
137 {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
138 GaimMonoPlugin *mplug;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
139
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
140 gaim_debug(GAIM_DEBUG_INFO, "mono", "Unloading plugin\n");
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
141
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
142 mplug = (GaimMonoPlugin*)plugin->info->extra_info;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
143
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
144 gaim_signals_disconnect_by_handle((gpointer)mplug->klass);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
145
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
146 mono_runtime_invoke(mplug->unload, mplug->obj, NULL, NULL);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
147
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
148 return TRUE;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
149 }
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
150
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
151 /* Destroys a Mono Plugin by calling 'destroy' in the class,
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
152 and cleaning up all the malloced memory */
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
153 static gboolean destroy_mono_plugin(GaimPlugin *plugin)
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
154 {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
155 GaimMonoPlugin *mplug;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
156
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
157 gaim_debug(GAIM_DEBUG_INFO, "mono", "Destroying plugin\n");
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
158
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
159 mplug = (GaimMonoPlugin*)plugin->info->extra_info;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
160
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
161 mono_runtime_invoke(mplug->destroy, mplug->obj, NULL, NULL);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
162
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
163 if (plugin->info) {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
164 if (plugin->info->name) g_free(plugin->info->name);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
165 if (plugin->info->version) g_free(plugin->info->version);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
166 if (plugin->info->summary) g_free(plugin->info->summary);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
167 if (plugin->info->description) g_free(plugin->info->description);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
168 if (plugin->info->author) g_free(plugin->info->author);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
169 if (plugin->info->homepage) g_free(plugin->info->homepage);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
170 }
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
171
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
172 if (mplug) {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
173 if (mplug->assm) {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
174 mono_assembly_close(mplug->assm);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
175 }
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
176
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
177 g_free(mplug);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
178 mplug = NULL;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
179 }
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
180
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
181 return TRUE;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
182 }
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
183
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
184 gboolean plugin_destroy(GaimPlugin *plugin)
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
185 {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
186 mono_jit_cleanup(domain);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
187
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
188 return TRUE;
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
189 }
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
190
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
191 static GaimPluginLoaderInfo loader_info =
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
192 {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
193 NULL,
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
194 probe_mono_plugin,
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
195 load_mono_plugin,
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
196 unload_mono_plugin,
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
197 destroy_mono_plugin
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
198 };
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
199
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
200 static GaimPluginInfo info =
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
201 {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
202 GAIM_PLUGIN_MAGIC,
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
203 GAIM_MAJOR_VERSION,
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
204 GAIM_MINOR_VERSION,
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
205 GAIM_PLUGIN_LOADER,
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
206 NULL,
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
207 0,
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
208 NULL,
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
209 GAIM_PRIORITY_DEFAULT,
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
210 MONO_PLUGIN_ID,
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
211 N_("Mono Plugin Loader"),
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
212 VERSION,
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
213 N_("Loads .NET plugins with Mono."),
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
214 N_("Loads .NET plugins with Mono."),
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
215 "Eoin Coffey <ecoffey@simla.colostate.edu>",
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
216 GAIM_WEBSITE,
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
217 NULL,
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
218 NULL,
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
219 plugin_destroy,
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
220 NULL,
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
221 &loader_info,
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
222 NULL,
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
223 NULL
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
224 };
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
225
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
226 /* Creates the domain to execute in, and setups our CS Gaim API (note:
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
227 in the future the 'mono_add_internal_call' will be spread through out
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
228 the source to whatever module is exposing the API; this function will
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
229 simply call helper functions to do so) */
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
230 static void init_plugin(GaimPlugin *plugin)
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
231 {
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
232 domain = mono_jit_init("gaim");
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
233
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
234 mono_loader_set_domain(domain);
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
235
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
236 mono_loader_init_internal_calls();
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
237
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
238 loader_info.exts = g_list_append(loader_info.exts, "dll");
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
239 }
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
240
a3302d271199 [gaim-migrate @ 13945]
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
241 GAIM_INIT_PLUGIN(mono, init_plugin, info)