From 1182a68393fc23493d65c1f3f43dba964ada2643 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sat, 17 Apr 2021 23:22:36 -0500 Subject: [PATCH] Update: use the action of the process type, preparing for implementing exit files and the control program. --- level_3/controller/c/private-controller.c | 2 +- level_3/controller/c/private-controller.h | 6 ++++-- level_3/controller/c/private-rule.c | 19 +++++++++---------- level_3/controller/c/private-rule.h | 11 +---------- level_3/controller/c/private-thread.c | 4 ++-- 5 files changed, 17 insertions(+), 25 deletions(-) diff --git a/level_3/controller/c/private-controller.c b/level_3/controller/c/private-controller.c index 63469fb..c365663 100644 --- a/level_3/controller/c/private-controller.c +++ b/level_3/controller/c/private-controller.c @@ -673,7 +673,7 @@ extern "C" { #endif // _di_controller_preprocess_entry_ #ifndef _di_controller_process_entry_ - f_status_t controller_process_entry(const bool failsafe, controller_main_t *main, controller_cache_t *cache) { + f_status_t controller_process_entry(const bool failsafe, const uint8_t action, controller_main_t *main, controller_cache_t *cache) { f_status_t status = F_none; f_status_t status_lock = F_none; diff --git a/level_3/controller/c/private-controller.h b/level_3/controller/c/private-controller.h index 09d5b7e..cef422a 100644 --- a/level_3/controller/c/private-controller.h +++ b/level_3/controller/c/private-controller.h @@ -317,11 +317,13 @@ extern "C" { #endif // _di_controller_preprocess_entry_ /** - * Process (execute) all items for the loaded entry. + * Process (execute) all items for the loaded entry or exit. * * @param failsafe * If TRUE, operate in failsafe mode (starts at designated failsafe Item). * If FALSE, operate in normal mode (starts at "main" Item). + * @param action + * The action to perform, should be either controller_rule_action_type_start (for entry) or controller_rule_action_type_stop (for exit). * @param main * The main data. * @param cache @@ -342,7 +344,7 @@ extern "C" { * @see controller_string_dynamic_append_terminated() */ #ifndef _di_controller_process_entry_ - extern f_status_t controller_process_entry(const bool failsafe, controller_main_t *main, controller_cache_t *cache) f_gcc_attribute_visibility_internal; + extern f_status_t controller_process_entry(const bool failsafe, const uint8_t action, controller_main_t *main, controller_cache_t *cache) f_gcc_attribute_visibility_internal; #endif // _di_controller_process_entry_ /** diff --git a/level_3/controller/c/private-rule.c b/level_3/controller/c/private-rule.c index 95f5ea7..054814b 100644 --- a/level_3/controller/c/private-rule.c +++ b/level_3/controller/c/private-rule.c @@ -1763,9 +1763,9 @@ extern "C" { #endif // _di_controller_rule_setting_limit_type_name_ #ifndef _di_controller_rule_process_ - f_status_t controller_rule_process(const uint8_t action, const controller_main_t main, controller_process_t *process) { + f_status_t controller_rule_process(const controller_main_t main, controller_process_t *process) { - switch (action) { + switch (process->action) { case controller_rule_action_type_freeze: case controller_rule_action_type_kill: case controller_rule_action_type_pause: @@ -1784,7 +1784,7 @@ extern "C" { fprintf(main.data->error.to.stream, "%c", f_string_eol_s[0]); fprintf(main.data->error.to.stream, "%s%sUnsupported action type '", main.data->error.context.before->string, main.data->error.prefix ? main.data->error.prefix : f_string_empty_s); - fprintf(main.data->error.to.stream, "%s%s%s%s", main.data->error.context.after->string, main.data->error.notable.before->string, controller_rule_action_type_name(action), main.data->error.notable.after->string); + fprintf(main.data->error.to.stream, "%s%s%s%s", main.data->error.context.after->string, main.data->error.notable.before->string, controller_rule_action_type_name(process->action), main.data->error.notable.after->string); fprintf(main.data->error.to.stream, "%s' while attempting to execute rule.%s%c", main.data->error.context.before->string, main.data->error.context.after->string, f_string_eol_s[0]); controller_rule_error_print_cache(main.data->error, process->cache.action, F_true); @@ -1843,7 +1843,7 @@ extern "C" { } if ((process->options & controller_process_option_simulate) && main.data->parameters[controller_parameter_validate].result == f_console_result_found) { - controller_rule_validate(process->rule, action, process->options, main, &process->cache); + controller_rule_validate(process->rule, process->action, process->options, main, &process->cache); } f_array_length_t i = 0; @@ -2015,7 +2015,7 @@ extern "C" { } // synchronously execute dependency. - status = controller_rule_process_begin(0, alias_other, action, options_process, process->stack, main, process_other->cache); + status = controller_rule_process_begin(0, alias_other, process->action, options_process, process->stack, main, process_other->cache); if (status == F_child || status == F_signal) { f_thread_unlock(&process_other->active); @@ -2152,7 +2152,7 @@ extern "C" { for (j = 0; j < process->rule.items.array[i].actions.used; ++j) { - if (process->rule.items.array[i].actions.array[j].type == action) { + if (process->rule.items.array[i].actions.array[j].type == process->action) { missing = F_false; break; } @@ -2167,7 +2167,7 @@ extern "C" { fprintf(main.data->error.to.stream, "%s%sThe rule '", main.data->error.context.before->string, main.data->error.prefix ? main.data->error.prefix : f_string_empty_s); fprintf(main.data->error.to.stream, "%s%s%s%s", main.data->error.context.after->string, main.data->error.notable.before->string, process->rule.name.used ? process->rule.name.string : f_string_empty_s, main.data->error.notable.after->string); fprintf(main.data->error.to.stream, "%s' has no '", main.data->error.context.before->string); - fprintf(main.data->error.to.stream, "%s%s%s%s", main.data->error.context.after->string, main.data->error.notable.before->string, controller_rule_action_type_name(action).string, main.data->error.notable.after->string); + fprintf(main.data->error.to.stream, "%s%s%s%s", main.data->error.context.after->string, main.data->error.notable.before->string, controller_rule_action_type_name(process->action).string, main.data->error.notable.after->string); fprintf(main.data->error.to.stream, "%s' action to execute.%s%c", main.data->error.context.before->string, main.data->error.context.after->string, f_string_eol_s[0]); controller_rule_error_print_cache(main.data->error, process->cache.action, F_true); @@ -2180,7 +2180,7 @@ extern "C" { } if (F_status_is_error_not(status)) { - status = controller_rule_execute(action, process->options, main, process); + status = controller_rule_execute(process->action, process->options, main, process); if (status == F_child || status == F_signal || status == F_status_set_error(F_lock)) { return status; @@ -2618,8 +2618,7 @@ extern "C" { } if (F_status_is_error_not(status)) { - // @todo this needs to support passing different (supported) types, particularly when the "control" is written, (an entry will always send start and an exit will always send stop). - status = controller_rule_process(controller_rule_action_type_start, main, process); + status = controller_rule_process(main, process); } } else { diff --git a/level_3/controller/c/private-rule.h b/level_3/controller/c/private-rule.h index 2eb8c87..0923566 100644 --- a/level_3/controller/c/private-rule.h +++ b/level_3/controller/c/private-rule.h @@ -589,15 +589,6 @@ extern "C" { * * The rule status will be updated by this function. * - * @param action - * The action to perform based on the action type codes. - * - * Only subset of the action type codes are supported: - * - controller_rule_action_type_kill - * - controller_rule_action_type_reload - * - controller_rule_action_type_restart - * - controller_rule_action_type_start - * - controller_rule_action_type_stop * @param main * The main data. * @param process @@ -615,7 +606,7 @@ extern "C" { * Errors (with error bit) from: controller_lock_write(). */ #ifndef _di_controller_rule_process_ - extern f_status_t controller_rule_process(const uint8_t action, const controller_main_t main, controller_process_t *process) f_gcc_attribute_visibility_internal; + extern f_status_t controller_rule_process(const controller_main_t main, controller_process_t *process) f_gcc_attribute_visibility_internal; #endif // _di_controller_rule_process_ /** diff --git a/level_3/controller/c/private-thread.c b/level_3/controller/c/private-thread.c index a11f091..f70c546 100644 --- a/level_3/controller/c/private-thread.c +++ b/level_3/controller/c/private-thread.c @@ -552,13 +552,13 @@ extern "C" { *status = F_status_set_error(F_available_not); } else { - *status = controller_process_entry(F_false, entry->main, cache); + *status = controller_process_entry(F_false, controller_rule_action_type_start, entry->main, cache); if (F_status_is_error(*status)) { entry->setting->ready = controller_setting_ready_fail; if (F_status_set_fine(*status) == F_require && entry->main->setting->failsafe_enabled) { - const f_status_t status_failsafe = controller_process_entry(F_true, entry->main, cache); + const f_status_t status_failsafe = controller_process_entry(F_true, controller_rule_action_type_start, entry->main, cache); if (F_status_is_error(status_failsafe)) { if (data->error.verbosity != f_console_verbosity_quiet) { -- 1.8.3.1