Skip to content

File wsh_shell.h

File List > src > wsh_shell.h

Go to the documentation of this file

#ifndef __WSH_SHELL_H
#define __WSH_SHELL_H

#include "wsh_shell_autocomplete.h"
#include "wsh_shell_cfg.h"
#include "wsh_shell_cmd.h"
#include "wsh_shell_cmd_def.h"
#include "wsh_shell_esc.h"
#include "wsh_shell_history.h"
#include "wsh_shell_interact.h"
#include "wsh_shell_io.h"
#include "wsh_shell_misc.h"
#include "wsh_shell_promptwait.h"
#include "wsh_shell_ps1_custom.h"
#include "wsh_shell_session.h"
#include "wsh_shell_str.h"
#include "wsh_shell_types.h"
#include "wsh_shell_user.h"
#include "wsh_shell_version.h"

/* detect operating system name */
#if defined(__linux)
#define OS_NAME "Linux"
#elif defined(__unix)
#define OS_NAME "Unix"
#elif defined(__APPLE__)
#define OS_NAME "Darwin"
#elif defined(_WIN32)
#define OS_NAME "Windows"
#elif defined(tskKERNEL_VERSION_NUMBER)
#define OS_NAME "FreeRTOS " tskKERNEL_VERSION_NUMBER
#else
#define OS_NAME WSH_SHELL_TARGET_OS
#endif

/* detect compiler name and version */
#if defined(__clang__)
#define COMPILER "clang " __clang_version__
#elif defined(__GNUC__)
#define COMPILER "GCC " __VERSION__
#elif defined(_MSC_VER)
#define COMPILER "MSVC"
#elif defined(__CC_ARM)
#define COMPILER "ARMCC"
#elif defined(__ICCARM__)
#define COMPILER "IAR"
#else
#define COMPILER "Unknown Compiler"
#endif

/* default welcome banner, printed by WshShell_Init() when no custom one is given;
 * define WSH_SHELL_HEADER in wsh_shell_cfg.h to replace it (or to "" to drop it) */
#ifndef WSH_SHELL_HEADER
/* clang-format off */
#define WSH_SHELL_HEADER "\
                __               __         ____  \r\n\
 _      _______/ /_        _____/ /_  ___  / / /  \r\n\
| | /| / / ___/ __ \\______/ ___/ __ \\/ _ \\/ / /\r\n\
| |/ |/ (__  ) / / /_____(__  ) / / /  __/ / /    \r\n\
|__/|__/____/_/ /_/     /____/_/ /_/\\___/_/_/    \r\n\
\r\n"
/* clang-format on */
#endif

#ifdef __cplusplus
extern "C" {
#endif

typedef void (*WshShell_ExtClbk_t)(void* pCtx);

typedef struct {
    WshShell_ExtClbk_t Auth;     
    WshShell_ExtClbk_t DeAuth;   
    WshShell_ExtClbk_t SymbolIn; 
} WshShellExtCallbacks_t;

typedef struct {
    WshShell_Char_t Login[WSH_SHELL_LOGIN_LEN]; 
    WshShell_Char_t Pass[WSH_SHELL_PASS_LEN];   
} WshShellAuthCtx_t;

typedef struct {
    WshShell_Char_t* Version;                           
    WshShell_Char_t DeviceName[WSH_SHELL_DEV_NAME_LEN]; 
    WshShell_Char_t PS1[WSH_SHELL_PS1_MAX_LEN];         
    WshShell_Char_t PrevSym;                            
    WshShellIO_CommandLine_t CommandLine; 
    const WshShellUser_t* CurrUser;       
    WshShellAuthCtx_t TmpAuth;            
    WshShellEsc_Storage_t EscStorage;     
    WshShellUser_Table_t Users;   
    WshShellCmd_Table_t Commands; 
    WshShellHistoryIO_t HistoryIO; 
    WshShellSessionIO_t SessionIO; 
    WshShellInteract_t Interact;   
    WshShellPromptWait_t PromptWait;

    WshShellExtCallbacks_t ExtCallbacks; 
} WshShell_t;

WSH_SHELL_RET_STATE_t WshShell_Init(WshShell_t* pShell, const WshShell_Char_t* pcDevName,
                                    const WshShell_Char_t* pcCustomHeader, WshShellExtCallbacks_t* pExtClbks);

WshShell_Bool_t WshShell_Auth(WshShell_t* pShell, const WshShell_Char_t* pcLogin, const WshShell_Char_t* pcPass);

WshShell_Bool_t WshShell_IsAuth(const WshShell_t* pcShell);

void WshShell_DeAuth(WshShell_t* pShell, const WshShell_Char_t* pcReason);

WshShell_Bool_t WshShell_SessionArm(WshShell_t* pShell, WshShell_U32_t reboots);

WshShell_Bool_t WshShell_SessionRestore(WshShell_t* pShell);

WshShell_Bool_t WshShell_SessionIsKeepActive(WshShell_t* pShell);

WshShell_U32_t WshShell_SessionRebootsLeft(WshShell_t* pShell);

void WshShell_InsertChar(WshShell_t* pShell, const WshShell_Char_t symbol);

#ifdef __cplusplus
}
#endif

#endif /* __WSH_SHELL_H */