Imported Upstream version 3.2.0
[debian/amanda] / ndmp-src / ndmpconnobj.h
1 /*
2  * Copyright (c) 2009, 2010 Zmanda, Inc.  All Rights Reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 2 as published
6  * by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11  * for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16  *
17  * Contact information: Zmanda Inc., 465 N Mathlida Ave, Suite 300
18  * Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
19  */
20
21 /* An interface for devices that support direct-tcp access to a the device */
22
23 #ifndef NDMCONNOBJ_H
24 #define NDMCONNOBJ_H
25
26 #include "amanda.h"
27 #include "ndmlib.h"
28 #include "directtcp.h"
29 #include <glib-object.h>
30
31 GType   ndmp_connection_get_type        (void);
32 #define TYPE_NDMP_CONNECTION    (ndmp_connection_get_type())
33 #define NDMP_CONNECTION(obj)    G_TYPE_CHECK_INSTANCE_CAST((obj), ndmp_connection_get_type(), NDMPConnection)
34 #define IS_NDMP_CONNECTION(obj) G_TYPE_CHECK_INSTANCE_TYPE((obj), ndmp_connection_get_type ())
35 #define NDMP_CONNECTION_GET_CLASS(obj) G_TYPE_INSTANCE_GET_CLASS((obj), ndmp_connection_get_type(), NDMPConnectionClass)
36
37 /*
38  * Parent class for connections
39  */
40
41 typedef struct NDMPConnection_ {
42     GObject __parent__;
43
44     /* the ndmconn - interface to ndmlib */
45     struct ndmconn *conn;
46
47     /* integer to identify this connection */
48     int connid;
49
50     /* received notifications; note that this does not include all possible
51      * notifications, and that only one "queued" version of each notification
52      * is possible.  Each reason is 0 if no such notification has been
53      * received.  */
54     ndmp9_data_halt_reason data_halt_reason;
55     ndmp9_mover_halt_reason mover_halt_reason;
56     ndmp9_mover_pause_reason mover_pause_reason;
57     guint64 mover_pause_seek_position;
58
59     /* log state, if using verbose logging (private) */
60     gpointer log_state;
61
62     /* error info */
63     int last_rc;
64     gchar *startup_err;
65 } NDMPConnection;
66
67 typedef struct NDMPConnectionClass_ {
68     GObjectClass __parent__;
69
70     /* NOTE: this class is not subclassed, so its "methods" are not
71      * implemented via the usual GObject function-pointer mechanism,
72      * but are simple C functions. */
73 } NDMPConnectionClass;
74
75 /* Error handling */
76
77 /* Get the last NDMP error on this connection; returns NDMP4_NO_ERR (0)
78  * if no error occurred, or if there was a communications error.  This
79  * will also detect errors from the constructor.
80  *
81  * @param self: object
82  * @returns: error code
83  */
84 ndmp4_error ndmp_connection_err_code(
85     NDMPConnection *self);
86
87 /* Get the error message describing the most recent error on this object.
88  * This will always return a non-NULL string.  The result must be freed
89  * by the caller.
90  *
91  * @param self: object
92  * @returns: heap-allocated error message
93  */
94 gchar *ndmp_connection_err_msg(
95     NDMPConnection *self);
96
97 /* Set the verbose flag for this connection
98  *
99  * @param self: object
100  * @param verbose: TRUE for verbose logging
101  */
102 void ndmp_connection_set_verbose(
103     NDMPConnection *self,
104     gboolean verbose);
105
106 /*
107  * basic NDMP protocol operations
108  *
109  * All of these functions return TRUE on success.
110  */
111
112 gboolean ndmp_connection_scsi_open(
113         NDMPConnection *self,
114         gchar *device);
115
116 gboolean ndmp_connection_scsi_close(
117         NDMPConnection *self);
118
119 gboolean ndmp_connection_scsi_execute_cdb(
120         NDMPConnection *self,
121         guint32 flags, /* bitmask: NDMP9_SCSI_DATA_DIR_{IN,OUT}; OUT = to device */
122         guint32 timeout, /* in ms */
123         gpointer cdb,
124         gsize cdb_len,
125         gpointer dataout,
126         gsize dataout_len,
127         gsize *actual_dataout_len, /* output */
128         gpointer datain, /* output */
129         gsize datain_max_len, /* output buffer size */
130         gsize *actual_datain_len, /* output */
131         guint8 *status, /* output */
132         gpointer ext_sense, /* output */
133         gsize ext_sense_max_len, /* output buffer size */
134         gsize *actual_ext_sense_len /* output */
135         );
136
137 gboolean ndmp_connection_tape_open(
138         NDMPConnection *self,
139         gchar *device,
140         ndmp9_tape_open_mode mode);
141
142 gboolean ndmp_connection_tape_close(
143         NDMPConnection *self);
144
145 gboolean ndmp_connection_tape_mtio(
146         NDMPConnection *self,
147         ndmp9_tape_mtio_op tape_op,
148         gint count,
149         guint *resid_count);
150
151 gboolean ndmp_connection_tape_write(
152         NDMPConnection *self,
153         gpointer buf,
154         guint64 len,
155         guint64 *count); /* output */
156
157 gboolean ndmp_connection_tape_read(
158         NDMPConnection *self,
159         gpointer buf, /* output */
160         guint64 count, /* buffer size/requested read size */
161         guint64 *out_count); /* bytes read */
162
163 gboolean ndmp_connection_tape_get_state(
164         NDMPConnection *self,
165         guint64 *blocksize, /* 0 if not supported */
166         guint64 *file_num, /* all 1's if not supported */
167         guint64 *blockno); /* all 1's if not supported */
168         /* (other state variables should be added as needed) */
169
170 gboolean ndmp_connection_mover_set_record_size(
171         NDMPConnection *self,
172         guint32 record_size);
173
174 gboolean ndmp_connection_mover_set_window(
175         NDMPConnection *self,
176         guint64 offset,
177         guint64 length);
178
179 gboolean ndmp_connection_mover_read(
180         NDMPConnection *self,
181         guint64 offset,
182         guint64 length);
183
184 gboolean ndmp_connection_mover_continue(
185         NDMPConnection *self);
186
187 gboolean ndmp_connection_mover_listen(
188         NDMPConnection *self,
189         ndmp9_mover_mode mode,
190         ndmp9_addr_type addr_type,
191         DirectTCPAddr **addrs);
192
193 gboolean ndmp_connection_mover_connect(
194         NDMPConnection *self,
195         ndmp9_mover_mode mode,
196         DirectTCPAddr *addrs);
197
198 gboolean ndmp_connection_mover_abort(
199         NDMPConnection *self);
200
201 gboolean ndmp_connection_mover_stop(
202         NDMPConnection *self);
203
204 gboolean ndmp_connection_mover_close(
205         NDMPConnection *self);
206
207 gboolean ndmp_connection_mover_get_state(
208         NDMPConnection *self,
209         ndmp9_mover_state *state,
210         guint64 *bytes_moved,
211         guint64 *window_offset,
212         guint64 *window_length);
213         /* (other state variables should be added as needed) */
214
215 /* Synchronous notification interface.  This handles all types of notification,
216  * returning the result in the appropriate output parameter. */
217 gboolean ndmp_connection_wait_for_notify(
218         NDMPConnection *self,
219         /* NDMP_NOTIFY_DATA_HALTED */
220         ndmp9_data_halt_reason *data_halt_reason,
221         /* NDMP_NOTIFY_MOVER_HALTED */
222         ndmp9_mover_halt_reason *mover_halt_reason,
223         /* NDMP_NOTIFY_MOVER_PAUSED */
224         ndmp9_mover_pause_reason *mover_pause_reason,
225         guint64 *mover_pause_seek_position);
226
227 /*
228  * Constructor
229  */
230
231 /* Get a new NDMP connection. If an error occurs, this returns an empty object
232  * with its err_msg and err_code set appropriately.
233  *
234  * @param hostname: hostname to connect to
235  * @param port: port to connect on
236  * @param username: username to login with
237  * @param password: password to login with
238  * @param auth: authentication method to use ("MD5", "TEXT", "NONE", or "VOID")
239  * @returns: NDMPConnection object
240  */
241 NDMPConnection *
242 ndmp_connection_new(
243     gchar *hostname,
244     gint port,
245     gchar *username,
246     gchar *password,
247     gchar *auth);
248
249 #endif