source: rtems/cpukit/include/rtems/stdio-redirect.h @ 2aa5b98

5
Last change on this file since 2aa5b98 was 2afb22b, checked in by Chris Johns <chrisj@…>, on 12/23/17 at 07:18:56

Remove make preinstall

A speciality of the RTEMS build system was the make preinstall step. It
copied header files from arbitrary locations into the build tree. The
header files were included via the -Bsome/build/tree/path GCC command
line option.

This has at least seven problems:

  • The make preinstall step itself needs time and disk space.
  • Errors in header files show up in the build tree copy. This makes it hard for editors to open the right file to fix the error.
  • There is no clear relationship between source and build tree header files. This makes an audit of the build process difficult.
  • The visibility of all header files in the build tree makes it difficult to enforce API barriers. For example it is discouraged to use BSP-specifics in the cpukit.
  • An introduction of a new build system is difficult.
  • Include paths specified by the -B option are system headers. This may suppress warnings.
  • The parallel build had sporadic failures on some hosts.

This patch removes the make preinstall step. All installed header
files are moved to dedicated include directories in the source tree.
Let @RTEMS_CPU@ be the target architecture, e.g. arm, powerpc, sparc,
etc. Let @RTEMS_BSP_FAMILIY@ be a BSP family base directory, e.g.
erc32, imx, qoriq, etc.

The new cpukit include directories are:

  • cpukit/include
  • cpukit/score/cpu/@RTEMS_CPU@/include
  • cpukit/libnetworking

The new BSP include directories are:

  • bsps/include
  • bsps/@RTEMS_CPU@/include
  • bsps/@RTEMS_CPU@/@RTEMS_BSP_FAMILIY@/include

There are build tree include directories for generated files.

The include directory order favours the most general header file, e.g.
it is not possible to override general header files via the include path
order.

The "bootstrap -p" option was removed. The new "bootstrap -H" option
should be used to regenerate the "headers.am" files.

Update #3254.

  • Property mode set to 100644
File size: 4.3 KB
Line 
1/*
2 * Copyright (C) 2014 Chris Johns (chrisj@rtems.org)
3 *
4 * The license and distribution terms for this file may be
5 * found in the file LICENSE in this distribution.
6 *
7 * This software with is provided ``as is'' and with NO WARRANTY.
8 */
9
10/*
11 * @brief Redirect an stdio file decriptor.
12 *
13 * The is a helper module of code design to redirect an stdio file
14 * descriptor. You can optionally have the data buffered and/or you can provide
15 * a handler function that is called when data arrives.
16 *
17 * The module uses standard POSIX calls to implement the redirection and if the
18 * threading was POSIX based the code would be portable. Currently the code
19 * uses RTEMS threads.
20 *
21 * Redirecting stderr and stdout is useful in embedded system because you can
22 * transport the output off your device or create a web interface that can
23 * display the output. This can be a very powerful diagnostic and support tool.
24 *
25 * The implementation does:
26 *
27 *  1. Duplicate the file descriptor (fd) to redirect using the dup call. The
28 *     duplicated desciptor is used to echo the output out the existing path.
29 *
30 *  2. Create a pipe using the pipe call.
31 *
32 *  3. Duplicate the pipe's writer file descriptor to user's file
33 *     descriptor. This results in any writes to the user's fd being written to
34 *     the pipe.
35 *
36 *  4. Create a reader task that blocks on the pipe. It optionally calls a
37 *     handler and if configured buffers the data.
38 */
39
40#if !defined(RTEMS_STDIO_REDIRECT_H)
41#define RTEMS_STDIO_REDIRECT_H
42
43#include <stdbool.h>
44#include <rtems.h>
45
46#ifdef __cplusplus
47extern "C" {
48#endif /* __cplusplus */
49
50/*
51 * Handler called whenever redirected data arrives.
52 *
53 * @param buffer The data.
54 * @param length The amount of data in the buffer.
55 */
56typedef void (*rtems_stdio_redirect_handler)(const char* buffer,
57                                             ssize_t     length);
58
59/*
60 * Redirector data.
61 */
62typedef struct
63{
64  volatile uint32_t            state;       /**< The state. */
65  rtems_id                     reader;      /**< The reader thread. */
66  rtems_id                     lock;        /**< Lock for this struct. */
67  int                          fd;          /**< The file descriptor to redirect. */
68  int                          fd_dup;      /**< Duplicated fd to write to. */
69  int                          pipe[2];     /**< The pipe to the reader thread. */
70  char*                        input;       /**< The input buffer the reader uses. */
71  ssize_t                      input_size;  /**< The input buffer size. */
72  char*                        buffer;      /**< Captured redirected data. */
73  ssize_t                      buffer_size; /**< Capture buffer size. */
74  ssize_t                      in;          /**< Buffer in index. */
75  bool                         full;        /**< The buffer is full. */
76  bool                         echo;        /**< Echo the data out the existing path. */
77  rtems_stdio_redirect_handler handler;     /**< Redirected data handler. */
78} rtems_stdio_redirect;
79
80/*
81 * Open a redirector returning the handle to it.
82 *
83 * @param fd The file descriptor to redirect.
84 * @param priority The priority of the reader thread.
85 */
86rtems_stdio_redirect* rtems_stdio_redirect_open(int                          fd,
87                                                rtems_task_priority          priority,
88                                                size_t                       stack_size,
89                                                ssize_t                      input_size,
90                                                ssize_t                      buffer_size,
91                                                bool                         echo,
92                                                rtems_stdio_redirect_handler handler);
93
94/*
95 * Close the redirector.
96 */
97void rtems_stdio_redirect_close(rtems_stdio_redirect* sr);
98
99/*
100 * Get data from the capture buffer. Data read is removed from the buffer.
101 *
102 * @param sr The stdio redirection handle.
103 * @param buffer The buffer data is written into.
104 * @param length The size of the buffer.
105 * @return ssize_t The amount of data written and -1 or an error.
106 */
107ssize_t rtems_stdio_redirect_read(rtems_stdio_redirect* sr,
108                                  char*                 buffer,
109                                  ssize_t               length);
110
111#ifdef __cplusplus
112}
113#endif /* __cplusplus */
114
115#endif
Note: See TracBrowser for help on using the repository browser.