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 modify it
6 * under the terms of the GNU General Public License version 2 as published
7 * by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
19 * Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
26 #include "xfer-device.h"
31 * This declaration is entirely private; nothing but xfer_source_device() references
35 GType xfer_source_device_get_type(void);
36 #define XFER_SOURCE_DEVICE_TYPE (xfer_source_device_get_type())
37 #define XFER_SOURCE_DEVICE(obj) G_TYPE_CHECK_INSTANCE_CAST((obj), xfer_source_device_get_type(), XferSourceDevice)
38 #define XFER_SOURCE_DEVICE_CONST(obj) G_TYPE_CHECK_INSTANCE_CAST((obj), xfer_source_device_get_type(), XferSourceDevice const)
39 #define XFER_SOURCE_DEVICE_CLASS(klass) G_TYPE_CHECK_CLASS_CAST((klass), xfer_source_device_get_type(), XferSourceDeviceClass)
40 #define IS_XFER_SOURCE_DEVICE(obj) G_TYPE_CHECK_INSTANCE_TYPE((obj), xfer_source_device_get_type ())
41 #define XFER_SOURCE_DEVICE_GET_CLASS(obj) G_TYPE_INSTANCE_GET_CLASS((obj), xfer_source_device_get_type(), XferSourceDeviceClass)
43 static GObjectClass *parent_class = NULL;
46 * Main object structure
49 typedef struct XferSourceDevice {
50 XferElement __parent__;
62 XferElementClass __parent__;
63 } XferSourceDeviceClass;
74 XferSourceDevice *self = (XferSourceDevice *)elt;
79 /* indicate EOF on an cancel */
85 /* get the device block size */
86 if (self->block_size == 0) {
87 self->block_size = self->device->block_size;
91 buf = g_malloc(self->block_size);
92 devsize = (int)self->block_size;
93 result = device_read_block(self->device, buf, &devsize);
96 /* if the buffer was too small, loop around again */
98 g_assert(*size > self->block_size);
99 self->block_size = devsize;
102 } while (result == 0);
107 /* if we're not at EOF, it's an error */
108 if (!self->device->is_eof) {
109 xfer_cancel_with_error(elt,
110 _("error reading from %s: %s"),
111 self->device->device_name,
112 device_error_or_status(self->device));
113 wait_until_xfer_cancelled(elt->xfer);
127 elt->can_generate_eof = TRUE;
132 XferSourceDeviceClass * selfc)
134 XferElementClass *klass = XFER_ELEMENT_CLASS(selfc);
135 static xfer_element_mech_pair_t mech_pairs[] = {
136 { XFER_MECH_NONE, XFER_MECH_PULL_BUFFER, 0, 1},
137 { XFER_MECH_NONE, XFER_MECH_NONE, 0, 0},
140 klass->pull_buffer = pull_buffer_impl;
142 klass->perl_class = "Amanda::Xfer::Source::Device";
143 klass->mech_pairs = mech_pairs;
145 parent_class = g_type_class_peek_parent(selfc);
149 xfer_source_device_get_type (void)
151 static GType type = 0;
153 if G_UNLIKELY(type == 0) {
154 static const GTypeInfo info = {
155 sizeof (XferSourceDeviceClass),
156 (GBaseInitFunc) NULL,
157 (GBaseFinalizeFunc) NULL,
158 (GClassInitFunc) class_init,
159 (GClassFinalizeFunc) NULL,
160 NULL /* class_data */,
161 sizeof (XferSourceDevice),
163 (GInstanceInitFunc) instance_init,
167 type = g_type_register_static (XFER_ELEMENT_TYPE, "XferSourceDevice", &info, 0);
173 /* create an element of this class; prototype is in xfer-device.h */
178 XferSourceDevice *self = (XferSourceDevice *)g_object_new(XFER_SOURCE_DEVICE_TYPE, NULL);
179 XferElement *elt = XFER_ELEMENT(self);
181 g_assert(device != NULL);
183 self->device = device;