00001
00002 #ifndef WVSTREAMSDEBUGGER_H
00003 #define WVSTREAMSDEBUGGER_H
00004
00005 #include <map>
00006
00007 #include "wverror.h"
00008 #include "wvstringlist.h"
00009 #include "wvtclstring.h"
00010 #include "wvtr1.h"
00011
00012 class WvStreamsDebugger
00013 {
00014 public:
00015
00016
00017
00018
00019 typedef wv::function<void(WvStringParm, WvStringList&)> ResultCallback;
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 typedef wv::function<void*(WvStringParm)> InitCallback;
00030 typedef wv::function<WvString(WvStringParm, WvStringList&,
00031 ResultCallback, void*)> RunCallback;
00032
00033 typedef wv::function<void(WvStringParm, void*)> CleanupCallback;
00034
00035
00036
00037 typedef wv::function<void(WvStringParm, void*)> ForeachCallback;
00038
00039 private:
00040
00041 struct Command
00042 {
00043 InitCallback init_cb;
00044 RunCallback run_cb;
00045 CleanupCallback cleanup_cb;
00046
00047 Command(InitCallback _init_cb, RunCallback _run_cb,
00048 CleanupCallback _cleanup_cb)
00049 {
00050 init_cb = _init_cb;
00051 run_cb = _run_cb;
00052 cleanup_cb = _cleanup_cb;
00053 }
00054 };
00055 typedef std::map<WvString, Command> CommandMap;
00056 static CommandMap *commands;
00057 typedef std::map<WvString, void*> CommandDataMap;
00058 CommandDataMap command_data;
00059
00060 void *get_command_data(WvStringParm cmd, Command *command);
00061 friend class WvStreamsDebuggerStaticInitCleanup;
00062
00063 public:
00064
00065 WvStreamsDebugger();
00066 ~WvStreamsDebugger();
00067
00068 WvString run(WvStringParm cmd, WvStringList &args,
00069 ResultCallback result_cb);
00070
00071 static bool add_command(WvStringParm cmd,
00072 InitCallback init_cb,
00073 RunCallback run_cb,
00074 CleanupCallback cleanup_cb);
00075
00076 static bool foreach(WvStringParm cmd, ForeachCallback foreach_cb);
00077
00078 private:
00079
00080 static WvString help_run_cb(WvStringParm cmd,
00081 WvStringList &args,
00082 ResultCallback result_cb, void *);
00083 };
00084
00085 #endif