Uniform printer interface. An implementation of this interface must supply a constructor and implement all RDD_MSGPRINTER_OPS
(see the structure definition below).
There are two types of writers: bottom printers and stackable printers. A stackable printer receives input, optionally transforms it in some way, and passes the transformed data on to a lower-level parent printer. The parent printer is passed to the stackable printer at the time the stackable printer is constructed. The broadcast printer is a stackable writer.
A bottom printer receives input, optionally transforms it in some way, and passes the transformed data on to some output device (e.g. a file stream), but not to another printer. A bottom printer may well use other printer types in its implementation, but that does not make it a stackable printer.
Each constructor must be listed in this header file. Once a printer has been constructed, it should be accessed through the generic printer routines, rdd_mp_close()
, rdd_mp_print()
, or one of the routines that are layered on top of rdd_mp_print()
.
Definition in file msgprinter.h.
#include <stdarg.h>
#include <stdio.h>
Go to the source code of this file.
Data Structures | |
struct | _RDD_MSGPRINTER |
struct | _RDD_MSGPRINTER_OPS |
Typedefs | |
typedef enum _rdd_message_t | rdd_message_t |
typedef int(* | rdd_mp_close_fun )(struct _RDD_MSGPRINTER *printer, unsigned flags) |
typedef enum _rdd_mp_flags_t | rdd_mp_flags_t |
typedef void(* | rdd_mp_print_fun )(struct _RDD_MSGPRINTER *printer, rdd_message_t type, int errcode, const char *msg) |
typedef struct _RDD_MSGPRINTER | RDD_MSGPRINTER |
typedef struct _RDD_MSGPRINTER_OPS | RDD_MSGPRINTER_OPS |
Enumerations | |
enum | _rdd_message_t { RDD_MSG_INFO = 0x1, RDD_MSG_ERROR = 0x2, RDD_MSG_DEBUG = 0x4, RDD_MSG_WARN = 0x8 } |
enum | _rdd_mp_flags_t { RDD_MP_RECURSE = 0x1, RDD_MP_READONLY = 0x2 } |
Functions | |
int | rdd_mp_close (RDD_MSGPRINTER *printer, unsigned flags) |
Closes a printer instance. | |
uint32_t | rdd_mp_get_mask (RDD_MSGPRINTER *printer) |
Retrieves a printer's current message mask. | |
void | rdd_mp_message (RDD_MSGPRINTER *printer, rdd_message_t type, const char *fmt,...) |
Formats and prints a message. | |
int | rdd_mp_open_bcastprinter (RDD_MSGPRINTER **printer, unsigned nprinter, RDD_MSGPRINTER **printers) |
Opens a broadcast printer. A broadcast printer is a stackable printer that prints all its messages to all its parent printers. | |
int | rdd_mp_open_file_printer (RDD_MSGPRINTER **printer, const char *path, const int force_overwrite) |
Opens a file printer. A file printer prints all its messages to a named output file. | |
int | rdd_mp_open_log_printer (RDD_MSGPRINTER **printer, RDD_MSGPRINTER *next) |
Opens a log printer. A log printer is a stackable printer that prepends to each message a timestamp. The resulting, concatenated message is forwarded to parent printer next . | |
int | rdd_mp_open_printer (RDD_MSGPRINTER **printer, RDD_MSGPRINTER_OPS *ops, unsigned statesize) |
Allocates and partially initializes a new printer object. | |
int | rdd_mp_open_stdio_printer (RDD_MSGPRINTER **printer, FILE *stream) |
Opens a stream printer. A stream printer prints all its messages to a standard I/O file stream (stream ). | |
void | rdd_mp_print (RDD_MSGPRINTER *printer, rdd_message_t type, int errcode, const char *fmt,...) |
Formats and prints a message. | |
void | rdd_mp_rddmsg (RDD_MSGPRINTER *printer, rdd_message_t type, int rdd_errno, const char *fmt,...) |
Formats and prints an RDD error message. The value of rdd_errno must be one of the values defined in rdd.h. This routine will append the error message that corresponds to rdd_errno to the user's message and print the resulting, concatenated message. | |
void | rdd_mp_set_mask (RDD_MSGPRINTER *printer, uint32_t mask) |
Sets a printer's current message mask to value mask . | |
void | rdd_mp_unixmsg (RDD_MSGPRINTER *printer, rdd_message_t type, int unix_errno, const char *fmt,...) |
Formats and prints a Unix error message. The value of unix_errno must be one of the values defined in <errno.h>. This routine will append the error message that corresponds to unix_errno to the user's message and print the resulting, concatenated message. | |
void | rdd_mp_vmessage (RDD_MSGPRINTER *printer, rdd_message_t type, const char *fmt, va_list ap) |
Formats and prints a message for a varargs routine. | |
void | rdd_mp_vrddmsg (RDD_MSGPRINTER *printer, rdd_message_t type, int rdd_errno, const char *fmt, va_list ap) |
Formats and prints an RDD error message. The value of rdd_errno must be one of the values defined in rdd.h. This routine will append the error message that corresponds to rdd_errno to the user's message and print the resulting, concatenated message. |
typedef enum _rdd_message_t rdd_message_t |
Values of type rdd_message_t
specify the type of message that is passed to a printer instance. The message type is used to format or display the message in an appropriate manner.
typedef int(* rdd_mp_close_fun)(struct _RDD_MSGPRINTER *printer, unsigned flags) |
Definition at line 100 of file msgprinter.h.
typedef enum _rdd_mp_flags_t rdd_mp_flags_t |
Values of type rdd_mp_flags_t
determine the behavior of a printer's close
operation. If RDD_MP_RECURSE
is set, then a (stackable) printer will automatically close all parent printers. If RDD_MP_READONLY
is specified, then a printer that writes its messages to an output file will make that output file read-only when the printer is closed.
typedef void(* rdd_mp_print_fun)(struct _RDD_MSGPRINTER *printer, rdd_message_t type, int errcode, const char *msg) |
Definition at line 98 of file msgprinter.h.
typedef struct _RDD_MSGPRINTER RDD_MSGPRINTER |
Printer object. A printer object consists of a print buffer (printbuf
), a pointer to an operation table (ops
), a pointer to a state buffer (state
), and a message mask.
typedef struct _RDD_MSGPRINTER_OPS RDD_MSGPRINTER_OPS |
All printer implementations provide a structure of type RDD_WRITE_OPS
. This structure contains pointers to the routines that implement the interface.
enum _rdd_message_t |
Values of type rdd_message_t
specify the type of message that is passed to a printer instance. The message type is used to format or display the message in an appropriate manner.
Definition at line 76 of file msgprinter.h.
enum _rdd_mp_flags_t |
Values of type rdd_mp_flags_t
determine the behavior of a printer's close
operation. If RDD_MP_RECURSE
is set, then a (stackable) printer will automatically close all parent printers. If RDD_MP_READONLY
is specified, then a printer that writes its messages to an output file will make that output file read-only when the printer is closed.
Definition at line 91 of file msgprinter.h.
int rdd_mp_close | ( | RDD_MSGPRINTER * | printer, | |
unsigned | flags | |||
) |
Closes a printer instance.
Definition at line 75 of file msgprinter.c.
References _RDD_MSGPRINTER_OPS::close, _RDD_MSGPRINTER::ops, RDD_OK, and _RDD_MSGPRINTER::state.
uint32_t rdd_mp_get_mask | ( | RDD_MSGPRINTER * | printer | ) |
Retrieves a printer's current message mask.
Definition at line 91 of file msgprinter.c.
References _RDD_MSGPRINTER::mask.
void rdd_mp_message | ( | RDD_MSGPRINTER * | printer, | |
rdd_message_t | type, | |||
const char * | fmt, | |||
... | ||||
) |
Formats and prints a message.
Definition at line 143 of file msgprinter.c.
References rdd_mp_vmessage().
int rdd_mp_open_bcastprinter | ( | RDD_MSGPRINTER ** | printer, | |
unsigned | nprinter, | |||
RDD_MSGPRINTER ** | printers | |||
) |
Opens a broadcast printer. A broadcast printer is a stackable printer that prints all its messages to all its parent printers.
Definition at line 57 of file bcastprinter.c.
References _RDD_BCASTPRINTER_STATE::nprinter, _RDD_BCASTPRINTER_STATE::printers, RDD_BADARG, rdd_mp_open_printer(), RDD_NOMEM, RDD_OK, and _RDD_MSGPRINTER::state.
int rdd_mp_open_file_printer | ( | RDD_MSGPRINTER ** | printer, | |
const char * | path, | |||
const int | force_overwrite | |||
) |
Opens a file printer. A file printer prints all its messages to a named output file.
Definition at line 59 of file fileprinter.c.
References error(), outfile_fopen(), _RDD_FILE_MSGPRINTER::path, rdd_mp_open_printer(), RDD_NOMEM, RDD_OK, _RDD_MSGPRINTER::state, and _RDD_FILE_MSGPRINTER::stream.
int rdd_mp_open_log_printer | ( | RDD_MSGPRINTER ** | printer, | |
RDD_MSGPRINTER * | next | |||
) |
Opens a log printer. A log printer is a stackable printer that prepends to each message a timestamp. The resulting, concatenated message is forwarded to parent printer next
.
Definition at line 58 of file logprinter.c.
References _RDD_LOG_MSGPRINTER::next, rdd_mp_open_printer(), RDD_OK, and _RDD_MSGPRINTER::state.
int rdd_mp_open_printer | ( | RDD_MSGPRINTER ** | printer, | |
RDD_MSGPRINTER_OPS * | ops, | |||
unsigned | statesize | |||
) |
Allocates and partially initializes a new printer object.
printer | output value: a new printer object. | |
ops | pointers to implementation-specific printer functions. | |
statesize | size in bytes of implementation-specific state. |
RDD_OK
on success. Returns RDD_NOMEM
when there is insufficient memory to allocate the writer object or its state buffer.rdd_mp_open_printer()
allocates a writer object and initializes its ops
field to argument . The state
field is set to point to a new buffer (allocated with malloc()
) with size statesize
. The state buffer is zeroed. The mask is set so that it allows all message types to be printed.
Definition at line 52 of file msgprinter.c.
References _RDD_MSGPRINTER::mask, _RDD_MSGPRINTER::ops, RDD_MSG_DEBUG, RDD_MSG_ERROR, RDD_MSG_INFO, RDD_MSG_WARN, RDD_NOMEM, RDD_OK, and _RDD_MSGPRINTER::state.
int rdd_mp_open_stdio_printer | ( | RDD_MSGPRINTER ** | printer, | |
FILE * | stream | |||
) |
Opens a stream printer. A stream printer prints all its messages to a standard I/O file stream (stream
).
Definition at line 57 of file stdioprinter.c.
References rdd_mp_open_printer(), RDD_OK, _RDD_MSGPRINTER::state, and _RDD_STDIO_MSGPRINTER::stream.
void rdd_mp_print | ( | RDD_MSGPRINTER * | printer, | |
rdd_message_t | type, | |||
int | errcode, | |||
const char * | fmt, | |||
... | ||||
) |
Formats and prints a message.
Definition at line 115 of file msgprinter.c.
References mp_accept_message(), _RDD_MSGPRINTER::ops, _RDD_MSGPRINTER_OPS::print, and _RDD_MSGPRINTER::printbuf.
void rdd_mp_rddmsg | ( | RDD_MSGPRINTER * | printer, | |
rdd_message_t | type, | |||
int | rdd_errno, | |||
const char * | fmt, | |||
... | ||||
) |
Formats and prints an RDD error message. The value of rdd_errno
must be one of the values defined in rdd.h. This routine will append the error message that corresponds to rdd_errno
to the user's message and print the resulting, concatenated message.
Definition at line 223 of file msgprinter.c.
References rdd_mp_vrddmsg().
void rdd_mp_set_mask | ( | RDD_MSGPRINTER * | printer, | |
uint32_t | mask | |||
) |
Sets a printer's current message mask to value mask
.
Definition at line 97 of file msgprinter.c.
References _RDD_MSGPRINTER::mask.
void rdd_mp_unixmsg | ( | RDD_MSGPRINTER * | printer, | |
rdd_message_t | type, | |||
int | unix_errno, | |||
const char * | fmt, | |||
... | ||||
) |
Formats and prints a Unix error message. The value of unix_errno
must be one of the values defined in <errno.h>. This routine will append the error message that corresponds to unix_errno
to the user's message and print the resulting, concatenated message.
Definition at line 186 of file msgprinter.c.
References mp_accept_message(), mp_init(), mp_printf(), mp_vprintf(), _RDD_MSGPRINTER::ops, _RDD_MSGPRINTER_OPS::print, and _RDD_MSGPRINTER::printbuf.
void rdd_mp_vmessage | ( | RDD_MSGPRINTER * | printer, | |
rdd_message_t | type, | |||
const char * | fmt, | |||
va_list | ap | |||
) |
Formats and prints a message for a varargs routine.
Definition at line 131 of file msgprinter.c.
References mp_accept_message(), _RDD_MSGPRINTER::ops, _RDD_MSGPRINTER_OPS::print, and _RDD_MSGPRINTER::printbuf.
void rdd_mp_vrddmsg | ( | RDD_MSGPRINTER * | printer, | |
rdd_message_t | type, | |||
int | rdd_errno, | |||
const char * | fmt, | |||
va_list | ap | |||
) |
Formats and prints an RDD error message. The value of rdd_errno
must be one of the values defined in rdd.h. This routine will append the error message that corresponds to rdd_errno
to the user's message and print the resulting, concatenated message.
Definition at line 204 of file msgprinter.c.
References mp_accept_message(), mp_init(), mp_printf(), mp_vprintf(), _RDD_MSGPRINTER::ops, _RDD_MSGPRINTER_OPS::print, _RDD_MSGPRINTER::printbuf, RDD_OK, and rdd_strerror().