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:
46 
47  CommandHandler(const CommandHandler&) = delete;
48 
55  bool registerCommand(CommandDelegate reqDelegate);
56 
60  bool unregisterCommand(CommandDelegate reqDelegate);
61 
72 
77  CommandDelegate getCommandDelegate(const String& commandString);
78 
83  {
84  return verboseMode;
85  }
86 
90  void setVerboseMode(VerboseMode reqVerboseMode)
91  {
92  verboseMode = reqVerboseMode;
93  }
94 
101  {
102  return currentPrompt;
103  }
104 
110  void setCommandPrompt(const String& reqPrompt)
111  {
112  currentPrompt = reqPrompt;
113  }
114 
120  {
121  return currentEOL;
122  }
123 
128  void setCommandEOL(char reqEOL)
129  {
130  currentEOL = reqEOL;
131  }
132 
138  {
139  return currentWelcomeMessage;
140  }
141 
146  void setCommandWelcomeMessage(const String& reqWelcomeMessage)
147  {
148  currentWelcomeMessage = reqWelcomeMessage;
149  }
150 
151  // int deleteGroup(String reqGroup);
152 
153 private:
154  HashMap<String, CommandDelegate> registeredCommands;
155  void procesHelpCommand(String commandLine, CommandOutput* commandOutput);
156  void procesStatusCommand(String commandLine, CommandOutput* commandOutput);
157  void procesEchoCommand(String commandLine, CommandOutput* commandOutput);
158  void procesDebugOnCommand(String commandLine, CommandOutput* commandOutput);
159  void procesDebugOffCommand(String commandLine, CommandOutput* commandOutput);
160  void processCommandOptions(String commandLine, CommandOutput* commandOutput);
161 
162  VerboseMode verboseMode = VERBOSE;
163  String currentPrompt;
164 #ifdef ARCH_HOST
165  char currentEOL = '\n';
166 #else
167  char currentEOL = '\r';
168 #endif
169  String currentWelcomeMessage;
170 };
171 
174 
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:100
void setCommandWelcomeMessage(const String &reqWelcomeMessage)
Set the welcome message.
Definition: CommandHandler.h:146
void setVerboseMode(VerboseMode reqVerboseMode)
Set the verbose mode.
Definition: CommandHandler.h:90
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:119
void setCommandEOL(char reqEOL)
Set the end of line character.
Definition: CommandHandler.h:128
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:110
Command handler class.
Definition: CommandHandler.h:40
CommandHandler commandHandler
Global instance of CommandHandler.
Command delegate class.
Definition: CommandDelegate.h:26
void registerSystemCommands()
Register default system commands.
VerboseMode getVerboseMode()
Get the verbose mode.
Definition: CommandHandler.h:82
String getCommandWelcomeMessage()
Get the welcome message.
Definition: CommandHandler.h:137