1 /* 2 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. 3 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without modification, 6 * are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this list of 9 * conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 * of conditions and the following disclaimer in the documentation and/or other materials 13 * provided with the distribution. 14 * 15 * 3. Neither the name of the copyright holder nor the names of its contributors may be used 16 * to endorse or promote products derived from this software without specific prior written 17 * permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #ifndef _HWLITEOS_SHELL_H 33 #define _HWLITEOS_SHELL_H 34 35 #include "pthread.h" 36 #include "limits.h" 37 #include "los_base.h" 38 #include "los_event.h" 39 40 #ifdef __cplusplus 41 #if __cplusplus 42 extern "C" { 43 #endif /* __cplusplus */ 44 #endif /* __cplusplus */ 45 46 #define OS_ERRNO_SHELL_NO_HOOK LOS_ERRNO_OS_ERROR(LOS_MOD_SHELL, 0x00) 47 #define OS_ERRNO_SHELL_CMDREG_PARA_ERROR LOS_ERRNO_OS_ERROR(LOS_MOD_SHELL, 0x01) 48 #define OS_ERRNO_SHELL_CMDREG_CMD_ERROR LOS_ERRNO_OS_ERROR(LOS_MOD_SHELL, 0x02) 49 #define OS_ERRNO_SHELL_CMDREG_CMD_EXIST LOS_ERRNO_OS_ERROR(LOS_MOD_SHELL, 0x03) 50 #define OS_ERRNO_SHELL_CMDREG_MEMALLOC_ERROR LOS_ERRNO_OS_ERROR(LOS_MOD_SHELL, 0x04) 51 #define OS_ERRNO_SHELL_SHOW_HOOK_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_SHELL, 0x05) 52 #define OS_ERRNO_SHELL_SHOW_HOOK_EXIST LOS_ERRNO_OS_ERROR(LOS_MOD_SHELL, 0x06) 53 #define OS_ERRNO_SHELL_SHOW_HOOK_TOO_MUCH LOS_ERRNO_OS_ERROR(LOS_MOD_SHELL, 0x07) 54 #define OS_ERRNO_SHELL_NOT_INIT LOS_ERRNO_OS_ERROR(LOS_MOD_SHELL, 0x08) 55 #define OS_ERRNO_SHELL_CMD_HOOK_NULL LOS_ERRNO_OS_ERROR(LOS_MOD_SHELL, 0x09) 56 #define OS_ERRNO_SHELL_FIFO_ERROR LOS_ERRNO_OS_ERROR(LOS_MOD_SHELL, 0x10) 57 58 /* Max len of show str */ 59 #define SHOW_MAX_LEN CMD_MAX_LEN 60 61 #define XARGS 0xFFFFFFFF /* default args */ 62 63 #define CMD_MAX_PARAS 32 64 #define CMD_KEY_LEN 16U 65 #define CMD_MAX_LEN (256U + CMD_KEY_LEN) 66 #define CMD_KEY_NUM 32 67 #define CMD_HISTORY_LEN 10 68 #define CMD_MAX_PATH 256 69 #define DEFAULT_SCREEN_WIDTH 80 70 #define DEFAULT_SCREEN_HEIGHT 24 71 72 #define SHELL_MODE 0 73 #define OTHER_MODE 1 74 75 #define SWITCH_QUOTES_STATUS(qu) do { \ 76 if ((qu) == TRUE) { \ 77 (qu) = FALSE; \ 78 } else { \ 79 (qu) = TRUE; \ 80 } \ 81 } while (0) 82 83 #define QUOTES_STATUS_CLOSE(qu) ((qu) == FALSE) 84 #define QUOTES_STATUS_OPEN(qu) ((qu) == TRUE) 85 86 typedef struct { 87 UINT32 consoleID; 88 UINT32 shellTaskHandle; 89 UINT32 shellEntryHandle; 90 VOID *cmdKeyLink; 91 VOID *cmdHistoryKeyLink; 92 VOID *cmdMaskKeyLink; 93 UINT32 shellBufOffset; 94 UINT32 shellKeyType; 95 EVENT_CB_S shellEvent; 96 pthread_mutex_t keyMutex; 97 pthread_mutex_t historyMutex; 98 CHAR shellBuf[SHOW_MAX_LEN]; 99 CHAR shellWorkingDirectory[PATH_MAX]; 100 } ShellCB; 101 102 /* All support cmd types */ 103 typedef enum { 104 CMD_TYPE_SHOW = 0, 105 CMD_TYPE_STD = 1, 106 CMD_TYPE_EX = 2, 107 CMD_TYPE_BUTT 108 } CmdType; 109 110 typedef enum { 111 CMD_KEY_UP = 0, 112 CMD_KEY_DOWN = 1, 113 CMD_KEY_RIGHT = 2, 114 CMD_KEY_LEFT = 4, 115 CMD_KEY_BUTT 116 } CmdKeyDirection; 117 118 /* 119 * Hook for user-defined debug function 120 * Unify different module's func for registration 121 */ 122 typedef UINT32 (*CmdCallBackFunc)(UINT32 argc, const CHAR **argv); 123 124 /* External interface, need reserved */ 125 typedef CmdCallBackFunc CMD_CBK_FUNC; 126 typedef CmdType CMD_TYPE_E; 127 128 extern UINT32 osCmdReg(CmdType cmdType, const CHAR *cmdKey, UINT32 paraNum, CmdCallBackFunc cmdProc); 129 130 #ifdef __cplusplus 131 #if __cplusplus 132 } 133 #endif /* __cplusplus */ 134 #endif /* __cplusplus */ 135 136 #endif /* _HWLITEOS_SHELL_H */ 137