wvstreamsdebugger.h

00001 #ifndef WVSTREAMSDEBUGGER_H
00002 #define WVSTREAMSDEBUGGER_H
00003 
00004 #include "wvtclstring.h"
00005 #include "wvcallback.h"
00006 #include "wverror.h"
00007 #include "wvhashtable.h"
00008 #include "wvstringlist.h"
00009 
00010 class WvStreamsDebugger
00011 {
00012 public:
00013 
00014     // The callback type used to pass the results back to the application
00015     // that calls WvStreamsDebugger::run.  The application is allowed
00016     // to consume the WvStringList of results.
00017     typedef WvCallback<void, WvStringParm, WvStringList &> ResultCallback;
00018 
00019     // Debugging commands are implemented through the following three
00020     // callbacks:
00021     //   - InitCallback is optional and is used to allocate state
00022     //     for an instance of WvStreamsDebugger for the given command
00023     //   - RunCallback is required and is used to actually execute
00024     //     the command as a result of a call to WvStreamsDebugger::run
00025     //   - CleanupCallback is optional and is used to free state
00026     //     for an instance of WvStreamsDebugger for the given command
00027     typedef WvCallback<void *, WvStringParm> InitCallback;
00028     typedef WvCallback<WvString, WvStringParm, WvStringList &,
00029             ResultCallback, void *> RunCallback;
00030     typedef WvCallback<void, WvStringParm, void *> CleanupCallback;
00031 
00032     // The WvStreamsDebugger::foreach function can be used to update
00033     // state in every instance of WvStreamsDebugger for a given command.
00034     typedef WvCallback<void, WvStringParm, void *> ForeachCallback;
00035     
00036 private:
00037 
00038     struct Command
00039     {
00040         InitCallback init_cb;
00041         RunCallback run_cb;
00042         CleanupCallback cleanup_cb;
00043         
00044         Command(InitCallback _init_cb, RunCallback _run_cb,
00045                 CleanupCallback _cleanup_cb)
00046         {
00047             init_cb = _init_cb;
00048             run_cb = _run_cb;
00049             cleanup_cb = _cleanup_cb;
00050         }
00051     };
00052     typedef WvMap<WvString, Command *> CommandMap;
00053     static CommandMap *commands;
00054     typedef WvMap<WvString, char *> CommandDataMap;
00055     CommandDataMap command_data;
00056     
00057     void *get_command_data(WvStringParm cmd, Command *command);
00058     friend class WvStreamsDebuggerStaticInitCleanup;
00059     
00060 public:
00061 
00062     WvStreamsDebugger();
00063     ~WvStreamsDebugger();
00064 
00065     WvString run(WvStringParm cmd, WvStringList &args,
00066             ResultCallback result_cb);
00067     
00068     static bool add_command(WvStringParm cmd,
00069             InitCallback init_cb,
00070             RunCallback run_cb,
00071             CleanupCallback cleanup_cb);
00072             
00073     static bool foreach(WvStringParm cmd, ForeachCallback foreach_cb);
00074 
00075 private:
00076 
00077     static WvString help_run_cb(WvStringParm cmd,
00078             WvStringList &args,
00079             ResultCallback result_cb, void *);
00080 };
00081 
00082 #endif

Generated on Fri Oct 5 18:20:28 2007 for WvStreams by  doxygen 1.5.3