From 506bfc8580c365c48f2200772ddd0985e661ae34 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Tue, 21 Jun 2016 13:30:15 +0200 Subject: Move printer initialization to separate header The RTEMS print user need to know nothing about a particular printer implementation. In particular get rid of the include which would be visible via . --- c/src/lib/libbsp/shared/src/irq-info.c | 2 +- c/src/lib/libbsp/shared/src/irq-shell.c | 1 + cpukit/Makefile.am | 1 + cpukit/include/rtems/print.h | 83 ++------------------ cpukit/include/rtems/printer.h | 119 +++++++++++++++++++++++++++++ cpukit/libcsupport/src/print_fprintf.c | 4 +- cpukit/libcsupport/src/print_printf.c | 4 +- cpukit/libcsupport/src/printf_plugin.c | 4 +- cpukit/libcsupport/src/printk_plugin.c | 2 +- cpukit/libdl/rap.c | 1 + cpukit/libmisc/cpuuse/cpuusagereport.c | 1 + cpukit/libmisc/cpuuse/cpuusagetop.c | 1 + cpukit/libmisc/fb/mw_print.c | 1 + cpukit/libmisc/shell/main_blkstats.c | 1 + cpukit/libmisc/shell/main_cpuinfo.c | 1 + cpukit/libmisc/shell/main_cpuuse.c | 1 + cpukit/libmisc/shell/main_perioduse.c | 1 + cpukit/libmisc/shell/main_profreport.c | 1 + cpukit/libmisc/shell/main_stackuse.c | 1 + cpukit/libmisc/shell/main_top.c | 1 + cpukit/libmisc/stackchk/check.c | 1 + cpukit/libmisc/testsupport/test.h | 2 +- cpukit/mghttpd/mongoose.c | 2 +- cpukit/preinstall.am | 4 + cpukit/rtems/src/ratemonreportstatistics.c | 2 +- cpukit/score/src/cpusetprintsupport.c | 4 +- testsuites/samples/hello/init.c | 1 + 27 files changed, 153 insertions(+), 94 deletions(-) create mode 100644 cpukit/include/rtems/printer.h diff --git a/c/src/lib/libbsp/shared/src/irq-info.c b/c/src/lib/libbsp/shared/src/irq-info.c index f5f2323a01..ef965d3d07 100644 --- a/c/src/lib/libbsp/shared/src/irq-info.c +++ b/c/src/lib/libbsp/shared/src/irq-info.c @@ -21,7 +21,7 @@ #include -#include +#include #include #include diff --git a/c/src/lib/libbsp/shared/src/irq-shell.c b/c/src/lib/libbsp/shared/src/irq-shell.c index 512594c133..ca936f8038 100644 --- a/c/src/lib/libbsp/shared/src/irq-shell.c +++ b/c/src/lib/libbsp/shared/src/irq-shell.c @@ -21,6 +21,7 @@ #include +#include #include #include diff --git a/cpukit/Makefile.am b/cpukit/Makefile.am index aa1111e99b..ac9753052d 100644 --- a/cpukit/Makefile.am +++ b/cpukit/Makefile.am @@ -98,6 +98,7 @@ endif include_rtems_HEADERS += include/rtems/bspIo.h include_rtems_HEADERS += include/rtems/print.h +include_rtems_HEADERS += include/rtems/printer.h include_rtems_HEADERS += include/rtems/userenv.h include_rtems_HEADERS += include/rtems/fs.h if !LIBPCI diff --git a/cpukit/include/rtems/print.h b/cpukit/include/rtems/print.h index 07e50d0948..2fd744e44c 100644 --- a/cpukit/include/rtems/print.h +++ b/cpukit/include/rtems/print.h @@ -21,52 +21,20 @@ #include #include -#include #ifdef __cplusplus extern "C" { #endif +typedef struct rtems_printer rtems_printer; + /** - * @defgroup RTEMS Print Support + * @defgroup RTEMSPrintSupport 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 function which can be plugged in to certain reporting - * routines to redirect the output. - * - * Use the RTEMS Print interface to call these functions. Do not directly use - * them. - * - * If the user provides their own printer, then they may redirect those reports - * as they see fit. - */ -typedef int (*rtems_print_printer)(void *, const char *format, va_list ap); - -/** - * Type definition for the printer structure used to access the kernel print - * support. - */ -typedef struct rtems_printer { - void *context; - rtems_print_printer 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. @@ -95,51 +63,10 @@ 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 +#endif /* _RTEMS_PRINT_H */ diff --git a/cpukit/include/rtems/printer.h b/cpukit/include/rtems/printer.h new file mode 100644 index 0000000000..2ed6b6ac3f --- /dev/null +++ b/cpukit/include/rtems/printer.h @@ -0,0 +1,119 @@ +/** + * @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 + * 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_PRINTER_H +#define _RTEMS_PRINTER_H + +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @addtogroup XXX + * + * @{ + */ + +/** + * @defgroup RTEMSPrintSupport + */ + +/** + * Type definition for function which can be plugged in to certain reporting + * routines to redirect the output. + * + * Use the RTEMS Print interface to call these functions. Do not directly use + * them. + * + * If the user provides their own printer, then they may redirect those reports + * as they see fit. + */ +typedef int (*rtems_print_printer)(void *, const char *format, va_list ap); + +/** + * Type definition for the printer structure used to access the kernel print + * support. + */ +struct rtems_printer { + void *context; + rtems_print_printer 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 Initializes 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 Initializes 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 Initializes 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 Initializes 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 /* _RTEMS_PRINTER_H */ diff --git a/cpukit/libcsupport/src/print_fprintf.c b/cpukit/libcsupport/src/print_fprintf.c index 3ff80f7b2e..43ff4780d7 100644 --- a/cpukit/libcsupport/src/print_fprintf.c +++ b/cpukit/libcsupport/src/print_fprintf.c @@ -18,9 +18,7 @@ #include "config.h" #endif -#include - -#include +#include static int rtems_fprintf_plugin(void *context, const char *fmt, va_list ap) { diff --git a/cpukit/libcsupport/src/print_printf.c b/cpukit/libcsupport/src/print_printf.c index c8695234c0..c9b273a3af 100644 --- a/cpukit/libcsupport/src/print_printf.c +++ b/cpukit/libcsupport/src/print_printf.c @@ -18,9 +18,7 @@ #include "config.h" #endif -#include - -#include +#include int rtems_vprintf( const rtems_printer *printer, diff --git a/cpukit/libcsupport/src/printf_plugin.c b/cpukit/libcsupport/src/printf_plugin.c index 23ac9f693d..d8da6a0683 100644 --- a/cpukit/libcsupport/src/printf_plugin.c +++ b/cpukit/libcsupport/src/printf_plugin.c @@ -23,9 +23,7 @@ #include "config.h" #endif -#include - -#include +#include static int rtems_printf_plugin(void *context, const char *format, va_list ap) { diff --git a/cpukit/libcsupport/src/printk_plugin.c b/cpukit/libcsupport/src/printk_plugin.c index 38214f8018..3b4a911eb2 100644 --- a/cpukit/libcsupport/src/printk_plugin.c +++ b/cpukit/libcsupport/src/printk_plugin.c @@ -18,7 +18,7 @@ #include "config.h" #endif -#include +#include #include static int printk_plugin( diff --git a/cpukit/libdl/rap.c b/cpukit/libdl/rap.c index 4e07c5472e..87b3bc36e5 100644 --- a/cpukit/libdl/rap.c +++ b/cpukit/libdl/rap.c @@ -19,6 +19,7 @@ #include "config.h" #endif +#include #include #include #include diff --git a/cpukit/libmisc/cpuuse/cpuusagereport.c b/cpukit/libmisc/cpuuse/cpuusagereport.c index 2a6eaf348b..370eb05596 100644 --- a/cpukit/libmisc/cpuuse/cpuusagereport.c +++ b/cpukit/libmisc/cpuuse/cpuusagereport.c @@ -25,6 +25,7 @@ #include #include +#include #include #include #include diff --git a/cpukit/libmisc/cpuuse/cpuusagetop.c b/cpukit/libmisc/cpuuse/cpuusagetop.c index e300ee785c..aa2b74c160 100644 --- a/cpukit/libmisc/cpuuse/cpuusagetop.c +++ b/cpukit/libmisc/cpuuse/cpuusagetop.c @@ -32,6 +32,7 @@ #include #include +#include #include #include #include diff --git a/cpukit/libmisc/fb/mw_print.c b/cpukit/libmisc/fb/mw_print.c index 25a3456c80..c04f5a217a 100644 --- a/cpukit/libmisc/fb/mw_print.c +++ b/cpukit/libmisc/fb/mw_print.c @@ -21,6 +21,7 @@ #include #include +#include static const char *uid_buttons( unsigned short btns, diff --git a/cpukit/libmisc/shell/main_blkstats.c b/cpukit/libmisc/shell/main_blkstats.c index d814df673c..69548cfa7d 100644 --- a/cpukit/libmisc/shell/main_blkstats.c +++ b/cpukit/libmisc/shell/main_blkstats.c @@ -17,6 +17,7 @@ #endif #include +#include #include #include diff --git a/cpukit/libmisc/shell/main_cpuinfo.c b/cpukit/libmisc/shell/main_cpuinfo.c index c5bc9a3f3f..9245c0f147 100644 --- a/cpukit/libmisc/shell/main_cpuinfo.c +++ b/cpukit/libmisc/shell/main_cpuinfo.c @@ -19,6 +19,7 @@ #include #include #include +#include static int rtems_shell_main_cpuinfo(int argc, char **argv) { diff --git a/cpukit/libmisc/shell/main_cpuuse.c b/cpukit/libmisc/shell/main_cpuuse.c index 190fd039ff..726d907cba 100644 --- a/cpukit/libmisc/shell/main_cpuuse.c +++ b/cpukit/libmisc/shell/main_cpuuse.c @@ -18,6 +18,7 @@ #include #include +#include #include #include "internal.h" diff --git a/cpukit/libmisc/shell/main_perioduse.c b/cpukit/libmisc/shell/main_perioduse.c index 023e154cbc..6b74bb5f34 100644 --- a/cpukit/libmisc/shell/main_perioduse.c +++ b/cpukit/libmisc/shell/main_perioduse.c @@ -17,6 +17,7 @@ #include #include +#include #include #include "internal.h" diff --git a/cpukit/libmisc/shell/main_profreport.c b/cpukit/libmisc/shell/main_profreport.c index a98b8ba9aa..499e55d1aa 100644 --- a/cpukit/libmisc/shell/main_profreport.c +++ b/cpukit/libmisc/shell/main_profreport.c @@ -19,6 +19,7 @@ #include #include +#include #include #include diff --git a/cpukit/libmisc/shell/main_stackuse.c b/cpukit/libmisc/shell/main_stackuse.c index 40fc711f49..66ab863934 100644 --- a/cpukit/libmisc/shell/main_stackuse.c +++ b/cpukit/libmisc/shell/main_stackuse.c @@ -16,6 +16,7 @@ #include #include +#include #include #include #include "internal.h" diff --git a/cpukit/libmisc/shell/main_top.c b/cpukit/libmisc/shell/main_top.c index aea50d80fb..1596ff04ff 100644 --- a/cpukit/libmisc/shell/main_top.c +++ b/cpukit/libmisc/shell/main_top.c @@ -18,6 +18,7 @@ #include #include +#include #include #include "internal.h" diff --git a/cpukit/libmisc/stackchk/check.c b/cpukit/libmisc/stackchk/check.c index 39650f50e7..a4b606a0e3 100644 --- a/cpukit/libmisc/stackchk/check.c +++ b/cpukit/libmisc/stackchk/check.c @@ -40,6 +40,7 @@ #include #include +#include #include #include #include "internal.h" diff --git a/cpukit/libmisc/testsupport/test.h b/cpukit/libmisc/testsupport/test.h index ce5172fb95..94f917faec 100644 --- a/cpukit/libmisc/testsupport/test.h +++ b/cpukit/libmisc/testsupport/test.h @@ -16,7 +16,7 @@ #define _RTEMS_TEST_H #include -#include +#include #include #include diff --git a/cpukit/mghttpd/mongoose.c b/cpukit/mghttpd/mongoose.c index a89fc56885..3dd0d4baab 100644 --- a/cpukit/mghttpd/mongoose.c +++ b/cpukit/mghttpd/mongoose.c @@ -5520,7 +5520,7 @@ struct mg_context *mg_start(const struct mg_callbacks *callbacks, return ctx; } #ifdef __rtems__ -#include +#include static int mg_printer_plugin(void *context, const char *fmt, va_list ap) { return mg_vprintf(context, fmt, ap); diff --git a/cpukit/preinstall.am b/cpukit/preinstall.am index fdf2016ec5..5ba1ee4b97 100644 --- a/cpukit/preinstall.am +++ b/cpukit/preinstall.am @@ -228,6 +228,10 @@ $(PROJECT_INCLUDE)/rtems/print.h: include/rtems/print.h $(PROJECT_INCLUDE)/rtems $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/print.h PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/print.h +$(PROJECT_INCLUDE)/rtems/printer.h: include/rtems/printer.h $(PROJECT_INCLUDE)/rtems/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/printer.h +PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/printer.h + $(PROJECT_INCLUDE)/rtems/userenv.h: include/rtems/userenv.h $(PROJECT_INCLUDE)/rtems/$(dirstamp) $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/userenv.h PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/userenv.h diff --git a/cpukit/rtems/src/ratemonreportstatistics.c b/cpukit/rtems/src/ratemonreportstatistics.c index 3f264df487..a1bab4a2f8 100644 --- a/cpukit/rtems/src/ratemonreportstatistics.c +++ b/cpukit/rtems/src/ratemonreportstatistics.c @@ -20,7 +20,7 @@ #include #include -#include +#include #include diff --git a/cpukit/score/src/cpusetprintsupport.c b/cpukit/score/src/cpusetprintsupport.c index 83345d985c..13cffd9242 100644 --- a/cpukit/score/src/cpusetprintsupport.c +++ b/cpukit/score/src/cpusetprintsupport.c @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #ifdef __RTEMS_HAVE_SYS_CPUSET_H__ @@ -49,7 +49,7 @@ int i; rtems_printf(printer ,"%s: ", description); for(i=0; i<_NCPUWORDS; i++) - rtems_printf(printer ,"%x", cpuset->__bits[i]); + rtems_printf(printer ,"%" PRIx32 "", cpuset->__bits[i]); rtems_printf(printer ,"\n"); } diff --git a/testsuites/samples/hello/init.c b/testsuites/samples/hello/init.c index ea9af89940..acdabd8605 100644 --- a/testsuites/samples/hello/init.c +++ b/testsuites/samples/hello/init.c @@ -11,6 +11,7 @@ #include "config.h" #endif +#include #include #include /* for device driver prototypes */ -- cgit v1.2.3