system_api: return error on repeated registration of shutdown handler

This commit is contained in:
Ivan Grokhotkov 2019-04-08 19:30:07 +08:00
parent bd309a133f
commit b1a722b2ca
2 changed files with 14 additions and 8 deletions

View File

@ -211,14 +211,15 @@ esp_err_t esp_read_mac(uint8_t* mac, esp_mac_type_t type)
esp_err_t esp_register_shutdown_handler(shutdown_handler_t handler) esp_err_t esp_register_shutdown_handler(shutdown_handler_t handler)
{ {
int i; for (int i = 0; i < SHUTDOWN_HANDLERS_NO; i++) {
for (i = 0; i < SHUTDOWN_HANDLERS_NO; i++) { if (shutdown_handlers[i] == handler) {
if (shutdown_handlers[i] == NULL) { return ESP_ERR_INVALID_STATE;
shutdown_handlers[i] = handler; } else if (shutdown_handlers[i] == NULL) {
return ESP_OK; shutdown_handlers[i] = handler;
} return ESP_OK;
} }
return ESP_FAIL; }
return ESP_ERR_NO_MEM;
} }
esp_err_t esp_unregister_shutdown_handler(shutdown_handler_t handler) esp_err_t esp_unregister_shutdown_handler(shutdown_handler_t handler)

View File

@ -80,6 +80,11 @@ typedef void (*shutdown_handler_t)(void);
* *
* This function allows you to register a handler that gets invoked before * This function allows you to register a handler that gets invoked before
* the application is restarted using esp_restart function. * the application is restarted using esp_restart function.
* @param handle function to execute on restart
* @return
* - ESP_OK on success
* - ESP_ERR_INVALID_STATE if the handler has already been registered
* - ESP_ERR_NO_MEM if no more shutdown handler slots are available
*/ */
esp_err_t esp_register_shutdown_handler(shutdown_handler_t handle); esp_err_t esp_register_shutdown_handler(shutdown_handler_t handle);