// an empty stack is used here because each rule here is the first rule run in the rule's scope.
const f_array_lengths_t stack = f_array_lengths_t_initialize;
- const bool simulate = main->data->parameters[controller_parameter_test].result == f_console_result_found;
-
cache->ats.used = 0;
cache->stack.used = 0;
return status;
}
- if (simulate || main->data->error.verbosity == f_console_verbosity_verbose) {
+ if (main->data->parameters[controller_parameter_test].result == f_console_result_found || main->data->error.verbosity == f_console_verbosity_verbose) {
if (main->data->error.verbosity != f_console_verbosity_quiet) {
f_thread_mutex_lock(&main->thread->lock.print);
if (F_status_is_error(entry_action->status)) {
if (controller_entry_action_type_is_rule(entry_action->type)) {
- if (simulate) {
+ if (main->data->parameters[controller_parameter_test].result == f_console_result_found) {
if (main->data->error.verbosity != f_console_verbosity_quiet) {
f_thread_mutex_lock(&main->thread->lock.print);
}
}
else {
- if (simulate) {
+ if (main->data->parameters[controller_parameter_test].result == f_console_result_found) {
if (main->data->error.verbosity != f_console_verbosity_quiet) {
f_thread_mutex_lock(&main->thread->lock.print);
if (entry_action->type == controller_entry_action_type_ready) {
if (entry_action->code & controller_entry_rule_code_wait) {
- if (simulate || main->data->error.verbosity == f_console_verbosity_verbose) {
+ if (main->data->parameters[controller_parameter_test].result == f_console_result_found || main->data->error.verbosity == f_console_verbosity_verbose) {
if (main->data->error.verbosity != f_console_verbosity_quiet) {
f_thread_mutex_lock(&main->thread->lock.print);
}
if (main->setting->ready == controller_setting_ready_wait) {
- if (simulate || main->data->error.verbosity == f_console_verbosity_verbose) {
+ if (main->data->parameters[controller_parameter_test].result == f_console_result_found || main->data->error.verbosity == f_console_verbosity_verbose) {
if (main->data->error.verbosity != f_console_verbosity_quiet) {
f_thread_mutex_lock(&main->thread->lock.print);
}
}
- if (!simulate) {
+ if (main->data->parameters[controller_parameter_test].result == f_console_result_none) {
status = controller_perform_ready(is_entry, *main, cache);
if (F_status_is_error(status)) return status;
main->setting->ready = controller_setting_ready_yes;
}
- else if (simulate || main->data->error.verbosity == f_console_verbosity_verbose) {
+ else if (main->data->parameters[controller_parameter_test].result == f_console_result_found || main->data->error.verbosity == f_console_verbosity_verbose) {
if (main->data->error.verbosity != f_console_verbosity_quiet) {
f_thread_mutex_lock(&main->thread->lock.print);
return status;
}
- if (simulate || main->data->error.verbosity == f_console_verbosity_verbose) {
+ if (main->data->parameters[controller_parameter_test].result == f_console_result_found || main->data->error.verbosity == f_console_verbosity_verbose) {
if (main->data->error.verbosity != f_console_verbosity_quiet) {
f_thread_mutex_lock(&main->thread->lock.print);
f_thread_unlock(&main->thread->lock.rule);
- if (simulate || main->data->error.verbosity == f_console_verbosity_verbose) {
+ if (main->data->parameters[controller_parameter_test].result == f_console_result_found || main->data->error.verbosity == f_console_verbosity_verbose) {
if (main->data->error.verbosity != f_console_verbosity_quiet) {
f_thread_mutex_lock(&main->thread->lock.print);
controller_print_unlock_flush(main->data->output.stream, &main->thread->lock.print);
}
- if (!simulate) {
+ if (main->data->parameters[controller_parameter_test].result == f_console_result_none) {
f_thread_unlock(&main->thread->lock.rule);
break;
options_force = 0;
options_process = 0;
- if (simulate) {
+ if (main->data->parameters[controller_parameter_test].result == f_console_result_found) {
options_process |= controller_process_option_simulate;
}
}
if (entry_action->code & controller_entry_rule_code_asynchronous) {
- if (main->data->parameters[controller_parameter_validate].result != f_console_result_found) {
+ if (main->data->parameters[controller_parameter_validate].result == f_console_result_none) {
options_force |= controller_process_option_asynchronous;
}
break;
}
- if (F_status_is_error(status) && !simulate && (entry_action->code & controller_entry_rule_code_require)) {
+ if (F_status_is_error(status) && main->data->parameters[controller_parameter_test].result == f_console_result_none && (entry_action->code & controller_entry_rule_code_require)) {
return F_status_set_error(F_require);
}
}
}
else if (entry_action->type == controller_entry_action_type_execute) {
- if (simulate || main->data->error.verbosity == f_console_verbosity_verbose) {
+ if (main->data->parameters[controller_parameter_test].result == f_console_result_found || main->data->error.verbosity == f_console_verbosity_verbose) {
if (main->data->error.verbosity != f_console_verbosity_quiet) {
f_thread_mutex_lock(&main->thread->lock.print);
}
}
- if (simulate) {
+ if (main->data->parameters[controller_parameter_test].result == f_console_result_found) {
return F_execute;
}
}
else if (entry_action->type == controller_entry_action_type_timeout) {
- if (simulate || main->data->error.verbosity == f_console_verbosity_verbose) {
+ if (main->data->parameters[controller_parameter_test].result == f_console_result_found || main->data->error.verbosity == f_console_verbosity_verbose) {
f_string_t code = "";
if (entry_action->code == controller_entry_timeout_code_kill) {
main->setting->failsafe_enabled = F_true;
main->setting->failsafe_item_id = entry_action->number;
- if (simulate || main->data->error.verbosity == f_console_verbosity_verbose) {
+ if (main->data->parameters[controller_parameter_test].result == f_console_result_found || main->data->error.verbosity == f_console_verbosity_verbose) {
if (main->data->error.verbosity != f_console_verbosity_quiet) {
f_thread_mutex_lock(&main->thread->lock.print);
return status_lock;
}
- // check to see if any requied processes failed, but do not do this if already operating in failsafe.
+ // check to see if any required processes failed, but do not do this if already operating in failsafe.
if (F_status_is_error_not(status) && !failsafe && main->data->parameters[controller_parameter_validate].result == f_console_result_none) {
const f_status_t status_wait = controller_rule_wait_all(is_entry, *main, F_true, 0);
}
}
- if ((simulate && main->data->error.verbosity != f_console_verbosity_quiet) || main->data->error.verbosity == f_console_verbosity_verbose) {
+ if ((main->data->parameters[controller_parameter_test].result == f_console_result_found && main->data->error.verbosity != f_console_verbosity_quiet) || main->data->error.verbosity == f_console_verbosity_verbose) {
f_thread_mutex_lock(&main->thread->lock.print);
fprintf(main->data->output.stream, "%c", f_string_eol_s[0]);
controller_thread_join(&thread.id_entry);
status = thread.status;
+ thread.id_entry = 0;
}
}
}
// only make the rule and control threads available once any/all pre-processing and are completed.
- if (F_status_is_error_not(status) && status != F_signal && status != F_child && thread.enabled == controller_thread_enabled) {
+ if (F_status_is_error_not(status) && status != F_signal && status != F_failure && status != F_child && thread.enabled == controller_thread_enabled) {
if (data->parameters[controller_parameter_validate].result == f_console_result_none) {
return F_child;
}
- if (F_status_is_error(status) || status == F_signal || !(data->parameters[controller_parameter_validate].result == f_console_result_none || data->parameters[controller_parameter_test].result == f_console_result_found)) {
+ if (F_status_is_error_not(status) && status != F_signal && status != F_failure && data->parameters[controller_parameter_validate].result == f_console_result_none && controller_thread_is_enabled(F_true, &thread)) {
- if (main.data->parameters[controller_parameter_validate].result == f_console_result_found) {
- const controller_main_entry_t entry = controller_macro_main_entry_t_initialize(&main, main.setting);
-
- status = f_thread_create(0, &thread.id_entry, &controller_thread_exit, (void *) &entry);
-
- if (F_status_is_error(status)) {
- if (data->error.verbosity != f_console_verbosity_quiet) {
- controller_error_print(data->error, F_status_set_fine(status), "f_thread_create", F_true, &thread);
- }
- }
- else {
- controller_thread_join(&thread.id_entry);
-
- status = thread.status;
- }
- }
- }
- else {
- if (data->parameters[controller_parameter_validate].result == f_console_result_none && setting->mode == controller_setting_mode_service) {
+ if (setting->mode == controller_setting_mode_service) {
controller_thread_join(&thread.id_signal);
}
- else if (data->parameters[controller_parameter_validate].result == f_console_result_none && setting->mode == controller_setting_mode_program) {
+ else if (setting->mode == controller_setting_mode_program) {
controller_rule_wait_all(F_true, main, F_false, 0);
}
}
if ((F_status_set_fine(*status) == F_execute || F_status_set_fine(*status) == F_require) && entry->main->setting->failsafe_enabled) {
+ const uint8_t original_enabled = entry->main->thread->enabled;
+
// restore operating mode so that the failsafe can execute.
*status = f_thread_mutex_lock(&entry->main->thread->lock.alert);
controller_print_unlock_flush(data->error.to.stream, &entry->main->thread->lock.print);
}
+
+ *status = F_status_set_error(F_failure);
+ }
+ else {
+
+ // restore operating mode to value prior to failsafe mode.
+ *status = f_thread_mutex_lock(&entry->main->thread->lock.alert);
+
+ if (F_status_is_error_not(*status)) {
+ entry->main->thread->enabled = original_enabled;
+
+ f_thread_mutex_unlock(&entry->main->thread->lock.alert);
+ }
+
+ *status = F_failure;
}
}
}
if ((F_status_set_fine(*status) == F_execute || F_status_set_fine(*status) == F_require) && entry->main->setting->failsafe_enabled) {
+ const uint8_t original_enabled = entry->main->thread->enabled;
+
// restore operating mode so that the failsafe can execute.
if (F_status_set_fine(*status) == F_execute) {
*status = f_thread_mutex_lock(&entry->main->thread->lock.alert);
controller_print_unlock_flush(data->error.to.stream, &entry->main->thread->lock.print);
}
+
+ *status = F_status_set_error(F_failure);
+ }
+ else {
+
+ // restore operating mode to value prior to failsafe mode.
+ *status = f_thread_mutex_lock(&entry->main->thread->lock.alert);
+
+ if (F_status_is_error_not(*status)) {
+ entry->main->thread->enabled = original_enabled;
+
+ f_thread_mutex_unlock(&entry->main->thread->lock.alert);
+ }
+
+ *status = F_failure;
}
}
}