Make fn_open and fn_close take a struct file_handle instead of char *
[pspp] / src / output / driver-provider.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 1997-9, 2000, 2007, 2009, 2010, 2012, 2014 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17 #ifndef OUTPUT_DRIVER_PROVIDER_H
18 #define OUTPUT_DRIVER_PROVIDER_H 1
19
20 #include <stdbool.h>
21
22 #include "data/settings.h"
23 #include "libpspp/compiler.h"
24 #include "output/driver.h"
25
26 struct output_item;
27 struct string_map;
28 struct file_handle;
29
30 /* A configured output driver. */
31 struct output_driver
32   {
33     const struct output_driver_class *class; /* Driver class. */
34     char *name;                              /* Name of this driver. */
35     enum settings_output_devices device_type; /* One of SETTINGS_DEVICE_*. */
36   };
37
38 void output_driver_init (struct output_driver *,
39                          const struct output_driver_class *,
40                          const char *, enum settings_output_devices);
41
42 void output_driver_destroy (struct output_driver *);
43
44 const char *output_driver_get_name (const struct output_driver *);
45
46 /* One kind of output driver.
47
48    Output driver implementations must not call msg() to report errors.  This
49    can lead to reentrance in the output driver, because msg() may report error
50    messages using the output drivers.  Instead, this code should report errors
51    with error(), which will never call into the output drivers.  */
52 struct output_driver_class
53   {
54     /* Name of this driver class. */
55     const char *name;
56
57     /* Closes and frees DRIVER. */
58     void (*destroy) (struct output_driver *driver);
59
60     /* Passes ITEM to DRIVER to be written as output.  The caller retains
61        ownership of ITEM (but DRIVER may keep a copy of it by incrementing the
62        reference count by calling output_item_ref). */
63     void (*submit) (struct output_driver *driver,
64                     const struct output_item *item);
65
66     /* Ensures that any output items passed to the 'submit' function for DRIVER
67        have actually been displayed.
68
69        This is called from the text-based UI before showing the command prompt,
70        to ensure that the user has actually been shown any preceding output If
71        it doesn't make sense for DRIVER to be used this way, then this function
72        need not do anything. */
73     void (*flush) (struct output_driver *driver);
74   };
75
76 /* Useful for output driver implementation. */
77 void output_driver_track_current_command (const struct output_item *, char **);
78 \f
79 /* An abstract way for the output subsystem to create an output driver. */
80 struct output_driver_factory
81   {
82     /* The file extension, without the leading dot, e.g. "pdf". */
83     const char *extension;
84
85     /* The default file name, including extension.
86
87        If this is "-", that implies that by default output will be directed to
88        stdout. */
89     const char *default_file_name;
90
91     /* Creates a new output driver of this class.  NAME and TYPE should be
92        passed directly to output_driver_init.  Returns the new output driver if
93        successful, otherwise a null pointer.
94
95        It is up to the driver class to decide how to interpret OPTIONS.  The
96        create function should delete pairs that it understands from OPTIONS,
97        because the caller may issue errors about unknown options for any pairs
98        that remain.  The functions in output/options.h can be useful.
99
100        The returned driver should not have been registered (with
101        output_driver_register).  The caller will register the driver (if this
102        is desirable). */
103     struct output_driver *(*create) (struct file_handle *,
104                                      enum settings_output_devices type,
105                                      struct string_map *options);
106   };
107
108
109 #endif /* output/driver-provider.h */