13d8536b4Sopenharmony_ci/*
23d8536b4Sopenharmony_ci * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
33d8536b4Sopenharmony_ci * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
43d8536b4Sopenharmony_ci *
53d8536b4Sopenharmony_ci * Redistribution and use in source and binary forms, with or without modification,
63d8536b4Sopenharmony_ci * are permitted provided that the following conditions are met:
73d8536b4Sopenharmony_ci *
83d8536b4Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright notice, this list of
93d8536b4Sopenharmony_ci *    conditions and the following disclaimer.
103d8536b4Sopenharmony_ci *
113d8536b4Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright notice, this list
123d8536b4Sopenharmony_ci *    of conditions and the following disclaimer in the documentation and/or other materials
133d8536b4Sopenharmony_ci *    provided with the distribution.
143d8536b4Sopenharmony_ci *
153d8536b4Sopenharmony_ci * 3. Neither the name of the copyright holder nor the names of its contributors may be used
163d8536b4Sopenharmony_ci *    to endorse or promote products derived from this software without specific prior written
173d8536b4Sopenharmony_ci *    permission.
183d8536b4Sopenharmony_ci *
193d8536b4Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
203d8536b4Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
213d8536b4Sopenharmony_ci * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
223d8536b4Sopenharmony_ci * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
233d8536b4Sopenharmony_ci * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
243d8536b4Sopenharmony_ci * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
253d8536b4Sopenharmony_ci * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
263d8536b4Sopenharmony_ci * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
273d8536b4Sopenharmony_ci * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
283d8536b4Sopenharmony_ci * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
293d8536b4Sopenharmony_ci * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
303d8536b4Sopenharmony_ci */
313d8536b4Sopenharmony_ci
323d8536b4Sopenharmony_ci#ifndef _HWLITEOS_SHELL_H
333d8536b4Sopenharmony_ci#define _HWLITEOS_SHELL_H
343d8536b4Sopenharmony_ci
353d8536b4Sopenharmony_ci#include "pthread.h"
363d8536b4Sopenharmony_ci#include "limits.h"
373d8536b4Sopenharmony_ci#include "los_compiler.h"
383d8536b4Sopenharmony_ci
393d8536b4Sopenharmony_ci#ifdef __cplusplus
403d8536b4Sopenharmony_ci#if __cplusplus
413d8536b4Sopenharmony_ciextern "C" {
423d8536b4Sopenharmony_ci#endif /* __cplusplus */
433d8536b4Sopenharmony_ci#endif /* __cplusplus */
443d8536b4Sopenharmony_ci
453d8536b4Sopenharmony_ci#define OS_ERRNO_SHELL_NO_HOOK                  LOS_ERRNO_OS_ERROR(LOS_MOD_SHELL, 0x00)
463d8536b4Sopenharmony_ci#define OS_ERRNO_SHELL_CMDREG_PARA_ERROR        LOS_ERRNO_OS_ERROR(LOS_MOD_SHELL, 0x01)
473d8536b4Sopenharmony_ci#define OS_ERRNO_SHELL_CMDREG_CMD_ERROR         LOS_ERRNO_OS_ERROR(LOS_MOD_SHELL, 0x02)
483d8536b4Sopenharmony_ci#define OS_ERRNO_SHELL_CMDREG_CMD_EXIST         LOS_ERRNO_OS_ERROR(LOS_MOD_SHELL, 0x03)
493d8536b4Sopenharmony_ci#define OS_ERRNO_SHELL_CMDREG_MEMALLOC_ERROR    LOS_ERRNO_OS_ERROR(LOS_MOD_SHELL, 0x04)
503d8536b4Sopenharmony_ci#define OS_ERRNO_SHELL_SHOW_HOOK_NULL           LOS_ERRNO_OS_ERROR(LOS_MOD_SHELL, 0x05)
513d8536b4Sopenharmony_ci#define OS_ERRNO_SHELL_SHOW_HOOK_EXIST          LOS_ERRNO_OS_ERROR(LOS_MOD_SHELL, 0x06)
523d8536b4Sopenharmony_ci#define OS_ERRNO_SHELL_SHOW_HOOK_TOO_MUCH       LOS_ERRNO_OS_ERROR(LOS_MOD_SHELL, 0x07)
533d8536b4Sopenharmony_ci#define OS_ERRNO_SHELL_NOT_INIT                 LOS_ERRNO_OS_ERROR(LOS_MOD_SHELL, 0x08)
543d8536b4Sopenharmony_ci#define OS_ERRNO_SHELL_CMD_HOOK_NULL            LOS_ERRNO_OS_ERROR(LOS_MOD_SHELL, 0x09)
553d8536b4Sopenharmony_ci#define OS_ERRNO_SHELL_FIFO_ERROR               LOS_ERRNO_OS_ERROR(LOS_MOD_SHELL, 0x10)
563d8536b4Sopenharmony_ci
573d8536b4Sopenharmony_ci/* Max len of show str */
583d8536b4Sopenharmony_ci#define SHOW_MAX_LEN CMD_MAX_LEN
593d8536b4Sopenharmony_ci
603d8536b4Sopenharmony_ci#define XARGS 0xFFFFFFFF /* default args */
613d8536b4Sopenharmony_ci
623d8536b4Sopenharmony_ci#define CMD_MAX_PARAS           32
633d8536b4Sopenharmony_ci#define CMD_KEY_LEN             16U
643d8536b4Sopenharmony_ci#define CMD_MAX_LEN             (256U + CMD_KEY_LEN)
653d8536b4Sopenharmony_ci#define CMD_KEY_NUM             32
663d8536b4Sopenharmony_ci#define CMD_HISTORY_LEN         10
673d8536b4Sopenharmony_ci#define CMD_MAX_PATH            256
683d8536b4Sopenharmony_ci#define DEFAULT_SCREEN_WIDTH    80
693d8536b4Sopenharmony_ci#define DEFAULT_SCREEN_HEIGNT   24
703d8536b4Sopenharmony_ci
713d8536b4Sopenharmony_ci#define SHELL_MODE              0
723d8536b4Sopenharmony_ci#define OTHER_MODE              1
733d8536b4Sopenharmony_ci
743d8536b4Sopenharmony_ci#define SWITCH_QUOTES_STATUS(qu) do {   \
753d8536b4Sopenharmony_ci    if ((qu) == TRUE) {                 \
763d8536b4Sopenharmony_ci        (qu) = FALSE;                   \
773d8536b4Sopenharmony_ci    } else {                            \
783d8536b4Sopenharmony_ci        (qu) = TRUE;                    \
793d8536b4Sopenharmony_ci    }                                   \
803d8536b4Sopenharmony_ci} while (0)
813d8536b4Sopenharmony_ci
823d8536b4Sopenharmony_ci#define QUOTES_STATUS_CLOSE(qu) ((qu) == FALSE)
833d8536b4Sopenharmony_ci#define QUOTES_STATUS_OPEN(qu)  ((qu) == TRUE)
843d8536b4Sopenharmony_ci
853d8536b4Sopenharmony_citypedef struct {
863d8536b4Sopenharmony_ci    UINT32   consoleID;
873d8536b4Sopenharmony_ci    UINT32   shellTaskHandle;
883d8536b4Sopenharmony_ci    UINT32   shellEntryHandle;
893d8536b4Sopenharmony_ci    VOID     *cmdKeyLink;
903d8536b4Sopenharmony_ci    VOID     *cmdHistoryKeyLink;
913d8536b4Sopenharmony_ci    VOID     *cmdMaskKeyLink;
923d8536b4Sopenharmony_ci    UINT32   shellBufOffset;
933d8536b4Sopenharmony_ci    UINT32   shellKeyType;
943d8536b4Sopenharmony_ci    pthread_mutex_t keyMutex;
953d8536b4Sopenharmony_ci    pthread_mutex_t historyMutex;
963d8536b4Sopenharmony_ci    CHAR     shellBuf[SHOW_MAX_LEN];
973d8536b4Sopenharmony_ci    CHAR     shellWorkingDirectory[PATH_MAX];
983d8536b4Sopenharmony_ci} ShellCB;
993d8536b4Sopenharmony_ci
1003d8536b4Sopenharmony_ci/* All support cmd types */
1013d8536b4Sopenharmony_citypedef enum {
1023d8536b4Sopenharmony_ci    CMD_TYPE_SHOW = 0,
1033d8536b4Sopenharmony_ci    CMD_TYPE_STD = 1,
1043d8536b4Sopenharmony_ci    CMD_TYPE_EX = 2,
1053d8536b4Sopenharmony_ci    CMD_TYPE_BUTT
1063d8536b4Sopenharmony_ci} CmdType;
1073d8536b4Sopenharmony_ci
1083d8536b4Sopenharmony_citypedef enum {
1093d8536b4Sopenharmony_ci    CMD_KEY_UP = 0,
1103d8536b4Sopenharmony_ci    CMD_KEY_DOWN = 1,
1113d8536b4Sopenharmony_ci    CMD_KEY_RIGHT = 2,
1123d8536b4Sopenharmony_ci    CMD_KEY_LEFT = 4,
1133d8536b4Sopenharmony_ci    CMD_KEY_BUTT
1143d8536b4Sopenharmony_ci} CmdKeyDirection;
1153d8536b4Sopenharmony_ci
1163d8536b4Sopenharmony_ci/*
1173d8536b4Sopenharmony_ci * Hook for user-defined debug function
1183d8536b4Sopenharmony_ci * Unify different module's func for registration
1193d8536b4Sopenharmony_ci */
1203d8536b4Sopenharmony_citypedef UINT32 (*CmdCallBackFunc)(UINT32 argc, const CHAR **argv);
1213d8536b4Sopenharmony_ci
1223d8536b4Sopenharmony_ci/* External interface, need reserved */
1233d8536b4Sopenharmony_citypedef CmdCallBackFunc CMD_CBK_FUNC;
1243d8536b4Sopenharmony_citypedef CmdType CMD_TYPE_E;
1253d8536b4Sopenharmony_ci
1263d8536b4Sopenharmony_ciextern UINT32 osCmdReg(CmdType cmdType, const CHAR *cmdKey, UINT32 paraNum, CmdCallBackFunc cmdProc);
1273d8536b4Sopenharmony_ci
1283d8536b4Sopenharmony_ci#ifdef __cplusplus
1293d8536b4Sopenharmony_ci#if __cplusplus
1303d8536b4Sopenharmony_ci}
1313d8536b4Sopenharmony_ci#endif /* __cplusplus */
1323d8536b4Sopenharmony_ci#endif /* __cplusplus */
1333d8536b4Sopenharmony_ci
1343d8536b4Sopenharmony_ci#endif /* _HWLITEOS_SHELL_H */
135