gplugin/gplugin

more not working mono stuff...
feature/mono
2014-07-20, Gary Kramlich
46644a722d88
Parents 18385c5b10f9
Children 4dcc8894473b
more not working mono stuff...
--- a/mono/gplugin-mono-core.c Sat Jul 12 13:21:49 2014 -0500
+++ b/mono/gplugin-mono-core.c Sun Jul 20 03:35:08 2014 -0500
@@ -39,7 +39,8 @@
"version", GPLUGIN_VERSION,
"license-id", "GPL3",
"summary", "A plugin that can load mono plugins",
- "description", "This plugin loads plugins written in .Net with Mono",
+ "description", "This plugin loads plugins written in .Net with the " \
+ "Mono runtime",
"authors", authors,
"website", GPLUGIN_WEBSITE,
"category", "loaders",
--- a/mono/gplugin-mono-loader.c Sat Jul 12 13:21:49 2014 -0500
+++ b/mono/gplugin-mono-loader.c Sun Jul 20 03:35:08 2014 -0500
@@ -22,16 +22,22 @@
#include <mono/jit/jit.h>
#include <mono/metadata/assembly.h>
+#include <mono/metadata/image.h>
/******************************************************************************
* Globals
*****************************************************************************/
static GObjectClass *parent_class = NULL;
static GType type_real = 0;
+static MonoDomain *domain = NULL;
/******************************************************************************
* Helpers
*****************************************************************************/
+static void
+gplugin_mono_loader_init_mono(void) {
+ domain = mono_jit_init("gplugin");
+}
/******************************************************************************
* GPluginLoaderInterface API
@@ -46,15 +52,83 @@
}
static GPluginPlugin *
-gplugin_mono_loader_query(GPluginLoader *loader, const gchar *filename,
+gplugin_mono_loader_query(GPLUGIN_UNUSED GPluginLoader *loader,
+ const gchar *filename,
GError **error)
{
- MonoDomain *domain = NULL;
+ GPluginPluginInfo *info = NULL;
MonoAssembly *assembly = NULL;
+ MonoImage *image = NULL;
+ MonoImageOpenStatus status;
+ MonoClass *klass = NULL;
+ MonoMethod *query = NULL, *load = NULL, *unload = NULL;
+ MonoObject *info_obj = NULL;
+
+ assembly = mono_assembly_open(filename, &status);
+ if(!assembly) {
+ if(error) {
+ const char *msg = NULL;
+
+ switch(status) {
+ case MONO_IMAGE_ERROR_ERRNO:
+ msg = "check errno";
+ break;
+ case MONO_IMAGE_MISSING_ASSEMBLYREF:
+ msg = "missing assembly reference";
+ break;
+ case MONO_IMAGE_IMAGE_INVALID:
+ msg = "invalid image";
+ break;
+ default:
+ msg = "unknown error";
+ break;
+ }
+
+ *error = g_error_new(GPLUGIN_DOMAIN, 0,
+ "Failed to load %s: %s",
+ filename, msg);
+ }
+
+ return NULL;
+ }
- domain = mono_jit_init("gplugin");
+ /* okay, the code loaded, now get it as an image */
+ image = mono_assembly_get_image(assembly);
+ if(!image) {
+ if(error) {
+ *error = g_error_new(GPLUGIN_DOMAIN, 0,
+ "Failed to load %s: could not get image from assembly",
+ filename);
+ }
+
+ return NULL;
+ }
- assembly = mono_domain_assembly_open(domain, filename);
+ /* now that we have the image, get the Plugin class */
+ klass = mono_class_from_name(image, "", "Plugin");
+ if(!klass) {
+ if(error) {
+ *error = g_error_new(GPLUGIN_DOMAIN, 0,
+ "Failed to load %s: No Plugin class found",
+ filename);
+ }
+
+ return NULL;
+ }
+
+ /* Now find the query method */
+ query = mono_class_get_method_from_name(klass, "Query", 0);
+ if(!query) {
+ if(error) {
+ *error = g_error_new(GPLUGIN_DOMAIN, 0,
+ "Failed to load %s: No Query method found",
+ filename);
+ }
+
+ return NULL;
+ }
+
+ return NULL;
}
static gboolean
@@ -94,6 +168,9 @@
loader_class->query = gplugin_mono_loader_query;
loader_class->load = gplugin_mono_loader_load;
loader_class->unload = gplugin_mono_loader_unload;
+
+ /* initialize mono */
+ gplugin_mono_loader_init_mono();
}
/******************************************************************************
--- a/mono/tests/plugins/basic.cs Sat Jul 12 13:21:49 2014 -0500
+++ b/mono/tests/plugins/basic.cs Sun Jul 20 03:35:08 2014 -0500
@@ -1,8 +1,8 @@
using GPlugin;
-public class Plugin {
- static GPlugin.PluginInfo query() {
- return null;
+public class MonoPlugin : Plugin {
+ static PluginInfo Query() {
+ return PluginInfo.new();
}
}