1 | /****************************************************** |
2 | Copyright (c) 2011-2013 Percona LLC and/or its affiliates. |
3 | |
4 | Data sink interface. |
5 | |
6 | This program is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by |
8 | the Free Software Foundation; version 2 of the License. |
9 | |
10 | This program 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 |
13 | GNU General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software |
17 | Foundation, 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 |
28 | extern "C" { |
29 | #endif |
30 | |
31 | extern char *xtrabackup_tmpdir; |
32 | struct datasink_struct; |
33 | typedef struct datasink_struct datasink_t; |
34 | |
35 | typedef struct ds_ctxt { |
36 | datasink_t *datasink; |
37 | char *root; |
38 | void *ptr; |
39 | struct ds_ctxt *pipe_ctxt; |
40 | } ds_ctxt_t; |
41 | |
42 | typedef struct { |
43 | void *ptr; |
44 | char *path; |
45 | datasink_t *datasink; |
46 | } ds_file_t; |
47 | |
48 | struct 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 */ |
57 | typedef 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 | /************************************************************************ |
70 | Create a datasink of the specified type */ |
71 | ds_ctxt_t *ds_create(const char *root, ds_type_t type); |
72 | |
73 | /************************************************************************ |
74 | Open a datasink file */ |
75 | ds_file_t *ds_open(ds_ctxt_t *ctxt, const char *path, MY_STAT *stat); |
76 | |
77 | /************************************************************************ |
78 | Write to a datasink file. |
79 | @return 0 on success, 1 on error. */ |
80 | int ds_write(ds_file_t *file, const void *buf, size_t len); |
81 | |
82 | /************************************************************************ |
83 | Close a datasink file. |
84 | @return 0 on success, 1, on error. */ |
85 | int ds_close(ds_file_t *file); |
86 | |
87 | /************************************************************************ |
88 | Destroy a datasink handle */ |
89 | void ds_destroy(ds_ctxt_t *ctxt); |
90 | |
91 | /************************************************************************ |
92 | Set the destination pipe for a datasink (only makes sense for compress and |
93 | tmpfile). */ |
94 | void 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 | |