00001 #ifndef _SHELL_H__
00002 #define _SHELL_H__
00003
00004 #include <ostream>
00005 #include <string>
00006 #include <gea/posix/UnixFdHandle.h>
00007
00016 namespace awds {
00017
00018 class Shell;
00019
00020 class ShellClient {
00021 public:
00022 enum ClientState {
00023 CS_Idle,
00024 CS_Blocked
00025 };
00026
00027 gea::UnixFdHandle *sockin;
00028 std::ostream *sockout;
00029 enum ClientState state;
00030
00031 ShellClient(gea::UnixFdHandle *_sockin, std::ostream *_sockout) :
00032 sockin(_sockin),
00033 sockout(_sockout),
00034 state(CS_Idle)
00035 {}
00036
00037 ShellClient() :
00038 state(CS_Idle)
00039 {}
00040
00041 virtual void block() = 0;
00042 virtual void unblock() = 0;
00043
00044 virtual int exec(int argc, char **argv) = 0;
00045
00046 virtual ~ShellClient() {}
00047 };
00048
00049 typedef int (shell_command_fn)(ShellClient &sc, void *data, int argc, char **argv);
00050
00051 struct ShellCommand {
00052 shell_command_fn *command;
00053 void *data;
00054 const char *desc;
00055 const char *help;
00056 };
00057
00058
00062 class Shell {
00063 public:
00064
00066 Shell() {};
00067
00068 virtual void add_command(const std::string name, shell_command_fn *command,
00069 void *data, const char *descr, const char *help) = 0;
00070 virtual ShellCommand *get_command(std::string name) = 0;
00071
00072 virtual ~Shell() {}
00073 };
00074
00075 }
00076
00077 #endif
00078
00079
00080
00081
00082
00083