[libpeas/proxys: 1/25] Add PeasExtension
- From: Steve Frécinaux <sfre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libpeas/proxys: 1/25] Add PeasExtension
- Date: Sun, 23 May 2010 13:59:22 +0000 (UTC)
commit dda12aa4025b1b4ad7d61602d5abd9dfdd61b5ea
Author: Steve Frécinaux <code istique net>
Date: Thu May 13 15:34:59 2010 +0200
Add PeasExtension
libpeas/Makefile.am | 2 +
libpeas/peas-engine.c | 15 ++++++++
libpeas/peas-engine.h | 5 +++
libpeas/peas-extension.c | 83 ++++++++++++++++++++++++++++++++++++++++++
libpeas/peas-extension.h | 75 ++++++++++++++++++++++++++++++++++++++
libpeas/peas-plugin-loader.c | 15 ++++++++
libpeas/peas-plugin-loader.h | 7 ++++
7 files changed, 202 insertions(+), 0 deletions(-)
---
diff --git a/libpeas/Makefile.am b/libpeas/Makefile.am
index 1ffe430..f62adfc 100644
--- a/libpeas/Makefile.am
+++ b/libpeas/Makefile.am
@@ -19,6 +19,7 @@ libpeas_2_0_la_LIBADD = $(PEAS_LIBS) $(IGE_MAC_LIBS)
INST_H_FILES = \
peas-plugin.h \
peas-plugin-info.h \
+ peas-extension.h \
peas-engine.h
NOINST_H_FILES = \
@@ -35,6 +36,7 @@ C_FILES = \
peas-plugin.c \
peas-plugin-info.c \
peas-plugin-loader.c \
+ peas-extension.c \
peas-engine.c
libpeas_2_0_la_SOURCES = \
diff --git a/libpeas/peas-engine.c b/libpeas/peas-engine.c
index 33f2e8f..52f4eb4 100644
--- a/libpeas/peas-engine.c
+++ b/libpeas/peas-engine.c
@@ -32,6 +32,7 @@
#include "peas-plugin-loader.h"
#include "peas-object-module.h"
#include "peas-plugin.h"
+#include "peas-extension.h"
#include "peas-dirs.h"
/**
@@ -790,6 +791,20 @@ peas_engine_update_plugins_ui (PeasEngine *engine,
}
}
+PeasExtension *
+peas_engine_get_extension (PeasEngine *engine,
+ PeasPluginInfo *info,
+ GType extension_type)
+{
+ PeasPluginLoader *loader;
+
+ g_return_val_if_fail (PEAS_IS_ENGINE (engine), NULL);
+ g_return_val_if_fail (info != NULL, NULL);
+
+ loader = get_plugin_loader (engine, info);
+ return peas_plugin_loader_get_extension (loader, info, extension_type);
+}
+
/**
* peas_engine_get_active_plugins:
* @engine: A #PeasEngine.
diff --git a/libpeas/peas-engine.h b/libpeas/peas-engine.h
index a0f7167..f828b7f 100644
--- a/libpeas/peas-engine.h
+++ b/libpeas/peas-engine.h
@@ -25,6 +25,7 @@
#include <glib.h>
#include "peas-plugin-info.h"
#include "peas-plugin.h"
+#include "peas-extension.h"
G_BEGIN_DECLS
@@ -91,6 +92,10 @@ gboolean peas_engine_deactivate_plugin (PeasEngine *engine,
PeasPluginInfo *info);
void peas_engine_garbage_collect (PeasEngine *engine);
+PeasExtension *peas_engine_get_extension (PeasEngine *engine,
+ PeasPluginInfo *info,
+ GType ext_type);
+
/* plugin activation/deactivation per target_object */
void peas_engine_update_plugins_ui (PeasEngine *engine,
GObject *object);
diff --git a/libpeas/peas-extension.c b/libpeas/peas-extension.c
new file mode 100644
index 0000000..eadc1ec
--- /dev/null
+++ b/libpeas/peas-extension.c
@@ -0,0 +1,83 @@
+/*
+ * peas-extension.h
+ * This file is part of libpeas
+ *
+ * Copyright (C) 2010 Steve Frécinaux
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "peas-extension.h"
+
+/**
+ * SECTION:peas-extension
+ * @short_description: Proxy for extensions.
+ *
+ * A #PeasExtension is an object which proxies an actual extension.
+ **/
+
+G_DEFINE_ABSTRACT_TYPE (PeasExtension, peas_extension, G_TYPE_OBJECT);
+
+static void
+peas_extension_init (PeasExtension *exten)
+{
+}
+
+static void
+peas_extension_class_init (PeasExtensionClass *klass)
+{
+}
+
+/**
+ * peas_extension_call:
+ * @exten: A #PeasExtension.
+ * @method_name: the name of the method that should be called.
+ *
+ * Call a method of the object behind @extension.
+ *
+ * Return value: #TRUE on successful call.
+ */
+gboolean
+peas_extension_call (PeasExtension *exten,
+ const gchar *method_name,
+ ...)
+{
+ va_list args;
+ gboolean result;
+
+ va_start (args, method_name);
+ result = peas_extension_call_valist (exten, method_name, args);
+ va_end (args);
+
+ return result;
+}
+
+gboolean
+peas_extension_call_valist (PeasExtension *exten,
+ const gchar *method_name,
+ va_list args)
+{
+ PeasExtensionClass *klass;
+
+ g_return_val_if_fail (PEAS_IS_EXTENSION (exten), FALSE);
+ g_return_val_if_fail (method_name != NULL, FALSE);
+
+ klass = PEAS_EXTENSION_GET_CLASS (exten);
+ return klass->call (exten, method_name, args);
+}
diff --git a/libpeas/peas-extension.h b/libpeas/peas-extension.h
new file mode 100644
index 0000000..13b3290
--- /dev/null
+++ b/libpeas/peas-extension.h
@@ -0,0 +1,75 @@
+/*
+ * peas-extension.h
+ * This file is part of libpeas
+ *
+ * Copyright (C) 2010 - Steve Frécinaux
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Library General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __PEAS_EXTENSION_H__
+#define __PEAS_EXTENSION_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+/*
+ * Type checking and casting macros
+ */
+#define PEAS_TYPE_EXTENSION (peas_extension_get_type())
+#define PEAS_EXTENSION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PEAS_TYPE_EXTENSION, PeasExtension))
+#define PEAS_EXTENSION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PEAS_TYPE_EXTENSION, PeasExtensionClass))
+#define PEAS_IS_EXTENSION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), PEAS_TYPE_EXTENSION))
+#define PEAS_IS_EXTENSION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PEAS_TYPE_EXTENSION))
+#define PEAS_EXTENSION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PEAS_TYPE_EXTENSION, PeasExtensionClass))
+
+/**
+ * PeasExtension:
+ * @parent: the parent object.
+ *
+ * Base class for plugins.
+ */
+typedef struct _PeasExtension PeasExtension;
+typedef struct _PeasExtensionClass PeasExtensionClass;
+
+struct _PeasExtension {
+ GObject parent;
+};
+
+struct _PeasExtensionClass {
+ GObjectClass parent_class;
+
+ /* Virtual public methods */
+ gboolean (*call) (PeasExtension *exten,
+ const gchar *method,
+ va_list args);
+};
+
+/*
+ * Public methods
+ */
+GType peas_extension_get_type (void) G_GNUC_CONST;
+
+gboolean peas_extension_call (PeasExtension *exten,
+ const gchar *method,
+ ...);
+gboolean peas_extension_call_valist (PeasExtension *exten,
+ const gchar *method,
+ va_list args);
+
+G_END_DECLS
+
+#endif /* __PEAS_EXTENSION_H__ */
diff --git a/libpeas/peas-plugin-loader.c b/libpeas/peas-plugin-loader.c
index aec3e8f..7e0cbb8 100644
--- a/libpeas/peas-plugin-loader.c
+++ b/libpeas/peas-plugin-loader.c
@@ -75,6 +75,21 @@ peas_plugin_loader_unload (PeasPluginLoader *loader,
klass->unload (loader, info);
}
+PeasExtension *
+peas_plugin_loader_get_extension (PeasPluginLoader *loader,
+ PeasPluginInfo *info,
+ GType ext_type)
+{
+ PeasPluginLoaderClass *klass;
+
+ g_return_val_if_fail (PEAS_IS_PLUGIN_LOADER (loader), NULL);
+
+ klass = PEAS_PLUGIN_LOADER_GET_CLASS (loader);
+ g_return_val_if_fail (klass->get_extension != NULL, NULL);
+
+ return klass->get_extension (loader, info, ext_type);
+}
+
void
peas_plugin_loader_garbage_collect (PeasPluginLoader *loader)
{
diff --git a/libpeas/peas-plugin-loader.h b/libpeas/peas-plugin-loader.h
index 5271e15..38c7b14 100644
--- a/libpeas/peas-plugin-loader.h
+++ b/libpeas/peas-plugin-loader.h
@@ -26,6 +26,7 @@
#include <gmodule.h>
#include "peas-plugin.h"
#include "peas-plugin-info.h"
+#include "peas-extension.h"
G_BEGIN_DECLS
@@ -53,6 +54,9 @@ struct _PeasPluginLoaderClass {
PeasPluginInfo *info);
void (*unload) (PeasPluginLoader *loader,
PeasPluginInfo *info);
+ PeasExtension *(*get_extension) (PeasPluginLoader *loader,
+ PeasPluginInfo *info,
+ GType ext_type);
void (*garbage_collect) (PeasPluginLoader *loader);
};
@@ -66,6 +70,9 @@ PeasPlugin *peas_plugin_loader_load (PeasPluginLoader *loader,
PeasPluginInfo *info);
void peas_plugin_loader_unload (PeasPluginLoader *loader,
PeasPluginInfo *info);
+PeasExtension *peas_plugin_loader_get_extension (PeasPluginLoader *loader,
+ PeasPluginInfo *info,
+ GType ext_type);
void peas_plugin_loader_garbage_collect (PeasPluginLoader *loader);
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]