Mercurial > pidgin
annotate plugins/mono/loader/mono-helper.c @ 11850:0d793b594a23
[gaim-migrate @ 14141]
patch from Richard Stellingwerff to fix my CVS crash. I think I might put him up for sainthood.
(I could have sworn that I tried this, and it didn't work before, but it works now)
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Thu, 27 Oct 2005 14:40:48 +0000 |
parents | 2c8216659a84 |
children | 565d2e437c04 |
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 | |
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" | |
17 #include "value.h" | |
18 | |
19 MonoClass* mono_loader_find_plugin_class(MonoImage *image) | |
20 { | |
21 MonoClass *klass, *pklass = NULL; | |
22 int i, total; | |
23 | |
24 total = mono_image_get_table_rows (image, MONO_TABLE_TYPEDEF); | |
25 for (i = 1; i <= total; ++i) { | |
26 klass = mono_class_get (image, MONO_TOKEN_TYPE_DEF | i); | |
27 pklass = mono_class_get_parent(klass); | |
28 if (pklass) | |
29 if (strcmp("GaimPlugin", mono_class_get_name(pklass)) == 0) | |
30 return klass; | |
31 } | |
32 | |
33 return NULL; | |
34 } | |
35 | |
36 void mono_loader_set_prop_string(MonoObject *obj, char *field, char *data) | |
37 { | |
38 MonoClass *klass; | |
39 MonoProperty *prop; | |
40 MonoString *str; | |
41 gpointer args[1]; | |
42 | |
43 klass = mono_object_get_class(obj); | |
44 | |
45 prop = mono_class_get_property_from_name(klass, field); | |
46 | |
47 str = mono_string_new(mono_loader_get_domain(), data); | |
48 | |
49 args[0] = str; | |
50 | |
51 mono_property_set_value(prop, obj, args, NULL); | |
52 } | |
53 | |
54 gchar* mono_loader_get_prop_string(MonoObject *obj, char *field) | |
55 { | |
56 MonoClass *klass; | |
57 MonoProperty *prop; | |
58 MonoString *str; | |
59 | |
60 klass = mono_object_get_class(obj); | |
61 | |
62 prop = mono_class_get_property_from_name(klass, field); | |
63 | |
64 str = (MonoString*)mono_property_get_value(prop, obj, NULL, NULL); | |
65 | |
66 return mono_string_to_utf8(str); | |
67 } | |
68 | |
69 gboolean mono_loader_is_api_dll(MonoImage *image) | |
70 { | |
71 MonoClass *klass; | |
72 int i, total; | |
73 | |
74 total = mono_image_get_table_rows (image, MONO_TABLE_TYPEDEF); | |
75 for (i = 1; i <= total; ++i) { | |
76 klass = mono_class_get (image, MONO_TOKEN_TYPE_DEF | i); | |
77 if (strcmp(mono_class_get_name(klass), "Debug") == 0) | |
78 if (strcmp(mono_class_get_namespace(klass), "Gaim") == 0) { | |
79 mono_loader_set_api_image(image); | |
80 return TRUE; | |
81 } | |
82 } | |
83 | |
84 return FALSE; | |
85 } | |
86 | |
87 MonoObject* mono_loader_object_from_gaim_type(GaimType type, gpointer data) | |
88 { | |
89 return NULL; | |
90 } | |
91 | |
92 MonoObject* mono_loader_object_from_gaim_subtype(GaimSubType type, gpointer data) | |
93 { | |
11776
e66dbfdaea8a
[gaim-migrate @ 14067]
Gary Kramlich <grim@reaperworld.com>
parents:
11660
diff
changeset
|
94 MonoObject *obj = NULL; |
11660 | 95 |
96 switch (type) { | |
97 case GAIM_SUBTYPE_BLIST_BUDDY: | |
98 obj = gaim_blist_build_buddy_object(data); | |
99 break; | |
100 default: | |
101 break; | |
102 } | |
103 | |
104 return obj; | |
105 } | |
106 | |
11786
2c8216659a84
[gaim-migrate @ 14077]
Gary Kramlich <grim@reaperworld.com>
parents:
11776
diff
changeset
|
107 static MonoDomain *_domain = NULL; |
11660 | 108 |
109 MonoDomain* mono_loader_get_domain(void) | |
110 { | |
111 return _domain; | |
112 } | |
113 | |
114 void mono_loader_set_domain(MonoDomain *d) | |
115 { | |
116 _domain = d; | |
117 } | |
118 | |
119 static MonoImage *_api_image = NULL; | |
120 | |
121 void mono_loader_set_api_image(MonoImage *image) | |
122 { | |
123 _api_image = image; | |
124 } | |
125 | |
126 MonoImage* mono_loader_get_api_image() | |
127 { | |
128 return _api_image; | |
129 } | |
130 | |
131 void mono_loader_init_internal_calls(void) | |
132 { | |
133 mono_add_internal_call("Gaim.Debug::_debug", gaim_debug_glue); | |
134 mono_add_internal_call("Gaim.Signal::_connect", gaim_signal_connect_glue); | |
135 mono_add_internal_call("Gaim.BuddyList::_get_handle", gaim_blist_get_handle_glue); | |
136 } | |
137 | |
138 static GHashTable *plugins_hash = NULL; | |
139 | |
140 void mono_loader_add_plugin(GaimMonoPlugin *plugin) | |
141 { | |
142 if (!plugins_hash) | |
143 plugins_hash = g_hash_table_new(NULL, NULL); | |
144 | |
145 g_hash_table_insert(plugins_hash, plugin->klass, plugin); | |
146 } | |
147 | |
148 gboolean mono_loader_remove_plugin(GaimMonoPlugin *plugin) | |
149 { | |
150 return g_hash_table_remove(plugins_hash, plugin->klass); | |
151 } | |
152 | |
153 gpointer mono_loader_find_plugin(GaimMonoPlugin *plugin) | |
154 { | |
155 return g_hash_table_lookup(plugins_hash, plugin->klass); | |
156 } | |
157 | |
158 gpointer mono_loader_find_plugin_by_class(MonoClass *klass) | |
159 { | |
160 return g_hash_table_lookup(plugins_hash, klass); | |
161 } | |
162 | |
163 GHashTable* mono_loader_get_plugin_hash() | |
164 { | |
165 return plugins_hash; | |
166 } |