[libgit2-glib] Add get methods to TransferProgress



commit 934f63edfdd87b65a8f91bc3343476241d94848d
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Thu Mar 28 09:26:43 2013 +0100

    Add get methods to TransferProgress

 examples/clone.c                      |   13 ++++--
 libgit2-glib/ggit-transfer-progress.c |   72 +++++++++++++++++++++++++++++++++
 libgit2-glib/ggit-transfer-progress.h |   14 +++++-
 libgit2-glib/ggit-types.h             |    8 +---
 4 files changed, 92 insertions(+), 15 deletions(-)
---
diff --git a/examples/clone.c b/examples/clone.c
index fe65a1f..d03d59b 100644
--- a/examples/clone.c
+++ b/examples/clone.c
@@ -6,14 +6,17 @@ static int
 fetch_progress (const GgitTransferProgress *stats,
                 gpointer                    useless)
 {
-       gint network_percent = (100 * stats->received_objects) / stats->total_objects;
-       gint index_percent = (100 * stats->indexed_objects) / stats->total_objects;
-       gint kbytes = stats->received_bytes / 1024;
+       gint network_percent = (100 * ggit_transfer_progress_get_received_objects (stats)) / 
ggit_transfer_progress_get_total_objects (stats);
+       gint index_percent = (100 * ggit_transfer_progress_get_indexed_objects (stats)) / 
ggit_transfer_progress_get_total_objects (stats);
+       gint kbytes = ggit_transfer_progress_get_received_bytes (stats) / 1024;
 
        g_message ("net %3d%% (%4d kb, %5d/%5d)  /  idx %3d%% (%5d/%5d)",
                   network_percent, kbytes,
-                  stats->received_objects, stats->total_objects,
-                  index_percent, stats->indexed_objects, stats->total_objects);
+                  ggit_transfer_progress_get_received_objects (stats),
+                  ggit_transfer_progress_get_total_objects (stats),
+                  index_percent,
+                  ggit_transfer_progress_get_indexed_objects (stats),
+                  ggit_transfer_progress_get_total_objects (stats));
 
        return 0;
 }
diff --git a/libgit2-glib/ggit-transfer-progress.c b/libgit2-glib/ggit-transfer-progress.c
index a47895f..42fe76b 100644
--- a/libgit2-glib/ggit-transfer-progress.c
+++ b/libgit2-glib/ggit-transfer-progress.c
@@ -20,6 +20,14 @@
 
 #include "ggit-transfer-progress.h"
 
+struct _GgitTransferProgress
+{
+       guint total_objects;
+       guint indexed_objects;
+       guint received_objects;
+       gsize received_bytes;
+};
+
 G_DEFINE_BOXED_TYPE (GgitTransferProgress, ggit_transfer_progress,
                      ggit_transfer_progress_copy,
                      ggit_transfer_progress_free)
@@ -62,4 +70,68 @@ ggit_transfer_progress_free (GgitTransferProgress *progress)
        g_slice_free (GgitTransferProgress, progress);
 }
 
+/**
+ * ggit_transfer_progress_get_total_objects:
+ * @progress: a #GgitTransferProgress.
+ *
+ * Gets the total objects of the transfer.
+ *
+ * Returns: the total objects of the transfer.
+ */
+guint
+ggit_transfer_progress_get_total_objects (GgitTransferProgress *progress)
+{
+       g_return_val_if_fail (progress != NULL, 0);
+
+       return progress->total_objects;
+}
+
+/**
+ * ggit_transfer_progress_get_indexed_objects:
+ * @progress: a #GgitTransferProgress.
+ *
+ * Gets the indexed objects of the transfer.
+ *
+ * Returns: the indexed objects of the transfer.
+ */
+guint
+ggit_transfer_progress_get_indexed_objects (GgitTransferProgress *progress)
+{
+       g_return_val_if_fail (progress != NULL, 0);
+
+       return progress->indexed_objects;
+}
+
+/**
+ * ggit_transfer_progress_get_received_objects:
+ * @progress: a #GgitTransferProgress.
+ *
+ * Gets the received objects of the transfer.
+ *
+ * Returns: the received objects of the transfer.
+ */
+guint
+ggit_transfer_progress_get_received_objects (GgitTransferProgress *progress)
+{
+       g_return_val_if_fail (progress != NULL, 0);
+
+       return progress->received_objects;
+}
+
+/**
+ * ggit_transfer_progress_get_received_bytes:
+ * @progress: a #GgitTransferProgress.
+ *
+ * Gets the received bytes of the transfer.
+ *
+ * Returns: the received bytes of the transfer.
+ */
+gsize
+ggit_transfer_progress_get_received_bytes (GgitTransferProgress *progress)
+{
+       g_return_val_if_fail (progress != NULL, 0);
+
+       return progress->received_bytes;
+}
+
 /* ex:set ts=8 noet: */
diff --git a/libgit2-glib/ggit-transfer-progress.h b/libgit2-glib/ggit-transfer-progress.h
index 47336d8..6b62e01 100644
--- a/libgit2-glib/ggit-transfer-progress.h
+++ b/libgit2-glib/ggit-transfer-progress.h
@@ -30,10 +30,18 @@ G_BEGIN_DECLS
 #define GGIT_TYPE_TRANSFER_PROGRESS       (ggit_transfer_progress_get_type ())
 #define GGIT_TRANSFER_PROGRESS(obj)       ((GgitTransferProgress *)obj)
 
-GType                   ggit_transfer_progress_get_type        (void) G_GNUC_CONST;
+GType                   ggit_transfer_progress_get_type             (void) G_GNUC_CONST;
 
-GgitTransferProgress   *ggit_transfer_progress_copy            (GgitTransferProgress     *progress);
-void                    ggit_transfer_progress_free            (GgitTransferProgress     *progress);
+GgitTransferProgress   *ggit_transfer_progress_copy                 (GgitTransferProgress     *progress);
+void                    ggit_transfer_progress_free                 (GgitTransferProgress     *progress);
+
+guint                   ggit_transfer_progress_get_total_objects    (GgitTransferProgress     *progress);
+
+guint                   ggit_transfer_progress_get_indexed_objects  (GgitTransferProgress     *progress);
+
+guint                   ggit_transfer_progress_get_received_objects (GgitTransferProgress     *progress);
+
+gsize                   ggit_transfer_progress_get_received_bytes   (GgitTransferProgress     *progress);
 
 G_END_DECLS
 
diff --git a/libgit2-glib/ggit-types.h b/libgit2-glib/ggit-types.h
index 7a0997f..1970cd9 100644
--- a/libgit2-glib/ggit-types.h
+++ b/libgit2-glib/ggit-types.h
@@ -269,13 +269,7 @@ typedef struct _GgitTag GgitTag;
  *
  * Represents transfering progress.
  */
-typedef struct _GgitTransferProgress
-{
-       guint total_objects;
-       guint indexed_objects;
-       guint received_objects;
-       gsize received_bytes;
-} GgitTransferProgress;
+typedef struct _GgitTransferProgress GgitTransferProgress;
 
 /**
  * GgitTree:


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