~ubuntuone-control-tower/ubuntuone-client/stable-13-10

« back to all changes in this revision

Viewing changes to libsyncdaemon/syncdaemon-transfer-info.c

  • Committer: Tarmac
  • Author(s): Rodney Dawes
  • Date: 2013-07-11 13:27:51 UTC
  • mfrom: (1395.1.1 update-13-10)
  • Revision ID: tarmac-20130711132751-mqmfckniyripjl2a
[Rodney Dawes]

    Drop libsyncdaemon from tree and convert to pure Python project.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Syncdaemon API
3
 
 *
4
 
 * Authors: Rodrigo Moya <rodrigo.moya@canonical.com>
5
 
 *
6
 
 * Copyright 2010-2012 Canonical Ltd.
7
 
 *
8
 
 * This program is free software: you can redistribute it and/or modify it
9
 
 * under the terms of the GNU General Public License version 3, as published
10
 
 * by the Free Software Foundation.
11
 
 *
12
 
 * This program is distributed in the hope that it will be useful, but
13
 
 * WITHOUT ANY WARRANTY; without even the implied warranties of
14
 
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15
 
 * PURPOSE.  See the GNU General Public License for more details.
16
 
 *
17
 
 * You should have received a copy of the GNU General Public License along
18
 
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 
 *
20
 
 * In addition, as a special exception, the copyright holders give
21
 
 * permission to link the code of portions of this program with the
22
 
 * OpenSSL library under certain conditions as described in each
23
 
 * individual source file, and distribute linked combinations
24
 
 * including the two.
25
 
 * You must obey the GNU General Public License in all respects
26
 
 * for all of the code used other than OpenSSL.  If you modify
27
 
 * file(s) with this exception, you may extend this exception to your
28
 
 * version of the file(s), but you are not obligated to do so.  If you
29
 
 * do not wish to do so, delete this exception statement from your
30
 
 * version.  If you delete this exception statement from all source
31
 
 * files in the program, then also delete it here.
32
 
 *
33
 
 */
34
 
 
35
 
#include "syncdaemon-transfer-info.h"
36
 
 
37
 
#include <stdlib.h>
38
 
 
39
 
G_DEFINE_TYPE(SyncdaemonTransferInfo, syncdaemon_transfer_info, G_TYPE_OBJECT)
40
 
 
41
 
struct _SyncdaemonTransferInfoPrivate {
42
 
        gchar *path;
43
 
        gchar *share_id;
44
 
        gchar *node_id;
45
 
        glong bytes_transferred;
46
 
        glong total_size;
47
 
};
48
 
 
49
 
static void
50
 
syncdaemon_transfer_info_finalize (GObject *object)
51
 
{
52
 
        SyncdaemonTransferInfo *tinfo = SYNCDAEMON_TRANSFER_INFO (object);
53
 
 
54
 
        if (tinfo->priv != NULL) {
55
 
                if (tinfo->priv->path != NULL)
56
 
                        g_free (tinfo->priv->path);
57
 
 
58
 
                if (tinfo->priv->share_id != NULL)
59
 
                        g_free (tinfo->priv->share_id);
60
 
 
61
 
                if (tinfo->priv->node_id != NULL)
62
 
                        g_free (tinfo->priv->node_id);
63
 
 
64
 
                g_free (tinfo->priv);
65
 
        }
66
 
 
67
 
        G_OBJECT_CLASS (syncdaemon_transfer_info_parent_class)->finalize (object);
68
 
}
69
 
 
70
 
static void
71
 
syncdaemon_transfer_info_class_init (SyncdaemonTransferInfoClass *klass)
72
 
{
73
 
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
74
 
 
75
 
        object_class->finalize = syncdaemon_transfer_info_finalize;
76
 
}
77
 
 
78
 
static void
79
 
syncdaemon_transfer_info_init (SyncdaemonTransferInfo *tinfo)
80
 
{
81
 
        tinfo->priv = g_new0 (SyncdaemonTransferInfoPrivate, 1);
82
 
}
83
 
 
84
 
/**
85
 
 * syncdaemon_transfer_info_new:
86
 
 * @path: Local path of the file being transferred.
87
 
 *
88
 
 * Return value: A new #SyncdaemonTransferInfo object.
89
 
 */
90
 
SyncdaemonTransferInfo *
91
 
syncdaemon_transfer_info_new (const gchar *path)
92
 
{
93
 
        SyncdaemonTransferInfo *tinfo;
94
 
 
95
 
        tinfo = g_object_new (SYNCDAEMON_TYPE_TRANSFER_INFO, NULL);
96
 
        if (path != NULL)
97
 
                syncdaemon_transfer_info_set_path (tinfo, path);
98
 
 
99
 
        return tinfo;
100
 
}
101
 
 
102
 
/**
103
 
 * syncdaemon_transfer_info_new_from_hash_table:
104
 
 */
105
 
SyncdaemonTransferInfo *
106
 
syncdaemon_transfer_info_new_from_hash_table (GHashTable *hash)
107
 
{
108
 
        SyncdaemonTransferInfo *tinfo;
109
 
 
110
 
        tinfo = g_object_new (SYNCDAEMON_TYPE_TRANSFER_INFO, NULL);
111
 
        if (hash != NULL) {
112
 
                gchar *str;
113
 
 
114
 
                syncdaemon_transfer_info_set_path (tinfo, g_hash_table_lookup (hash, "path"));
115
 
                syncdaemon_transfer_info_set_share_id (tinfo, g_hash_table_lookup (hash, "share_id"));
116
 
                syncdaemon_transfer_info_set_node_id (tinfo, g_hash_table_lookup (hash, "node_id"));
117
 
 
118
 
                str = g_hash_table_lookup (hash, "n_bytes_read");
119
 
                if (str != NULL)
120
 
                        syncdaemon_transfer_info_set_bytes_transferred (tinfo, atol (str));
121
 
 
122
 
                str = g_hash_table_lookup (hash, "deflated_size");
123
 
                if (str != NULL)
124
 
                        syncdaemon_transfer_info_set_total_size (tinfo, atol (str));
125
 
        }
126
 
 
127
 
        return tinfo;
128
 
}
129
 
 
130
 
/**
131
 
 * syncdaemon_transfer_info_get_path:
132
 
 */
133
 
const gchar *
134
 
syncdaemon_transfer_info_get_path (SyncdaemonTransferInfo *tinfo)
135
 
{
136
 
        g_return_val_if_fail (SYNCDAEMON_IS_TRANSFER_INFO (tinfo), NULL);
137
 
 
138
 
        return (const gchar *) tinfo->priv->path;
139
 
}
140
 
 
141
 
/**
142
 
 * syncdaemon_transfer_info_set_path:
143
 
 */
144
 
void
145
 
syncdaemon_transfer_info_set_path (SyncdaemonTransferInfo *tinfo, const gchar *path)
146
 
{
147
 
        g_return_if_fail (SYNCDAEMON_IS_TRANSFER_INFO (tinfo));
148
 
 
149
 
        if (tinfo->priv->path != NULL)
150
 
                g_free (tinfo->priv->path);
151
 
 
152
 
        tinfo->priv->path = g_strdup (path);
153
 
}
154
 
 
155
 
/**
156
 
 * syncdaemon_transfer_info_get_share_id:
157
 
 */
158
 
const gchar *
159
 
syncdaemon_transfer_info_get_share_id (SyncdaemonTransferInfo *tinfo)
160
 
{
161
 
        g_return_val_if_fail (SYNCDAEMON_IS_TRANSFER_INFO (tinfo), NULL);
162
 
 
163
 
        return (const gchar *) tinfo->priv->share_id;
164
 
}
165
 
 
166
 
/**
167
 
 * syncdaemon_transfer_info_set_share_id:
168
 
 */
169
 
void
170
 
syncdaemon_transfer_info_set_share_id (SyncdaemonTransferInfo *tinfo, const gchar *share_id)
171
 
{
172
 
        g_return_if_fail (SYNCDAEMON_IS_TRANSFER_INFO (tinfo));
173
 
 
174
 
        if (tinfo->priv->share_id != NULL)
175
 
                g_free (tinfo->priv->share_id);
176
 
 
177
 
        tinfo->priv->share_id = g_strdup (share_id);
178
 
}
179
 
 
180
 
/**
181
 
 * syncdaemon_transfer_info_get_path:
182
 
 */
183
 
const gchar *
184
 
syncdaemon_transfer_info_get_node_id (SyncdaemonTransferInfo *tinfo)
185
 
{
186
 
        g_return_val_if_fail (SYNCDAEMON_IS_TRANSFER_INFO (tinfo), NULL);
187
 
 
188
 
        return (const gchar *) tinfo->priv->node_id;
189
 
}
190
 
 
191
 
/**
192
 
 * syncdaemon_transfer_info_set_node_id:
193
 
 */
194
 
void
195
 
syncdaemon_transfer_info_set_node_id (SyncdaemonTransferInfo *tinfo, const gchar *node_id)
196
 
{
197
 
        g_return_if_fail (SYNCDAEMON_IS_TRANSFER_INFO (tinfo));
198
 
 
199
 
        if (tinfo->priv->node_id != NULL)
200
 
                g_free (tinfo->priv->node_id);
201
 
 
202
 
        tinfo->priv->node_id = g_strdup (node_id);
203
 
}
204
 
 
205
 
/**
206
 
 * syncdaemon_transfer_info_get_bytes_transferred:
207
 
 */
208
 
glong
209
 
syncdaemon_transfer_info_get_bytes_transferred (SyncdaemonTransferInfo *tinfo)
210
 
{
211
 
        g_return_val_if_fail (SYNCDAEMON_IS_TRANSFER_INFO (tinfo), 0);
212
 
 
213
 
        return tinfo->priv->bytes_transferred;
214
 
}
215
 
 
216
 
/**
217
 
 * syncdaemon_transfer_info_set_bytes_transferred:
218
 
 */
219
 
void
220
 
syncdaemon_transfer_info_set_bytes_transferred (SyncdaemonTransferInfo *tinfo, glong bytes)
221
 
{
222
 
        g_return_if_fail (SYNCDAEMON_IS_TRANSFER_INFO (tinfo));
223
 
 
224
 
        tinfo->priv->bytes_transferred = bytes;
225
 
}
226
 
 
227
 
/**
228
 
 * syncdaemon_transfer_info_get_total_size:
229
 
 */
230
 
glong
231
 
syncdaemon_transfer_info_get_total_size (SyncdaemonTransferInfo *tinfo)
232
 
{
233
 
        g_return_val_if_fail (SYNCDAEMON_IS_TRANSFER_INFO (tinfo), 0);
234
 
 
235
 
        return tinfo->priv->total_size;
236
 
}
237
 
 
238
 
/**
239
 
 * syncdaemon_transfer_info_set_total_size:
240
 
 */
241
 
void
242
 
syncdaemon_transfer_info_set_total_size (SyncdaemonTransferInfo *tinfo, glong bytes)
243
 
{
244
 
        g_return_if_fail (SYNCDAEMON_IS_TRANSFER_INFO (tinfo));
245
 
 
246
 
        tinfo->priv->total_size = bytes;
247
 
}