zephyr/include/zephyr/shell/shell_fprintf.h
Gerard Marull-Paretas 79e6b0e0f6 includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.

The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.

NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-09-05 16:31:47 +02:00

84 lines
1.9 KiB
C

/*
* Copyright (c) 2018 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef SHELL_FPRINTF_H__
#define SHELL_FPRINTF_H__
#include <zephyr/kernel.h>
#include <stdbool.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef void (*shell_fprintf_fwrite)(const void *user_ctx,
const char *data,
size_t length);
struct shell_fprintf_control_block {
size_t buffer_cnt;
bool autoflush;
};
/**
* @brief fprintf context
*/
struct shell_fprintf {
uint8_t *buffer;
size_t buffer_size;
shell_fprintf_fwrite fwrite;
const void *user_ctx;
struct shell_fprintf_control_block *ctrl_blk;
};
/**
* @brief Macro for defining shell_fprintf instance.
*
* @param _name Instance name.
* @param _user_ctx Pointer to user data.
* @param _buf Pointer to output buffer
* @param _size Size of output buffer.
* @param _autoflush Indicator if buffer shall be automatically flush.
* @param _fwrite Pointer to function sending data stream.
*/
#define Z_SHELL_FPRINTF_DEFINE(_name, _user_ctx, _buf, _size, \
_autoflush, _fwrite) \
static struct shell_fprintf_control_block \
_name##_shell_fprintf_ctx = { \
.autoflush = _autoflush, \
.buffer_cnt = 0 \
}; \
static const struct shell_fprintf _name = { \
.buffer = _buf, \
.buffer_size = _size, \
.fwrite = _fwrite, \
.user_ctx = _user_ctx, \
.ctrl_blk = &_name##_shell_fprintf_ctx \
}
/**
* @brief fprintf like function which send formatted data stream to output.
*
* @param sh_fprintf fprintf instance.
* @param fmt Format string.
* @param args List of parameters to print.
*/
void z_shell_fprintf_fmt(const struct shell_fprintf *sh_fprintf,
char const *fmt, va_list args);
/**
* @brief function flushing data stored in io_buffer.
*
* @param sh_fprintf fprintf instance
*/
void z_shell_fprintf_buffer_flush(const struct shell_fprintf *sh_fprintf);
#ifdef __cplusplus
}
#endif
#endif /* SHELL_FPRINTF_H__ */