gplugin/gplugin

a bunch more work on the ruby stuff
feature/ruby-loader
2014-12-10, Gary Kramlich
e2beb8f8474f
Parents 303be9417562
Children f075b38e5e7c
a bunch more work on the ruby stuff
--- a/ruby/CMakeLists.txt Wed Dec 10 01:05:11 2014 -0600
+++ b/ruby/CMakeLists.txt Wed Dec 10 01:05:43 2014 -0600
@@ -13,13 +13,11 @@
gplugin-ruby-core.c
gplugin-ruby-loader.c
gplugin-ruby-plugin.c
- gplugin-ruby-utils.c
)
set(GPLUGIN_RUBY_HEADERS
gplugin-ruby-loader.h
gplugin-ruby-plugin.h
- gplugin-ruby-utils.h
)
pkg_check_modules(RUBY REQUIRED ruby-2.1)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ruby/gplugin-ruby-core.c Wed Dec 10 01:05:43 2014 -0600
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2011-2014 Gary Kramlich <grim@reaperworld.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <gplugin.h>
+#include <gplugin-native.h>
+
+#include "gplugin-ruby-loader.h"
+#include "gplugin-ruby-plugin.h"
+
+G_MODULE_EXPORT GPluginPluginInfo *
+gplugin_query(GPLUGIN_UNUSED GError **error) {
+ const gchar * const authors[] = {
+ "Gary Kramlich <grim@reaperworld.com>",
+ NULL
+ };
+
+ return gplugin_plugin_info_new(
+ "gplugin/ruby-loader",
+ GPLUGIN_NATIVE_PLUGIN_ABI_VERSION,
+ "internal", TRUE,
+ "load-on-query", TRUE,
+ "name", "Ruby Plugin Loader",
+ "version", GPLUGIN_VERSION,
+ "license-id", "GPL3",
+ "summary", "A plugin that can load ruby plugins",
+ "description", "This plugin allows the loading of plugins written in "
+ "the ruby programming language.",
+ "authors", authors,
+ "website", GPLUGIN_WEBSITE,
+ "category", "loaders",
+ NULL
+ );
+}
+
+G_MODULE_EXPORT gboolean
+gplugin_load(GPluginNativePlugin *plugin,
+ GPLUGIN_UNUSED GError **error)
+{
+ gplugin_ruby_plugin_register(plugin);
+ gplugin_ruby_loader_register(plugin);
+
+ gplugin_manager_register_loader(GPLUGIN_TYPE_RUBY_LOADER);
+
+ return TRUE;
+}
+
+G_MODULE_EXPORT gboolean
+gplugin_unload(GPLUGIN_UNUSED GPluginNativePlugin *plugin,
+ GPLUGIN_UNUSED GError **error)
+{
+ return FALSE;
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ruby/gplugin-ruby-loader.c Wed Dec 10 01:05:43 2014 -0600
@@ -0,0 +1,152 @@
+/*
+ * Copyright (C) 2011-2014 Gary Kramlich <grim@reaperworld.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdlib.h>
+
+#include <ruby.h>
+
+#include "gplugin-ruby-loader.h"
+
+#include "gplugin-ruby-plugin.h"
+
+#define GPLUGIN_RUBY_LOADER_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE((obj), GPLUGIN_TYPE_RUBY_LOADER, GPluginRubyLoaderPrivate))
+
+/******************************************************************************
+ * Typedefs
+ *****************************************************************************/
+typedef struct {
+ gint dummy;
+} GPluginRubyLoaderPrivate;
+
+/******************************************************************************
+ * Globals
+ *****************************************************************************/
+static GObjectClass *parent_class = NULL;
+static GType type_real = 0;
+
+/******************************************************************************
+ * GPluginLoaderInterface API
+ *****************************************************************************/
+static GSList *
+gplugin_ruby_loader_class_supported_extensions(GPLUGIN_UNUSED const GPluginLoaderClass *klass) {
+ return g_slist_append(NULL, "rb");
+}
+
+static GPluginPlugin *
+gplugin_ruby_loader_query(GPLUGIN_UNUSED GPluginLoader *loader,
+ const gchar *filename,
+ GPLUGIN_UNUSED GError **error)
+{
+ GPluginPlugin *plugin = NULL;
+
+ return plugin;
+}
+
+static gboolean
+gplugin_ruby_loader_load(GPLUGIN_UNUSED GPluginLoader *loader,
+ GPluginPlugin *plugin,
+ GError **error)
+{
+ gboolean ret = FALSE;
+
+ return ret;
+}
+
+static gboolean
+gplugin_ruby_loader_unload(GPLUGIN_UNUSED GPluginLoader *loader,
+ GPluginPlugin *plugin,
+ GError **error)
+{
+ gboolean ret = FALSE;
+
+ return ret;
+}
+
+/******************************************************************************
+ * Ruby Stuff
+ *****************************************************************************/
+static gboolean
+gplugin_ruby_loader_init_ruby(void) {
+ ruby_init();
+
+ return TRUE;
+}
+
+/******************************************************************************
+ * Object Stuff
+ *****************************************************************************/
+static void
+gplugin_ruby_loader_finalize(GObject *obj) {
+ G_OBJECT_CLASS(parent_class)->finalize(obj);
+}
+
+static void
+gplugin_ruby_loader_class_init(GPluginRubyLoaderClass *klass) {
+ GObjectClass *obj_class = G_OBJECT_CLASS(klass);
+ GPluginLoaderClass *loader_class =
+ GPLUGIN_LOADER_CLASS(klass);
+
+ parent_class = g_type_class_peek_parent(klass);
+
+ g_type_class_add_private(klass, sizeof(GPluginRubyLoaderPrivate));
+
+ obj_class->finalize = gplugin_ruby_loader_finalize;
+
+ loader_class->supported_extensions =
+ gplugin_ruby_loader_class_supported_extensions;
+ loader_class->query = gplugin_ruby_loader_query;
+ loader_class->load = gplugin_ruby_loader_load;
+ loader_class->unload = gplugin_ruby_loader_unload;
+}
+
+/******************************************************************************
+ * API
+ *****************************************************************************/
+void
+gplugin_ruby_loader_register(GPluginNativePlugin *plugin) {
+ if(g_once_init_enter(&type_real)) {
+ GType type = 0;
+
+ static const GTypeInfo info = {
+ .class_size = sizeof(GPluginRubyLoaderClass),
+ .class_init = (GClassInitFunc)gplugin_ruby_loader_class_init,
+ .instance_size = sizeof(GPluginRubyLoader),
+ };
+
+ type = gplugin_native_plugin_register_type(plugin,
+ GPLUGIN_TYPE_LOADER,
+ "GPluginRubyLoader",
+ &info,
+ 0);
+
+ gplugin_ruby_loader_init_ruby();
+
+ g_once_init_leave(&type_real, type);
+ }
+}
+
+GType
+gplugin_ruby_loader_get_type(void) {
+ if(G_UNLIKELY(type_real == 0)) {
+ g_warning("gplugin_ruby_loader_get_type was called before "
+ "the type was registered!\n");
+ }
+
+ return type_real;
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ruby/gplugin-ruby-loader.h Wed Dec 10 01:05:43 2014 -0600
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2011-2014 Gary Kramlich <grim@reaperworld.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GPLUGIN_RUBY_LOADER_H
+#define GPLUGIN_RUBY_LOADER_H
+
+#define GPLUGIN_TYPE_RUBY_LOADER (gplugin_ruby_loader_get_type())
+#define GPLUGIN_RUBY_LOADER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GPLUGIN_TYPE_RUBY_LOADER, GPluginRubyLoader))
+#define GPLUGIN_RUBY_LOADER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((obj), GPLUGIN_TYPE_RUBY_LOADER, GPluginRubyLoaderClass))
+#define GPLUGIN_IS_RUBY_LOADER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GPLUGIN_TYPE_RUBY_LOADER))
+#define GPLUGIN_IS_RUBY_LOADER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((obj), GPLUGIN_TYPE_RUBY_LOADER))
+#define GPLUGIN_RUBY_LOADER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GPLUGIN_TYPE_RUBY_LOADER, GPluginRubyLoaderClass))
+
+typedef struct _GPluginRubyLoader GPluginRubyLoader;
+typedef struct _GPluginRubyLoaderClass GPluginRubyLoaderClass;
+
+#include <gplugin.h>
+#include <gplugin-native.h>
+
+struct _GPluginRubyLoader {
+ GPluginLoader parent;
+
+ void (*_gplugin_reserved_1)(void);
+ void (*_gplugin_reserved_2)(void);
+ void (*_gplugin_reserved_3)(void);
+ void (*_gplugin_reserved_4)(void);
+};
+
+struct _GPluginRubyLoaderClass {
+ GPluginLoaderClass parent;
+
+ void (*_gplugin_reserved_1)(void);
+ void (*_gplugin_reserved_2)(void);
+ void (*_gplugin_reserved_3)(void);
+ void (*_gplugin_reserved_4)(void);
+};
+
+G_BEGIN_DECLS
+
+void gplugin_ruby_loader_register(GPluginNativePlugin *plugin);
+GType gplugin_ruby_loader_get_type(void);
+
+G_END_DECLS
+
+#endif /* GPLUGIN_RUBY_LOADER_H */
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ruby/gplugin-ruby-plugin.c Wed Dec 10 01:05:43 2014 -0600
@@ -0,0 +1,161 @@
+/*
+ * Copyright (C) 2011-2014 Gary Kramlich <grim@reaperworld.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <ruby.h>
+
+#include "gplugin-ruby-plugin.h"
+
+#define GPLUGIN_RUBY_PLUGIN_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE((obj), GPLUGIN_TYPE_RUBY_PLUGIN, GPluginRubyPluginPrivate))
+
+/******************************************************************************
+ * Typedefs
+ *****************************************************************************/
+typedef struct {
+ void *node;
+} GPluginRubyPluginPrivate;
+
+/******************************************************************************
+ * Enums
+ *****************************************************************************/
+enum {
+ PROP_ZERO,
+ PROP_NODE,
+ PROP_LAST,
+};
+
+/******************************************************************************
+ * Globals
+ *****************************************************************************/
+static GObjectClass *parent_class = NULL;
+static GType type_real = 0;
+
+/******************************************************************************
+ * Private Stuff
+ *****************************************************************************/
+static void *
+gplugin_ruby_plugin_get_node(const GPluginRubyPlugin *plugin) {
+ GPluginRubyPluginPrivate *priv = GPLUGIN_RUBY_PLUGIN_GET_PRIVATE(plugin);
+
+ return priv->node;
+}
+
+static void
+gplugin_ruby_plugin_set_node(GPluginRubyPlugin *plugin, void *node) {
+ GPluginRubyPluginPrivate *priv = GPLUGIN_RUBY_PLUGIN_GET_PRIVATE(plugin);
+
+ priv->node = node;
+}
+
+/******************************************************************************
+ * Object Stuff
+ *****************************************************************************/
+static void
+gplugin_ruby_plugin_get_property(GObject *obj, guint param_id, GValue *value,
+ GParamSpec *pspec)
+{
+ GPluginRubyPlugin *plugin = GPLUGIN_RUBY_PLUGIN(obj);
+
+ switch(param_id) {
+ case PROP_NODE:
+ g_value_set_pointer(value, gplugin_ruby_plugin_get_node(plugin));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
+ break;
+ }
+}
+
+static void
+gplugin_ruby_plugin_set_property(GObject *obj, guint param_id,
+ const GValue *value, GParamSpec *pspec)
+{
+ GPluginRubyPlugin *plugin = GPLUGIN_RUBY_PLUGIN(obj);
+
+ switch(param_id) {
+ case PROP_NODE:
+ gplugin_ruby_plugin_set_node(plugin, g_value_get_pointer(value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
+ break;
+ }
+}
+
+static void
+gplugin_ruby_plugin_finalize(GObject *obj) {
+ GPluginRubyPluginPrivate *priv =
+ GPLUGIN_RUBY_PLUGIN_GET_PRIVATE(obj);
+
+ if(priv->node)
+ priv->node = NULL;
+
+ G_OBJECT_CLASS(parent_class)->finalize(obj);
+}
+
+static void
+gplugin_ruby_plugin_class_init(GPluginRubyPluginClass *klass) {
+ GObjectClass *obj_class = G_OBJECT_CLASS(klass);
+
+ parent_class = g_type_class_peek_parent(klass);
+
+ g_type_class_add_private(klass, sizeof(GPluginRubyPluginPrivate));
+
+ obj_class->get_property = gplugin_ruby_plugin_get_property;
+ obj_class->set_property = gplugin_ruby_plugin_set_property;
+ obj_class->finalize = gplugin_ruby_plugin_finalize;
+
+ g_object_class_install_property(obj_class, PROP_NODE,
+ g_param_spec_pointer("node", "node",
+ "The ruby node object",
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+}
+
+/******************************************************************************
+ * API
+ *****************************************************************************/
+void
+gplugin_ruby_plugin_register(GPluginNativePlugin *plugin) {
+ if(g_once_init_enter(&type_real)) {
+ GType type = 0;
+
+ static const GTypeInfo info = {
+ .class_size = sizeof(GPluginRubyPluginClass),
+ .class_init = (GClassInitFunc)gplugin_ruby_plugin_class_init,
+ .instance_size = sizeof(GPluginRubyPlugin),
+ };
+
+ type = gplugin_native_plugin_register_type(plugin,
+ GPLUGIN_TYPE_PLUGIN,
+ "GPluginRubyPlugin",
+ &info,
+ 0);
+
+ g_once_init_leave(&type_real, type);
+ }
+}
+
+GType
+gplugin_ruby_plugin_get_type(void) {
+ if(G_UNLIKELY(type_real == 0)) {
+ g_warning("gplugin_ruby_plugin_get_type was called before "
+ "the type was registered!\n");
+ }
+
+ return type_real;
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/ruby/gplugin-ruby-plugin.h Wed Dec 10 01:05:43 2014 -0600
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2011-2014 Gary Kramlich <grim@reaperworld.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GPLUGIN_RUBY_PLUGIN_H
+#define GPLUGIN_RUBY_PLUGIN_H
+
+#define GPLUGIN_TYPE_RUBY_PLUGIN (gplugin_ruby_plugin_get_type())
+#define GPLUGIN_RUBY_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GPLUGIN_TYPE_RUBY_PLUGIN, GPluginRubyPlugin))
+#define GPLUGIN_RUBY_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((obj), GPLUGIN_TYPE_RUBY_PLUGIN, GPluginRubyPluginClass))
+#define GPLUGIN_IS_RUBY_PLUGIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GPLUGIN_TYPE_RUBY_PLUGIN))
+#define GPLUGIN_IS_RUBY_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((obj), GPLUGIN_TYPE_RUBY_PLUGIN))
+#define GPLUGIN_RUBY_PLUGIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GPLUGIN_TYPE_RUBY_PLUGIN, GPluginRubyPluginClass))
+
+typedef struct _GPluginRubyPlugin GPluginRubyPlugin;
+typedef struct _GPluginRubyPluginClass GPluginRubyPluginClass;
+
+#include <gplugin.h>
+#include <gplugin-native.h>
+
+struct _GPluginRubyPlugin {
+ GPluginPlugin parent;
+};
+
+struct _GPluginRubyPluginClass {
+ GPluginPluginClass parent;
+
+ void (*_gplugin_reserved_1)(void);
+ void (*_gplugin_reserved_2)(void);
+ void (*_gplugin_reserved_3)(void);
+ void (*_gplugin_reserved_4)(void);
+};
+
+G_BEGIN_DECLS
+
+void gplugin_ruby_plugin_register(GPluginNativePlugin *plugin);
+GType gplugin_ruby_plugin_get_type(void);
+
+G_END_DECLS
+
+#endif /* GPLUGIN_RUBY_PLUGIN_H */
+
--- a/ruby/tests/plugins/basic.rb Wed Dec 10 01:05:11 2014 -0600
+++ b/ruby/tests/plugins/basic.rb Wed Dec 10 01:05:43 2014 -0600
@@ -4,8 +4,7 @@
def gplugin_query()
return GPlugin::PluginInfo.new(
- 'ruby/ruby-basic-plugin',
- ['basic plugin']
+ GPlugin::PluginInfo, ['id' => 'ruby/ruby-basic-plugin', "abi_version" => 0x01020304]
)
end