[gnome-builder] build-result: add IdeBuildResultAddin



commit da6f1c141f90c1889e5a63a73bc9da248a942870
Author: Christian Hergert <christian hergert me>
Date:   Wed Dec 23 19:37:17 2015 -0800

    build-result: add IdeBuildResultAddin
    
    This new interface allows plugins to add hooks during the build process.
    Currently, this could include diagnostic extraction.

 libide/Makefile.am              |    2 +
 libide/ide-build-result-addin.c |   60 +++++++++++++++++++++++++++++
 libide/ide-build-result-addin.h |   47 ++++++++++++++++++++++
 libide/ide-build-result.c       |   81 ++++++++++++++++++++++++++++++++++-----
 libide/ide.h                    |    1 +
 5 files changed, 181 insertions(+), 10 deletions(-)
---
diff --git a/libide/Makefile.am b/libide/Makefile.am
index f2ab9ed..b78ed7b 100644
--- a/libide/Makefile.am
+++ b/libide/Makefile.am
@@ -48,6 +48,8 @@ libide_1_0_la_public_sources = \
        ide-buffer.h \
        ide-build-result.c \
        ide-build-result.h \
+       ide-build-result-addin.c \
+       ide-build-result-addin.h \
        ide-build-system.c \
        ide-build-system.h \
        ide-builder.c \
diff --git a/libide/ide-build-result-addin.c b/libide/ide-build-result-addin.c
new file mode 100644
index 0000000..df9096a
--- /dev/null
+++ b/libide/ide-build-result-addin.c
@@ -0,0 +1,60 @@
+/* ide-build-result-addin.c
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "ide-build-result-addin.h"
+
+G_DEFINE_INTERFACE (IdeBuildResultAddin, ide_build_result_addin, G_TYPE_OBJECT)
+
+static void
+ide_build_result_addin_real_load (IdeBuildResultAddin *self,
+                                  IdeBuildResult      *result)
+{
+}
+
+static void
+ide_build_result_addin_real_unload (IdeBuildResultAddin *self,
+                                    IdeBuildResult      *result)
+{
+}
+
+static void
+ide_build_result_addin_default_init (IdeBuildResultAddinInterface *iface)
+{
+  iface->load = ide_build_result_addin_real_load;
+  iface->unload = ide_build_result_addin_real_unload;
+}
+
+void
+ide_build_result_addin_load (IdeBuildResultAddin *self,
+                             IdeBuildResult      *result)
+{
+  g_return_if_fail (IDE_IS_BUILD_RESULT_ADDIN (self));
+  g_return_if_fail (IDE_IS_BUILD_RESULT (result));
+
+  IDE_BUILD_RESULT_ADDIN_GET_IFACE (self)->load (self, result);
+}
+
+void
+ide_build_result_addin_unload (IdeBuildResultAddin *self,
+                               IdeBuildResult      *result)
+{
+  g_return_if_fail (IDE_IS_BUILD_RESULT_ADDIN (self));
+  g_return_if_fail (IDE_IS_BUILD_RESULT (result));
+
+  IDE_BUILD_RESULT_ADDIN_GET_IFACE (self)->unload (self, result);
+}
diff --git a/libide/ide-build-result-addin.h b/libide/ide-build-result-addin.h
new file mode 100644
index 0000000..6ba2081
--- /dev/null
+++ b/libide/ide-build-result-addin.h
@@ -0,0 +1,47 @@
+/* ide-build-result-addin.h
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef IDE_BUILD_RESULT_ADDIN_H
+#define IDE_BUILD_RESULT_ADDIN_H
+
+#include "ide-build-result.h"
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_BUILD_RESULT_ADDIN (ide_build_result_addin_get_type ())
+
+G_DECLARE_INTERFACE (IdeBuildResultAddin, ide_build_result_addin, IDE, BUILD_RESULT_ADDIN, GObject)
+
+struct _IdeBuildResultAddinInterface
+{
+  GTypeInterface parent;
+
+  void (*load)   (IdeBuildResultAddin *self,
+                  IdeBuildResult      *result);
+  void (*unload) (IdeBuildResultAddin *self,
+                  IdeBuildResult      *result);
+};
+
+void ide_build_result_addin_load   (IdeBuildResultAddin *self,
+                                    IdeBuildResult      *result);
+void ide_build_result_addin_unload (IdeBuildResultAddin *self,
+                                    IdeBuildResult      *result);
+
+G_END_DECLS
+
+#endif /* IDE_BUILD_RESULT_ADDIN_H */
diff --git a/libide/ide-build-result.c b/libide/ide-build-result.c
index 9e4b7ae..f6c28b3 100644
--- a/libide/ide-build-result.c
+++ b/libide/ide-build-result.c
@@ -22,26 +22,29 @@
 #include <libpeas/peas.h>
 
 #include "ide-build-result.h"
+#include "ide-build-result-addin.h"
 #include "ide-enums.h"
 #include "ide-file.h"
 #include "ide-source-location.h"
 
 typedef struct
 {
-  GMutex         mutex;
+  GMutex            mutex;
 
-  GInputStream  *stdout_reader;
-  GOutputStream *stdout_writer;
+  GInputStream     *stdout_reader;
+  GOutputStream    *stdout_writer;
 
-  GInputStream  *stderr_reader;
-  GOutputStream *stderr_writer;
+  GInputStream     *stderr_reader;
+  GOutputStream    *stderr_writer;
 
-  GTimer        *timer;
-  gchar         *mode;
+  PeasExtensionSet *addins;
 
-  gchar         *current_dir;
+  GTimer           *timer;
+  gchar            *mode;
 
-  guint          running : 1;
+  gchar            *current_dir;
+
+  guint             running : 1;
 } IdeBuildResultPrivate;
 
 typedef struct
@@ -503,12 +506,67 @@ ide_build_result_log_subprocess (IdeBuildResult *self,
 }
 
 static void
+ide_build_result_addin_added (PeasExtensionSet    *set,
+                              PeasPluginInfo      *plugin_info,
+                              IdeBuildResultAddin *addin,
+                              IdeBuildResult      *self)
+{
+  g_assert (PEAS_IS_EXTENSION_SET (set));
+  g_assert (plugin_info != NULL);
+  g_assert (IDE_IS_BUILD_RESULT_ADDIN (addin));
+  g_assert (IDE_IS_BUILD_RESULT (self));
+
+  ide_build_result_addin_load (addin, self);
+}
+
+static void
+ide_build_result_addin_removed (PeasExtensionSet    *set,
+                                PeasPluginInfo      *plugin_info,
+                                IdeBuildResultAddin *addin,
+                                IdeBuildResult      *self)
+{
+  g_assert (PEAS_IS_EXTENSION_SET (set));
+  g_assert (plugin_info != NULL);
+  g_assert (IDE_IS_BUILD_RESULT_ADDIN (addin));
+  g_assert (IDE_IS_BUILD_RESULT (self));
+
+  ide_build_result_addin_unload (addin, self);
+}
+
+static void
+ide_build_result_constructed (GObject *object)
+{
+  IdeBuildResult *self = (IdeBuildResult *)object;
+  IdeBuildResultPrivate *priv = ide_build_result_get_instance_private (self);
+  PeasEngine *engine = peas_engine_get_default ();
+
+  G_OBJECT_CLASS (ide_build_result_parent_class)->constructed (object);
+
+  priv->addins = peas_extension_set_new (engine,
+                                         IDE_TYPE_BUILD_RESULT_ADDIN,
+                                         NULL);
+  peas_extension_set_foreach (priv->addins,
+                              (PeasExtensionSetForeachFunc)ide_build_result_addin_added,
+                              self);
+  g_signal_connect_object (priv->addins,
+                           "extension-added",
+                           G_CALLBACK (ide_build_result_addin_added),
+                           self,
+                           0);
+  g_signal_connect_object (priv->addins,
+                           "extension-removed",
+                           G_CALLBACK (ide_build_result_addin_removed),
+                           self,
+                           0);
+}
+
+static void
 ide_build_result_finalize (GObject *object)
 {
   IdeBuildResult *self = (IdeBuildResult *)object;
   IdeBuildResultPrivate *priv = ide_build_result_get_instance_private (self);
 
-  g_mutex_clear (&priv->mutex);
+  g_clear_object (&priv->addins);
 
   g_clear_object (&priv->stderr_reader);
   g_clear_object (&priv->stderr_writer);
@@ -519,6 +577,8 @@ ide_build_result_finalize (GObject *object)
   g_clear_pointer (&priv->mode, g_free);
   g_clear_pointer (&priv->timer, g_timer_destroy);
 
+  g_mutex_clear (&priv->mutex);
+
   G_OBJECT_CLASS (ide_build_result_parent_class)->finalize (object);
 }
 
@@ -573,6 +633,7 @@ ide_build_result_class_init (IdeBuildResultClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
+  object_class->constructed = ide_build_result_constructed;
   object_class->finalize = ide_build_result_finalize;
   object_class->get_property = ide_build_result_get_property;
   object_class->set_property = ide_build_result_set_property;
diff --git a/libide/ide.h b/libide/ide.h
index 06efa74..926fc5e 100644
--- a/libide/ide.h
+++ b/libide/ide.h
@@ -30,6 +30,7 @@ G_BEGIN_DECLS
 #include "ide-back-forward-item.h"
 #include "ide-back-forward-list.h"
 #include "ide-build-result.h"
+#include "ide-build-result-addin.h"
 #include "ide-build-system.h"
 #include "ide-builder.h"
 #include "ide-buffer.h"


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]