command_handler.hpp
Go to the documentation of this file.
1 
19 /*
20  * @brief Provides command handling mapping with a function pointer as handler
21  * @ingroup Utilities
22  *
23  * Version: 11102013 Removed 4th parameter (size) of command handler
24  * Version: 05022013 Removed output string and replaced with output interface.
25  * Version: 04192013 Removed restriction of command limit, just rely on source str as the command.
26  * Version: 02162013 Removed input str (moved to stack). Improved 'help' command output.
27  * Version: 12082012 Added short-command handler capability
28  * Version: 07262012 Removed "Version" Handler
29  * Version: 06192012 Initial
30  */
31 #ifndef COMMANDHANDLER_HPP_
32 #define COMMANDHANDLER_HPP_
33 
34 #include "vector.hpp"
35 #include "str.hpp"
36 #include "char_dev.hpp"
37 
38 
39 
50 typedef bool (*CmdHandlerFuncPtr)(str& cmdParams, CharDev& output, void* pDataParam);
51 
65 #define CMD_HANDLER_FUNC(name) bool name(str& cmdParams, CharDev& output, void* pDataParam)
66 
67 
68 
69 
97 {
98  public:
104  CommandProcessor(int numCmds=8) :
105  mCmdHandlerVector(numCmds), mEnShortCmds(true)
106  {
107  }
108 
119  void addHandler(CmdHandlerFuncPtr pFunc, const char* pPersistantCmdStr,
120  const char* pPersistentCmdHelpStr=0, void* pDataParam=0);
121 
129  bool handleCommand(str& cmd, CharDev& out);
138  inline void enableShortCmds(bool en) { mEnShortCmds = en;}
139 
140  private:
142  typedef struct
143  {
144  const char* pCommandStr;
145  const char* pCmdHelpText;
146  CmdHandlerFuncPtr pFunc;
147  void* pDataParam;
148  } CmdProcessorType;
149 
150  VECTOR<CmdProcessorType> mCmdHandlerVector;
151  bool mEnShortCmds;
152 
154  void handleCmd(str& input, CharDev& output);
155 
157  void getRegisteredCommandList(CharDev& output);
158 
166  void getHelpText(str& helpForCmd, CharDev& output);
167 
169  void prepareCmdParam(str& input, const char* pCmdToRemove);
170 };
171 
172 #endif /* COMMANDHANDLER_HPP_ */
Provides a &#39;char&#39; device base class functionality for stream oriented char devices.
void enableShortCmds(bool en)
Definition: command_handler.hpp:138
Definition: command_handler.hpp:96
Definition: str.hpp:100
Provides string class with a small foot-printVersion: 01102013 Added eraseFirstWords() Version: 05052...
void addHandler(CmdHandlerFuncPtr pFunc, const char *pPersistantCmdStr, const char *pPersistentCmdHelpStr=0, void *pDataParam=0)
Definition: command_handler.cpp:34
CommandProcessor(int numCmds=8)
Definition: command_handler.hpp:104
bool handleCommand(str &cmd, CharDev &out)
Definition: command_handler.cpp:51
Definition: char_dev.hpp:43
bool(* CmdHandlerFuncPtr)(str &cmdParams, CharDev &output, void *pDataParam)
Definition: command_handler.hpp:50
Vector Class with a small footprintVersion: 05172013 Added at() to ease element access when vector is...