[gnome-builder/wip/libide: 86/153] libide: define API for diagnostician



commit c57896fffcfd3e9b2e4b8f90149dbc99c1b4ec7f
Author: Christian Hergert <christian hergert me>
Date:   Wed Feb 11 18:12:44 2015 -0800

    libide: define API for diagnostician

 libide/ide-diagnostician.h |    8 +++
 libide/ide-diagnostics.c   |  104 ++++++++++++++++++++++++++++++++++++++++++++
 libide/ide-diagnostics.h   |   37 ++++++++++++++++
 libide/ide-types.h         |    2 +
 4 files changed, 151 insertions(+), 0 deletions(-)
---
diff --git a/libide/ide-diagnostician.h b/libide/ide-diagnostician.h
index b86b10b..f23f492 100644
--- a/libide/ide-diagnostician.h
+++ b/libide/ide-diagnostician.h
@@ -32,6 +32,14 @@ struct _IdeDiagnostician
   IdeObject parent_instance;
 };
 
+void            ide_diagnostician_diagnose_async  (IdeDiagnostician     *diagnostician,
+                                                   IdeFile              *file,
+                                                   GCancellable         *cancellable,
+                                                   GAsyncReadyCallback   callback,
+                                                   gpointer              user_data);
+IdeDiagnostics *ide_diagnostician_diagnose_finish (IdeDiagnostician     *diagnostician,
+                                                   GAsyncResult         *result,
+                                                   GError              **error);
 
 G_END_DECLS
 
diff --git a/libide/ide-diagnostics.c b/libide/ide-diagnostics.c
new file mode 100644
index 0000000..81d5919
--- /dev/null
+++ b/libide/ide-diagnostics.c
@@ -0,0 +1,104 @@
+/* ide-diagnostics.c
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This file 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 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This file 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 General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "ide-diagnostics.h"
+
+struct _IdeDiagnostics
+{
+  volatile gint  ref_count;
+  GPtrArray     *diagnostics;
+};
+
+GType
+ide_diagnostics_get_type (void)
+{
+  static gsize type_id;
+
+  if (g_once_init_enter (&type_id))
+    {
+      gsize _type_id;
+
+      _type_id = g_boxed_type_register_static (
+          "IdeDiagnostics",
+          (GBoxedCopyFunc)ide_diagnostics_ref,
+          (GBoxedFreeFunc)ide_diagnostics_unref);
+
+      g_once_init_leave (&type_id, _type_id);
+    }
+
+  return type_id;
+}
+
+IdeDiagnostics *
+ide_diagnostics_ref (IdeDiagnostics *self)
+{
+  g_return_val_if_fail (self, NULL);
+  g_return_val_if_fail (self->ref_count > 0, NULL);
+
+  g_atomic_int_inc (&self->ref_count);
+
+  return self;
+}
+
+void
+ide_diagnostics_unref (IdeDiagnostics *self)
+{
+  g_return_if_fail (self);
+  g_return_if_fail (self->ref_count > 0);
+
+  if (g_atomic_int_dec_and_test (&self->ref_count))
+    {
+      g_ptr_array_unref (self->diagnostics);
+      g_slice_free (IdeDiagnostics, self);
+    }
+}
+
+/**
+ * ide_diagnostics_get_size:
+ *
+ * Retrieves the number of diagnostics that can be accessed via
+ * ide_diagnostics_index().
+ *
+ * Returns: The number of diagnostics in @self.
+ */
+gsize
+ide_diagnostics_get_size (IdeDiagnostics *self)
+{
+  g_return_val_if_fail (self, 0);
+  g_return_val_if_fail (self->diagnostics, 0);
+
+  return self->diagnostics->len;
+}
+
+/**
+ * ide_diagnostics_index:
+ *
+ * Retrieves the diagnostic at @index.
+ *
+ * Returns: (transfer none): An #IdeDiagnostic.
+ */
+IdeDiagnostic *
+ide_diagnostics_index (IdeDiagnostics *self,
+                       gsize           index)
+{
+  g_return_val_if_fail (self, NULL);
+  g_return_val_if_fail (self->diagnostics, NULL);
+  g_return_val_if_fail (index < self->diagnostics->len, NULL);
+
+  return g_ptr_array_index (self->diagnostics, index);
+}
diff --git a/libide/ide-diagnostics.h b/libide/ide-diagnostics.h
new file mode 100644
index 0000000..5ec47da
--- /dev/null
+++ b/libide/ide-diagnostics.h
@@ -0,0 +1,37 @@
+/* ide-diagnostics.h
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This file 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 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This file 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 General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef IDE_DIAGNOSTICS_H
+#define IDE_DIAGNOSTICS_H
+
+#include "ide-types.h"
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_DIAGNOSTICS (ide_diagnostics_get_type())
+
+GType           ide_diagnostics_get_type (void);
+IdeDiagnostics *ide_diagnostics_ref      (IdeDiagnostics *self);
+void            ide_diagnostics_unref    (IdeDiagnostics *self);
+gsize           ide_diagnostics_get_size (IdeDiagnostics *self);
+IdeDiagnostic  *ide_diagnostics_index    (IdeDiagnostics *self,
+                                          gsize           index);
+
+G_END_DECLS
+
+#endif /* IDE_DIAGNOSTICS_H */
diff --git a/libide/ide-types.h b/libide/ide-types.h
index f2379f2..de23fda 100644
--- a/libide/ide-types.h
+++ b/libide/ide-types.h
@@ -55,6 +55,8 @@ typedef struct _IdeDeviceProviderInterface     IdeDeviceProviderInterface;
 
 typedef struct _IdeDiagnostic                  IdeDiagnostic;
 
+typedef struct _IdeDiagnostics                 IdeDiagnostics;
+
 typedef struct _IdeDiagnostician               IdeDiagnostician;
 
 typedef struct _IdeDiagnosticProvider          IdeDiagnosticProvider;


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