The parser_register_cmd() function does not return any error in case the
hashtable used for storing the commands is full, a condition that is
hard to debug.
This patch modifies the function prototype to return success or failure
and changes the REGISTER_CMD macro to detect the error.
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4900
38d2e660-2303-0410-9eaa-
f027e97ec537
* Register a new command into the parser
*
* \param cmd Command template describing the command
+ * \return true if registration was successful, false otherwise
*/
-void parser_register_cmd(const struct CmdTemplate* cmd)
+bool parser_register_cmd(const struct CmdTemplate* cmd)
{
- ht_insert(&commands, cmd);
+ return ht_insert(&commands, cmd);
}
void parser_init(void)
#include "cfg/cfg_parser.h"
#include <cpu/types.h>
+#include <cfg/debug.h>
/**
* Error generated by the commands through the return code.
*
* \param NAME Command name to register
*/
-#define REGISTER_CMD(NAME) REGISTER_FUNCTION(&cmd_ ## NAME ## _template)
+#define REGISTER_CMD(NAME) \
+ do { \
+ if (!REGISTER_FUNCTION(&cmd_ ## NAME ## _template)) \
+ ASSERT2(0, "Error in registering command, no space left"); \
+ } while (0)
/**
* Utility macro to create a command template.
*/
void parser_init(void);
-void parser_register_cmd(const struct CmdTemplate* cmd);
+bool parser_register_cmd(const struct CmdTemplate* cmd);
/**