2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 2009-2012 Zmanda, Inc. All Rights Reserved.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
20 * Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
27 #include "xfer-device.h"
32 * This declaration is entirely private; nothing but xfer_source_device() references
36 GType xfer_source_device_get_type(void);
37 #define XFER_SOURCE_DEVICE_TYPE (xfer_source_device_get_type())
38 #define XFER_SOURCE_DEVICE(obj) G_TYPE_CHECK_INSTANCE_CAST((obj), xfer_source_device_get_type(), XferSourceDevice)
39 #define XFER_SOURCE_DEVICE_CONST(obj) G_TYPE_CHECK_INSTANCE_CAST((obj), xfer_source_device_get_type(), XferSourceDevice const)
40 #define XFER_SOURCE_DEVICE_CLASS(klass) G_TYPE_CHECK_CLASS_CAST((klass), xfer_source_device_get_type(), XferSourceDeviceClass)
41 #define IS_XFER_SOURCE_DEVICE(obj) G_TYPE_CHECK_INSTANCE_TYPE((obj), xfer_source_device_get_type ())
42 #define XFER_SOURCE_DEVICE_GET_CLASS(obj) G_TYPE_INSTANCE_GET_CLASS((obj), xfer_source_device_get_type(), XferSourceDeviceClass)
44 static GObjectClass *parent_class = NULL;
47 * Main object structure
50 typedef struct XferSourceDevice {
51 XferElement __parent__;
63 XferElementClass __parent__;
64 } XferSourceDeviceClass;
75 XferSourceDevice *self = (XferSourceDevice *)elt;
80 /* indicate EOF on an cancel */
86 /* get the device block size */
87 if (self->block_size == 0) {
88 self->block_size = self->device->block_size;
92 buf = g_malloc(self->block_size);
93 devsize = (int)self->block_size;
94 result = device_read_block(self->device, buf, &devsize);
97 /* if the buffer was too small, loop around again */
99 g_assert(*size > self->block_size);
100 self->block_size = devsize;
103 } while (result == 0);
108 /* if we're not at EOF, it's an error */
109 if (!self->device->is_eof) {
110 xfer_cancel_with_error(elt,
111 _("error reading from %s: %s"),
112 self->device->device_name,
113 device_error_or_status(self->device));
114 wait_until_xfer_cancelled(elt->xfer);
128 elt->can_generate_eof = TRUE;
133 XferSourceDeviceClass * selfc)
135 XferElementClass *klass = XFER_ELEMENT_CLASS(selfc);
136 static xfer_element_mech_pair_t mech_pairs[] = {
137 { XFER_MECH_NONE, XFER_MECH_PULL_BUFFER, 0, 1},
138 { XFER_MECH_NONE, XFER_MECH_NONE, 0, 0},
141 klass->pull_buffer = pull_buffer_impl;
143 klass->perl_class = "Amanda::Xfer::Source::Device";
144 klass->mech_pairs = mech_pairs;
146 parent_class = g_type_class_peek_parent(selfc);
150 xfer_source_device_get_type (void)
152 static GType type = 0;
154 if G_UNLIKELY(type == 0) {
155 static const GTypeInfo info = {
156 sizeof (XferSourceDeviceClass),
157 (GBaseInitFunc) NULL,
158 (GBaseFinalizeFunc) NULL,
159 (GClassInitFunc) class_init,
160 (GClassFinalizeFunc) NULL,
161 NULL /* class_data */,
162 sizeof (XferSourceDevice),
164 (GInstanceInitFunc) instance_init,
168 type = g_type_register_static (XFER_ELEMENT_TYPE, "XferSourceDevice", &info, 0);
174 /* create an element of this class; prototype is in xfer-device.h */
179 XferSourceDevice *self = (XferSourceDevice *)g_object_new(XFER_SOURCE_DEVICE_TYPE, NULL);
180 XferElement *elt = XFER_ELEMENT(self);
182 g_assert(device != NULL);
184 self->device = device;