[libpeas] Add new API peas_engine_get_default()
- From: Steve Frécinaux <sfre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libpeas] Add new API peas_engine_get_default()
- Date: Sat, 2 Oct 2010 23:17:08 +0000 (UTC)
commit b5790681ee0a6239be515c56923cb7e80cfb2486
Author: Steve Frécinaux <code istique net>
Date: Thu Aug 26 10:58:21 2010 +0200
Add new API peas_engine_get_default()
https://bugzilla.gnome.org/show_bug.cgi?id=628194
libpeas/peas-engine.c | 26 ++++++++++++++++++++++++++
libpeas/peas-engine.h | 1 +
2 files changed, 27 insertions(+), 0 deletions(-)
---
diff --git a/libpeas/peas-engine.c b/libpeas/peas-engine.c
index ef13770..e88e690 100644
--- a/libpeas/peas-engine.c
+++ b/libpeas/peas-engine.c
@@ -57,6 +57,8 @@
**/
G_DEFINE_TYPE (PeasEngine, peas_engine, G_TYPE_OBJECT);
+static PeasEngine *default_engine = NULL;
+
/* Signals */
enum {
LOAD_PLUGIN,
@@ -291,6 +293,12 @@ add_loader (PeasEngine *engine,
static void
peas_engine_init (PeasEngine *engine)
{
+ /* Set the default engine pointer, for peas_engine_get_default().
+ * We only allow one single instance of a PeasEngine subclass. */
+ g_assert (default_engine == NULL);
+ default_engine = engine;
+ g_object_add_weak_pointer (engine, &default_engine);
+
if (!g_module_supported ())
{
g_warning ("libpeas is not able to initialize the plugins engine.");
@@ -1105,3 +1113,21 @@ peas_engine_new (void)
return PEAS_ENGINE (g_object_new (PEAS_TYPE_ENGINE,
NULL));
}
+
+/**
+ * peas_engine_get_default:
+ *
+ * Return the existing instance of #PeasEngine or a subclass of it.
+ * If no #PeasEngine subclass has been instantiated yet, the first call
+ * of this function will return a new instance of #PeasEngine.
+ *
+ * Returns: the existing instance of #PeasEngine.
+ */
+PeasEngine *
+peas_engine_get_default (void)
+{
+ if (default_engine == NULL)
+ return peas_engine_new ();
+
+ return default_engine;
+}
diff --git a/libpeas/peas-engine.h b/libpeas/peas-engine.h
index 1194b69..0e7bd86 100644
--- a/libpeas/peas-engine.h
+++ b/libpeas/peas-engine.h
@@ -69,6 +69,7 @@ struct _PeasEngineClass {
GType peas_engine_get_type (void) G_GNUC_CONST;
PeasEngine *peas_engine_new (void);
+PeasEngine *peas_engine_get_default (void);
void peas_engine_add_search_path (PeasEngine *engine,
const gchar *plugin_dir,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]