Line data Source code
1 0 : /*
2 : * Copyright (c) 2023 Meta
3 : *
4 : * SPDX-License-Identifier: Apache-2.0
5 : */
6 :
7 : #ifndef ZEPHYR_INCLUDE_SHELL_BACKEND_H_
8 : #define ZEPHYR_INCLUDE_SHELL_BACKEND_H_
9 :
10 : #include <zephyr/types.h>
11 : #include <zephyr/shell/shell.h>
12 : #include <zephyr/sys/iterable_sections.h>
13 :
14 : #ifdef __cplusplus
15 : extern "C" {
16 : #endif
17 :
18 : /**
19 : * @brief Get backend.
20 : *
21 : * @param[in] idx Pointer to the backend instance.
22 : *
23 : * @return Pointer to the backend instance.
24 : */
25 1 : static inline const struct shell *shell_backend_get(uint32_t idx)
26 : {
27 : const struct shell *backend;
28 :
29 : STRUCT_SECTION_GET(shell, idx, &backend);
30 :
31 : return backend;
32 : }
33 :
34 : /**
35 : * @brief Get number of backends.
36 : *
37 : * @return Number of backends.
38 : */
39 1 : static inline int shell_backend_count_get(void)
40 : {
41 : int cnt;
42 :
43 : STRUCT_SECTION_COUNT(shell, &cnt);
44 :
45 : return cnt;
46 : }
47 :
48 : /**
49 : * @brief Get backend by name.
50 : *
51 : * @param[in] backend_name Name of the backend as defined by the SHELL_DEFINE.
52 : *
53 : * @retval Pointer to the backend instance if found, NULL if backend is not found.
54 : */
55 1 : const struct shell *shell_backend_get_by_name(const char *backend_name);
56 :
57 : #ifdef __cplusplus
58 : }
59 : #endif
60 :
61 : #endif /* ZEPHYR_INCLUDE_SHELL_BACKEND_H_ */
|