mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 16:50:55 +08:00
Concurrent telnet+serial
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@824 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
+8
-5
@@ -96,8 +96,9 @@
|
||||
#define nsh_addref(v) (v)->addref(v)
|
||||
#define nsh_release(v) (v)->release(v)
|
||||
#define nsh_linebuffer(v) (v)->linebuffer(v)
|
||||
#define nsh_redirect(v,f) (v)->redirect(v,f)
|
||||
#define nsh_undirect(v,d) (v)->undirect(v,d)
|
||||
#define nsh_redirect(v,f,s) (v)->redirect(v,f,s)
|
||||
#define nsh_undirect(v,s) (v)->undirect(v,s)
|
||||
#define nsh_exit(v) (v)->exit(v)
|
||||
|
||||
#ifdef CONFIG_CPP_HAVE_VARARGS
|
||||
# define nsh_output(v, fmt...) (v)->output(v, ##fmt)
|
||||
@@ -105,6 +106,8 @@
|
||||
# define nsh_output vtbl->output
|
||||
#endif
|
||||
|
||||
#define SAVE_SIZE (sizeof(int) + sizeof(FILE*) + sizeof(boolean))
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
@@ -116,8 +119,9 @@ struct nsh_vtbl_s
|
||||
void (*release)(FAR struct nsh_vtbl_s *vtbl);
|
||||
int (*output)(FAR struct nsh_vtbl_s *vtbl, const char *fmt, ...);
|
||||
FAR char *(*linebuffer)(FAR struct nsh_vtbl_s *vtbl);
|
||||
FAR void *(*redirect)(FAR struct nsh_vtbl_s *vtbl, int fd);
|
||||
void (*undirect)(FAR struct nsh_vtbl_s *vtbl, FAR void *direct);
|
||||
void (*redirect)(FAR struct nsh_vtbl_s *vtbl, int fd, FAR ubyte *save);
|
||||
void (*undirect)(FAR struct nsh_vtbl_s *vtbl, FAR ubyte *save);
|
||||
void (*exit)(FAR struct nsh_vtbl_s *vtbl);
|
||||
};
|
||||
|
||||
typedef void (*cmd_t)(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
@@ -158,7 +162,6 @@ extern int nsh_telnetmain(int argc, char *argv[]);
|
||||
|
||||
extern void cmd_echo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
extern void cmd_exec(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
extern void cmd_exit(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
extern void cmd_ps(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||
|
||||
+13
-3
@@ -73,6 +73,7 @@ struct cmdmap_s
|
||||
****************************************************************************/
|
||||
|
||||
static void cmd_help(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
static void cmd_exit(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
static void cmd_unrecognized(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||
|
||||
/****************************************************************************
|
||||
@@ -196,6 +197,15 @@ static void cmd_unrecognized(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
nsh_output(vtbl, g_fmtcmdnotfound, argv[0]);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: cmd_exit
|
||||
****************************************************************************/
|
||||
|
||||
static void cmd_exit(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
nsh_exit(vtbl);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nsh_execute
|
||||
****************************************************************************/
|
||||
@@ -596,7 +606,7 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
|
||||
|
||||
if (redirect)
|
||||
{
|
||||
(void)nsh_redirect(bkgvtbl, fd);
|
||||
(void)nsh_redirect(bkgvtbl, fd, NULL);
|
||||
}
|
||||
|
||||
/* Get the execution priority of this task */
|
||||
@@ -659,7 +669,7 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
|
||||
}
|
||||
else
|
||||
{
|
||||
void *save;
|
||||
ubyte save[SAVE_SIZE];
|
||||
|
||||
/* Increment the reference count on the vtbl. This reference count will
|
||||
* be decremented at the end of nsh_execute() and exists only for compatibility
|
||||
@@ -677,7 +687,7 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
|
||||
|
||||
if (redirect)
|
||||
{
|
||||
save = nsh_redirect(vtbl, fd);
|
||||
nsh_redirect(vtbl, fd, save);
|
||||
}
|
||||
|
||||
/* Then execute the command in "foreground" -- i.e., while the user waits
|
||||
|
||||
+55
-38
@@ -58,13 +58,19 @@
|
||||
|
||||
struct serial_s
|
||||
{
|
||||
struct nsh_vtbl_s vtbl;
|
||||
struct nsh_vtbl_s ss_vtbl;
|
||||
int ss_refs; /* Reference counts on the instance */
|
||||
int ss_fd; /* Re-direct file descriptor */
|
||||
FILE *ss_stream; /* Redirect file descriptor */
|
||||
FILE *ss_stream; /* Re-direct stream */
|
||||
char ss_line[CONFIG_EXAMPLES_NSH_LINELEN];
|
||||
};
|
||||
|
||||
struct serialsave_s
|
||||
{
|
||||
int ss_fd; /* Re-direct file descriptor */
|
||||
FILE *ss_stream; /* Re-direct stream */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
@@ -74,8 +80,9 @@ static void nsh_consoleaddref(FAR struct nsh_vtbl_s *vtbl);
|
||||
static void nsh_consolerelease(FAR struct nsh_vtbl_s *vtbl);
|
||||
static int nsh_consoleoutput(FAR struct nsh_vtbl_s *vtbl, const char *fmt, ...);
|
||||
static FAR char *nsh_consolelinebuffer(FAR struct nsh_vtbl_s *vtbl);
|
||||
static FAR void *nsh_consoleredirect(FAR struct nsh_vtbl_s *vtbl, int fd);
|
||||
static void nsh_consoleundirect(FAR struct nsh_vtbl_s *vtbl, FAR void *direct);
|
||||
static void nsh_consoleredirect(FAR struct nsh_vtbl_s *vtbl, int fd, FAR ubyte *save);
|
||||
static void nsh_consoleundirect(FAR struct nsh_vtbl_s *vtbl, FAR ubyte *save);
|
||||
static void nsh_consoleexit(FAR struct nsh_vtbl_s *vtbl);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
@@ -98,17 +105,18 @@ static inline FAR struct serial_s *nsh_allocstruct(void)
|
||||
struct serial_s *pstate = (struct serial_s *)malloc(sizeof(struct serial_s));
|
||||
if (pstate)
|
||||
{
|
||||
pstate->vtbl.clone = nsh_consoleclone;
|
||||
pstate->vtbl.addref = nsh_consoleaddref;
|
||||
pstate->vtbl.release = nsh_consolerelease;
|
||||
pstate->vtbl.output = nsh_consoleoutput;
|
||||
pstate->vtbl.linebuffer = nsh_consolelinebuffer;
|
||||
pstate->vtbl.redirect = nsh_consoleredirect;
|
||||
pstate->vtbl.undirect = nsh_consoleundirect;
|
||||
pstate->ss_vtbl.clone = nsh_consoleclone;
|
||||
pstate->ss_vtbl.addref = nsh_consoleaddref;
|
||||
pstate->ss_vtbl.release = nsh_consolerelease;
|
||||
pstate->ss_vtbl.output = nsh_consoleoutput;
|
||||
pstate->ss_vtbl.linebuffer = nsh_consolelinebuffer;
|
||||
pstate->ss_vtbl.redirect = nsh_consoleredirect;
|
||||
pstate->ss_vtbl.undirect = nsh_consoleundirect;
|
||||
pstate->ss_vtbl.exit = nsh_consoleexit;
|
||||
|
||||
pstate->ss_refs = 1;
|
||||
pstate->ss_fd = 1;
|
||||
pstate->ss_stream = stdout;
|
||||
pstate->ss_refs = 1;
|
||||
pstate->ss_fd = 1;
|
||||
pstate->ss_stream = stdout;
|
||||
}
|
||||
return pstate;
|
||||
}
|
||||
@@ -221,7 +229,7 @@ static FAR struct nsh_vtbl_s *nsh_consoleclone(FAR struct nsh_vtbl_s *vtbl)
|
||||
FAR struct serial_s *pclone = nsh_allocstruct();
|
||||
pclone->ss_fd = pstate->ss_fd;
|
||||
pclone->ss_stream = NULL;
|
||||
return &pclone->vtbl;
|
||||
return &pclone->ss_vtbl;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@@ -269,18 +277,25 @@ static void nsh_consolerelease(FAR struct nsh_vtbl_s *vtbl)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static FAR void *nsh_consoleredirect(FAR struct nsh_vtbl_s *vtbl, int fd)
|
||||
static void nsh_consoleredirect(FAR struct nsh_vtbl_s *vtbl, int fd, FAR ubyte *save)
|
||||
{
|
||||
FAR struct serial_s *pstate = (FAR struct serial_s *)vtbl;
|
||||
void *ret;
|
||||
FAR struct serial_s *pstate = (FAR struct serial_s *)vtbl;
|
||||
FAR struct serialsave_s *ssave = (FAR struct serialsave_s *)save;
|
||||
|
||||
(void)nsh_openifnotopen(pstate);
|
||||
ret = pstate->ss_stream;
|
||||
fflush(pstate->ss_stream);
|
||||
if (ssave)
|
||||
{
|
||||
ssave->ss_fd = pstate->ss_fd;
|
||||
ssave->ss_stream = pstate->ss_stream;
|
||||
}
|
||||
else
|
||||
{
|
||||
fclose(pstate->ss_stream);
|
||||
}
|
||||
|
||||
pstate->ss_fd = fd;
|
||||
pstate->ss_stream = NULL;
|
||||
return ret;
|
||||
pstate->ss_stream = NULL;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@@ -291,12 +306,27 @@ static FAR void *nsh_consoleredirect(FAR struct nsh_vtbl_s *vtbl, int fd)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void nsh_consoleundirect(FAR struct nsh_vtbl_s *vtbl, FAR void *direct)
|
||||
static void nsh_consoleundirect(FAR struct nsh_vtbl_s *vtbl, FAR ubyte *save)
|
||||
{
|
||||
FAR struct serial_s *pstate = (FAR struct serial_s *)vtbl;
|
||||
FAR struct serialsave_s *ssave = (FAR struct serialsave_s *)save;
|
||||
|
||||
nsh_closeifnotclosed(pstate);
|
||||
pstate->ss_fd = -1;
|
||||
pstate->ss_stream = (FILE*)direct;
|
||||
pstate->ss_fd = ssave->ss_fd;
|
||||
pstate->ss_stream = ssave->ss_stream;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nsh_consoleexit
|
||||
*
|
||||
* Description:
|
||||
* Exit the shell task
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void nsh_consoleexit(FAR struct nsh_vtbl_s *vtbl)
|
||||
{
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@@ -327,21 +357,8 @@ int nsh_consolemain(int argc, char *argv[])
|
||||
{
|
||||
/* Parse process the command */
|
||||
|
||||
(void)nsh_parse(&pstate->vtbl, pstate->ss_line);
|
||||
(void)nsh_parse(&pstate->ss_vtbl, pstate->ss_line);
|
||||
fflush(pstate->ss_stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: cmd_exit
|
||||
*
|
||||
* Description:
|
||||
* Exit the shell task
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void cmd_exit(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
exit(0);
|
||||
}
|
||||
|
||||
+335
-88
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user