2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 2008 Zmanda Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 * This declaration is entirely private; nothing but xfer_source_device() references
31 GType xfer_source_device_get_type(void);
32 #define XFER_SOURCE_DEVICE_TYPE (xfer_source_device_get_type())
33 #define XFER_SOURCE_DEVICE(obj) G_TYPE_CHECK_INSTANCE_CAST((obj), xfer_source_device_get_type(), XferSourceDevice)
34 #define XFER_SOURCE_DEVICE_CONST(obj) G_TYPE_CHECK_INSTANCE_CAST((obj), xfer_source_device_get_type(), XferSourceDevice const)
35 #define XFER_SOURCE_DEVICE_CLASS(klass) G_TYPE_CHECK_CLASS_CAST((klass), xfer_source_device_get_type(), XferSourceDeviceClass)
36 #define IS_XFER_SOURCE_DEVICE(obj) G_TYPE_CHECK_INSTANCE_TYPE((obj), xfer_source_device_get_type ())
37 #define XFER_SOURCE_DEVICE_GET_CLASS(obj) G_TYPE_INSTANCE_GET_CLASS((obj), xfer_source_device_get_type(), XferSourceDeviceClass)
39 static GObjectClass *parent_class = NULL;
42 * Main object structure
45 typedef struct XferSourceDevice {
46 XferElement __parent__;
58 XferElementClass __parent__;
59 } XferSourceDeviceClass;
70 XferSourceDevice *self = (XferSourceDevice *)elt;
75 /* indicate EOF on an cancel */
81 /* get the device block size */
82 if (self->block_size == 0) {
83 self->block_size = self->device->block_size;
87 buf = g_malloc(self->block_size);
88 devsize = (int)self->block_size;
89 result = device_read_block(self->device, buf, &devsize);
92 /* if the buffer was too small, loop around again */
94 g_assert(*size > self->block_size);
95 self->block_size = devsize;
98 } while (result == 0);
101 /* if we're not at EOF, it's an error */
102 if (!self->device->is_eof) {
103 xfer_element_handle_error(elt,
104 _("error reading from %s: %s"),
105 self->device->device_name,
106 device_error_or_status(self->device));
120 elt->can_generate_eof = TRUE;
125 XferSourceDeviceClass * selfc)
127 XferElementClass *klass = XFER_ELEMENT_CLASS(selfc);
128 static xfer_element_mech_pair_t mech_pairs[] = {
129 { XFER_MECH_NONE, XFER_MECH_PULL_BUFFER, 0, 1},
130 { XFER_MECH_NONE, XFER_MECH_NONE, 0, 0},
133 klass->pull_buffer = pull_buffer_impl;
135 klass->perl_class = "Amanda::Xfer::Source::Device";
136 klass->mech_pairs = mech_pairs;
138 parent_class = g_type_class_peek_parent(selfc);
142 xfer_source_device_get_type (void)
144 static GType type = 0;
146 if G_UNLIKELY(type == 0) {
147 static const GTypeInfo info = {
148 sizeof (XferSourceDeviceClass),
149 (GBaseInitFunc) NULL,
150 (GBaseFinalizeFunc) NULL,
151 (GClassInitFunc) class_init,
152 (GClassFinalizeFunc) NULL,
153 NULL /* class_data */,
154 sizeof (XferSourceDevice),
156 (GInstanceInitFunc) instance_init,
160 type = g_type_register_static (XFER_ELEMENT_TYPE, "XferSourceDevice", &info, 0);
166 /* create an element of this class; prototype is in xfer-element.h */
171 XferSourceDevice *self = (XferSourceDevice *)g_object_new(XFER_SOURCE_DEVICE_TYPE, NULL);
172 XferElement *elt = XFER_ELEMENT(self);
174 g_assert(device != NULL);
176 self->device = device;