summaryrefslogtreecommitdiffstats
path: root/cpukit/include/rtems/print.h
blob: 91c45150a6a892f3ac312d7bf8ce481ac8d51735 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/**
 * @file rtems/print.h
 *
 * @brief User print interface to the bspIO print plug in.
 *
 * This include file defines the user interface to kernel print methods.
 */

/*
 *  Copyright (c) 2016 Chris Johns <chrisj@rtems.org>
 *  All rights reserved.
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.org/license/LICENSE.
 */

#ifndef _RTEMS_PRINT_H
#define _RTEMS_PRINT_H

#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>

#include <rtems/bspIo.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @defgroup RTEMS Print Support
 *
 * This module contains all methods and support related to providing the user
 * with an interface to the kernel level print support.
 */

/**
 * Type definition for the printer structure used to access the kernel print
 * support.
 */
typedef struct rtems_printer {
  void                *context;
  rtems_print_plugin_t printer;
} rtems_printer;

/**
 * @brief check if the printer is valid.
 *
 * @param[in] printer Pointer to the printer structure.
 *
 * @return true The printer is valid else false is returned.
 */
static inline bool rtems_print_printer_valid(const rtems_printer *printer)
{
  return printer != NULL && printer->printer != NULL;
}

/**
 * @brief Print to the kernel plugin handler. This has to be a macro because
 * there is no vprint version of the plug in handlers.
 *
 * @param[in] printer Pointer to the printer structure.
 * @param[in] fmt Print format string.
 * @param[in] ... Print variable argument list.
 *
 * @return int Number of characters printed.
 */
extern int rtems_printf(const rtems_printer *printer,
                        const char          *format,
                        ...) RTEMS_PRINTF_ATTRIBUTE(2, 3);

/**
 * @brief Print to the kernel plugin handler. This has to be a macro because
 * there is no vprint version of the plug in handlers.
 *
 * @param[in] printer Pointer to the printer structure.
 * @param[in] fmt Print format string.
 * @param[in] ap Print variable argument list pointer.
 *
 * @return int Number of characters printed.
 */
extern int rtems_vprintf(const rtems_printer *printer,
                         const char          *format,
                         va_list              ap);

/**
 * @brief Intiialise the rtems_printer struct to empty.
 *
 * An empty printer prints nothing. You can use this to implement an enable and
 * disable type print implementation.
 *
 * @param[in] printer Pointer to the printer structure.
 */
static inline void rtems_print_printer_empty(rtems_printer *printer)
{
  printer->context = NULL;
  printer->printer = NULL;
}

/**
 * @brief Intiialise the rtems_printer struct to printk
 *
 * The printer will output to the kernel printk support.
 *
 * @param[in] printer Pointer to the printer structure.
 */
void rtems_print_printer_printk(rtems_printer *printer);

/**
 * @brief Intiialise the rtems_printer struct to printf
 *
 * The printer will output to the libc printf support.
 *
 * @param[in] printer Pointer to the printer structure.
 */
extern void rtems_print_printer_printf(rtems_printer *printer);

/**
 * @brief Intiialise the rtems_printer struct to a fprintf device.
 *
 * The printer will output to the libc fprintf file provided.
 *
 * @param[in] printer Pointer to the printer structure.
 */
extern void rtems_print_printer_fprintf(rtems_printer *printer, FILE *file);

/**@}*/

#ifdef __cplusplus
}
#endif

#endif