1/*
2Copyright (c) 2012, Broadcom Europe Ltd
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12 * Neither the name of the copyright holder nor the
13 names of its contributors may be used to endorse or promote products
14 derived from this software without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27
28#if !defined( VCOS_CMD_H )
29#define VCOS_CMD_H
30
31/* ---- Include Files ----------------------------------------------------- */
32
33#ifndef VCOS_H
34#include "interface/vcos/vcos.h"
35#endif
36#include "interface/vcos/vcos_stdint.h"
37
38
39/* ---- Constants and Types ---------------------------------------------- */
40
41struct VCOS_CMD_S;
42typedef struct VCOS_CMD_S VCOS_CMD_T;
43
44typedef struct
45{
46 int argc; /* Number of arguments (includes the command/sub-command) */
47 char **argv; /* Array of arguments */
48 char **argv_orig; /* Original array of arguments */
49
50 VCOS_CMD_T *cmd_entry;
51 VCOS_CMD_T *cmd_parent_entry;
52
53 int use_log; /* Output being logged? */
54 size_t result_size; /* Size of result buffer. */
55 char *result_ptr; /* Next place to put output. */
56 char *result_buf; /* Start of the buffer. */
57
58} VCOS_CMD_PARAM_T;
59
60typedef VCOS_STATUS_T (*VCOS_CMD_FUNC_T)( VCOS_CMD_PARAM_T *param );
61
62struct VCOS_CMD_S
63{
64 const char *name;
65 const char *args;
66 VCOS_CMD_FUNC_T cmd_fn;
67 VCOS_CMD_T *sub_cmd_entry;
68 const char *descr;
69
70};
71
72/* ---- Variable Externs ------------------------------------------------- */
73
74/* ---- Function Prototypes ---------------------------------------------- */
75
76/*
77 * Common printing routine for generating command output.
78 */
79VCOSPRE_ void VCOSPOST_ vcos_cmd_error( VCOS_CMD_PARAM_T *param, const char *fmt, ... ) VCOS_FORMAT_ATTR_(printf, 2, 3);
80VCOSPRE_ void VCOSPOST_ vcos_cmd_printf( VCOS_CMD_PARAM_T *param, const char *fmt, ... ) VCOS_FORMAT_ATTR_(printf, 2, 3);
81VCOSPRE_ void VCOSPOST_ vcos_cmd_vprintf( VCOS_CMD_PARAM_T *param, const char *fmt, va_list args ) VCOS_FORMAT_ATTR_(printf, 2, 0);
82
83/*
84 * Cause vcos_cmd_error, printf and vprintf to always log to the provided
85 * category. When this call is made, the results buffer passed into
86 * vcos_cmd_execute is used as a line buffer and does not need to be
87 * output by the caller.
88 */
89struct VCOS_LOG_CAT_T;
90VCOSPRE_ void VCOSPOST_ vcos_cmd_always_log_output( struct VCOS_LOG_CAT_T *log_category );
91
92/*
93 * Prints command usage for the current command.
94 */
95VCOSPRE_ void VCOSPOST_ vcos_cmd_usage( VCOS_CMD_PARAM_T *param );
96
97/*
98 * Register commands to be processed
99 */
100VCOSPRE_ VCOS_STATUS_T VCOSPOST_ vcos_cmd_register( VCOS_CMD_T *cmd_entry );
101
102/*
103 * Registers multiple commands to be processed. The array should
104 * be terminated by an entry with all zeros.
105 */
106VCOSPRE_ VCOS_STATUS_T VCOSPOST_ vcos_cmd_register_multiple( VCOS_CMD_T *cmd_entry );
107
108/*
109 * Executes a command based on a command line.
110 */
111VCOSPRE_ VCOS_STATUS_T VCOSPOST_ vcos_cmd_execute( int argc, char **argv, size_t result_size, char *result_buf );
112
113/*
114 * Shut down the command system and free all allocated data.
115 * Do not call any other command functions after this.
116 */
117VCOSPRE_ void VCOSPOST_ vcos_cmd_shutdown( void );
118
119#endif /* VCOS_CMD_H */
120
121