AceRoutine  0.2
A low-memory, fast-switching, cooperative multitasking library using stackless coroutines on Arduino platforms.
CommandHandler.h
1 /*
2 MIT License
3 
4 Copyright (c) 2018 Brian T. Park
5 
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12 
13 The above copyright notice and this permission notice shall be included in all
14 copies or substantial portions of the Software.
15 
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 SOFTWARE.
23 */
24 
25 #ifndef ACE_ROUTINE_COMMAND_HANDLER_H
26 #define ACE_ROUTINE_COMMAND_HANDLER_H
27 
28 #include <AceRoutine.h> // FCString
29 
30 class Print;
31 
32 namespace ace_routine {
33 namespace cli {
34 
39  public:
55  virtual void run(Print& printer, int argc, const char** argv) const = 0;
56 
58  FCString getName() const { return mName; }
59 
61  FCString getHelpString() const { return mHelpString; }
62 
63  protected:
65  CommandHandler(const char* name, const char* helpString):
66  mName(name),
67  mHelpString(helpString) {}
68 
70  CommandHandler(const __FlashStringHelper* name,
71  const __FlashStringHelper* helpString):
72  mName(name),
73  mHelpString(helpString) {}
74 
75  private:
76  FCString const mName;
77  FCString const mHelpString;
78 };
79 
80 }
81 }
82 
83 #endif
Signature for a command handler.
CommandHandler(const __FlashStringHelper *name, const __FlashStringHelper *helpString)
Constructor.
CommandHandler(const char *name, const char *helpString)
Constructor.
A union of (const char*) and (const __FlashStringHelper*) with a discriminator.
Definition: FCString.h:53
FCString getHelpString() const
Return the help string of the command.
virtual void run(Print &printer, int argc, const char **argv) const =0
Run the command.
FCString getName() const
Return the name of the command.