1 /*
2  * ggit-transfer-progress.c
3  * This file is part of libgit2-glib
4  *
5  * Copyright (C) 2013 - Ignacio Casal Quinteiro
6  *
7  * libgit2-glib is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * libgit2-glib is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with libgit2-glib. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include "ggit-transfer-progress.h"
22 #include <git2.h>
23 #include <string.h>
24 
25 struct _GgitTransferProgress
26 {
27 	git_transfer_progress progress;
28 };
29 
G_DEFINE_BOXED_TYPE(GgitTransferProgress,ggit_transfer_progress,ggit_transfer_progress_copy,ggit_transfer_progress_free)30 G_DEFINE_BOXED_TYPE (GgitTransferProgress, ggit_transfer_progress,
31                      ggit_transfer_progress_copy,
32                      ggit_transfer_progress_free)
33 
34 GgitTransferProgress *
35 _ggit_transfer_progress_wrap (const git_transfer_progress *progress)
36 {
37 	GgitTransferProgress *gprogress;
38 
39 	g_return_val_if_fail (progress != NULL, NULL);
40 
41 	gprogress = g_slice_new (GgitTransferProgress);
42 	memcpy (&gprogress->progress, progress, sizeof (git_transfer_progress));
43 
44 	return gprogress;
45 }
46 
47 /**
48  * ggit_transfer_progress_copy:
49  * @progress: a #GgitTransferProgress.
50  *
51  * Copies @progress into a newly allocated #GgitTransferProgress.
52  *
53  * Returns: (transfer full) (nullable): a newly allocated #GgitTransferProgress or %NULL.
54  */
55 GgitTransferProgress *
ggit_transfer_progress_copy(GgitTransferProgress * progress)56 ggit_transfer_progress_copy (GgitTransferProgress *progress)
57 {
58 	g_return_val_if_fail (progress != NULL, NULL);
59 
60 	return _ggit_transfer_progress_wrap (&progress->progress);
61 }
62 
63 /**
64  * ggit_transfer_progress_free:
65  * @progress: a #GgitTransferProgress.
66  *
67  * Frees @progress.
68  */
69 void
ggit_transfer_progress_free(GgitTransferProgress * progress)70 ggit_transfer_progress_free (GgitTransferProgress *progress)
71 {
72 	g_return_if_fail (progress != NULL);
73 
74 	g_slice_free (GgitTransferProgress, progress);
75 }
76 
77 /**
78  * ggit_transfer_progress_get_total_objects:
79  * @progress: a #GgitTransferProgress.
80  *
81  * Gets the total objects of the transfer.
82  *
83  * Returns: the total objects of the transfer.
84  */
85 guint
ggit_transfer_progress_get_total_objects(GgitTransferProgress * progress)86 ggit_transfer_progress_get_total_objects (GgitTransferProgress *progress)
87 {
88 	g_return_val_if_fail (progress != NULL, 0);
89 
90 	return progress->progress.total_objects;
91 }
92 
93 /**
94  * ggit_transfer_progress_get_indexed_objects:
95  * @progress: a #GgitTransferProgress.
96  *
97  * Gets the indexed objects of the transfer.
98  *
99  * Returns: the indexed objects of the transfer.
100  */
101 guint
ggit_transfer_progress_get_indexed_objects(GgitTransferProgress * progress)102 ggit_transfer_progress_get_indexed_objects (GgitTransferProgress *progress)
103 {
104 	g_return_val_if_fail (progress != NULL, 0);
105 
106 	return progress->progress.indexed_objects;
107 }
108 
109 /**
110  * ggit_transfer_progress_get_received_objects:
111  * @progress: a #GgitTransferProgress.
112  *
113  * Gets the received objects of the transfer.
114  *
115  * Returns: the received objects of the transfer.
116  */
117 guint
ggit_transfer_progress_get_received_objects(GgitTransferProgress * progress)118 ggit_transfer_progress_get_received_objects (GgitTransferProgress *progress)
119 {
120 	g_return_val_if_fail (progress != NULL, 0);
121 
122 	return progress->progress.received_objects;
123 }
124 
125 /**
126  * ggit_transfer_progress_get_received_bytes:
127  * @progress: a #GgitTransferProgress.
128  *
129  * Gets the received bytes of the transfer.
130  *
131  * Returns: the received bytes of the transfer.
132  */
133 gsize
ggit_transfer_progress_get_received_bytes(GgitTransferProgress * progress)134 ggit_transfer_progress_get_received_bytes (GgitTransferProgress *progress)
135 {
136 	g_return_val_if_fail (progress != NULL, 0);
137 
138 	return progress->progress.received_bytes;
139 }
140 
141 /* ex:set ts=8 noet: */
142