esp_modem: Add ConsoleCommand destructor

Commands are registered in Constructor. But there is now of deregistering it
This is needed for correct console re-construction,
for example with USB modem replugging.
This commit is contained in:
Tomas Rezucha
2022-09-09 11:08:44 +02:00
parent fe536e476c
commit a89a0ab7a3
2 changed files with 15 additions and 0 deletions

View File

@ -18,6 +18,16 @@ ConsoleCommand::ConsoleCommand(const char *command, const char *help, const std:
RegisterCommand(command, help, args);
}
ConsoleCommand::~ConsoleCommand()
{
// Find this command in static list of commands and remove it
auto cmd = std::find(console_commands.begin(), console_commands.end(), this);
if (cmd != console_commands.end()) {
console_commands.erase(cmd);
last_command--;
}
}
void ConsoleCommand::RegisterCommand(const char *command, const char *help, const std::vector<CommandArgs> &args)
{
assert(last_command <= MAX_REPEAT_NR);

View File

@ -92,6 +92,11 @@ public:
*/
explicit ConsoleCommand(const char *command, const char *help, const std::vector<CommandArgs> &args, std::function<bool(ConsoleCommand *)> f);
/**
* @brief Destructor of ConsoleCommand
*/
~ConsoleCommand();
/**
* @brief Utility getters of various params from the argument list
*/