37d0f7a3147c0aa939177727fb4412147759c690
[debian/amanda] / server-src / taper-source.h
1 /*
2  * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3  * Copyright (c) 2006 Zmanda Inc.
4  *
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.
9  *
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.
14  *
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
18  */
19
20 /* The taper source object abstracts the different ways that taper can
21  * retrieve and buffer data on its way to the device. It handles all
22  * splitting up and re-reading of split-tape parts, as well as all
23  * holding-disk related actions. */
24
25 #include <glib.h>
26 #include <glib-object.h>
27
28 #include <amanda.h>
29 #include "server_util.h"
30 #include "fileheader.h"
31 #include "queueing.h"
32
33 #ifndef __TAPER_SOURCE_H__
34 #define __TAPER_SOURCE_H__
35
36
37 /*
38  * Type checking and casting macros
39  */
40 #define TAPER_TYPE_SOURCE       (taper_source_get_type())
41 #define TAPER_SOURCE(obj)       G_TYPE_CHECK_INSTANCE_CAST((obj), taper_source_get_type(), TaperSource)
42 #define TAPER_SOURCE_CONST(obj) G_TYPE_CHECK_INSTANCE_CAST((obj), taper_source_get_type(), TaperSource const)
43 #define TAPER_SOURCE_CLASS(klass)       G_TYPE_CHECK_CLASS_CAST((klass), taper_source_get_type(), TaperSourceClass)
44 #define TAPER_IS_SOURCE(obj)    G_TYPE_CHECK_INSTANCE_TYPE((obj), taper_source_get_type ())
45
46 #define TAPER_SOURCE_GET_CLASS(obj)     G_TYPE_INSTANCE_GET_CLASS((obj), taper_source_get_type(), TaperSourceClass)
47
48 /*
49  * Main object structure
50  */
51 #ifndef __TYPEDEF_TAPER_SOURCE__
52 #define __TYPEDEF_TAPER_SOURCE__
53 typedef struct _TaperSource TaperSource;
54 #endif
55 struct _TaperSource {
56     GObject __parent__;
57     /*< private >*/
58     gboolean end_of_data; /* protected */
59     gboolean end_of_part; /* protected */
60     guint64 max_part_size; /* protected */
61     dumpfile_t * first_header;
62     char * driver_handle;
63 };
64
65 /*
66  * Class definition
67  */
68 typedef struct _TaperSourceClass TaperSourceClass;
69 struct _TaperSourceClass {
70     GObjectClass __parent__;
71     ssize_t (* read) (TaperSource * self, void * buf, size_t count);
72     gboolean (* seek_to_part_start) (TaperSource * self);
73     void (* start_new_part) (TaperSource * self);
74     gboolean (* is_partial) (TaperSource * self);
75     gboolean (* get_end_of_data)(TaperSource * self);
76     gboolean (* get_end_of_part)(TaperSource * self);
77     dumpfile_t * (* get_first_header)(TaperSource * self);
78     int (* predict_parts)(TaperSource * self);
79 };
80
81
82 /*
83  * Public methods
84  */
85 GType   taper_source_get_type   (void);
86 ssize_t         taper_source_read       (TaperSource * self,
87                                         void * buf,
88                                         size_t count);
89 gboolean        taper_source_get_end_of_data    (TaperSource * self);
90 gboolean        taper_source_get_end_of_part    (TaperSource * self);
91 dumpfile_t *    taper_source_get_first_header   (TaperSource * self);
92 /* Returns -1 for an unknown number of splits, or a positive integer if the
93  * number of splits is exactly known. Should never return zero. */
94 int             taper_source_predict_parts      (TaperSource * self);
95
96 /* You can only call this function (and expect to get an accurate
97    result) if taper_source_get_end_of_data() has already returned
98    TRUE. */
99 gboolean        taper_source_is_partial         (TaperSource * self);
100
101 gboolean        taper_source_seek_to_part_start (TaperSource * self);
102 void    taper_source_start_new_part     (TaperSource * self);
103
104 /* This function is how you get a taper source. Call it with the
105    relevant parameters, and the return value is yours to
106    keep. Arguments must be consistant (e.g., if you specify FILE_WRITE
107    mode, then you must provide a holding disk file). Input strings are
108    copied internally. */
109 TaperSource * taper_source_new(char * handle,
110                                cmd_t mode, char * holding_disk_file,
111                                int socket_fd,
112                                char * split_disk_buffer,
113                                guint64 splitsize,
114                                guint64 fallback_splitsize);
115
116 /* This function is a ProducerFunctor, as that type is defined in
117    device-src/queueing.h. */
118 producer_result_t taper_source_producer(gpointer taper_source,
119                                         queue_buffer_t * buffer,
120                                         int hint_size);
121
122 #endif