1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2007 Collabora Ltd.
4 * @author: Xavier Claessens <xclaesse@gmail.com>
5 * Copyright (C) 2007 Marco Barisione <marco@barisione.org>
7 * This library 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.
12 * This library 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.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #include <sys/types.h>
27 #include <sys/socket.h>
30 #include <glib/gi18n.h>
33 #include <gio/gunixinputstream.h>
34 #include <gio/gunixoutputstream.h>
36 #include <libtelepathy/tp-conn.h>
37 #include <libtelepathy/tp-helpers.h>
38 #include <libtelepathy/tp-props-iface.h>
40 #include <telepathy-glib/proxy-subclass.h>
42 #include "empathy-tp-file.h"
43 #include "empathy-file.h"
44 #include "empathy-tp-file-priv.h"
45 #include "empathy-contact-factory.h"
46 #include "empathy-marshal.h"
47 #include "empathy-time.h"
48 #include "empathy-utils.h"
50 #define DEBUG_FLAG EMPATHY_DEBUG_FT
51 #include "empathy-debug.h"
54 * SECTION:empathy-tp-file
55 * @short_description: File channel
56 * @see_also: #EmpathyFile, #EmpathyContact, empathy_send_file()
57 * @include: libempthy/empathy-tp-file.h
59 * The #EmpathyTpFile object represents a Telepathy file channel.
62 static void empathy_tp_file_class_init (EmpathyTpFileClass *klass);
63 static void empathy_tp_file_init (EmpathyTpFile *tp_file);
64 static void tp_file_finalize (GObject *object);
65 static GObject * tp_file_constructor (GType type,
67 GObjectConstructParam *props);
68 static void tp_file_get_property (GObject *object,
72 static void tp_file_set_property (GObject *object,
76 static void tp_file_destroy_cb (TpChannel *file_chan,
77 EmpathyTpFile *tp_file);
78 static void tp_file_closed_cb (TpChannel *file_chan,
79 EmpathyTpFile *tp_file,
80 GObject *weak_object);
81 static void tp_file_state_changed_cb (DBusGProxy *file_iface,
84 EmpathyTpFile *tp_file);
85 static void tp_file_transferred_bytes_changed_cb (DBusGProxy *file_iface,
86 guint64 transferred_bytes,
87 EmpathyTpFile *tp_file);
88 static void copy_stream (GInputStream *in,
90 GCancellable *cancellable);
92 /* EmpathyTpFile object */
94 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
95 EMPATHY_TYPE_TP_FILE, EmpathyTpFilePriv))
97 typedef struct _EmpathyTpFilePriv EmpathyTpFilePriv;
99 struct _EmpathyTpFilePriv {
100 EmpathyContactFactory *factory;
107 /* Previously in File/FT struct */
108 EmpathyFile *cached_empathy_file;
109 EmpathyContact *contact;
110 GInputStream *in_stream;
111 GOutputStream *out_stream;
113 EmpFileTransferDirection direction;
114 EmpFileTransferState state;
115 EmpFileTransferStateChangeReason state_change_reason;
117 guint64 transferred_bytes;
119 gchar *unix_socket_path;
123 GCancellable *cancellable;
139 G_DEFINE_TYPE (EmpathyTpFile, empathy_tp_file, G_TYPE_OBJECT);
142 empathy_tp_file_class_init (EmpathyTpFileClass *klass)
144 GObjectClass *object_class = G_OBJECT_CLASS (klass);
146 object_class->finalize = tp_file_finalize;
147 object_class->constructor = tp_file_constructor;
148 object_class->get_property = tp_file_get_property;
149 object_class->set_property = tp_file_set_property;
151 /* Construct-only properties */
152 g_object_class_install_property (object_class,
154 g_param_spec_object ("account",
156 "The account associated with the channel",
159 G_PARAM_CONSTRUCT_ONLY));
161 g_object_class_install_property (object_class,
163 g_param_spec_object ("channel",
165 "The file transfer channel",
168 G_PARAM_CONSTRUCT_ONLY));
170 g_object_class_install_property (object_class,
172 g_param_spec_uint ("state",
173 "state of the transfer",
174 "The file transfer state",
181 g_object_class_install_property (object_class,
183 g_param_spec_uint ("direction",
184 "direction of the transfer",
185 "The file transfer direction",
192 g_object_class_install_property (object_class,
194 g_param_spec_string ("filename",
195 "name of the transfer",
196 "The file transfer filename",
200 g_object_class_install_property (object_class,
202 g_param_spec_uint64 ("size",
204 "The file transfer size",
210 g_object_class_install_property (object_class,
212 g_param_spec_string ("content-type",
213 "file transfer content-type",
214 "The file transfer content-type",
218 g_object_class_install_property (object_class,
220 g_param_spec_string ("content-md5",
221 "file transfer md5sum",
222 "The md5 sum of the transfer's contents",
226 g_object_class_install_property (object_class,
228 g_param_spec_object ("in-stream",
229 "transfer input stream",
230 "The input stream for file transfer",
234 g_type_class_add_private (object_class, sizeof (EmpathyTpFilePriv));
238 empathy_tp_file_init (EmpathyTpFile *tp_file)
243 tp_file_finalize (GObject *object)
245 EmpathyTpFilePriv *priv;
246 EmpathyTpFile *tp_file;
248 tp_file = EMPATHY_TP_FILE (object);
249 priv = GET_PRIV (tp_file);
253 DEBUG ("Closing channel..");
254 g_signal_handlers_disconnect_by_func (priv->channel,
255 tp_file_destroy_cb, object);
256 tp_cli_channel_run_close (priv->channel, -1, NULL, NULL);
257 g_object_unref (priv->channel);
262 g_object_unref (priv->factory);
266 g_object_unref (priv->account);
270 g_object_unref (priv->mc);
274 g_free (priv->filename);
275 g_free (priv->unix_socket_path);
276 g_free (priv->description);
277 g_free (priv->content_md5);
278 g_free (priv->content_type);
281 g_object_unref (priv->in_stream);
283 if (priv->out_stream)
284 g_object_unref (priv->out_stream);
287 g_object_unref (priv->contact);
289 if (priv->cancellable)
290 g_object_unref (priv->cancellable);
292 G_OBJECT_CLASS (empathy_tp_file_parent_class)->finalize (object);
296 tp_file_constructor (GType type,
298 GObjectConstructParam *props)
301 EmpathyTpFilePriv *priv;
302 GError *error = NULL;
303 GHashTable *properties;
305 tp_file = G_OBJECT_CLASS (empathy_tp_file_parent_class)->constructor (type, n_props, props);
307 priv = GET_PRIV (tp_file);
309 priv->factory = empathy_contact_factory_new ();
310 priv->mc = empathy_mission_control_new ();
312 tp_cli_channel_connect_to_closed (priv->channel,
313 (tp_cli_channel_signal_callback_closed) tp_file_closed_cb,
317 emp_cli_channel_type_file_connect_to_file_transfer_state_changed (TP_PROXY (priv->channel),
318 (emp_cli_channel_type_file_signal_callback_file_transfer_state_changed) tp_file_state_changed_cb,
322 emp_cli_channel_type_file_connect_to_transferred_bytes_changed (TP_PROXY (priv->channel),
323 (emp_cli_channel_type_file_signal_callback_transferred_bytes_changed) tp_file_transferred_bytes_changed_cb,
327 if (!tp_cli_dbus_properties_run_get_all (priv->channel,
328 -1, EMP_IFACE_CHANNEL_TYPE_FILE, &properties, &error, NULL))
330 DEBUG ("Failed to get properties: %s",
331 error ? error->message : "No error given");
332 g_clear_error (&error);
336 priv->size = g_value_get_uint64 (g_hash_table_lookup (properties, "Size"));
338 priv->state = g_value_get_uint (g_hash_table_lookup (properties, "State"));
340 /* Invalid reason, so empathy_file_get_state_change_reason() can give
341 * a warning if called for a not closed file transfer. */
342 priv->state_change_reason = -1;
344 priv->transferred_bytes = g_value_get_uint64 (g_hash_table_lookup (properties, "TransferredBytes"));
346 priv->filename = g_value_dup_string (g_hash_table_lookup (properties, "Filename"));
348 priv->content_md5 = g_value_dup_string (g_hash_table_lookup (properties, "ContentMD5"));
350 priv->description = g_value_dup_string (g_hash_table_lookup (properties, "Description"));
352 priv->unix_socket_path = g_value_dup_string (g_hash_table_lookup (properties, "SocketPath"));
354 priv->direction = g_value_get_uint (g_hash_table_lookup (properties, "Direction"));
356 g_hash_table_destroy (properties);
362 tp_file_get_property (GObject *object,
367 EmpathyTpFilePriv *priv;
368 EmpathyTpFile *tp_file;
370 priv = GET_PRIV (object);
371 tp_file = EMPATHY_TP_FILE (object);
376 g_value_set_object (value, priv->account);
379 g_value_set_object (value, priv->channel);
382 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
388 tp_file_channel_set_dbus_property (gpointer proxy,
389 const gchar *property,
392 DEBUG ("Setting %s property", property);
393 tp_cli_dbus_properties_run_set (TP_PROXY (proxy),
395 EMP_IFACE_CHANNEL_TYPE_FILE,
405 tp_file_set_property (GObject *object,
410 EmpathyTpFilePriv *priv;
412 priv = GET_PRIV (object);
417 priv->account = g_object_ref (g_value_get_object (value));
420 priv->channel = g_object_ref (g_value_get_object (value));
423 priv->state = g_value_get_uint (value);
426 priv->direction = g_value_get_uint (value);
429 g_free (priv->filename);
430 priv->filename = g_value_dup_string (value);
431 tp_file_channel_set_dbus_property (priv->channel, "Filename", value);
434 priv->size = g_value_get_uint64 (value);
435 tp_file_channel_set_dbus_property (priv->channel, "Size", value);
437 case PROP_CONTENT_TYPE:
438 tp_file_channel_set_dbus_property (priv->channel, "ContentType", value);
439 g_free (priv->content_type);
440 priv->content_type = g_value_dup_string (value);
442 case PROP_CONTENT_MD5:
443 tp_file_channel_set_dbus_property (priv->channel, "ContentMD5", value);
444 g_free (priv->content_md5);
445 priv->content_md5 = g_value_dup_string (value);
449 g_object_unref (priv->in_stream);
450 priv->in_stream = g_object_ref (g_value_get_object (value));
453 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
459 * empathy_tp_file_new:
460 * @account: the #McAccount for the channel
461 * @channel: a Telepathy channel
463 * Creates a new #EmpathyTpFile wrapping @channel.
465 * Returns: a new #EmpathyTpFile
468 empathy_tp_file_new (McAccount *account,
471 return g_object_new (EMPATHY_TYPE_TP_FILE,
478 * empathy_tp_file_get_id:
479 * @tp_file: an #EmpathyTpFile
481 * Returns the ID of @tp_file.
486 empathy_tp_file_get_id (EmpathyTpFile *tp_file)
488 EmpathyTpFilePriv *priv;
490 g_return_val_if_fail (EMPATHY_IS_TP_FILE (tp_file), NULL);
492 priv = GET_PRIV (tp_file);
498 * empathy_tp_file_get_channel
499 * @tp_file: an #EmpathyTpFile
501 * Returns the Telepathy file transfer channel
503 * Returns: the #TpChannel
506 empathy_tp_file_get_channel (EmpathyTpFile *tp_file)
508 EmpathyTpFilePriv *priv;
510 g_return_val_if_fail (EMPATHY_IS_TP_FILE (tp_file), NULL);
512 priv = GET_PRIV (tp_file);
514 return priv->channel;
518 tp_file_destroy_cb (TpChannel *file_channel, EmpathyTpFile *tp_file)
520 EmpathyTpFilePriv *priv;
522 priv = GET_PRIV (tp_file);
524 DEBUG ("Channel Closed or CM crashed");
526 g_object_unref (priv->channel);
527 priv->channel = NULL;
531 tp_file_closed_cb (TpChannel *file_channel, EmpathyTpFile *tp_file, GObject *weak_object)
533 EmpathyTpFilePriv *priv;
535 priv = GET_PRIV (tp_file);
537 /* The channel is closed, do just like if the proxy was destroyed */
538 g_signal_handlers_disconnect_by_func (priv->channel,
541 tp_file_destroy_cb (file_channel, tp_file);
549 g_get_current_time (&tv);
550 return ((gint64) tv.tv_sec) * 1000 + tv.tv_usec / 1000;
554 _get_local_socket (EmpathyTpFile *tp_file)
558 struct sockaddr_un addr;
559 EmpathyTpFilePriv *priv;
561 priv = GET_PRIV (tp_file);
563 if (priv->unix_socket_path == NULL)
566 fd = socket (PF_UNIX, SOCK_STREAM, 0);
570 memset (&addr, 0, sizeof (addr));
571 addr.sun_family = AF_UNIX;
572 path_len = strlen (priv->unix_socket_path);
573 strncpy (addr.sun_path, priv->unix_socket_path, path_len);
575 if (connect (fd, (struct sockaddr*) &addr,
576 G_STRUCT_OFFSET (struct sockaddr_un, sun_path) + path_len) < 0)
586 send_file (EmpathyTpFile *tp_file)
589 GOutputStream *socket_stream;
590 EmpathyTpFilePriv *priv;
592 priv = GET_PRIV (tp_file);
594 DEBUG ("Sending file content: filename=%s",
597 g_return_if_fail (priv->in_stream);
599 socket_fd = _get_local_socket (tp_file);
602 DEBUG ("failed to get local socket fd");
605 DEBUG ("got local socket fd");
606 socket_stream = g_unix_output_stream_new (socket_fd, TRUE);
608 priv->cancellable = g_cancellable_new ();
610 copy_stream (priv->in_stream, socket_stream, priv->cancellable);
612 g_object_unref (socket_stream);
616 tp_file_state_changed_cb (DBusGProxy *file_iface,
617 EmpFileTransferState state,
618 EmpFileTransferStateChangeReason reason,
619 EmpathyTpFile *tp_file)
621 EmpathyTpFilePriv *priv;
623 priv = GET_PRIV (tp_file);
625 DEBUG ("File transfer state changed: filename=%s, "
626 "old state=%u, state=%u, reason=%u",
627 priv->filename, priv->state, state, reason);
629 if (state == EMP_FILE_TRANSFER_STATE_OPEN)
630 priv->start_time = get_time_msec ();
632 DEBUG ("state = %u, direction = %u, in_stream = %s",
633 state, priv->direction, priv->in_stream ? "present" : "not present");
635 if (state == EMP_FILE_TRANSFER_STATE_OPEN &&
636 priv->direction == EMP_FILE_TRANSFER_DIRECTION_OUTGOING &&
641 priv->state_change_reason = reason;
643 g_object_notify (G_OBJECT (tp_file), "state");
647 tp_file_transferred_bytes_changed_cb (DBusGProxy *file_iface,
648 guint64 transferred_bytes, EmpathyTpFile *tp_file)
650 EmpathyTpFilePriv *priv;
652 priv = GET_PRIV (tp_file);
654 if (priv->transferred_bytes == transferred_bytes)
657 priv->transferred_bytes = transferred_bytes;
659 g_object_notify (G_OBJECT (tp_file), "transferred-bytes");
663 _empathy_tp_file_get_contact (EmpathyTpFile *tp_file)
665 EmpathyTpFilePriv *priv;
667 priv = GET_PRIV (tp_file);
669 return priv->contact;
673 _empathy_tp_file_get_input_stream (EmpathyTpFile *tp_file)
675 EmpathyTpFilePriv *priv;
677 priv = GET_PRIV (tp_file);
679 return priv->in_stream;
683 _empathy_tp_file_get_output_stream (EmpathyTpFile *tp_file)
685 EmpathyTpFilePriv *priv;
687 priv = GET_PRIV (tp_file);
689 return priv->out_stream;
693 _empathy_tp_file_get_filename (EmpathyTpFile *tp_file)
695 EmpathyTpFilePriv *priv;
697 priv = GET_PRIV (tp_file);
699 return priv->filename;
702 EmpFileTransferDirection
703 _empathy_tp_file_get_direction (EmpathyTpFile *tp_file)
705 EmpathyTpFilePriv *priv;
707 priv = GET_PRIV (tp_file);
709 return priv->direction;
713 _empathy_tp_file_get_state (EmpathyTpFile *tp_file)
715 EmpathyTpFilePriv *priv;
717 priv = GET_PRIV (tp_file);
722 EmpFileTransferStateChangeReason
723 _empathy_tp_file_get_state_change_reason (EmpathyTpFile *tp_file)
725 EmpathyTpFilePriv *priv;
727 priv = GET_PRIV (tp_file);
729 g_return_val_if_fail (priv->state_change_reason >= 0,
730 EMP_FILE_TRANSFER_STATE_CHANGE_REASON_NONE);
732 return priv->state_change_reason;
736 _empathy_tp_file_get_size (EmpathyTpFile *tp_file)
738 EmpathyTpFilePriv *priv;
740 priv = GET_PRIV (tp_file);
746 _empathy_tp_file_get_transferred_bytes (EmpathyTpFile *tp_file)
748 EmpathyTpFilePriv *priv;
750 priv = GET_PRIV (tp_file);
752 return priv->transferred_bytes;
756 _empathy_tp_file_get_remaining_time (EmpathyTpFile *tp_file)
758 EmpathyTpFilePriv *priv;
759 gint64 curr_time, elapsed_time;
760 gdouble time_per_byte;
761 gdouble remaining_time;
763 priv = GET_PRIV (tp_file);
765 if (priv->size == EMPATHY_FILE_UNKNOWN_SIZE)
768 if (priv->transferred_bytes == priv->size)
771 curr_time = get_time_msec ();
772 elapsed_time = curr_time - priv->start_time;
773 time_per_byte = (gdouble) elapsed_time / (gdouble) priv->transferred_bytes;
774 remaining_time = (time_per_byte * (priv->size - priv->transferred_bytes)) / 1000;
776 return (gint) (remaining_time + 0.5);
780 _empathy_tp_file_set_input_stream (EmpathyTpFile *tp_file,
781 GInputStream *in_stream)
783 EmpathyTpFilePriv *priv;
785 priv = GET_PRIV (tp_file);
787 if (priv->in_stream == in_stream)
790 if (priv->direction == EMP_FILE_TRANSFER_DIRECTION_INCOMING)
791 g_warning ("Setting an input stream for incoming file "
792 "transfers is useless");
795 g_object_unref (priv->in_stream);
797 g_object_ref (in_stream);
798 priv->in_stream = in_stream;
800 g_object_notify (G_OBJECT (tp_file), "in-stream");
804 _empathy_tp_file_set_output_stream (EmpathyTpFile *tp_file,
805 GOutputStream *out_stream)
807 EmpathyTpFilePriv *priv;
809 priv = GET_PRIV (tp_file);
811 if (priv->out_stream == out_stream)
814 if (priv->direction == EMP_FILE_TRANSFER_DIRECTION_OUTGOING)
815 g_warning ("Setting an output stream for outgoing file "
816 "transfers is useless");
818 if (priv->out_stream)
819 g_object_unref (priv->out_stream);
821 g_object_ref (out_stream);
822 priv->out_stream = out_stream;
824 g_object_notify (G_OBJECT (tp_file), "output-stream");
828 _empathy_tp_file_set_filename (EmpathyTpFile *tp_file,
829 const gchar *filename)
831 EmpathyTpFilePriv *priv;
833 priv = GET_PRIV (tp_file);
835 g_return_if_fail (filename != NULL);
837 if (priv->filename && strcmp (filename, priv->filename) == 0) {
841 g_free (priv->filename);
842 priv->filename = g_strdup (filename);
844 g_object_notify (G_OBJECT (tp_file), "filename");
847 /* Functions to copy the content of a GInputStream to a GOutputStream */
850 #define BUFFER_SIZE 4096
855 GCancellable *cancellable;
856 char *buff[N_BUFFERS]; /* the temporary buffers */
857 gsize count[N_BUFFERS]; /* how many bytes are used in the buffers */
858 gboolean is_full[N_BUFFERS]; /* whether the buffers contain data */
859 gint curr_read; /* index of the buffer used for reading */
860 gint curr_write; /* index of the buffer used for writing */
861 gboolean is_reading; /* we are reading */
862 gboolean is_writing; /* we are writing */
863 guint n_closed; /* number of streams that have been closed */
866 static void schedule_next (CopyData *copy);
869 free_copy_data_if_closed (CopyData *copy)
873 /* Free the data only if both the input and output streams have
876 if (copy->n_closed < 2)
879 if (copy->in != NULL)
880 g_object_unref (copy->in);
882 if (copy->out != NULL)
883 g_object_unref (copy->out);
885 for (i = 0; i < N_BUFFERS; i++)
886 g_free (copy->buff[i]);
888 g_object_unref (copy->cancellable);
893 io_error (CopyData *copy, GError *error)
895 g_cancellable_cancel (copy->cancellable);
898 g_warning ("I/O error");
899 else if (error->domain == G_IO_ERROR && error->code == G_IO_ERROR_CANCELLED)
900 ; /* Ignore cancellations */
902 g_warning ("I/O error: %d: %s\n", error->code, error->message);
904 if (copy->in != NULL)
905 g_input_stream_close (copy->in, NULL, NULL);
907 if (copy->out != NULL)
908 g_output_stream_close (copy->out, NULL, NULL);
910 free_copy_data_if_closed (copy);
914 close_done (GObject *source_object, GAsyncResult *res, gpointer user_data)
916 CopyData *copy = user_data;
918 g_object_unref (source_object);
919 free_copy_data_if_closed (copy);
923 write_done_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
925 CopyData *copy = user_data;
927 GError *error = NULL;
929 count_write = g_output_stream_write_finish (copy->out, res, &error);
931 if (count_write <= 0) {
932 io_error (copy, error);
933 g_error_free (error);
937 copy->is_full[copy->curr_write] = FALSE;
938 copy->curr_write = (copy->curr_write + 1) % N_BUFFERS;
939 copy->is_writing = FALSE;
941 schedule_next (copy);
945 read_done_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
947 CopyData *copy = user_data;
949 GError *error = NULL;
951 count_read = g_input_stream_read_finish (copy->in, res, &error);
953 if (count_read == 0) {
954 g_input_stream_close_async (copy->in, 0, copy->cancellable,
958 else if (count_read < 0) {
959 io_error (copy, error);
960 g_error_free (error);
964 copy->count[copy->curr_read] = count_read;
965 copy->is_full[copy->curr_read] = TRUE;
966 copy->curr_read = (copy->curr_read + 1) % N_BUFFERS;
967 copy->is_reading = FALSE;
969 schedule_next (copy);
973 schedule_next (CopyData *copy)
975 if (copy->in != NULL &&
977 !copy->is_full[copy->curr_read]) {
978 /* We are not reading and the current buffer is empty, so
979 * start an async read. */
980 copy->is_reading = TRUE;
981 g_input_stream_read_async (copy->in,
982 copy->buff[copy->curr_read],
983 BUFFER_SIZE, 0, copy->cancellable,
987 if (!copy->is_writing &&
988 copy->is_full[copy->curr_write]) {
989 if (copy->count[copy->curr_write] == 0) {
990 /* The last read on the buffer read 0 bytes, this
991 * means that we got an EOF, so we can close
992 * the output channel. */
993 g_output_stream_close_async (copy->out, 0,
998 /* We are not writing and the current buffer contains
999 * data, so start an async write. */
1000 copy->is_writing = TRUE;
1001 g_output_stream_write_async (copy->out,
1002 copy->buff[copy->curr_write],
1003 copy->count[copy->curr_write],
1004 0, copy->cancellable,
1005 write_done_cb, copy);
1011 copy_stream (GInputStream *in, GOutputStream *out, GCancellable *cancellable)
1016 g_return_if_fail (in != NULL);
1017 g_return_if_fail (out != NULL);
1019 copy = g_new0 (CopyData, 1);
1020 copy->in = g_object_ref (in);
1021 copy->out = g_object_ref (out);
1023 if (cancellable != NULL)
1024 copy->cancellable = g_object_ref (cancellable);
1026 copy->cancellable = g_cancellable_new ();
1028 for (i = 0; i < N_BUFFERS; i++)
1029 copy->buff[i] = g_malloc (BUFFER_SIZE);
1031 schedule_next (copy);