Rewrite PSPP output engine.
[pspp-builds.git] / src / output / driver-provider.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 1997-9, 2000, 2007, 2009 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 <libpspp/compiler.h>
21 #include <stdbool.h>
22 #include <output/driver.h>
23
24 struct output_item;
25 struct string_map;
26
27 /* A configured output driver. */
28 struct output_driver
29   {
30     const struct output_driver_class *class; /* Driver class. */
31     char *name;                              /* Name of this driver. */
32     enum output_device_type device_type;     /* One of OUTPUT_DEVICE_*. */
33   };
34
35 void output_driver_init (struct output_driver *,
36                          const struct output_driver_class *,
37                          const char *name, enum output_device_type);
38 void output_driver_destroy (struct output_driver *);
39
40 const char *output_driver_get_name (const struct output_driver *);
41
42 /* One kind of output driver.
43
44    Output driver implementations must not call msg() to report errors.  This
45    can lead to reentrance in the output driver, because msg() may report error
46    messages using the output drivers.  Instead, this code should report errors
47    with error(), which will never call into the output drivers.  */
48 struct output_driver_class
49   {
50     const char *name;           /* Name of this driver class. */
51
52     /* Creates a new output driver of this class.  NAME and TYPE should be
53        passed directly to output_driver_init.  Returns the new output driver if
54        successful, otherwise a null pointer.
55
56        It is up to the driver class to decide how to interpret OPTIONS.  The
57        functions in output/options.h can be useful.  OPTIONS may be modified
58        but the caller is responsible for destroying it.
59
60        The returned driver should not have been registered (with
61        output_driver_register).  The caller will register the driver (if this
62        is desirable). */
63     struct output_driver *(*create) (const char *name,
64                                      enum output_device_type type,
65                                      struct string_map *options);
66
67     /* Closes and frees DRIVER. */
68     void (*destroy) (struct output_driver *driver);
69
70     /* Passes ITEM to DRIVER to be written as output.  The caller retains
71        ownership of ITEM (but DRIVER may keep a copy of it by incrementing the
72        reference count by calling output_item_ref). */
73     void (*submit) (struct output_driver *driver,
74                     const struct output_item *item);
75
76     /* Ensures that any output items passed to the 'submit' function for DRIVER
77        have actually been displayed.
78
79        This is called from the text-based UI before showing the command prompt,
80        to ensure that the user has actually been shown any preceding output If
81        it doesn't make sense for DRIVER to be used this way, then this function
82        need not do anything. */
83     void (*flush) (struct output_driver *driver);
84   };
85
86 void output_driver_register (struct output_driver *);
87 void output_driver_unregister (struct output_driver *);
88 bool output_driver_is_registered (const struct output_driver *);
89
90 /* Common drivers. */
91 extern const struct output_driver_class ascii_class;
92 extern const struct output_driver_class html_class;
93 extern const struct output_driver_class odt_class;
94 extern const struct output_driver_class csv_class;
95 #ifdef HAVE_CAIRO
96 extern const struct output_driver_class cairo_class;
97 #endif
98
99 #endif /* output/driver-provider.h */