1/******************************************************
2Copyright (c) 2011-2013 Percona LLC and/or its affiliates.
3
4Data sink interface.
5
6This program is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; version 2 of the License.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
18
19*******************************************************/
20
21#ifndef XB_DATASINK_H
22#define XB_DATASINK_H
23
24#include <my_global.h>
25#include <my_dir.h>
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31extern char *xtrabackup_tmpdir;
32struct datasink_struct;
33typedef struct datasink_struct datasink_t;
34
35typedef struct ds_ctxt {
36 datasink_t *datasink;
37 char *root;
38 void *ptr;
39 struct ds_ctxt *pipe_ctxt;
40} ds_ctxt_t;
41
42typedef struct {
43 void *ptr;
44 char *path;
45 datasink_t *datasink;
46} ds_file_t;
47
48struct datasink_struct {
49 ds_ctxt_t *(*init)(const char *root);
50 ds_file_t *(*open)(ds_ctxt_t *ctxt, const char *path, MY_STAT *stat);
51 int (*write)(ds_file_t *file, const unsigned char *buf, size_t len);
52 int (*close)(ds_file_t *file);
53 void (*deinit)(ds_ctxt_t *ctxt);
54};
55
56/* Supported datasink types */
57typedef enum {
58 DS_TYPE_STDOUT,
59 DS_TYPE_LOCAL,
60 DS_TYPE_ARCHIVE,
61 DS_TYPE_XBSTREAM,
62 DS_TYPE_COMPRESS,
63 DS_TYPE_ENCRYPT,
64 DS_TYPE_DECRYPT,
65 DS_TYPE_TMPFILE,
66 DS_TYPE_BUFFER
67} ds_type_t;
68
69/************************************************************************
70Create a datasink of the specified type */
71ds_ctxt_t *ds_create(const char *root, ds_type_t type);
72
73/************************************************************************
74Open a datasink file */
75ds_file_t *ds_open(ds_ctxt_t *ctxt, const char *path, MY_STAT *stat);
76
77/************************************************************************
78Write to a datasink file.
79@return 0 on success, 1 on error. */
80int ds_write(ds_file_t *file, const void *buf, size_t len);
81
82/************************************************************************
83Close a datasink file.
84@return 0 on success, 1, on error. */
85int ds_close(ds_file_t *file);
86
87/************************************************************************
88Destroy a datasink handle */
89void ds_destroy(ds_ctxt_t *ctxt);
90
91/************************************************************************
92Set the destination pipe for a datasink (only makes sense for compress and
93tmpfile). */
94void ds_set_pipe(ds_ctxt_t *ctxt, ds_ctxt_t *pipe_ctxt);
95
96#ifdef __cplusplus
97} /* extern "C" */
98#endif
99
100#endif /* XB_DATASINK_H */
101