source: rtems/cpukit/libmisc/shell/shell.h @ 6c5ee7f0

4.11
Last change on this file since 6c5ee7f0 was 6c5ee7f0, checked in by Sebastian Huber <sebastian.huber@…>, on Sep 16, 2011 at 9:16:32 AM

2011-09-16 Sebastian Huber <sebastian.huber@…>

  • libmisc/shell/shell-wait-for-input.c: New file.
  • libmisc/Makefile.am: Reflect change above.
  • libmisc/shell/shell.h: Declare rtems_shell_wait_for_input().
  • Property mode set to 100644
File size: 7.9 KB
Line 
1/**
2 * @file rtems/shell.h
3 *
4 *  Instantatiate a new terminal shell.
5 */
6
7/*
8 *  Author:
9 *
10 *   WORK: fernando.ruiz@ctv.es
11 *   HOME: correo@fernando-ruiz.com
12 *
13 *   Thanks at:
14 *    Chris Johns
15 *
16 *  $Id$
17 */
18
19#ifndef __RTEMS_SHELL_H__
20#define __RTEMS_SHELL_H__
21
22#include <rtems.h>
23#include <stdio.h>
24#include <termios.h>
25#include <rtems/fs.h>
26#include <rtems/libio.h>
27#include <rtems/chain.h>
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33/*
34 * Some key labels to define special keys.
35 */
36
37#define RTEMS_SHELL_KEYS_EXTENDED    (0x8000)
38#define RTEMS_SHELL_KEYS_NORMAL_MASK (0x00ff)
39#define RTEMS_SHELL_KEYS_INS         (0)
40#define RTEMS_SHELL_KEYS_DEL         (1)
41#define RTEMS_SHELL_KEYS_UARROW      (2)
42#define RTEMS_SHELL_KEYS_DARROW      (3)
43#define RTEMS_SHELL_KEYS_LARROW      (4)
44#define RTEMS_SHELL_KEYS_RARROW      (5)
45#define RTEMS_SHELL_KEYS_HOME        (6)
46#define RTEMS_SHELL_KEYS_END         (7)
47#define RTEMS_SHELL_KEYS_F1          (8)
48#define RTEMS_SHELL_KEYS_F2          (9)
49#define RTEMS_SHELL_KEYS_F3          (10)
50#define RTEMS_SHELL_KEYS_F4          (11)
51#define RTEMS_SHELL_KEYS_F5          (12)
52#define RTEMS_SHELL_KEYS_F6          (13)
53#define RTEMS_SHELL_KEYS_F7          (14)
54#define RTEMS_SHELL_KEYS_F8          (15)
55#define RTEMS_SHELL_KEYS_F9          (16)
56#define RTEMS_SHELL_KEYS_F10         (17)
57
58typedef bool (*rtems_shell_login_check_t)(
59  const char * /* user */,
60  const char * /* passphrase */
61);
62
63bool rtems_shell_login_prompt(
64  FILE *in,
65  FILE *out,
66  const char *device,
67  rtems_shell_login_check_t check
68);
69
70bool rtems_shell_login_check(
71  const char *user,
72  const char *passphrase
73);
74
75typedef int (*rtems_shell_command_t)(int argc, char **argv);
76
77struct rtems_shell_cmd_tt;
78typedef struct rtems_shell_cmd_tt rtems_shell_cmd_t;
79
80struct rtems_shell_cmd_tt {
81  const char            *name;
82  const char            *usage;
83  const char            *topic;
84  rtems_shell_command_t  command;
85  rtems_shell_cmd_t     *alias;
86  rtems_shell_cmd_t     *next;
87};
88
89typedef struct {
90  const char *name;
91  const char *alias;
92} rtems_shell_alias_t;
93
94/*
95 * The return value has RTEMS_SHELL_KEYS_EXTENDED set if the key
96 * is extended, ie a special key.
97 */
98unsigned int rtems_shell_getchar(FILE *in);
99
100rtems_shell_cmd_t * rtems_shell_lookup_cmd(const char *cmd);
101
102rtems_shell_cmd_t *rtems_shell_add_cmd_struct(
103  rtems_shell_cmd_t *shell_cmd
104);
105
106rtems_shell_cmd_t * rtems_shell_add_cmd(
107  const char            *cmd,
108  const char            *topic,
109  const char            *usage,
110  rtems_shell_command_t  command
111);
112
113rtems_shell_cmd_t * rtems_shell_alias_cmd(
114  const char *cmd,
115  const char *alias
116);
117
118int rtems_shell_make_args(
119  char  *commandLine,
120  int   *argc_p,
121  char **argv_p,
122  int    max_args
123);
124
125int rtems_shell_cat_file(
126  FILE *out,
127  const char *name
128);
129
130void rtems_shell_write_file(
131  const char *name,
132  const char *content
133);
134
135int rtems_shell_script_file(
136  int    argc,
137  char **argv
138);
139
140/**
141 * Initialise the shell creating tasks to login and run the shell
142 * sessions.
143 *
144 * @param task_name Name of the shell task.
145 * @param task_stacksize The size of the stack. If 0 the default size is used.
146 * @param task_priority The priority the shell runs at.
147 * @param forever Repeat logins.
148 * @param wait Caller should block until shell exits.
149 * @param login_check User login check function, NULL disables login checks.
150 *
151 */
152rtems_status_code rtems_shell_init(
153  const char *task_name,
154  size_t task_stacksize,
155  rtems_task_priority task_priority,
156  const char *devname,
157  bool forever,
158  bool wait,
159  rtems_shell_login_check_t login_check
160);
161
162/**
163 * Run a shell script creating a shell tasks to execute the command under.
164 *
165 * @param task_name Name of the shell task.
166 * @param task_stacksize The size of the stack. If 0 the default size is used.
167 * @param task_priority The priority the shell runs at.
168 * @param input The file of commands. Can be 'stdin' to use stdin.
169 * @param output The output file to write commands to. Can be 'stdout',
170 *              'stderr' or '/dev/null'.
171 * @param output_append Append the output to the file or truncate the file.
172 *                      Create if it does not exist.
173 * @param wait Wait for the script to finish.
174 */
175rtems_status_code rtems_shell_script(
176  const char          *task_name,
177  size_t               task_stacksize,  /* 0 default*/
178  rtems_task_priority  task_priority,
179  const char          *input,
180  const char          *output,
181  bool                 output_append,
182  bool                 wait,
183  bool                 echo
184);
185
186/**
187 *  Private environment associated with each shell instance.
188 */
189typedef struct {
190  /** 'S','E','N','V': Shell Environment */
191  rtems_name magic;
192  const char *devname;
193  const char *taskname;
194  bool exit_shell; /* logout */
195  bool forever; /* repeat login */
196  int errorlevel;
197  bool echo;
198  char cwd[256];
199  const char *input;
200  const char *output;
201  bool output_append;
202  rtems_id wake_on_end;
203  rtems_shell_login_check_t login_check;
204} rtems_shell_env_t;
205
206bool rtems_shell_main_loop(
207  rtems_shell_env_t *rtems_shell_env
208);
209
210extern rtems_shell_env_t  rtems_global_shell_env;
211extern rtems_shell_env_t *rtems_current_shell_env;
212
213/*
214 * The types of file systems we can mount. We have them broken out
215 * out like this so they can be configured by shellconfig.h. The
216 * mount command needs special treatment due to some file systems
217 * being dependent on the network stack and some not. If we had
218 * all possible file systems being included it would force the
219 * networking stack into the applcation and this may not be
220 * required.
221 */
222struct rtems_shell_filesystems_tt;
223typedef struct rtems_shell_filesystems_tt rtems_shell_filesystems_t;
224
225typedef int (*rtems_shell_filesystems_mounter_t)(
226  const char*                driver,
227  const char*                path,
228  rtems_shell_filesystems_t* fs,
229  rtems_filesystem_options_t options
230);
231
232struct rtems_shell_filesystems_tt {
233  rtems_chain_node                         link;
234  const char                              *name;
235  int                                      driver_needed;
236  const rtems_filesystem_operations_table *fs_ops;
237  rtems_shell_filesystems_mounter_t        mounter;
238};
239
240/**
241 *  This method dynamically builds the command line prompt string
242 *  and places it in @a prompt.
243 *
244 *  @param[in] shell_env is the shell execution environment
245 *  @param[in] prompt is a pointer to a string buffer area
246 *  @param[in] size is length of the prompt buffer area
247 *
248 *  @return This method fills in the memory pointed to by @a prompt.
249 *
250 *  @note An application specific implementation can be provided
251 *        by the user.
252 */
253void rtems_shell_get_prompt(
254  rtems_shell_env_t *shell_env,
255  char              *prompt,
256  size_t             size
257);
258
259/**
260 * Helper for the mount command.
261 *
262 * @param[in] driver The path to the driver.
263 * @param[in] path The path to mount on.
264 * @param[in] fs The file system definition.
265 * @param[in] options Special file system options.
266 */
267int rtems_shell_libc_mounter(
268  const char*                driver,
269  const char*                path,
270  rtems_shell_filesystems_t* fs,
271  rtems_filesystem_options_t options
272);
273
274/**
275 * Add a new file system mount configuration to the mount command.
276 *
277 * @param[in] fs The file system mount data.
278 */
279void rtems_shell_mount_add_fsys(rtems_shell_filesystems_t* fs);
280
281/**
282 * Delete file system mount configuration from the mount command.
283 *
284 * @param[in] fs The file system mount data to remove.
285 */
286void rtems_shell_mount_del_fsys(rtems_shell_filesystems_t* fs);
287
288typedef void (*rtems_shell_wait_for_input_notification)(
289  int fd,
290  int seconds_remaining,
291  void *arg
292);
293
294/**
295 * @brief Waits for input.
296 *
297 * @retval RTEMS_SUCCESSFUL Input detected.
298 * @retval RTEMS_TIMEOUT Timeout expired.
299 * @retval RTEMS_UNSATISFIED Cannot change or restore termios attributes.
300 */
301rtems_status_code rtems_shell_wait_for_input(
302  int fd,
303  int timeout_in_seconds,
304  rtems_shell_wait_for_input_notification notification,
305  void *notification_arg
306);
307
308#ifdef __cplusplus
309}
310#endif
311
312#endif
Note: See TracBrowser for help on using the repository browser.