00001 #ifndef _SHELL_H__
00002 #define _SHELL_H__
00003
00004 #include <ostream>
00005 #include <string>
00006 #include <gea/posix/UnixFdHandle.h>
00007
00017 namespace awds {
00018
00019 class Shell;
00020
00023 class ShellClient {
00024 public:
00025
00028 enum ClientState {
00029 CS_Idle,
00030 CS_Blocked
00031 };
00032
00033 gea::UnixFdHandle *sockin;
00034 std::ostream *sockout;
00035 enum ClientState state;
00036
00037 ShellClient(gea::UnixFdHandle *_sockin, std::ostream *_sockout) :
00038 sockin(_sockin),
00039 sockout(_sockout),
00040 state(CS_Idle)
00041 {}
00042
00043 ShellClient() :
00044 state(CS_Idle)
00045 {}
00046
00047 virtual void block() = 0;
00048 virtual void unblock() = 0;
00049
00051 virtual int exec(int argc, char **argv) = 0;
00052
00053 virtual ~ShellClient() {}
00054 };
00055
00064 typedef int (shell_command_fn)(ShellClient &sc, void *data, int argc, char **argv);
00065
00068 struct ShellCommand {
00069 shell_command_fn *command;
00070 void *data;
00071 const char *desc;
00072 const char *help;
00073 };
00074
00075
00079 class Shell {
00080 public:
00081
00083 Shell() {};
00084
00093 virtual void add_command(const std::string name, shell_command_fn *command,
00094 void *data, const char *descr, const char *help) = 0;
00095
00098 virtual ShellCommand *get_command(std::string name) = 0;
00099
00100
00105 virtual ~Shell() {}
00106
00107 };
00108
00109 }
00110
00111 #endif
00112
00113
00114
00115
00116
00117