1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
/*
* Copyright © 2011 Intel Corp.
*
* This library 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 2 of the License, or (at your option) any later version.
*
* This library 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 Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*
* Authored by: Rob Staudinger <robsta@linux.intel.com>
*/
#include <stdbool.h>
#include "yts-file-transfer.h"
#include "yts-marshal.h"
#include "config.h"
G_DEFINE_INTERFACE (YtsFileTransfer, yts_file_transfer, G_TYPE_OBJECT)
/**
* SECTION:yts-file-transfer
* @short_description: Common interface for file transfers between Ytstenut
* services.
*
* #YtsFileTransfer represents an ongoing file transfer operation between
* Ytstenut services, and offers progress- and status-reporting facilities.
*/
enum {
SIG_ERROR = 0,
LAST_SIGNAL
};
static unsigned _signals[LAST_SIGNAL] = { 0, };
/**
* SECTION:yts-file_transfer
* @short_description: Common interface for file up- and downloads.
*
* #YtsFileTransfer is an common interface for the #YtsIncomingFile and
* #YtsOutgoingFile file transmission classes. A value smaller than 0.0
* denotes error state.
*/
static void
yts_file_transfer_default_init (YtsFileTransferInterface *interface)
{
static bool _initialized = false;
if (!_initialized) {
GParamSpec *pspec;
/**
* YtsFileTransfer:progress:
*
* Read-only property that holds the file transmission progress. Values range
* from 0.0 at the start of the transfer, to 1.0 upon completion.
*/
pspec = g_param_spec_float ("progress", "", "",
-0.1, 1.1, 0.0,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
g_object_interface_install_property (interface, pspec);
/*
* Signals
*/
/**
* YtsFileTransfer::error:
* @self: object which emitted the signal.
* @error: the #GError causing the transmission to fail.
*
* This signal is emitted when the transmission failed, transporting
* error details.
*
* Since: 0.4
*/
_signals[SIG_ERROR] = g_signal_new ("error",
G_TYPE_FROM_INTERFACE (interface),
G_SIGNAL_RUN_LAST,
0, NULL, NULL,
yts_marshal_VOID__BOXED,
G_TYPE_NONE, 1,
G_TYPE_ERROR);
}
}
/**
* yts_file_transfer_get_progress:
* @self: object on which to invoke this method.
*
* Get progress of file transfer operation, see #YtsFileTransfer.progress for
* details about the range of values.
*
* Returns: file transfer progress.
*/
float
yts_file_transfer_get_progress (YtsFileTransfer *self)
{
float progress;
g_return_val_if_fail (YTS_IS_FILE_TRANSFER (self), -1.0);
g_object_get (self, "progress", &progress, NULL);
return progress;
}
|