X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=device-src%2Fdevice.h;h=f53ca001f975ef0f2d9cc8099f2abfee70683e74;hb=HEAD;hp=b39a7d0b462e94598334f79ce91698ac78a71a37;hpb=d5853102f67d85d8e169f9dbe973ad573306c215;p=debian%2Famanda diff --git a/device-src/device.h b/device-src/device.h index b39a7d0..f53ca00 100644 --- a/device-src/device.h +++ b/device-src/device.h @@ -1,9 +1,10 @@ /* - * Copyright (c) 2007, 2008, 2009, 2010 Zmanda, Inc. All Rights Reserved. + * Copyright (c) 2007-2012 Zmanda, Inc. All Rights Reserved. * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 as published - * by the Free Software Foundation. + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY @@ -91,6 +92,11 @@ typedef struct Device { /* You can peek at the stuff below, but only subclasses should change these values.*/ + /* A mutex to protect field accessed from another thread. + * Only get_bytes_read and get_bytes_written are allowed from another + * Only in_file, bytes_read and bytes_written are protected */ + GMutex *device_mutex; + /* What file, block are we at? (and are we in the middle of a file?) */ int file; guint64 block; @@ -132,6 +138,10 @@ typedef struct Device { gsize min_block_size; gsize max_block_size; gsize block_size; + gsize header_block_size; + + guint64 bytes_read; + guint64 bytes_written; /* surety and source for the block size; if you set block_size directly, * set these, too! */ @@ -175,12 +185,10 @@ struct _DeviceClass { char * label, char * timestamp); gboolean (* start_file) (Device * self, dumpfile_t * info); gboolean (* write_block) (Device * self, guint size, gpointer data); - gboolean (* write_from_fd) (Device * self, queue_fd_t *queue_fd); gboolean (* finish_file) (Device * self); dumpfile_t* (* seek_file) (Device * self, guint file); gboolean (* seek_block) (Device * self, guint64 block); int (* read_block) (Device * self, gpointer buf, int * size); - gboolean (* read_to_fd) (Device * self, queue_fd_t *queue_fd); gboolean (* property_get_ex) (Device * self, DevicePropertyId id, GValue * val, PropertySurety *surety, @@ -194,12 +202,30 @@ struct _DeviceClass { gboolean (* erase) (Device * self); gboolean (* eject) (Device * self); gboolean (* finish) (Device * self); + guint64 (* get_bytes_read) (Device * self); + guint64 (* get_bytes_written) (Device * self); gboolean (* listen)(Device *self, gboolean for_writing, DirectTCPAddr **addrs); - gboolean (* accept)(Device *self, DirectTCPConnection **conn, - ProlongProc prolong, gpointer prolong_data); - gboolean (* write_from_connection)(Device *self, guint64 size, guint64 *actual_size); - gboolean (* read_to_connection)(Device *self, guint64 size, guint64 *actual_size); + /* The MainLoop must be running, but the following 4 methods must not be + * called from an event. they must be called from a different thread. + * They return: + * 0 - success + * 1 - failed + * 2 - interupted + */ + int (* accept)(Device *self, DirectTCPConnection **conn, + int *cancelled, GMutex *abort_mutex, GCond *abort_cond); + int (* connect)(Device *self, gboolean for_writing, + DirectTCPAddr *addrs, DirectTCPConnection **conn, + int *cancelled, + GMutex *abort_mutex, GCond *abort_cond); + int (* write_from_connection)(Device *self, guint64 size, + guint64 *actual_size, int *cancelled, + GMutex *abort_mutex, GCond *abort_cond); + int (* read_to_connection)(Device *self, guint64 size, + guint64 *actual_size, int *cancelled, + GMutex *abort_mutex, GCond *abort_cond); + gboolean (* use_connection)(Device *self, DirectTCPConnection *conn); /* array of DeviceProperty objects for this class, keyed by ID */ @@ -292,21 +318,19 @@ gboolean device_start (Device * self, DeviceAccessMode mode, char * label, char * timestamp); gboolean device_finish (Device * self); +guint64 device_get_bytes_read (Device * self); +guint64 device_get_bytes_written(Device * self); gboolean device_start_file (Device * self, dumpfile_t * jobInfo); gboolean device_write_block (Device * self, guint size, gpointer data); -gboolean device_write_from_fd (Device * self, - queue_fd_t *queue_fd); gboolean device_finish_file (Device * self); dumpfile_t* device_seek_file (Device * self, guint file); gboolean device_seek_block (Device * self, guint64 block); int device_read_block (Device * self, gpointer buffer, int * size); -gboolean device_read_to_fd (Device * self, - queue_fd_t *queue_fd); const GSList * device_property_get_list (Device * self); gboolean device_property_get_ex (Device * self, DevicePropertyId id, @@ -331,10 +355,18 @@ gboolean device_eject (Device * self); #define device_directtcp_supported(self) (DEVICE_GET_CLASS((self))->directtcp_supported) gboolean device_listen(Device *self, gboolean for_writing, DirectTCPAddr **addrs); -gboolean device_accept(Device *self, DirectTCPConnection **conn, - ProlongProc prolong, gpointer prolong_data); -gboolean device_write_from_connection(Device *self, guint64 size, guint64 *actual_size); -gboolean device_read_to_connection(Device *self, guint64 size, guint64 *actual_size); +int device_accept(Device *self, DirectTCPConnection **conn, + int *cancelled, GMutex *abort_mutex, GCond *abort_cond); +int device_connect(Device *self, gboolean for_writing, + DirectTCPAddr *addrs, DirectTCPConnection **conn, + int *cancelled, + GMutex *abort_mutex, GCond *abort_cond); +int device_write_from_connection(Device *self, guint64 size, + guint64 *actual_size, int *cancelled, + GMutex *abort_mutex, GCond *abort_cond); +int device_read_to_connection(Device *self, guint64 size, + guint64 *actual_size, int *cancelled, + GMutex *abort_mutex, GCond *abort_cond); gboolean device_use_connection(Device *self, DirectTCPConnection *conn); /* Protected methods. Don't call these except in subclass implementations. */