CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
ICommandRegistry.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <cstddef>
5
6namespace cdc::serial {
7
12using CommandHandler = void (*)(const char* args);
13
21struct SubCommand {
22 const char* name;
23 const char* args;
24 const char* help;
26};
27
29constexpr size_t kSubCommandHeadBufSize = 80;
30
34struct Command {
35 const char* name;
36 const char* help;
38 const char* moduleName;
40 const SubCommand* subCommands = nullptr;
41};
42
52public:
53 virtual ~ICommandRegistry() = default;
54
60 virtual bool registerCommand(const Command& cmd) = 0;
61
66 virtual void unregisterModule(const char* moduleName) = 0;
67
73 virtual bool processCommand(const char* line) = 0;
74
78 virtual void showHelp() = 0;
79
83 virtual size_t getCommandCount() const = 0;
84
89 virtual void setAuthProvider(bool (*authCheck)()) = 0;
90
95 virtual void setOnCommandExecuted(void (*callback)()) = 0;
96
102 using LineInterceptor = bool (*)(const char* line);
103
108 virtual void setLineInterceptor(LineInterceptor interceptor) { (void)interceptor; }
109
119 using ByteInterceptor = void (*)(uint8_t byte);
120
125 virtual void setByteInterceptor(ByteInterceptor interceptor) { (void)interceptor; }
126 virtual ByteInterceptor getByteInterceptor() const { return nullptr; }
127};
128
129// Get global command registry instance
130ICommandRegistry& getCommandRegistry();
131
132} // namespace cdc::serial
virtual void unregisterModule(const char *moduleName)=0
virtual void setByteInterceptor(ByteInterceptor interceptor)
virtual void setLineInterceptor(LineInterceptor interceptor)
void(*)(uint8_t byte) ByteInterceptor
virtual ByteInterceptor getByteInterceptor() const
virtual void setAuthProvider(bool(*authCheck)())=0
bool(*)(const char *line) LineInterceptor
virtual bool processCommand(const char *line)=0
virtual size_t getCommandCount() const =0
virtual bool registerCommand(const Command &cmd)=0
virtual ~ICommandRegistry()=default
virtual void setOnCommandExecuted(void(*callback)())=0
constexpr size_t kSubCommandHeadBufSize
Buffer size for the "<name> <args>" column built during HELP rendering.
ICommandRegistry & getCommandRegistry()
Returns singleton command-registry interface.
void(*)(const char *args) CommandHandler
CommandHandler handler
Top-level dispatcher / handler.
const char * moduleName
Module that registered the command (used for HELP grouping).
const char * help
One-line summary shown in HELP.
const char * name
Top-level command (e.g. "TOTP" or "PING").
const SubCommand * subCommands
Optional null-terminated sub-command table for HELP.
bool requiresAuth
Whether the command needs an authenticated session.
CommandHandler handler
Invoked with the args following the sub-command keyword.
const char * args
Argument hint shown in HELP, e.g. "<ns> <key>". May be "" or nullptr.
const char * help
One-line description.
const char * name
Sub-command keyword, e.g. "LIST". nullptr terminates the array.