CommandHandler.h
Go to the documentation of this file.
1 /*
2  * CommandHandler.h
3  *
4  * Created on: 2 jul. 2015
5  * Author: Herman
6  */
25 #pragma once
26 
27 #include "CommandDelegate.h"
28 #include <WHashMap.h>
29 #include <SystemClock.h>
30 #include <HardwareSerial.h>
31 
37 };
38 
41 {
42 public:
47 
48  CommandHandler(const CommandHandler&) = delete;
49 
56  bool registerCommand(CommandDelegate reqDelegate);
57 
61  bool unregisterCommand(CommandDelegate reqDelegate);
62 
73 
78  CommandDelegate getCommandDelegate(const String& commandString);
79 
84  {
85  return verboseMode;
86  }
87 
91  void setVerboseMode(VerboseMode reqVerboseMode)
92  {
93  verboseMode = reqVerboseMode;
94  }
95 
102  {
103  return currentPrompt;
104  }
105 
111  void setCommandPrompt(const String& reqPrompt)
112  {
113  currentPrompt = reqPrompt;
114  }
115 
121  {
122  return currentEOL;
123  }
124 
129  void setCommandEOL(char reqEOL)
130  {
131  currentEOL = reqEOL;
132  }
133 
139  {
140  return currentWelcomeMessage;
141  }
142 
147  void setCommandWelcomeMessage(const String& reqWelcomeMessage)
148  {
149  currentWelcomeMessage = reqWelcomeMessage;
150  }
151 
152  // int deleteGroup(String reqGroup);
153 
154 private:
155  HashMap<String, CommandDelegate>* registeredCommands;
156  void procesHelpCommand(String commandLine, CommandOutput* commandOutput);
157  void procesStatusCommand(String commandLine, CommandOutput* commandOutput);
158  void procesEchoCommand(String commandLine, CommandOutput* commandOutput);
159  void procesDebugOnCommand(String commandLine, CommandOutput* commandOutput);
160  void procesDebugOffCommand(String commandLine, CommandOutput* commandOutput);
161  void processCommandOptions(String commandLine, CommandOutput* commandOutput);
162 
163  VerboseMode verboseMode = VERBOSE;
164  String currentPrompt;
165 #ifdef ARCH_HOST
166  char currentEOL = '\n';
167 #else
168  char currentEOL = '\r';
169 #endif
170  String currentWelcomeMessage;
171 };
172 
175 
CommandDelegate getCommandDelegate(const String &commandString)
Get the command delegate for a command.
CommandLine commandLine
CommandHandler()
Instantiate a CommandHandler.
String getCommandPrompt()
Get the command line prompt.
Definition: CommandHandler.h:101
void setCommandWelcomeMessage(const String &reqWelcomeMessage)
Set the welcome message.
Definition: CommandHandler.h:147
void setVerboseMode(VerboseMode reqVerboseMode)
Set the verbose mode.
Definition: CommandHandler.h:91
Silent mode.
Definition: CommandHandler.h:36
VerboseMode
Verbose mode.
Definition: CommandHandler.h:34
Verbose mode.
Definition: CommandHandler.h:35
The String class.
Definition: WString.h:136
char getCommandEOL()
Get the end of line character.
Definition: CommandHandler.h:120
void setCommandEOL(char reqEOL)
Set the end of line character.
Definition: CommandHandler.h:129
bool registerCommand(CommandDelegate reqDelegate)
Add a new command to the command handler.
bool unregisterCommand(CommandDelegate reqDelegate)
Remove a command from the command handler.
Definition: CommandOutput.h:18
void setCommandPrompt(const String &reqPrompt)
Set the command line prompt.
Definition: CommandHandler.h:111
Command handler class.
Definition: CommandHandler.h:40
CommandHandler commandHandler
Global instance of CommandHandler.
Command delegate class.
Definition: CommandDelegate.h:29
void registerSystemCommands()
Register default system commands.
VerboseMode getVerboseMode()
Get the verbose mode.
Definition: CommandHandler.h:83
String getCommandWelcomeMessage()
Get the welcome message.
Definition: CommandHandler.h:138