[rtems commit] Move printer initialization to separate header

Sebastian Huber sebh at rtems.org
Wed Jun 22 05:46:10 UTC 2016


Module:    rtems
Branch:    master
Commit:    506bfc8580c365c48f2200772ddd0985e661ae34
Changeset: http://git.rtems.org/rtems/commit/?id=506bfc8580c365c48f2200772ddd0985e661ae34

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Tue Jun 21 13:30:15 2016 +0200

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 <stdio.h> include which
would be visible via <rtems.h>.

---

 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(-)

diff --git a/c/src/lib/libbsp/shared/src/irq-info.c b/c/src/lib/libbsp/shared/src/irq-info.c
index f5f2323..ef965d3 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 <inttypes.h>
 
-#include <rtems/print.h>
+#include <rtems/printer.h>
 
 #include <bsp/irq-generic.h>
 #include <bsp/irq-info.h>
diff --git a/c/src/lib/libbsp/shared/src/irq-shell.c b/c/src/lib/libbsp/shared/src/irq-shell.c
index 512594c..ca936f8 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 <stdio.h>
 
+#include <rtems/printer.h>
 #include <rtems/shell.h>
 
 #include <bsp/irq-info.h>
diff --git a/cpukit/Makefile.am b/cpukit/Makefile.am
index aa1111e..ac97530 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 07e50d0..2fd744e 100644
--- a/cpukit/include/rtems/print.h
+++ b/cpukit/include/rtems/print.h
@@ -21,53 +21,21 @@
 #include <rtems/score/basedefs.h>
 
 #include <stdarg.h>
-#include <stdio.h>
 
 #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 0000000..2ed6b6a
--- /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 <chrisj at 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_PRINTER_H
+#define _RTEMS_PRINTER_H
+
+#include <rtems/print.h>
+
+#include <stdio.h>
+
+#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 3ff80f7..43ff478 100644
--- a/cpukit/libcsupport/src/print_fprintf.c
+++ b/cpukit/libcsupport/src/print_fprintf.c
@@ -18,9 +18,7 @@
   #include "config.h"
 #endif
 
-#include <rtems/print.h>
-
-#include <stdio.h>
+#include <rtems/printer.h>
 
 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 c869523..c9b273a 100644
--- a/cpukit/libcsupport/src/print_printf.c
+++ b/cpukit/libcsupport/src/print_printf.c
@@ -18,9 +18,7 @@
   #include "config.h"
 #endif
 
-#include <rtems/print.h>
-
-#include <stdio.h>
+#include <rtems/printer.h>
 
 int rtems_vprintf(
   const rtems_printer *printer,
diff --git a/cpukit/libcsupport/src/printf_plugin.c b/cpukit/libcsupport/src/printf_plugin.c
index 23ac9f6..d8da6a0 100644
--- a/cpukit/libcsupport/src/printf_plugin.c
+++ b/cpukit/libcsupport/src/printf_plugin.c
@@ -23,9 +23,7 @@
   #include "config.h"
 #endif
 
-#include <rtems/print.h>
-
-#include <stdio.h>
+#include <rtems/printer.h>
 
 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 38214f8..3b4a911 100644
--- a/cpukit/libcsupport/src/printk_plugin.c
+++ b/cpukit/libcsupport/src/printk_plugin.c
@@ -18,7 +18,7 @@
 #include "config.h"
 #endif
 
-#include <rtems/print.h>
+#include <rtems/printer.h>
 #include <rtems/bspIo.h>
 
 static int printk_plugin(
diff --git a/cpukit/libdl/rap.c b/cpukit/libdl/rap.c
index 4e07c54..87b3bc3 100644
--- a/cpukit/libdl/rap.c
+++ b/cpukit/libdl/rap.c
@@ -19,6 +19,7 @@
 #include "config.h"
 #endif
 
+#include <stdarg.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
diff --git a/cpukit/libmisc/cpuuse/cpuusagereport.c b/cpukit/libmisc/cpuuse/cpuusagereport.c
index 2a6eaf3..370eb05 100644
--- a/cpukit/libmisc/cpuuse/cpuusagereport.c
+++ b/cpukit/libmisc/cpuuse/cpuusagereport.c
@@ -25,6 +25,7 @@
 #include <inttypes.h>
 
 #include <rtems/cpuuse.h>
+#include <rtems/printer.h>
 #include <rtems/score/objectimpl.h>
 #include <rtems/score/threadimpl.h>
 #include <rtems/score/todimpl.h>
diff --git a/cpukit/libmisc/cpuuse/cpuusagetop.c b/cpukit/libmisc/cpuuse/cpuusagetop.c
index e300ee7..aa2b74c 100644
--- a/cpukit/libmisc/cpuuse/cpuusagetop.c
+++ b/cpukit/libmisc/cpuuse/cpuusagetop.c
@@ -32,6 +32,7 @@
 #include <inttypes.h>
 
 #include <rtems/cpuuse.h>
+#include <rtems/printer.h>
 #include <rtems/malloc.h>
 #include <rtems/score/objectimpl.h>
 #include <rtems/score/protectedheap.h>
diff --git a/cpukit/libmisc/fb/mw_print.c b/cpukit/libmisc/fb/mw_print.c
index 25a3456..c04f5a2 100644
--- a/cpukit/libmisc/fb/mw_print.c
+++ b/cpukit/libmisc/fb/mw_print.c
@@ -21,6 +21,7 @@
 #include <stdio.h>
 
 #include <rtems/mw_uid.h>
+#include <rtems/printer.h>
 
 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 d814df6..69548cf 100644
--- a/cpukit/libmisc/shell/main_blkstats.c
+++ b/cpukit/libmisc/shell/main_blkstats.c
@@ -17,6 +17,7 @@
 #endif
 
 #include <rtems/blkdev.h>
+#include <rtems/printer.h>
 #include <rtems/shellconfig.h>
 
 #include <string.h>
diff --git a/cpukit/libmisc/shell/main_cpuinfo.c b/cpukit/libmisc/shell/main_cpuinfo.c
index c5bc9a3..9245c0f 100644
--- a/cpukit/libmisc/shell/main_cpuinfo.c
+++ b/cpukit/libmisc/shell/main_cpuinfo.c
@@ -19,6 +19,7 @@
 #include <rtems/shell.h>
 #include <rtems/shellconfig.h>
 #include <rtems/cpuuse.h>
+#include <rtems/printer.h>
 
 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 190fd03..726d907 100644
--- a/cpukit/libmisc/shell/main_cpuuse.c
+++ b/cpukit/libmisc/shell/main_cpuuse.c
@@ -18,6 +18,7 @@
 
 #include <rtems.h>
 #include <rtems/cpuuse.h>
+#include <rtems/printer.h>
 #include <rtems/shell.h>
 #include "internal.h"
 
diff --git a/cpukit/libmisc/shell/main_perioduse.c b/cpukit/libmisc/shell/main_perioduse.c
index 023e154..6b74bb5 100644
--- a/cpukit/libmisc/shell/main_perioduse.c
+++ b/cpukit/libmisc/shell/main_perioduse.c
@@ -17,6 +17,7 @@
 #include <string.h>
 
 #include <rtems.h>
+#include <rtems/printer.h>
 #include <rtems/shell.h>
 #include "internal.h"
 
diff --git a/cpukit/libmisc/shell/main_profreport.c b/cpukit/libmisc/shell/main_profreport.c
index a98b8ba..499e55d 100644
--- a/cpukit/libmisc/shell/main_profreport.c
+++ b/cpukit/libmisc/shell/main_profreport.c
@@ -19,6 +19,7 @@
 #include <stdio.h>
 
 #include <rtems/profiling.h>
+#include <rtems/printer.h>
 #include <rtems/shell.h>
 #include <rtems/shellconfig.h>
 
diff --git a/cpukit/libmisc/shell/main_stackuse.c b/cpukit/libmisc/shell/main_stackuse.c
index 40fc711..66ab863 100644
--- a/cpukit/libmisc/shell/main_stackuse.c
+++ b/cpukit/libmisc/shell/main_stackuse.c
@@ -16,6 +16,7 @@
 #include <stdio.h>
 
 #include <rtems.h>
+#include <rtems/printer.h>
 #include <rtems/stackchk.h>
 #include <rtems/shell.h>
 #include "internal.h"
diff --git a/cpukit/libmisc/shell/main_top.c b/cpukit/libmisc/shell/main_top.c
index aea50d8..1596ff0 100644
--- a/cpukit/libmisc/shell/main_top.c
+++ b/cpukit/libmisc/shell/main_top.c
@@ -18,6 +18,7 @@
 
 #include <rtems.h>
 #include <rtems/cpuuse.h>
+#include <rtems/printer.h>
 #include <rtems/shell.h>
 #include "internal.h"
 
diff --git a/cpukit/libmisc/stackchk/check.c b/cpukit/libmisc/stackchk/check.c
index 39650f5..a4b606a 100644
--- a/cpukit/libmisc/stackchk/check.c
+++ b/cpukit/libmisc/stackchk/check.c
@@ -40,6 +40,7 @@
 #include <stdlib.h>
 
 #include <rtems/bspIo.h>
+#include <rtems/printer.h>
 #include <rtems/stackchk.h>
 #include <rtems/score/percpu.h>
 #include "internal.h"
diff --git a/cpukit/libmisc/testsupport/test.h b/cpukit/libmisc/testsupport/test.h
index ce5172f..94f917f 100644
--- a/cpukit/libmisc/testsupport/test.h
+++ b/cpukit/libmisc/testsupport/test.h
@@ -16,7 +16,7 @@
 #define _RTEMS_TEST_H
 
 #include <rtems.h>
-#include <rtems/print.h>
+#include <rtems/printer.h>
 #include <rtems/score/atomic.h>
 #include <rtems/score/smpbarrier.h>
 
diff --git a/cpukit/mghttpd/mongoose.c b/cpukit/mghttpd/mongoose.c
index a89fc56..3dd0d4b 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 <rtems/print.h>
+#include <rtems/printer.h>
 
 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 fdf2016..5ba1ee4 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 3f264df..a1bab4a 100644
--- a/cpukit/rtems/src/ratemonreportstatistics.c
+++ b/cpukit/rtems/src/ratemonreportstatistics.c
@@ -20,7 +20,7 @@
 
 #include <rtems/rtems/ratemonimpl.h>
 #include <rtems/rtems/object.h>
-#include <rtems/print.h>
+#include <rtems/printer.h>
 
 #include <inttypes.h>
 
diff --git a/cpukit/score/src/cpusetprintsupport.c b/cpukit/score/src/cpusetprintsupport.c
index 83345d9..13cffd9 100644
--- a/cpukit/score/src/cpusetprintsupport.c
+++ b/cpukit/score/src/cpusetprintsupport.c
@@ -23,7 +23,7 @@
 #include <stdio.h>
 #include <ctype.h>
 #include <inttypes.h>
-#include <rtems/print.h>
+#include <rtems/printer.h>
 #include <rtems/score/cpusetimpl.h>
 
 #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 ea9af89..acdabd8 100644
--- a/testsuites/samples/hello/init.c
+++ b/testsuites/samples/hello/init.c
@@ -11,6 +11,7 @@
 #include "config.h"
 #endif
 
+#include <rtems/printer.h>
 #include <rtems/test.h>
 
 #include <bsp.h> /* for device driver prototypes */



More information about the vc mailing list