From: Kevin Day Date: Sun, 2 Jun 2024 17:28:29 +0000 (-0500) Subject: Progress: Continue migrating the project. X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=433d2841eec914f12a92edd6ee3479069c3f10ca;p=controller Progress: Continue migrating the project. --- diff --git a/data/build/settings b/data/build/settings index d8d1ffe..3550b86 100644 --- a/data/build/settings +++ b/data/build/settings @@ -43,7 +43,8 @@ build_libraries-monolithic -lfll build_sources_library main/common.c main/common/define.c main/common/enumeration.c main/common/print.c main/common/string.c main/common/type.c build_sources_library main/common/type/cache.c main/common/type/control.c main/common/type/entry.c main/common/type/execute.c main/common/type/global.c main/common/type/lock.c main/common/type/instance.c main/common/type/program.c main/common/type/rule.c main/common/type/thread.c build_sources_library main/common/string/general.c main/common/string/rule.c -build_sources_library main/instance.c main/lock.c main/path.c main/process.c +build_sources_library main/convert.c main/instance.c main/instance/prepare.c main/instance/wait.c +build_sources_library main/file.c main/lock.c main/path.c main/process.c build_sources_library main/rule.c main/rule/action.c main/rule/execute.c main/rule/expand.c main/rule/instance.c main/rule/is.c main/rule/item.c main/rule/parameter.c main/rule/read.c main/rule/setting.c main/rule/validate.c main/rule/wait.c build_sources_library main/print/action.c main/print/data.c main/print/debug.c main/print/error.c main/print/lock.c main/print/message.c main/print/rule.c main/print/verbose.c main/print/warning.c build_sources_library main/print/rule/action.c main/print/rule/item.c main/print/rule/setting.c @@ -55,7 +56,8 @@ build_sources_headers main/common/define/control.h main/common/define/entry.h ma build_sources_headers main/common/enumeration/control.h main/common/enumeration/entry.h main/common/enumeration/instance.h main/common/enumeration/program.h main/common/enumeration/rule.h main/common/enumeration/thread.h build_sources_headers main/common/string/general.h main/common/string/rule.h build_sources_headers main/common/type/cache.h main/common/type/control.h main/common/type/defs.h main/common/type/entry.h main/common/type/execute.h main/common/type/global.h main/common/type/lock.h main/common/type/instance.h main/common/type/program.h main/common/type/rule.h main/common/type/thread.h -build_sources_headers main/instance.h main/lock.h main/path.h main/process.h +build_sources_headers main/convert.h main/instance.h main/instance/prepare.h main/instance/wait.h +build_sources_headers main/file.h main/lock.h main/path.h main/process.h build_sources_headers main/rule.h main/rule/action.h main/rule/execute.h main/rule/expand.h main/rule/instance.h main/rule/is.h main/rule/item.h main/rule/parameter.h main/rule/read.h main/rule/setting.h main/rule/validate.h main/rule/wait.h build_sources_headers main/print/action.h main/print/data.h main/print/debug.h main/print/error.h main/print/lock.h main/print/message.h main/print/rule.h main/print/verbose.h main/print/warning.h build_sources_headers main/print/rule/action.h main/print/rule/item.h main/print/rule/setting.h diff --git a/sources/c/controller/main.c b/sources/c/controller/main.c index 6dd82da..a1fb0a7 100644 --- a/sources/c/controller/main.c +++ b/sources/c/controller/main.c @@ -2,7 +2,7 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { - controller_main_t data = controller_main_t_initialize; + controller_t data = controller_t_initialize; controller_program_t program = controller_program_t_initialize; data.program.debug.flag |= controller_print_flag_debug_e | controller_print_flag_out_e; @@ -35,12 +35,12 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { { const f_console_arguments_t arguments = macro_f_console_arguments_t_initialize_1(argc, argv, envp); - controller_main_setting_load(arguments, &data, &program); + controller_setting_load(arguments, &data, &program); } - controller_main_process(&data, &program); + controller_process(&data, &program); - controller_main_delete(&data); + controller_delete(&data); fll_program_standard_set_down(&data.program); diff --git a/sources/c/controller/main.h b/sources/c/controller/main.h index 7a5afbd..8e7c09a 100644 --- a/sources/c/controller/main.h +++ b/sources/c/controller/main.h @@ -8,8 +8,8 @@ * This file is only ever included by main/main.c and should not normally be included anywhere else. * Anything that wants to include this should be providing the "controller" program functionality in some manner. */ -#ifndef _controller_controller_main_h -#define _controller_controller_main_h +#ifndef _controller_controller_h +#define _controller_controller_h #ifdef __cplusplus extern "C" { @@ -35,4 +35,4 @@ extern int main(const int argc, const f_string_t *argv, const f_string_t *envp); } // extern "C" #endif -#endif // _controller_controller_main_h +#endif // _controller_controller_h diff --git a/sources/c/init/main.c b/sources/c/init/main.c index fde1ef2..c244528 100644 --- a/sources/c/init/main.c +++ b/sources/c/init/main.c @@ -2,7 +2,7 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { - controller_main_t data = controller_main_t_initialize; + controller_t data = controller_t_initialize; controller_program_t program = controller_program_t_initialize; data.program.debug.flag |= controller_print_flag_debug_e | controller_print_flag_out_e; @@ -38,10 +38,10 @@ int main(const int argc, const f_string_t *argv, const f_string_t *envp) { { const f_console_arguments_t arguments = macro_f_console_arguments_t_initialize_1(argc, argv, envp); - controller_main_setting_load(arguments, &data, &program); + controller_setting_load(arguments, &data, &program); } - controller_main_process(&data, &program); + controller_process(&data, &program); fll_program_standard_set_down(&data.program); diff --git a/sources/c/main/common.c b/sources/c/main/common.c index ff52c3e..2527263 100644 --- a/sources/c/main/common.c +++ b/sources/c/main/common.c @@ -4,8 +4,8 @@ extern "C" { #endif -#ifndef _di_controller_main_error_simplify_ - f_status_t controller_main_error_simplify(const f_status_t status) { +#ifndef _di_controller_error_simplify_ + f_status_t controller_error_simplify(const f_status_t status) { if (status == F_memory_not) { return F_status_set_error(F_memory); @@ -37,10 +37,10 @@ extern "C" { return F_status_set_error(F_failure); } -#endif // _di_controller_main_error_simplify_ +#endif // _di_controller_error_simplify_ -#ifndef _di_controller_main_range_after_number_sign_ - f_range_t controller_main_range_after_number_sign(const f_string_static_t buffer, const f_range_t range) { +#ifndef _di_controller_range_after_number_sign_ + f_range_t controller_range_after_number_sign(const f_string_static_t buffer, const f_range_t range) { f_range_t result = range; @@ -57,10 +57,10 @@ extern "C" { return result; } -#endif // _di_controller_main_range_after_number_sign_ +#endif // _di_controller_range_after_number_sign_ -#ifndef _di_controller_main_setting_load_ - void controller_main_setting_load(const f_console_arguments_t arguments, controller_main_t * const main, controller_program_t * const program) { +#ifndef _di_controller_setting_load_ + void controller_setting_load(const f_console_arguments_t arguments, controller_t * const main, controller_program_t * const program) { if (!main || !program) return; @@ -71,7 +71,7 @@ extern "C" { main->setting.state.step_small = controller_allocation_small_d; if (F_status_is_error(main->setting.state.status)) { - controller_main_print_error(&main->program.error, macro_controller_f(f_console_parameter_process)); + controller_print_error(&main->program.error, macro_controller_f(f_console_parameter_process)); return; } @@ -79,7 +79,7 @@ extern "C" { main->setting.state.status = fll_program_parameter_process_context_standard(F_true, &main->program); if (F_status_is_error(main->setting.state.status)) { - controller_main_print_error(&main->program.error, macro_controller_f(fll_program_parameter_process_context_standard)); + controller_print_error(&main->program.error, macro_controller_f(fll_program_parameter_process_context_standard)); return; } @@ -87,7 +87,7 @@ extern "C" { main->setting.state.status = fll_program_parameter_process_verbosity_standard(F_true, &main->program); if (F_status_is_error(main->setting.state.status)) { - controller_main_print_error(&main->program.error, macro_controller_f(fll_program_parameter_process_verbosity_standard)); + controller_print_error(&main->program.error, macro_controller_f(fll_program_parameter_process_verbosity_standard)); return; } @@ -157,7 +157,7 @@ extern "C" { main->setting.state.status = f_string_dynamic_append(main->program.parameters.remaining.used ? args[main->program.parameters.remaining.array[0]] : controller_default_s, &program->name_entry); if (F_status_is_error(main->setting.state.status)) { - controller_main_print_error(&main->program.error, macro_controller_f(fll_program_parameter_process_verbosity_standard)); + controller_print_error(&main->program.error, macro_controller_f(fll_program_parameter_process_verbosity_standard)); return; } @@ -165,7 +165,7 @@ extern "C" { main->setting.state.status = f_path_current(F_false, &program->path_current); if (F_status_is_error(main->setting.state.status)) { - controller_main_print_error(&main->program.error, macro_controller_f(f_path_current)); + controller_print_error(&main->program.error, macro_controller_f(f_path_current)); return; } @@ -178,7 +178,7 @@ extern "C" { controller_path_canonical_relative(main, program->path_current, args[index], &program->path_setting); if (F_status_is_error(main->setting.state.status)) { - controller_main_print_error_file(&main->program.error, macro_controller_f(controller_path_canonical_relative), args[index], f_file_operation_verify_s, fll_error_file_type_path_e); + controller_print_error_file(&main->program.error, macro_controller_f(controller_path_canonical_relative), args[index], f_file_operation_verify_s, fll_error_file_type_path_e); return; } @@ -187,7 +187,7 @@ extern "C" { main->setting.state.status = f_string_dynamic_append(controller_default_path_settings_s, &program->path_setting); if (F_status_is_error(main->setting.state.status)) { - controller_main_print_error(&main->program.error, macro_controller_f(f_string_dynamic_append)); + controller_print_error(&main->program.error, macro_controller_f(f_string_dynamic_append)); return; } @@ -213,7 +213,7 @@ extern "C" { } if (F_status_is_error(main->setting.state.status)) { - controller_main_print_error(&main->program.error, macro_controller_f(f_string_dynamic_append)); + controller_print_error(&main->program.error, macro_controller_f(f_string_dynamic_append)); return; } @@ -226,7 +226,7 @@ extern "C" { controller_path_canonical_relative(main, program->path_current, args[index], &program->path_cgroup); if (F_status_is_error(main->setting.state.status)) { - controller_main_print_error_file(&main->program.error, macro_controller_f(controller_path_canonical_relative), args[index], f_file_operation_verify_s, fll_error_file_type_path_e); + controller_print_error_file(&main->program.error, macro_controller_f(controller_path_canonical_relative), args[index], f_file_operation_verify_s, fll_error_file_type_path_e); return; } @@ -234,13 +234,13 @@ extern "C" { main->setting.state.status = f_string_append_assure(F_path_separator_s, 1, &program->path_cgroup); if (F_status_is_error(main->setting.state.status)) { - controller_main_print_error(&main->program.error, macro_controller_f(f_string_append_assure)); + controller_print_error(&main->program.error, macro_controller_f(f_string_append_assure)); return; } } else { - controller_main_print_debug_directory_path_empty(&main->program.warning, f_console_symbol_long_normal_s, controller_long_cgroup_s); + controller_print_debug_directory_path_empty(&main->program.warning, f_console_symbol_long_normal_s, controller_long_cgroup_s); } } else { @@ -251,7 +251,7 @@ extern "C" { } if (F_status_is_error(main->setting.state.status)) { - controller_main_print_error(&main->program.error, macro_controller_f(f_string_dynamic_append_nulless)); + controller_print_error(&main->program.error, macro_controller_f(f_string_dynamic_append_nulless)); return; } @@ -259,7 +259,7 @@ extern "C" { main->setting.state.status = f_string_dynamic_append_assure(f_path_separator_s, &program->path_cgroup); if (F_status_is_error(main->setting.state.status)) { - controller_main_print_error(&main->program.error, macro_controller_f(f_string_dynamic_append_assure)); + controller_print_error(&main->program.error, macro_controller_f(f_string_dynamic_append_assure)); return; } @@ -290,7 +290,7 @@ extern "C" { main->setting.flag |= controller_main_flag_validate_e; } } -#endif // _di_controller_main_setting_load_ +#endif // _di_controller_setting_load_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/common.h b/sources/c/main/common.h index 5474eb4..e15e40f 100644 --- a/sources/c/main/common.h +++ b/sources/c/main/common.h @@ -25,9 +25,9 @@ extern "C" { * @return * A subset of status codes (with error bit set). */ -#ifndef _di_controller_main_error_simplify_ - extern f_status_t controller_main_error_simplify(const f_status_t status); -#endif // _di_controller_main_error_simplify_ +#ifndef _di_controller_error_simplify_ + extern f_status_t controller_error_simplify(const f_status_t status); +#endif // _di_controller_error_simplify_ /** * Given a string whose range represents a number, seek past the first positive or negative sign. @@ -45,9 +45,9 @@ extern "C" { * The string range. * The start range will be past the stop range on overflow or on any failure. */ -#ifndef _di_controller_main_range_after_number_sign_ - extern f_range_t controller_main_range_after_number_sign(const f_string_static_t buffer, const f_range_t range); -#endif // _di_controller_main_range_after_number_sign_ +#ifndef _di_controller_range_after_number_sign_ + extern f_range_t controller_range_after_number_sign(const f_string_static_t buffer, const f_range_t range); +#endif // _di_controller_range_after_number_sign_ /** * Perform the standard program setting load settings. @@ -76,9 +76,9 @@ extern "C" { * @see f_console_parameter_process() * @see fll_program_parameter_process_context() */ -#ifndef _di_controller_main_setting_load_ - extern void controller_main_setting_load(const f_console_arguments_t arguments, controller_main_t * const main, controller_program_t * const program); -#endif // _di_controller_main_setting_load_ +#ifndef _di_controller_setting_load_ + extern void controller_setting_load(const f_console_arguments_t arguments, controller_t * const main, controller_program_t * const program); +#endif // _di_controller_setting_load_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/common/define/thread.h b/sources/c/main/common/define/thread.h index 88873a3..0a72c81 100644 --- a/sources/c/main/common/define/thread.h +++ b/sources/c/main/common/define/thread.h @@ -20,15 +20,15 @@ extern "C" { * Thread related defines. */ #ifndef _di_controller_thread_d_ - #define controller_main_thread_cleanup_interval_long_d 3600 // 1 hour in seconds. - #define controller_main_thread_cleanup_interval_short_d 180 // 3 minutes in seconds. - #define controller_main_thread_exit_timeout_d 500 // 0.5 seconds in milliseconds. - #define controller_main_thread_exit_process_cancel_wait_d 600000000 // 0.6 seconds in nanoseconds. - #define controller_main_thread_exit_process_cancel_total_d 150 // 90 seconds in multiples of wait. + #define controller_thread_cleanup_interval_long_d 3600 // 1 hour in seconds. + #define controller_thread_cleanup_interval_short_d 180 // 3 minutes in seconds. + #define controller_thread_exit_timeout_d 500 // 0.5 seconds in milliseconds. + #define controller_thread_exit_process_cancel_wait_d 600000000 // 0.6 seconds in nanoseconds. + #define controller_thread_exit_process_cancel_total_d 150 // 90 seconds in multiples of wait. #define controller_thread_simulation_timeout_d 200 // 0.2 seconds in milliseconds. - #define controller_main_thread_signal_wait_timeout_seconds_d 70 - #define controller_main_thread_signal_wait_timeout_nanoseconds_d 0 + #define controller_thread_signal_wait_timeout_seconds_d 70 + #define controller_thread_signal_wait_timeout_nanoseconds_d 0 #define controller_thread_lock_read_timeout_seconds_d 3 #define controller_thread_lock_read_timeout_nanoseconds_d 0 @@ -48,11 +48,11 @@ extern "C" { #define controller_thread_wait_timeout_4_seconds_d 20 #define controller_thread_wait_timeout_4_nanoseconds_d 0 - #define controller_main_thread_exit_helper_timeout_seconds_d 0 - #define controller_main_thread_exit_helper_timeout_nanoseconds_d 100000000 // 0.1 seconds in nanoseconds. + #define controller_thread_exit_helper_timeout_seconds_d 0 + #define controller_thread_exit_helper_timeout_nanoseconds_d 100000000 // 0.1 seconds in nanoseconds. - #define controller_main_thread_exit_ready_timeout_seconds_d 0 - #define controller_main_thread_exit_ready_timeout_nanoseconds_d 500000000 // 0.5 seconds in nanoseconds. + #define controller_thread_exit_ready_timeout_seconds_d 0 + #define controller_thread_exit_ready_timeout_nanoseconds_d 500000000 // 0.5 seconds in nanoseconds. #endif // _di_controller_thread_d_ #ifdef __cplusplus diff --git a/sources/c/main/common/enumeration/rule.h b/sources/c/main/common/enumeration/rule.h index f1534b6..f7a8942 100644 --- a/sources/c/main/common/enumeration/rule.h +++ b/sources/c/main/common/enumeration/rule.h @@ -21,7 +21,7 @@ extern "C" { * * Execute type starts at 0 because it is intended to be used as an index within a static array. * - * controller_main_rule_action_execute_type_*_e: + * controller_rule_action_execute_type_*_e: * - freeze: The Freeze execution instructions. * - kill: The Kill execution instructions. * - pause: The Pause execution instructions. @@ -32,43 +32,43 @@ extern "C" { * - stop: The Stop execution instructions. * - thaw: The Thaw execution instructions. */ -#ifndef _di_controller_main_rule_action_execute_type_e_ +#ifndef _di_controller_rule_action_execute_type_e_ enum { - controller_main_rule_action_execute_type_freeze_e = 0, - controller_main_rule_action_execute_type_kill_e, - controller_main_rule_action_execute_type_pause_e, - controller_main_rule_action_execute_type_reload_e, - controller_main_rule_action_execute_type_restart_e, - controller_main_rule_action_execute_type_resume_e, - controller_main_rule_action_execute_type_start_e, - controller_main_rule_action_execute_type_stop_e, - controller_main_rule_action_execute_type_thaw_e, + controller_rule_action_execute_type_freeze_e = 0, + controller_rule_action_execute_type_kill_e, + controller_rule_action_execute_type_pause_e, + controller_rule_action_execute_type_reload_e, + controller_rule_action_execute_type_restart_e, + controller_rule_action_execute_type_resume_e, + controller_rule_action_execute_type_start_e, + controller_rule_action_execute_type_stop_e, + controller_rule_action_execute_type_thaw_e, // Designate the largest value in the enum, the '__' is intentional. - controller_main_rule_action_execute_type__enum_size_e, + controller_rule_action_execute_type__enum_size_e, }; // enum -#endif // _di_controller_main_rule_action_execute_type_e_ +#endif // _di_controller_rule_action_execute_type_e_ /** * Controller Rule Action method enumeration. * - * controller_main_rule_action_method_*_e: + * controller_rule_action_method_*_e: * - none: Nothing set. * - extended: Designate that this Action is represented using FSS Extended. * - extended_list: Designate that this Action is represented using FSS Extended List. */ -#ifndef _di_controller_main_rule_action_method_e_ +#ifndef _di_controller_rule_action_method_e_ enum { - controller_main_rule_action_method_none_e = 0, - controller_main_rule_action_method_extended_e, - controller_main_rule_action_method_extended_list_e, + controller_rule_action_method_none_e = 0, + controller_rule_action_method_extended_e, + controller_rule_action_method_extended_list_e, }; // enum -#endif // _di_controller_main_rule_action_method_e_ +#endif // _di_controller_rule_action_method_e_ /** * Controller Rule Action type enumeration. * - * controller_main_rule_action_type_*_e: + * controller_rule_action_type_*_e: * - none: Nothing set. * - freeze: The Freeze execution instructions. * - group: The Group setting. @@ -85,28 +85,28 @@ extern "C" { * - user: The User setting. * - with: The With flags. */ -#ifndef _di_controller_main_rule_action_type_e_ +#ifndef _di_controller_rule_action_type_e_ enum { - controller_main_rule_action_type_none_e = 0, - controller_main_rule_action_type_freeze_e, - controller_main_rule_action_type_group_e, - controller_main_rule_action_type_kill_e, - controller_main_rule_action_type_pause_e, - controller_main_rule_action_type_pid_file_e, - controller_main_rule_action_type_reload_e, - controller_main_rule_action_type_rerun_e, - controller_main_rule_action_type_restart_e, - controller_main_rule_action_type_resume_e, - controller_main_rule_action_type_start_e, - controller_main_rule_action_type_stop_e, - controller_main_rule_action_type_thaw_e, - controller_main_rule_action_type_user_e, - controller_main_rule_action_type_with_e, + controller_rule_action_type_none_e = 0, + controller_rule_action_type_freeze_e, + controller_rule_action_type_group_e, + controller_rule_action_type_kill_e, + controller_rule_action_type_pause_e, + controller_rule_action_type_pid_file_e, + controller_rule_action_type_reload_e, + controller_rule_action_type_rerun_e, + controller_rule_action_type_restart_e, + controller_rule_action_type_resume_e, + controller_rule_action_type_start_e, + controller_rule_action_type_stop_e, + controller_rule_action_type_thaw_e, + controller_rule_action_type_user_e, + controller_rule_action_type_with_e, // Designate the largest value in the enum, the '__' is intentional. - controller_main_rule_action_type__enum_size_e, + controller_rule_action_type__enum_size_e, }; // enum -#endif // _di_controller_main_rule_action_type_e_ +#endif // _di_controller_rule_action_type_e_ /** * Controller Rule Item type enumeration. diff --git a/sources/c/main/common/print.c b/sources/c/main/common/print.c index 11c9d89..e32df44 100644 --- a/sources/c/main/common/print.c +++ b/sources/c/main/common/print.c @@ -6,17 +6,19 @@ extern "C" { #ifndef _di_controller_f_a_ const f_string_t controller_f_a[] = { - "controller_main_lock_create", + "controller_lock_create", "controller_rule_copy", - "controller_rule_items_increase_by", "controller_path_canonical_relative", - "controller_pids_increase", "f_console_parameter_process", "f_environment_get_all", + "f_file_exists", + "f_file_stream_open", + "f_file_stream_read", "f_fss_apply_delimit", "f_fss_count_lines", "f_memory_array_increase", "f_memory_array_increase_by", + "f_memory_array_resize", "f_path_current", "f_rip_dynamic_partial", "f_rip_dynamic_partial_nulless", @@ -29,10 +31,12 @@ extern "C" { "f_string_dynamic_partial_mash_nulless", "f_string_maps_append", "f_thread_create", + "f_time_spec_millisecond", "fl_conversion_dynamic_partial_to_signed_detect", "fl_environment_load_names", "fl_fss_extended_list_content_read", "fl_fss_extended_list_object_read", + "fl_fss_extended_object_read", "fl_iki_read", "fll_control_group_prepare", "fll_execute_program", diff --git a/sources/c/main/common/print.h b/sources/c/main/common/print.h index af3773e..bd99a16 100644 --- a/sources/c/main/common/print.h +++ b/sources/c/main/common/print.h @@ -39,17 +39,19 @@ extern "C" { */ #ifndef _di_controller_f_e_ enum { - controller_f_controller_main_lock_create_e, + controller_f_controller_lock_create_e, controller_f_controller_rule_copy_e, - controller_f_controller_rule_items_increase_by_e, controller_f_controller_path_canonical_relative_e, - controller_f_controller_pids_increase_e, controller_f_f_console_parameter_process_e, controller_f_f_environment_get_all_e, + controller_f_f_file_exists_e, + controller_f_f_file_stream_open_e, + controller_f_f_file_stream_read_e, controller_f_f_fss_apply_delimit_e, controller_f_f_fss_count_lines_e, controller_f_f_memory_array_increase_e, controller_f_f_memory_array_increase_by_e, + controller_f_f_memory_array_resize_e, controller_f_f_path_current_e, controller_f_f_rip_dynamic_partial_e, controller_f_f_rip_dynamic_partial_nulless_e, @@ -62,10 +64,12 @@ extern "C" { controller_f_f_string_dynamic_partial_mash_nulless_e, controller_f_f_string_maps_append_e, controller_f_f_thread_create_e, + controller_f_f_time_spec_millisecond_e, controller_f_fl_conversion_dynamic_partial_to_signed_detect_e, controller_f_fl_environment_load_names_e, controller_f_fl_fss_extended_list_content_read_e, controller_f_fl_fss_extended_list_object_read_e, + controller_f_fl_fss_extended_object_read_e, controller_f_fl_iki_read_e, controller_f_fll_control_group_prepare_e, controller_f_fll_execute_program_e, diff --git a/sources/c/main/common/string/general.c b/sources/c/main/common/string/general.c index 357f260..fdfe696 100644 --- a/sources/c/main/common/string/general.c +++ b/sources/c/main/common/string/general.c @@ -62,7 +62,7 @@ extern "C" { const f_string_static_t controller_length_s = macro_f_string_static_t_initialize_1(CONTROLLER_length_s, 0, CONTROLLER_length_s_length); const f_string_static_t controller_limit_s = macro_f_string_static_t_initialize_1(CONTROLLER_limit_s, 0, CONTROLLER_limit_s_length); const f_string_static_t controller_locks_s = macro_f_string_static_t_initialize_1(CONTROLLER_locks_s, 0, CONTROLLER_locks_s_length); - const f_string_static_t controller_main_s = macro_f_string_static_t_initialize_1(CONTROLLER_main_s, 0, CONTROLLER_main_s_length); + const f_string_static_t controller_s = macro_f_string_static_t_initialize_1(CONTROLLER_main_s, 0, CONTROLLER_main_s_length); const f_string_static_t controller_max_s = macro_f_string_static_t_initialize_1(CONTROLLER_max_s, 0, CONTROLLER_max_s_length); const f_string_static_t controller_memlock_s = macro_f_string_static_t_initialize_1(CONTROLLER_memlock_s, 0, CONTROLLER_memlock_s_length); const f_string_static_t controller_method_s = macro_f_string_static_t_initialize_1(CONTROLLER_method_s, 0, CONTROLLER_method_s_length); diff --git a/sources/c/main/common/string/general.h b/sources/c/main/common/string/general.h index 0450ea0..d099c47 100644 --- a/sources/c/main/common/string/general.h +++ b/sources/c/main/common/string/general.h @@ -353,7 +353,7 @@ extern "C" { extern const f_string_static_t controller_length_s; extern const f_string_static_t controller_limit_s; extern const f_string_static_t controller_locks_s; - extern const f_string_static_t controller_main_s; + extern const f_string_static_t controller_s; extern const f_string_static_t controller_max_s; extern const f_string_static_t controller_memlock_s; extern const f_string_static_t controller_method_s; diff --git a/sources/c/main/common/string/rule.c b/sources/c/main/common/string/rule.c index 742f4bd..5484055 100644 --- a/sources/c/main/common/string/rule.c +++ b/sources/c/main/common/string/rule.c @@ -4,10 +4,10 @@ extern "C" { #endif -#ifndef _di_controller_main_rule_action_method_s_ - const f_string_static_t controller_main_rule_action_method_extended_s = macro_f_string_static_t_initialize_1(CONTROLLER_rule_action_method_extended_s, 0, CONTROLLER_rule_action_method_extended_s_length); - const f_string_static_t controller_main_rule_action_method_extended_list_s = macro_f_string_static_t_initialize_1(CONTROLLER_rule_action_method_extended_list_s, 0, CONTROLLER_rule_action_method_extended_list_s_length); -#endif // _di_controller_main_rule_action_method_s_ +#ifndef _di_controller_rule_action_method_s_ + const f_string_static_t controller_rule_action_method_extended_s = macro_f_string_static_t_initialize_1(CONTROLLER_rule_action_method_extended_s, 0, CONTROLLER_rule_action_method_extended_s_length); + const f_string_static_t controller_rule_action_method_extended_list_s = macro_f_string_static_t_initialize_1(CONTROLLER_rule_action_method_extended_list_s, 0, CONTROLLER_rule_action_method_extended_list_s_length); +#endif // _di_controller_rule_action_method_s_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/common/string/rule.h b/sources/c/main/common/string/rule.h index 1a0c1de..08e8c13 100644 --- a/sources/c/main/common/string/rule.h +++ b/sources/c/main/common/string/rule.h @@ -19,20 +19,20 @@ extern "C" { /** * Controller Rule Action strings. * - * controller_main_rule_action_method_*_s: + * controller_rule_action_method_*_s: * - extended: Designate that this Action is represented using FSS Extended. * - extended_list: Designate that this Action is represented using FSS Extended List. */ -#ifndef _di_controller_main_rule_action_method_s_ +#ifndef _di_controller_rule_action_method_s_ #define CONTROLLER_rule_action_method_extended_s "FSS-0001 (Extended)" #define CONTROLLER_rule_action_method_extended_list_s "FSS-0003 (Extended List)" #define CONTROLLER_rule_action_method_extended_s_length 19 #define CONTROLLER_rule_action_method_extended_list_s_length 24 - extern const f_string_static_t controller_main_rule_action_method_extended_s; - extern const f_string_static_t controller_main_rule_action_method_extended_list_s; -#endif // _di_controller_main_rule_action_method_s_ + extern const f_string_static_t controller_rule_action_method_extended_s; + extern const f_string_static_t controller_rule_action_method_extended_list_s; +#endif // _di_controller_rule_action_method_s_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/common/type.c b/sources/c/main/common/type.c index dd56813..a624d91 100644 --- a/sources/c/main/common/type.c +++ b/sources/c/main/common/type.c @@ -4,15 +4,15 @@ extern "C" { #endif -#ifndef _di_controller_main_delete_ - void controller_main_delete(controller_main_t * const main) { +#ifndef _di_controller_delete_ + void controller_delete(controller_t * const main) { if (!main) return; fll_program_data_delete(&main->program); controller_setting_delete(&main->setting); } -#endif // _di_controller_main_delete_ +#endif // _di_controller_delete_ #ifndef _di_controller_setting_delete_ void controller_setting_delete(controller_setting_t * const setting) { diff --git a/sources/c/main/common/type.h b/sources/c/main/common/type.h index 6335657..4e0f4d0 100644 --- a/sources/c/main/common/type.h +++ b/sources/c/main/common/type.h @@ -61,20 +61,20 @@ extern "C" { * - program: The main program data. * - setting: The settings data. */ -#ifndef _di_controller_main_t_ - struct controller_main_t_ { +#ifndef _di_controller_t_ + struct controller_t_ { fll_program_data_t program; controller_setting_t setting; controller_cache_t cache; }; - #define controller_main_t_initialize \ + #define controller_t_initialize \ { \ fll_program_data_t_initialize, \ controller_setting_t_initialize, \ controller_cache_t_initialize, \ } -#endif // _di_controller_main_t_ +#endif // _di_controller_t_ /** * De-allocate main program data. @@ -90,9 +90,9 @@ extern "C" { * @see controller_setting_delete() * @see fll_program_data_delete() */ -#ifndef _di_controller_main_delete_ - extern void controller_main_delete(controller_main_t * const main); -#endif // _di_controller_main_delete_ +#ifndef _di_controller_delete_ + extern void controller_delete(controller_t * const main); +#endif // _di_controller_delete_ /** * Delete the program main setting data. diff --git a/sources/c/main/common/type/defs.h b/sources/c/main/common/type/defs.h index 08e7dc4..fdfad2f 100644 --- a/sources/c/main/common/type/defs.h +++ b/sources/c/main/common/type/defs.h @@ -40,9 +40,9 @@ extern "C" { /** * The controller main typedef. */ -#ifndef _di_controller_main_t_ - typedef struct controller_main_t_ controller_main_t; -#endif // _di_controller_main_t_ +#ifndef _di_controller_t_ + typedef struct controller_t_ controller_t; +#endif // _di_controller_t_ /** * The controller program typedef. diff --git a/sources/c/main/common/type/entry.h b/sources/c/main/common/type/entry.h index cec9f15..2ae474a 100644 --- a/sources/c/main/common/type/entry.h +++ b/sources/c/main/common/type/entry.h @@ -174,7 +174,7 @@ extern "C" { 0, \ 0, \ 0, \ - controller_main_thread_exit_timeout_d, \ + controller_thread_exit_timeout_d, \ 0, \ 0, \ 0, \ diff --git a/sources/c/main/common/type/global.h b/sources/c/main/common/type/global.h index a1d6983..b1a2417 100644 --- a/sources/c/main/common/type/global.h +++ b/sources/c/main/common/type/global.h @@ -34,7 +34,7 @@ extern "C" { */ #ifndef _di_controller_global_t_ struct controller_global_t_ { - controller_main_t *main; + controller_t *main; controller_program_t *program; controller_thread_t *thread; @@ -64,13 +64,13 @@ extern "C" { * * Properties: * - is_normal: Boolean designating if this is operating in a normal state. - * - thread: The thread data. + * - global: The global data. */ #ifndef _di_controller_interrupt_t_ typedef struct { bool is_normal; - controller_thread_t *thread; + controller_global_t *global; } controller_interrupt_t; #define controller_interrupt_t_initialize { \ @@ -78,9 +78,9 @@ extern "C" { 0, \ } - #define macro_controller_interrupt_t_initialize_1(is_normal, thread) { \ + #define macro_controller_interrupt_t_initialize_1(is_normal, global) { \ is_normal, \ - thread, \ + global, \ } #endif // _di_controller_interrupt_t_ diff --git a/sources/c/main/common/type/instance.h b/sources/c/main/common/type/instance.h index c38c8a8..5e90dc9 100644 --- a/sources/c/main/common/type/instance.h +++ b/sources/c/main/common/type/instance.h @@ -71,7 +71,7 @@ extern "C" { controller_rule_t rule; controller_cache_t cache; - controller_global_t global; + controller_global_t *global; }; #define controller_instance_t_initialize { \ @@ -91,7 +91,7 @@ extern "C" { f_number_unsigneds_t_initialize, \ controller_rule_t_initialize, \ controller_cache_t_initialize, \ - controller_global_t_initialize, \ + 0, \ } #endif // _di_controller_instance_t_ diff --git a/sources/c/main/common/type/rule.c b/sources/c/main/common/type/rule.c index 3872698..0cc50ad 100644 --- a/sources/c/main/common/type/rule.c +++ b/sources/c/main/common/type/rule.c @@ -34,8 +34,8 @@ extern "C" { } #endif // _di_controller_rule_delete_ -#ifndef _di_controller_main_rule_action_delete_ - void controller_main_rule_action_delete(controller_main_rule_action_t * const action) { +#ifndef _di_controller_rule_action_delete_ + void controller_rule_action_delete(controller_rule_action_t * const action) { if (!action) return; @@ -43,22 +43,22 @@ extern "C" { f_memory_array_resize(0, sizeof(f_iki_data_t), (void **) &action->ikis.array, &action->ikis.used, &action->ikis.size); } -#endif // _di_controller_main_rule_action_delete_ +#endif // _di_controller_rule_action_delete_ -#ifndef _di_controller_main_rule_actions_delete_callback_ - f_status_t controller_main_rule_actions_delete_callback(const f_number_unsigned_t start, const f_number_unsigned_t stop, void * const void_array) { +#ifndef _di_controller_rule_actions_delete_callback_ + f_status_t controller_rule_actions_delete_callback(const f_number_unsigned_t start, const f_number_unsigned_t stop, void * const void_array) { { - controller_main_rule_action_t * const controller_main_rule_actions = (controller_main_rule_action_t *) void_array; + controller_rule_action_t * const controller_rule_actions = (controller_rule_action_t *) void_array; for (f_number_unsigned_t i = start; i < stop; ++i) { - controller_main_rule_action_delete(&controller_main_rule_actions[i]); + controller_rule_action_delete(&controller_rule_actions[i]); } // for } return F_okay; } -#endif // _di_controller_main_rule_actions_delete_callback_ +#endif // _di_controller_rule_actions_delete_callback_ #ifndef _di_controller_rule_item_delete_ void controller_rule_item_delete(controller_rule_item_t * const item) { @@ -66,7 +66,7 @@ extern "C" { if (!item) return; f_memory_array_resize(0, sizeof(f_char_t), (void **) &item->pid_file.string, &item->pid_file.used, &item->pid_file.size); - f_memory_arrays_resize(0, sizeof(controller_main_rule_action_t), (void **) &item->actions.array, &item->actions.used, &item->actions.size, &controller_main_rule_actions_delete_callback); + f_memory_arrays_resize(0, sizeof(controller_rule_action_t), (void **) &item->actions.array, &item->actions.used, &item->actions.size, &controller_rule_actions_delete_callback); } #endif // _di_controller_rule_item_delete_ diff --git a/sources/c/main/common/type/rule.h b/sources/c/main/common/type/rule.h index 73b43d8..5371a2e 100644 --- a/sources/c/main/common/type/rule.h +++ b/sources/c/main/common/type/rule.h @@ -83,7 +83,7 @@ extern "C" { * - status: The last execution status of the Rule Action. * - parameters: All parameters associated with the Rule Action. */ -#ifndef _di_controller_main_rule_action_t_ +#ifndef _di_controller_rule_action_t_ typedef struct { uint8_t type; f_number_unsigned_t line; @@ -91,16 +91,16 @@ extern "C" { f_string_dynamics_t parameters; f_iki_datas_t ikis; - } controller_main_rule_action_t; + } controller_rule_action_t; - #define controller_main_rule_action_t_initialize { \ + #define controller_rule_action_t_initialize { \ 0, \ 0, \ F_known_not, \ f_string_dynamics_t_initialize, \ f_iki_datas_t_initialize, \ } -#endif // _di_controller_main_rule_action_t_ +#endif // _di_controller_rule_action_t_ /** * Controller Rule Actions. @@ -110,20 +110,20 @@ extern "C" { * - size: Total amount of allocated space. * - used: Total number of allocated spaces used. */ -#ifndef _di_controller_main_rule_actions_t_ +#ifndef _di_controller_rule_actions_t_ typedef struct { - controller_main_rule_action_t *array; + controller_rule_action_t *array; f_number_unsigned_t size; f_number_unsigned_t used; - } controller_main_rule_actions_t; + } controller_rule_actions_t; - #define controller_main_rule_actions_t_initialize { \ + #define controller_rule_actions_t_initialize { \ 0, \ 0, \ 0, \ } -#endif // _di_controller_main_rule_actions_t_ +#endif // _di_controller_rule_actions_t_ /** * Controller Rule Item. @@ -142,8 +142,8 @@ extern "C" { f_number_unsigned_t line; f_string_dynamic_t pid_file; - controller_rule_rerun_t reruns[controller_main_rule_action_execute_type__enum_size_e]; - controller_main_rule_actions_t actions; + controller_rule_rerun_t reruns[controller_rule_action_execute_type__enum_size_e]; + controller_rule_actions_t actions; } controller_rule_item_t; #define controller_rule_item_t_initialize \ @@ -163,7 +163,7 @@ extern "C" { controller_rule_rerun_t_initialize, \ controller_rule_rerun_t_initialize, \ }, \ - controller_main_rule_actions_t_initialize, \ + controller_rule_actions_t_initialize, \ } #endif // _di_controller_rule_item_t_ @@ -262,7 +262,7 @@ extern "C" { * - parameter: Any parameters made available to the Rule for IKI substitution. * - path: The path to the Rule file. * - scheduler: The scheduler setting if the Rule "has" a scheduler. - * - status: A set of action-specific success/failure status of the Rule. Each index represents a controller_main_rule_action_type_* enum value. Index 0 represents a global status. + * - status: A set of action-specific success/failure status of the Rule. Each index represents a controller_rule_action_type_* enum value. Index 0 represents a global status. * - timeout_exit: The timeout to wait when exiting the Controller program after sending the terminate signal to send the kill signal. * - timeout_kill: The timeout to wait relating to using a kill signal. * - timeout_start: The timeout to wait relating to starting a process. @@ -272,7 +272,7 @@ extern "C" { */ #ifndef _di_controller_rule_t_ typedef struct { - f_status_t status[controller_main_rule_action_type__enum_size_e]; + f_status_t status[controller_rule_action_type__enum_size_e]; f_number_unsigned_t timeout_kill; f_number_unsigned_t timeout_start; @@ -398,12 +398,12 @@ extern "C" { * @see f_memory_array_resize() * @see f_memory_arrays_resize() */ -#ifndef _di_controller_main_rule_action_delete_ - extern void controller_main_rule_action_delete(controller_main_rule_action_t * const action); -#endif // _di_controller_main_rule_action_delete_ +#ifndef _di_controller_rule_action_delete_ + extern void controller_rule_action_delete(controller_rule_action_t * const action); +#endif // _di_controller_rule_action_delete_ /** - * A callback intended to be passed to f_memory_arrays_resize() for an controller_main_rule_actions_t structure. + * A callback intended to be passed to f_memory_arrays_resize() for an controller_rule_actions_t structure. * * This is only called when shrinking the array and generally should perform de-allocations. * @@ -423,11 +423,11 @@ extern "C" { * * F_parameter (with error bit) if a parameter is invalid. * - * @see controller_main_rule_action_delete() + * @see controller_rule_action_delete() */ -#ifndef _di_controller_main_rule_actions_delete_callback_ - extern f_status_t controller_main_rule_actions_delete_callback(const f_number_unsigned_t start, const f_number_unsigned_t stop, void * const array); -#endif // _di_controller_main_rule_actions_delete_callback_ +#ifndef _di_controller_rule_actions_delete_callback_ + extern f_status_t controller_rule_actions_delete_callback(const f_number_unsigned_t start, const f_number_unsigned_t stop, void * const array); +#endif // _di_controller_rule_actions_delete_callback_ /** * Delete the Controller Rule Item data. @@ -435,7 +435,7 @@ extern "C" { * @param item * The Rule Item data. * - * @see controller_main_rule_actions_delete() + * @see controller_rule_actions_delete() * * @see f_memory_array_resize() */ diff --git a/sources/c/main/controller.h b/sources/c/main/controller.h index 2702008..7e317be 100644 --- a/sources/c/main/controller.h +++ b/sources/c/main/controller.h @@ -48,22 +48,20 @@ #include #ifndef _di_thread_support_ + #include + #include #include #endif // _di_thread_support_ // FLL-1 includes. #include #include -#include -#include -#include -#include #include #include -#include // FLL-2 includes. #include +#include #include #include #include @@ -103,6 +101,7 @@ #include #include #include +#include #include #include #include @@ -127,7 +126,10 @@ #include #include #include +#include #include +#include +#include #include #include #include diff --git a/sources/c/main/convert.c b/sources/c/main/convert.c new file mode 100644 index 0000000..b58200d --- /dev/null +++ b/sources/c/main/convert.c @@ -0,0 +1,150 @@ +#include "controller.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_controller_convert_user_id_ + f_status_t controller_convert_user_id(const f_string_static_t buffer, const f_range_t range, controller_cache_t * const cache, uid_t * const id) { + + f_number_unsigned_t number = 0; + + f_status_t status = fl_conversion_dynamic_partial_to_unsigned_detect(fl_conversion_data_base_10_c, buffer, range, &number); + + if (F_status_is_error(status)) { + if (F_status_set_fine(status) == F_number) { + cache->action.generic.used = 0; + + status = f_rip_dynamic_partial_nulless(buffer, range, &cache->action.generic); + if (F_status_is_error(status)) return status; + + status = f_account_id_by_name(cache->action.generic, id); + if (F_status_is_error(status)) return status; + + return (status == F_exist_not) ? F_status_set_error(F_exist_not) : F_okay; + } + + return status; + } + + return (number > F_type_size_32_unsigned_d) ? F_status_set_error(F_number_too_large) : F_okay; + } +#endif // _di_controller_convert_user_id_ + +#ifndef _di_controller_convert_group_id_ + f_status_t controller_convert_group_id(const f_string_static_t buffer, const f_range_t range, controller_cache_t * const cache, gid_t * const id) { + + f_number_unsigned_t number = 0; + + f_status_t status = fl_conversion_dynamic_partial_to_unsigned_detect(fl_conversion_data_base_10_c, buffer, range, &number); + + if (F_status_is_error(status)) { + if (F_status_set_fine(status) == F_number) { + cache->action.generic.used = 0; + + status = f_rip_dynamic_partial_nulless(buffer, range, &cache->action.generic); + if (F_status_is_error(status)) return status; + + status = f_account_group_id_by_name(cache->action.generic, id); + if (F_status_is_error(status)) return status; + + return (status == F_exist_not) ? F_status_set_error(F_exist_not) : F_okay; + } + + return status; + } + + return (number > F_type_size_32_unsigned_d) ? F_status_set_error(F_number_too_large) : F_okay; + } +#endif // _di_controller_convert_group_id_ + +#ifndef _di_controller_convert_rule_action_execute_type_string_ + f_string_static_t controller_convert_rule_action_execute_type_string(const uint8_t type) { + + switch (type) { + case controller_rule_action_execute_type_freeze_e: + return controller_freeze_s; + + case controller_rule_action_execute_type_kill_e: + return controller_kill_s; + + case controller_rule_action_execute_type_pause_e: + return controller_pause_s; + + case controller_rule_action_execute_type_reload_e: + return controller_reload_s; + + case controller_rule_action_execute_type_restart_e: + return controller_restart_s; + + case controller_rule_action_execute_type_resume_e: + return controller_resume_s; + + case controller_rule_action_execute_type_start_e: + return controller_start_s; + + case controller_rule_action_execute_type_stop_e: + return controller_stop_s; + + case controller_rule_action_execute_type_thaw_e: + return controller_thaw_s; + } + + return f_string_empty_s; + } +#endif // _di_controller_convert_rule_action_execute_type_string_ + +#ifndef _di_controller_convert_rule_action_type_string_ + f_string_static_t controller_convert_rule_action_type_string(const uint8_t type) { + + switch (type) { + case controller_rule_action_type_freeze_e: + return controller_freeze_s; + + case controller_rule_action_type_group_e: + return controller_group_s; + + case controller_rule_action_type_kill_e: + return controller_kill_s; + + case controller_rule_action_type_pause_e: + return controller_pause_s; + + case controller_rule_action_type_pid_file_e: + return controller_pid_file_s; + + case controller_rule_action_type_reload_e: + return controller_reload_s; + + case controller_rule_action_type_rerun_e: + return controller_rerun_s; + + case controller_rule_action_type_restart_e: + return controller_restart_s; + + case controller_rule_action_type_resume_e: + return controller_resume_s; + + case controller_rule_action_type_start_e: + return controller_start_s; + + case controller_rule_action_type_stop_e: + return controller_stop_s; + + case controller_rule_action_type_thaw_e: + return controller_thaw_s; + + case controller_rule_action_type_user_e: + return controller_user_s; + + case controller_rule_action_type_with_e: + return controller_with_s; + } + + return f_string_empty_s; + } +#endif // _di_controller_convert_rule_action_type_string_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/sources/c/main/convert.h b/sources/c/main/convert.h new file mode 100644 index 0000000..07850ff --- /dev/null +++ b/sources/c/main/convert.h @@ -0,0 +1,111 @@ +/** + * FLL - Level 3 + * + * Project: Controller + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Provides convert functionality. + * + * This is auto-included and should not need to be explicitly included. + */ +#ifndef _controller_convert_h +#define _controller_convert_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Convert the string from a string representation of an ID or a user name into the numeric representation of that ID or user name. + * + * @param buffer + * A string containing user name or ID. + * @param range + * The range within the buffer specifically containing the name or ID. + * @param cache + * The cache. + * @param id + * The determined user ID. + * + * @return + * F_okay on success. + * + * F_exist_not (with error bit) if failed to match the name to an ID. + * F_number_too_large (with error bit) if the given ID is too large. + * + * Errors (with error bit) from: f_account_id_by_name(). + * Errors (with error bit) from: fl_conversion_dynamic_partial_to_unsigned_detect(). + * Errors (with error bit) from: f_rip_dynamic_partial_nulless(). + * + * @see f_account_id_by_name() + * @see fl_conversion_dynamic_partial_to_unsigned_detect() + * @see f_rip_dynamic_partial_nulless() + */ +#ifndef _di_controller_convert_user_id_ + f_status_t controller_convert_user_id(const f_string_static_t buffer, const f_range_t range, controller_cache_t * const cache, uid_t * const id); +#endif // _di_controller_convert_user_id_ + +/** + * Convert the string from a string representation of an ID or a group name into the numeric representation of that ID or group name. + * + * @param buffer + * A string containing group name or ID. + * @param range + * The range within the buffer specifically containing the name or ID. + * @param cache + * The cache. + * @param id + * The determined group ID. + * + * @return + * F_okay on success. + * + * F_exist_not (with error bit) if failed to match the name to an ID. + * F_number_too_large (with error bit) if the given ID is too large. + * + * Errors (with error bit) from: f_account_group_id_by_name(). + * Errors (with error bit) from: fl_conversion_dynamic_partial_to_unsigned_detect(). + * Errors (with error bit) from: f_rip_dynamic_partial_nulless(). + * + * @see f_account_group_id_by_name() + * @see fl_conversion_dynamic_partial_to_unsigned_detect() + * @see f_rip_dynamic_partial_nulless() + */ +#ifndef _di_controller_convert_group_id_ + f_status_t controller_convert_group_id(const f_string_static_t buffer, const f_range_t range, controller_cache_t * const cache, gid_t * const id); +#endif // _di_controller_convert_group_id_ + +/** + * Convert the rule action execute type code to the string representation. + * + * @param type + * The rule action execute type code. + * + * @return + * The string with used > 0 on success. + * The string with used == 0 if no match was found. + */ +#ifndef _di_controller_convert_rule_action_execute_type_string_ + extern f_string_static_t controller_convert_rule_action_execute_type_string(const uint8_t type); +#endif // _di_controller_convert_rule_action_execute_type_string_ + +/** + * Convert the rule action type code to the string representation. + * + * @param type + * The rule action type code. + * + * @return + * The string with used > 0 on success. + * The string with used == 0 if no match was found. + */ +#ifndef _di_controller_convert_rule_action_type_string_ + extern f_string_static_t controller_convert_rule_action_type_string(const uint8_t type); +#endif // _di_controller_convert_rule_action_type_string_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _controller_convert_h diff --git a/sources/c/main/file.c b/sources/c/main/file.c new file mode 100644 index 0000000..d31f75e --- /dev/null +++ b/sources/c/main/file.c @@ -0,0 +1,261 @@ +#include "controller.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_controller_file_load_ + f_status_t controller_file_load(controller_global_t * const global, controller_cache_t * const cache, const bool required, const f_string_static_t path_prefix, const f_string_static_t path_name, const f_string_static_t path_suffix) { + + if (!global || !cache) return F_status_set_error(F_parameter); + + f_status_t status = F_okay; + f_file_t file = f_file_t_initialize; + + cache->action.name_file.used = 0; + cache->buffer_file.used = 0; + cache->timestamp.seconds = 0; + cache->timestamp.seconds_nano = 0; + + status = f_string_dynamic_append(path_prefix, &cache->action.name_file); + + if (F_status_is_error_not(status)) { + status = f_string_dynamic_append(f_path_separator_s, &cache->action.name_file); + } + + if (F_status_is_error_not(status)) { + status = f_string_dynamic_append(path_name, &cache->action.name_file); + } + + if (F_status_is_error_not(status)) { + status = f_string_dynamic_append(f_path_extension_separator_s, &cache->action.name_file); + } + + if (F_status_is_error_not(status)) { + status = f_string_dynamic_append(path_suffix, &cache->action.name_file); + } + + if (F_status_is_error(status)) { + controller_print_error_status(&global->main->program.error, macro_controller_f(f_string_dynamic_append), F_status_set_fine(status)); + + return status; + } + + f_string_static_t path = f_string_static_t_initialize; + + if (global->setting->path_setting.used) { + path.used = global->setting->path_setting.used + F_path_separator_s_length + cache->action.name_file.used; + } + else { + path.used = cache->action.name_file.used; + } + + f_char_t path_string[path.used + 1]; + path.string = path_string; + + if (global->setting->path_setting.used) { + memcpy(path_string, global->setting->path_setting.string, sizeof(f_char_t) * global->setting->path_setting.used); + memcpy(path_string + global->setting->path_setting.used + F_path_separator_s_length, cache->action.name_file.string, sizeof(f_char_t) * cache->action.name_file.used); + + path_string[global->setting->path_setting.used] = f_path_separator_s.string[0]; + } + else { + memcpy(path_string, cache->action.name_file.string, sizeof(f_char_t) * cache->action.name_file.used); + } + + path_string[path.used] = 0; + + + status = f_file_stream_open(path, f_string_empty_s, &file); + + if (F_status_is_error(status)) { + if (!required && F_status_set_fine(status) == F_file_found_not) { + f_file_stream_flush(file); + f_file_stream_close(&file); + + return F_file_found_not; + } + + if (global->main->program.error.verbosity > f_console_verbosity_quiet_e) { + controller_print_error_file_status(&global->main->program.error, macro_controller_f(f_file_stream_open), F_true, path, f_file_operation_open_s, fll_error_file_type_file_e, F_status_set_fine(status)); + } + } + else { + status = f_file_stream_read(file, &cache->buffer_file); + + if (F_status_is_error(status)) { + if (global->main->program.error.verbosity > f_console_verbosity_quiet_e) { + controller_print_error_file(global->thread, &global->main->program.error, F_status_set_fine(status), "f_file_stream_read", F_true, path, f_file_operation_read_s, fll_error_file_type_file_e); + } + } + } + + f_file_stream_flush(file); + f_file_stream_close(&file); + + if (F_status_is_error_not(status)) { + struct stat stat_file; + + status = f_file_stat(path, F_true, &stat_file); + + if (F_status_is_error(status)) { + if (global->main->program.error.verbosity > f_console_verbosity_quiet_e) { + controller_print_error_file(global->thread, &global->main->program.error, F_status_set_fine(status), "f_file_stat", F_true, path, f_file_operation_stat_s, fll_error_file_type_file_e); + } + } + else { + cache->timestamp.seconds = stat_file.st_ctim.tv_sec; + cache->timestamp.seconds_nano = stat_file.st_ctim.tv_nsec; + } + } + + return F_status_is_error(status) ? status : F_okay; + } +#endif // _di_controller_file_load_ + +#ifndef _di_controller_file_pid_create_ + f_status_t controller_file_pid_create(const pid_t pid, const f_string_static_t path) { + + f_status_t status = F_okay; + + // The file exists, do not attempt to overwrite. + if (f_file_exists(path, F_true) == F_true) return F_status_set_error(F_file_found); + + { + f_string_dynamic_t path_directory = f_string_dynamic_t_initialize; + + status = f_file_name_directory(path, &path_directory); + + if (F_status_is_error_not(status)) { + status = f_directory_exists(path_directory); + } + + f_memory_array_resize(0, sizeof(f_char_t), (void **) &path_directory.string, &path_directory.used, &path_directory.size); + if (F_status_is_error(status)) return status; + + // The directory does not exist so do not bother attempting to create a pid file. + if (status == F_false) return F_status_set_error(F_directory_not); + } + + f_file_t file = f_file_t_initialize; + + file.flag = F_file_flag_write_only_d; + + status = f_file_stream_open(path, f_file_open_mode_read_truncate_s, &file); + if (F_status_is_error(status)) return status; + + fll_print_format("%i%r", file, pid, f_string_eol_s); + + f_file_stream_flush(file); + f_file_stream_close(&file); + + return F_status_is_error(status) ? status : F_okay; + } +#endif // _di_controller_file_pid_create_ + +#ifndef _di_controller_file_pid_delete_ + f_status_t controller_file_pid_delete(const pid_t pid, const f_string_static_t path) { + + // Only delete if the file exists and there is no error while checking. + if (f_file_exists(path, F_true) != F_true) return F_okay; + + f_status_t status = F_okay; + f_file_t pid_file = f_file_t_initialize; + + status = f_file_stream_open(path, f_file_open_mode_read_s, &pid_file); + if (F_status_is_error(status)) return status; + + f_string_dynamic_t pid_buffer = f_string_dynamic_t_initialize; + + status = f_file_stream_read(pid_file, &pid_buffer); + + if (F_status_is_error_not(status)) { + status = f_file_stream_flush(pid_file); + } + + if (F_status_is_error_not(status)) { + status = f_file_stream_close(&pid_file); + } + + if (F_status_is_error_not(status)) { + f_number_unsigned_t number = 0; + f_range_t range = macro_f_range_t_initialize_2(pid_buffer.used); + + for (; range.start < pid_buffer.used; ++range.start) { + if (!isspace(pid_buffer.string[range.start])) break; + } // for + + for (; range.stop > 0; --range.stop) { + if (!isspace(pid_buffer.string[range.stop])) break; + } // for + + status = fl_conversion_dynamic_partial_to_unsigned(fl_conversion_data_base_10_c, pid_buffer, range, &number); + + if (F_status_is_error_not(status) && number == pid) { + status = f_file_remove(path); + } + else { + status = F_status_set_error(F_number_not); + } + } + + f_memory_array_resize(0, sizeof(f_char_t), (void **) &pid_buffer.string, &pid_buffer.used, &pid_buffer.size); + + return status; + } +#endif // _di_controller_file_pid_delete_ + +#ifndef _di_controller_file_pid_read_ + f_status_t controller_file_pid_read(const f_string_static_t path, pid_t * const pid) { + + *pid = 0; + + f_status_t status = f_file_exists(path, F_true); + if (F_status_is_error(status)) return status; + if (status != F_true) return F_data_not; + + f_file_t pid_file = f_file_t_initialize; + + status = f_file_stream_open(path, f_file_open_mode_read_s, &pid_file); + if (F_status_is_error(status)) return status; + + f_string_dynamic_t pid_buffer = f_string_dynamic_t_initialize; + + status = f_file_stream_read(pid_file, &pid_buffer); + + if (F_status_is_error_not(status)) { + status = f_file_stream_flush(pid_file); + } + + if (F_status_is_error_not(status)) { + status = f_file_stream_close(&pid_file); + } + + if (F_status_is_error_not(status)) { + f_number_unsigned_t number = 0; + f_range_t range = macro_f_range_t_initialize_2(pid_buffer.used); + + for (; range.start < pid_buffer.used; ++range.start) { + if (!isspace(pid_buffer.string[range.start])) break; + } // for + + for (; range.stop > 0; --range.stop) { + if (!isspace(pid_buffer.string[range.stop])) break; + } // for + + status = fl_conversion_dynamic_partial_to_unsigned(fl_conversion_data_base_10_c, pid_buffer, range, &number); + + if (F_status_is_error_not(status)) { + *pid = (pid_t) number; + } + } + + f_memory_array_resize(0, sizeof(f_char_t), (void **) &pid_buffer.string, &pid_buffer.used, &pid_buffer.size); + + return status; + } +#endif // _di_controller_file_pid_read_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/sources/c/main/file.h b/sources/c/main/file.h new file mode 100644 index 0000000..b250539 --- /dev/null +++ b/sources/c/main/file.h @@ -0,0 +1,135 @@ +/** + * FLL - Level 3 + * + * Project: Controller + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Provides file functionality. + * + * This is auto-included and should not need to be explicitly included. + */ +#ifndef _controller_file_h +#define _controller_file_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Load a file from the controller settings directory. + * + * @param global + * The global data. + * + * Must not be NULL. + * @param cache + * The following within the cache is updated: + * - name_file: The partial path of the file is inserted. + * - buffer_file: The contents of the file is inserted. + * - timestamp: This is updated to reflect the last changed timestamp. + * + * Must not be NULL. + * + * @param required + * If TRUE, the file is required to exist and will throw an error if not found. + * If FALSE, the file is not required to exist and will return without error if not found. + * @param path_prefix + * The path prefix, such as 'entries' from '/etc/controller/entries/default.entry'. + * @param path_name + * The path name, such as 'default' from '/etc/controller/entries/default.entry'. + * @param path_suffix + * The path suffix, such as 'entry' from '/etc/controller/entries/default.entry'. + * + * @return + * F_okay on success. + * F_file_found_not if required is FALSE and the file is not found. + * + * Errors (with error bit) from: f_file_stat(). + * Errors (with error bit) from: f_file_stream_open(). + * Errors (with error bit) from: f_file_stream_read(). + * Errors (with error bit) from: f_string_append(). + * + * @see f_file_stat() + * @see f_file_stream_open() + * @see f_file_stream_read() + * @see f_string_append() + */ +#ifndef _di_controller_file_load_ + extern f_status_t controller_file_load(controller_global_t * const global, controller_cache_t * const cache, const bool required, const f_string_static_t path_prefix, const f_string_static_t path_name, const f_string_static_t path_suffix); +#endif // _di_controller_file_load_ + +/** + * Create the pid file, if possible. + * + * @param pid + * The PID (process id). + * @param path + * The file path to the pid file to create. + * + * @return + * F_okay on success. + * F_access_denied if pid file is not created due to access denied errors. + * F_directory_not if pid file is not created due to a parent directory is unavailable or invalid. + * + * Errors (with error bit) from: f_directory_exists(). + * Errors (with error bit) from: f_file_name_directory(). + * Errors (with error bit) from: f_file_stream_open(). + * + * @see f_directory_exists() + * @see f_file_name_directory() + * @see f_file_stream_open() + */ +#ifndef _di_controller_file_pid_create_ + f_status_t controller_file_pid_create(const pid_t pid, const f_string_static_t path); +#endif // _di_controller_file_pid_create_ + +/** + * Delete the pid file, if exists and is valid. + * + * This is meant to be called on exit and avoids checking status codes, returning void. + * + * @param pid + * The PID (process id). + * @param path + * The file path to the pid file to create. + * + * @return + * F_okay on success. + * + * F_number_not (with error bit) if the number from the pid file doesn't match the expected pid. + * + * Errors (with error bit) from: f_file_stream_close(). + * Errors (with error bit) from: f_file_stream_open(). + * Errors (with error bit) from: f_file_stream_read(). + * Errors (with error bit) from: fl_conversion_dynamic_partial_to_unsigned() + */ +#ifndef _di_controller_file_pid_delete_ + f_status_t controller_file_pid_delete(const pid_t pid, const f_string_static_t path); +#endif // _di_controller_file_pid_delete_ + +/** + * Read the PID from a PID file. + * + * @param path + * The file path to the pid file to create. + * @param pid + * The PID to be read. + * + * @return + * F_okay on success. + * + * Errors (with error bit) from: f_file_stream_close(). + * Errors (with error bit) from: f_file_stream_open(). + * Errors (with error bit) from: f_file_stream_read(). + * Errors (with error bit) from: fl_conversion_dynamic_partial_to_unsigned() + */ +#ifndef _di_controller_file_pid_read_ + f_status_t controller_file_pid_read(const f_string_static_t path, pid_t * const pid); +#endif // _di_controller_file_pid_read_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _controller_file_h diff --git a/sources/c/main/instance.c b/sources/c/main/instance.c index b4400f9..7ad9a91 100644 --- a/sources/c/main/instance.c +++ b/sources/c/main/instance.c @@ -4,6 +4,25 @@ extern "C" { #endif +#ifndef _di_controller_instance_find_ + f_status_t controller_instance_find(const f_number_unsigned_t action, const f_string_static_t alias, const controller_instances_t instances, f_number_unsigned_t * const at) { + + if (!alias.used) return F_okay; + if (!instances.used) return F_false; + + for (f_number_unsigned_t i = 0; i < instances.used; ++i) { + + if (instances.array[i] && instances.array[i]->action == action && f_compare_dynamic(alias, instances.array[i]->rule.alias) == F_equal_to) { + if (at) *at = i; + + return F_true; + } + } // for + + return F_false; + } +#endif // _di_controller_instance_find_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/sources/c/main/instance.h b/sources/c/main/instance.h index 8916aa5..663c93d 100644 --- a/sources/c/main/instance.h +++ b/sources/c/main/instance.h @@ -9,15 +9,40 @@ * * This is auto-included and should not need to be explicitly included. */ -#ifndef _controller_main_instance_h -#define _controller_main_instance_h +#ifndef _controller_instance_h +#define _controller_instance_h #ifdef __cplusplus extern "C" { #endif +/** + * Find an existing instance, for the given Rule Action. + * + * This does not do any locking or unlocking for the instances data, be sure to lock appropriately before and after calling this. + * + * @param action + * The Rule Action to find. + * @param alias + * The Rule alias to find. + * @param instances + * The array of instancees to. + * @param at + * (optional) The location within instances the id was found. + * + * Set to NULL to disable. + * + * @return + * F_okay if not given a valid id to search. + * F_false if there is no instance found. + * F_true if there is a instance found (address is stored in "at"). + */ +#ifndef _di_controller_instance_find_ + f_status_t controller_instance_find(const f_number_unsigned_t action, const f_string_static_t alias, const controller_instances_t instances, f_number_unsigned_t * const at); +#endif // _di_controller_instance_find_ + #ifdef __cplusplus } // extern "C" #endif -#endif // _controller_main_instance_h +#endif // _controller_instance_h diff --git a/sources/c/main/instance/prepare.c b/sources/c/main/instance/prepare.c new file mode 100644 index 0000000..4403f5f --- /dev/null +++ b/sources/c/main/instance/prepare.c @@ -0,0 +1,79 @@ +#include "../controller.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_controller_instance_prepare_ + f_status_t controller_instance_prepare(controller_global_t * const global, const bool is_normal, const uint8_t action, const f_string_static_t alias, f_number_unsigned_t *id) { + + if (!global) return F_status_set_error(F_parameter); + + f_status_t status = F_okay; + + if (controller_instance_find(action, alias, global->thread->instances, id) == F_false) { + f_thread_unlock(&global->thread->lock.instance); + + status = controller_lock_write(is_normal, global->thread, &global->thread->lock.instance); + + if (F_status_is_error(status)) { + controller_lock_print_error_critical(&global->main->program.error, F_status_set_fine(status), F_false, global->thread); + } + else { + status = f_memory_array_increase(controller_allocation_small_d, sizeof(controller_instance_t), (void **) &global->thread->instances.array, &global->thread->instances.used, &global->thread->instances.size); + } + + if (F_status_is_error_not(status) && global->thread->instances.array[global->thread->instances.used]) { + + controller_instance_t * const instance = global->thread->instances.array[global->thread->instances.used]; + + status = controller_lock_write(is_normal, global->thread, &instance->lock); + + if (F_status_is_error(status)) { + controller_lock_print_error_critical(&global->main->program.error, F_status_set_fine(status), F_false, global->thread); + } + else { + instance->action = action; + instance->rule.alias.used = 0; + instance->global = global; + + status = f_string_dynamic_append(alias, &instance->rule.alias); + + if (F_status_is_error_not(status)) { + instance->id = global->thread->instances.used++; + status = F_okay; + + if (id) { + *id = instance->id; + } + } + + f_thread_unlock(&instance->lock); + } + } + + f_thread_unlock(&global->thread->lock.instance); + + // The read lock must be restored on return. + status = F_status_is_error(controller_lock_read(is_normal, global->thread, &global->thread->lock.instance)) + ? F_status_set_error(F_lock) + : F_okay; + } + else { + status = F_found; + } + + return status; + } +#endif // _di_controller_instance_prepare_ + +#ifndef _di_controller_instance_prepare_instance_type_ + f_status_t controller_instance_prepare_instance_type(controller_global_t * const global, const uint8_t type, const uint8_t action, const f_string_static_t alias, f_number_unsigned_t *id) { + + return controller_instance_prepare(global, type != controller_instance_type_exit_e, action, alias, id); + } +#endif // _di_controller_instance_prepare_instance_type_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/sources/c/main/instance/prepare.h b/sources/c/main/instance/prepare.h new file mode 100644 index 0000000..ff31315 --- /dev/null +++ b/sources/c/main/instance/prepare.h @@ -0,0 +1,105 @@ +/** + * FLL - Level 3 + * + * Project: Controller + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Provides the instance prepare functionality. + * + * This is auto-included and should not need to be explicitly included. + */ +#ifndef _controller_main_instance_prepare_h +#define _controller_main_instance_prepare_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Prepare the instance. + * + * The instance is initialized with the instance id, the rule alias, and the rule action type. + * These are the necessary parts for uniquely identifying the instance. + * + * If a instance by the given Rule alias and Rule Action already exists, then nothing is done. + * + * This requires that a global.thread->lock.instance lock be set on instance->lock before being called. + * + * @param global + * The global data. + * + * Must not be NULL. + * @param is_normal + * If TRUE, then instance as if this operates during a normal operation (entry and control). + * If FALSE, then instance as if this operates during a an exit operation. + * @param action + * The Rule Action to use. + * @param alias + * The Rule alias to use. + * @param id + * (optional) The instance ID when found or created. + * + * Set to NULL to not use. + * + * @return + * F_okay on success. + * F_found on success, but nothing was done because an existing instance was found. + * + * F_lock (with error bit) if failed to re-establish read lock on global.thread->lock.instance while returning. + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_string_dynamic_append(). + * + * Errors (with error bit) from: controller_lock_read(). + * Errors (with error bit) from: controller_lock_write(). + * + * @see f_string_dynamic_append() + * @see controller_lock_read() + * @see controller_lock_write() + */ +#ifndef _di_controller_instance_prepare_ + extern f_status_t controller_instance_prepare(controller_global_t * const global, const bool is_normal, const uint8_t action, const f_string_static_t alias, f_number_unsigned_t *id); +#endif // _di_controller_instance_prepare_ + +/** + * Prepare the instance for some instance type. + * + * The instance is initialized with the instance id, the rule alias, and the rule action type. + * These are the necessary parts for uniquely identifying the instance. + * + * If a instance by the given Rule alias and Rule Action already exists, then nothing is done. + * + * This requires that a global.thread->lock.instance lock be set on instance->lock before being called. + * + * @param global + * The global data. + * + * Must not be NULL. + * @param type + * The instance type to use when checking if thread is enabled. + * @param action + * The Rule Action to use. + * @param alias + * The Rule alias to use. + * @param id + * (optional) The instance ID when found or created. + * + * Set to NULL to not use. + * + * @return + * Success from: controller_instance_prepare() + * + * Errors (with error bit) from: controller_instance_prepare(). + * + * @see controller_instance_prepare() + */ +#ifndef _di_controller_instance_prepare_instance_type_ + extern f_status_t controller_instance_prepare_instance_type(controller_global_t * const global, const uint8_t type, const uint8_t action, const f_string_static_t alias, f_number_unsigned_t *id); +#endif // _di_controller_instance_prepare_instance_type_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _controller_main_instance_prepare_h diff --git a/sources/c/main/instance/wait.c b/sources/c/main/instance/wait.c new file mode 100644 index 0000000..0b2c523 --- /dev/null +++ b/sources/c/main/instance/wait.c @@ -0,0 +1,85 @@ +#include "../controller.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_controller_instance_wait_ + f_status_t controller_instance_wait(controller_instance_t * const instance) { + + if (!instance || !instance->global || !instance->global->main || !instance->global->thread) return F_status_set_error(F_parameter); + if (!controller_thread_is_enabled_instance(instance)) return F_status_set_error(F_interrupt); + + f_time_spec_t time; + + f_status_t status = F_okay; + f_status_t status_lock = F_okay; + + uint8_t count = 0; + + do { + f_thread_mutex_lock(&instance->wait_lock); + + if (count < controller_thread_wait_timeout_1_before_d) { + controller_time_now(controller_thread_wait_timeout_1_seconds_d, controller_thread_wait_timeout_1_nanoseconds_d, &time); + } + else if (count < controller_thread_wait_timeout_2_before_d) { + controller_time_now(controller_thread_wait_timeout_2_seconds_d, controller_thread_wait_timeout_2_nanoseconds_d, &time); + } + else if (count < controller_thread_wait_timeout_3_before_d) { + controller_time_now(controller_thread_wait_timeout_3_seconds_d, controller_thread_wait_timeout_3_nanoseconds_d, &time); + } + else { + controller_time_now(controller_thread_wait_timeout_4_seconds_d, controller_thread_wait_timeout_4_nanoseconds_d, &time); + } + + status = f_thread_condition_wait_timed(&time, &instance->wait, &instance->wait_lock); + + f_thread_mutex_unlock(&instance->wait_lock); + + if (!controller_thread_is_enabled_instance(instance)) return F_status_set_error(F_interrupt); + if (F_status_is_error(status)) break; + + status_lock = controller_lock_read_instance(instance, &instance->lock); + + if (F_status_is_error(status_lock)) { + controller_lock_print_error_critical(&instance->global->main->program.error, F_status_set_fine(status_lock), F_true, instance->global->thread); + + break; + } + + if (!controller_rule_status_is_available(instance->action, instance->rule) && !(instance->state == controller_instance_state_active_e || instance->state == controller_instance_state_busy_e)) { + f_thread_unlock(&instance->lock); + + return F_okay; + } + + if (status != F_time) { + + // move up the wait timer after a trigger was received. + if (count < controller_thread_wait_timeout_2_before_d) { + count = 0; + } + else if (count < controller_thread_wait_timeout_3_before_d) { + count = controller_thread_wait_timeout_1_before_d; + } + else { + count = controller_thread_wait_timeout_2_before_d; + } + } + + f_thread_unlock(&instance->lock); + + if (count < controller_thread_wait_timeout_3_before_d) { + ++count; + } + + } while (status == F_time && controller_thread_is_enabled_instance(instance)); + + return status; + } +#endif // _di_controller_instance_wait_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/sources/c/main/instance/wait.h b/sources/c/main/instance/wait.h new file mode 100644 index 0000000..8717a04 --- /dev/null +++ b/sources/c/main/instance/wait.h @@ -0,0 +1,47 @@ +/** + * FLL - Level 3 + * + * Project: Controller + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Provides the instance wait functionality. + * + * This is auto-included and should not need to be explicitly included. + */ +#ifndef _controller_main_instance_wait_h +#define _controller_main_instance_wait_h + +#ifdef __cplusplus +extern "C" { +#endif + +/*** + * Safely wait for a instance, periodically checking to see if instance completed or check if exiting. + * + * @param instance + * The instance to wait on. + * + * Must not be NULL. + * + * @return + * F_okay on success. + * + * F_interrupt (with error bit) on receiving a instance signal, such as an interrupt signal. + * F_parameter (with error bit) if a parameter is invalid. + * + * Success from: f_thread_condition_wait_timed(). + * + * Errors (with error bit) from: f_thread_condition_wait_timed(). + * + * @see f_thread_condition_wait_timed() + */ +#ifndef _di_controller_instance_wait_ + extern f_status_t controller_instance_wait(controller_instance_t * const instance); +#endif // _di_controller_instance_wait_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _controller_main_instance_wait_h diff --git a/sources/c/main/lock.c b/sources/c/main/lock.c index 6d90c1e..440ba78 100644 --- a/sources/c/main/lock.c +++ b/sources/c/main/lock.c @@ -4,8 +4,8 @@ extern "C" { #endif -#ifndef _di_controller_main_lock_create_ - f_status_t controller_main_lock_create(controller_lock_t * const lock) { +#ifndef _di_controller_lock_create_ + f_status_t controller_lock_create(controller_lock_t * const lock) { if (!lock) return F_status_set_error(F_parameter); @@ -37,10 +37,10 @@ extern "C" { return F_status_is_error(status) ? status : F_okay; } -#endif // _di_controller_main_lock_create_ +#endif // _di_controller_lock_create_ -#ifndef _di_controller_main_lock_read_ - f_status_t controller_main_lock_read(const bool is_normal, controller_thread_t * const thread, f_thread_lock_t * const lock) { +#ifndef _di_controller_lock_read_ + f_status_t controller_lock_read(const bool is_normal, controller_thread_t * const thread, f_thread_lock_t * const lock) { if (!thread || !lock) return F_status_set_error(F_parameter); @@ -48,12 +48,12 @@ extern "C" { for (f_time_spec_t time; ; ) { - controller_main_time_now(controller_thread_lock_read_timeout_seconds_d, controller_thread_lock_read_timeout_nanoseconds_d, &time); + controller_time_now(controller_thread_lock_read_timeout_seconds_d, controller_thread_lock_read_timeout_nanoseconds_d, &time); status = f_thread_lock_read_timed(&time, lock); if (status == F_time) { - if (!controller_main_thread_is_enabled(is_normal, thread)) return F_status_set_error(F_interrupt); + if (!controller_thread_is_enabled(is_normal, thread)) return F_status_set_error(F_interrupt); } else { break; @@ -62,28 +62,28 @@ extern "C" { return status; } -#endif // _di_controller_main_lock_read_ +#endif // _di_controller_lock_read_ -#ifndef _di_controller_main_lock_read_instance_ - f_status_t controller_main_lock_read_instance(controller_instance_t * const instance, controller_thread_t * const thread, f_thread_lock_t * const lock) { +#ifndef _di_controller_lock_read_instance_ + f_status_t controller_lock_read_instance(controller_instance_t * const instance, f_thread_lock_t * const lock) { - if (!thread || !lock) return F_status_set_error(F_parameter); + if (!instance || !lock) return F_status_set_error(F_parameter); - return controller_main_lock_read_instance_type(instance->type, thread, lock); + return controller_lock_read_instance_type(instance->type, instance->global->thread, lock); } -#endif // _di_controller_main_lock_read_instance_ +#endif // _di_controller_lock_read_instance_ -#ifndef _di_controller_main_lock_read_instance_type_ - f_status_t controller_main_lock_read_instance_type(const uint8_t type, controller_thread_t * const thread, f_thread_lock_t * const lock) { +#ifndef _di_controller_lock_read_instance_type_ + f_status_t controller_lock_read_instance_type(const uint8_t type, controller_thread_t * const thread, f_thread_lock_t * const lock) { if (!thread || !lock) return F_status_set_error(F_parameter); - return controller_main_lock_read(type != controller_instance_type_exit_e, thread, lock); + return controller_lock_read(type != controller_instance_type_exit_e, thread, lock); } -#endif // _di_controller_main_lock_read_instance_type_ +#endif // _di_controller_lock_read_instance_type_ -#ifndef _di_controller_main_lock_write_ - f_status_t controller_main_lock_write(const bool is_normal, controller_thread_t * const thread, f_thread_lock_t * const lock) { +#ifndef _di_controller_lock_write_ + f_status_t controller_lock_write(const bool is_normal, controller_thread_t * const thread, f_thread_lock_t * const lock) { if (!thread || !lock) return F_status_set_error(F_parameter); @@ -91,12 +91,12 @@ extern "C" { for (f_time_spec_t time; ; ) { - controller_main_time_now(controller_thread_lock_write_timeout_seconds_d, controller_thread_lock_write_timeout_nanoseconds_d, &time); + controller_time_now(controller_thread_lock_write_timeout_seconds_d, controller_thread_lock_write_timeout_nanoseconds_d, &time); status = f_thread_lock_write_timed(&time, lock); if (status == F_time) { - if (!controller_main_thread_is_enabled(is_normal, thread)) return F_status_set_error(F_interrupt); + if (!controller_thread_is_enabled(is_normal, thread)) return F_status_set_error(F_interrupt); } else { break; @@ -105,25 +105,25 @@ extern "C" { return status; } -#endif // _di_controller_main_lock_write_ +#endif // _di_controller_lock_write_ -#ifndef _di_controller_main_lock_write_instance_ - f_status_t controller_main_lock_write_instance(controller_instance_t * const instance, controller_thread_t * const thread, f_thread_lock_t * const lock) { +#ifndef _di_controller_lock_write_instance_ + f_status_t controller_lock_write_instance(controller_instance_t * const instance, f_thread_lock_t * const lock) { - if (!thread || !lock) return F_status_set_error(F_parameter); + if (!instance || !lock) return F_status_set_error(F_parameter); - return controller_main_lock_write_instance_type(instance->type, thread, lock); + return controller_lock_write_instance_type(instance->type, instance->global->thread, lock); } -#endif // _di_controller_main_lock_write_instance_ +#endif // _di_controller_lock_write_instance_ -#ifndef _di_controller_main_lock_write_instance_type_ - f_status_t controller_main_lock_write_instance_type(const uint8_t type, controller_thread_t * const thread, f_thread_lock_t * const lock) { +#ifndef _di_controller_lock_write_instance_type_ + f_status_t controller_lock_write_instance_type(const uint8_t type, controller_thread_t * const thread, f_thread_lock_t * const lock) { if (!thread || !lock) return F_status_set_error(F_parameter); - return controller_main_lock_write(type != controller_instance_type_exit_e, thread, lock); + return controller_lock_write(type != controller_instance_type_exit_e, thread, lock); } -#endif // _di_controller_main_lock_write_instance_type_ +#endif // _di_controller_lock_write_instance_type_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/lock.h b/sources/c/main/lock.h index 65cb454..cdd8805 100644 --- a/sources/c/main/lock.h +++ b/sources/c/main/lock.h @@ -9,8 +9,8 @@ * * This is auto-included and should not need to be explicitly included. */ -#ifndef _controller_main_lock_h -#define _controller_main_lock_h +#ifndef _controller_lock_h +#define _controller_lock_h #ifdef __cplusplus extern "C" { @@ -35,9 +35,9 @@ extern "C" { * @see f_thread_lock_delete() * @see f_thread_mutex_delete() */ -#ifndef _di_controller_main_lock_create_ - extern f_status_t controller_main_lock_create(controller_lock_t * const lock); -#endif // _di_controller_main_lock_create_ +#ifndef _di_controller_lock_create_ + extern f_status_t controller_lock_create(controller_lock_t * const lock); +#endif // _di_controller_lock_create_ /** * Wait to get a read lock. @@ -68,9 +68,9 @@ extern "C" { * * @see f_thread_lock_read_timed() */ -#ifndef _di_controller_main_lock_read_ - extern f_status_t controller_main_lock_read(const bool is_normal, controller_thread_t * const thread, f_thread_lock_t * const lock); -#endif // _di_controller_main_lock_read_ +#ifndef _di_controller_lock_read_ + extern f_status_t controller_lock_read(const bool is_normal, controller_thread_t * const thread, f_thread_lock_t * const lock); +#endif // _di_controller_lock_read_ /** * Wait to get a read lock for some instance. @@ -79,8 +79,6 @@ extern "C" { * * @param instance * The instance to use when checking if thread is enabled. - * @param thread - * The thread data used to determine if the main thread is disabled or not. * * Must not be NULL. * @param lock @@ -89,17 +87,17 @@ extern "C" { * Must not be NULL. * * @return - * Status from: controller_main_lock_read(). + * Status from: controller_lock_read(). * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: controller_main_lock_read(). + * Errors (with error bit) from: controller_lock_read(). * - * @see controller_main_lock_read() + * @see controller_lock_read() */ -#ifndef _di_controller_main_lock_read_instance_ - extern f_status_t controller_main_lock_read_instance(controller_instance_t * const instance, controller_thread_t * const thread, f_thread_lock_t * const lock); -#endif // _di_controller_main_lock_read_instance_ +#ifndef _di_controller_lock_read_instance_ + extern f_status_t controller_lock_read_instance(controller_instance_t * const instance, f_thread_lock_t * const lock); +#endif // _di_controller_lock_read_instance_ /** * Wait to get a read lock for some instance type. @@ -118,17 +116,17 @@ extern "C" { * Must not be NULL. * * @return - * Status from: controller_main_lock_read(). + * Status from: controller_lock_read(). * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: controller_main_lock_read(). + * Errors (with error bit) from: controller_lock_read(). * - * @see controller_main_lock_read() + * @see controller_lock_read() */ -#ifndef _di_controller_main_lock_read_instance_type_ - extern f_status_t controller_main_lock_read_instance_type(const uint8_t type, controller_thread_t * const thread, f_thread_lock_t * const lock); -#endif // _di_controller_main_lock_read_instance_type_ +#ifndef _di_controller_lock_read_instance_type_ + extern f_status_t controller_lock_read_instance_type(const uint8_t type, controller_thread_t * const thread, f_thread_lock_t * const lock); +#endif // _di_controller_lock_read_instance_type_ /** * Wait to get a write lock. @@ -159,9 +157,9 @@ extern "C" { * * @see f_thread_lock_write_timed() */ -#ifndef _di_controller_main_lock_write_ - extern f_status_t controller_main_lock_write(const bool is_normal, controller_thread_t * const thread, f_thread_lock_t * const lock); -#endif // _di_controller_main_lock_write_ +#ifndef _di_controller_lock_write_ + extern f_status_t controller_lock_write(const bool is_normal, controller_thread_t * const thread, f_thread_lock_t * const lock); +#endif // _di_controller_lock_write_ /** * Wait to get a write lock for some instance. @@ -170,8 +168,6 @@ extern "C" { * * @param instance * The instance to use when checking if thread is enabled. - * @param thread - * The thread data used to determine if the main thread is disabled or not. * * Must not be NULL. * @param lock @@ -180,17 +176,17 @@ extern "C" { * Must not be NULL. * * @return - * Status from: controller_main_lock_write_instance_type(). + * Status from: controller_lock_write_instance_type(). * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: controller_main_lock_write_instance_type(). + * Errors (with error bit) from: controller_lock_write_instance_type(). * - * @see controller_main_lock_write_instance_type() + * @see controller_lock_write_instance_type() */ -#ifndef _di_controller_main_lock_write_instance_ - extern f_status_t controller_main_lock_write_instance(controller_instance_t * const instance, controller_thread_t * const thread, f_thread_lock_t * const lock); -#endif // _di_controller_main_lock_write_instance_ +#ifndef _di_controller_lock_write_instance_ + extern f_status_t controller_lock_write_instance(controller_instance_t * const instance, f_thread_lock_t * const lock); +#endif // _di_controller_lock_write_instance_ /** * Wait to get a write lock for some instance type. @@ -209,20 +205,20 @@ extern "C" { * Must not be NULL. * * @return - * Status from: controller_main_lock_write(). + * Status from: controller_lock_write(). * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: controller_main_lock_write(). + * Errors (with error bit) from: controller_lock_write(). * - * @see controller_main_lock_write() + * @see controller_lock_write() */ -#ifndef _di_controller_main_lock_write_instance_type_ - extern f_status_t controller_main_lock_write_instance_type(const uint8_t type, controller_thread_t * const thread, f_thread_lock_t * const lock); -#endif // _di_controller_main_lock_write_instance_type_ +#ifndef _di_controller_lock_write_instance_type_ + extern f_status_t controller_lock_write_instance_type(const uint8_t type, controller_thread_t * const thread, f_thread_lock_t * const lock); +#endif // _di_controller_lock_write_instance_type_ #ifdef __cplusplus } // extern "C" #endif -#endif // _controller_main_lock_h +#endif // _controller_lock_h diff --git a/sources/c/main/path.c b/sources/c/main/path.c index e3dd8e7..a9d17b9 100644 --- a/sources/c/main/path.c +++ b/sources/c/main/path.c @@ -5,7 +5,7 @@ extern "C" { #endif #ifndef _di_controller_path_canonical_relative_ - void controller_path_canonical_relative(controller_main_t * const main, const f_string_static_t current, const f_string_static_t source, f_string_dynamic_t * const destination) { + void controller_path_canonical_relative(controller_t * const main, const f_string_static_t current, const f_string_static_t source, f_string_dynamic_t * const destination) { if (!main || !destination) return; diff --git a/sources/c/main/path.h b/sources/c/main/path.h index 782c161..119f2ff 100644 --- a/sources/c/main/path.h +++ b/sources/c/main/path.h @@ -9,8 +9,8 @@ * * This is auto-included and should not need to be explicitly included. */ -#ifndef _controller_main_path_h -#define _controller_main_path_h +#ifndef _controller_path_h +#define _controller_path_h #ifdef __cplusplus extern "C" { @@ -48,11 +48,11 @@ extern "C" { * @see memmove() */ #ifndef _di_controller_path_canonical_relative_ - extern void controller_path_canonical_relative(controller_main_t * const main, const f_string_static_t current, const f_string_static_t source, f_string_dynamic_t * const destination); + extern void controller_path_canonical_relative(controller_t * const main, const f_string_static_t current, const f_string_static_t source, f_string_dynamic_t * const destination); #endif // _di_controller_path_canonical_relative_ #ifdef __cplusplus } // extern "C" #endif -#endif // _controller_main_path_h +#endif // _controller_path_h diff --git a/sources/c/main/print/debug.c b/sources/c/main/print/debug.c index 62f8447..05b6edc 100644 --- a/sources/c/main/print/debug.c +++ b/sources/c/main/print/debug.c @@ -4,13 +4,13 @@ extern "C" { #endif -#ifndef _di_controller_main_print_debug_directory_path_empty_ - f_status_t controller_main_print_debug_directory_path_empty(fl_print_t * const print, const f_string_static_t symbol, const f_string_static_t name) { +#ifndef _di_controller_print_debug_directory_path_empty_ + f_status_t controller_print_debug_directory_path_empty(fl_print_t * const print, const f_string_static_t symbol, const f_string_static_t name) { if (!print || !print->custom) return F_status_set_error(F_output_not); if (print->verbosity < f_console_verbosity_debug_e) return F_output_not; - controller_main_t * const main = (controller_main_t *) print->custom; + controller_t * const main = (controller_t *) print->custom; controller_lock_print(print->to, 0); @@ -22,7 +22,7 @@ extern "C" { return F_okay; } -#endif // _di_controller_main_print_debug_directory_path_empty_ +#endif // _di_controller_print_debug_directory_path_empty_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/print/debug.h b/sources/c/main/print/debug.h index 2263455..778e3d8 100644 --- a/sources/c/main/print/debug.h +++ b/sources/c/main/print/debug.h @@ -40,9 +40,9 @@ extern "C" { * * @see fll_error_print() */ -#ifndef _di_controller_main_print_debug_directory_path_empty_ - extern f_status_t controller_main_print_debug_directory_path_empty(fl_print_t * const print, const f_string_static_t symbol, const f_string_static_t name); -#endif // _di_controller_main_print_debug_directory_path_empty_ +#ifndef _di_controller_print_debug_directory_path_empty_ + extern f_status_t controller_print_debug_directory_path_empty(fl_print_t * const print, const f_string_static_t symbol, const f_string_static_t name); +#endif // _di_controller_print_debug_directory_path_empty_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/print/error.c b/sources/c/main/print/error.c index 8feac22..871ce48 100644 --- a/sources/c/main/print/error.c +++ b/sources/c/main/print/error.c @@ -4,22 +4,22 @@ extern "C" { #endif -#ifndef _di_controller_main_print_error_ - f_status_t controller_main_print_error(fl_print_t * const print, const f_string_t function) { +#ifndef _di_controller_print_error_ + f_status_t controller_print_error(fl_print_t * const print, const f_string_t function) { if (!print || !print->custom) return F_status_set_error(F_output_not); if (print->verbosity < f_console_verbosity_error_e) return F_output_not; - controller_main_t * const main = (controller_main_t *) print->custom; + controller_t * const main = (controller_t *) print->custom; fll_error_print(print, F_status_set_fine(main->setting.state.status), function, fll_error_file_flag_fallback_e); return F_okay; } -#endif // _di_controller_main_print_error_ +#endif // _di_controller_print_error_ -#ifndef _di_controller_main_print_error_failsafe_item_ - f_status_t controller_main_print_error_failsafe_item(fl_print_t * const print, controller_thread_t * const thread, f_string_dynamic_t * const name) { +#ifndef _di_controller_print_error_failsafe_item_ + f_status_t controller_print_error_failsafe_item(fl_print_t * const print, controller_thread_t * const thread, f_string_dynamic_t * const name) { if (!print) return F_status_set_error(F_output_not); if (print->verbosity < f_console_verbosity_error_e) return F_output_not; @@ -34,24 +34,24 @@ extern "C" { return F_okay; } -#endif // _di_controller_main_print_error_failsafe_item_ +#endif // _di_controller_print_error_failsafe_item_ -#ifndef _di_controller_main_print_error_file_ - f_status_t controller_main_print_error_file(fl_print_t * const print, const f_string_t function, const f_string_static_t name, const f_string_static_t operation, const uint8_t type) { +#ifndef _di_controller_print_error_file_ + f_status_t controller_print_error_file(fl_print_t * const print, const f_string_t function, const f_string_static_t name, const f_string_static_t operation, const uint8_t type) { if (!print || !print->custom) return F_status_set_error(F_output_not); if (print->verbosity == f_console_verbosity_quiet_e) return F_output_not; - controller_main_t * const main = (controller_main_t *) print->custom; + controller_t * const main = (controller_t *) print->custom; fll_error_file_print(print, F_status_set_fine(main->setting.state.status), function, fll_error_file_flag_fallback_e, name, operation, type); return F_okay; } -#endif // _di_controller_main_print_error_file_ +#endif // _di_controller_print_error_file_ -#ifndef _di_controller_main_print_error_file_status_ - f_status_t controller_main_print_error_file_status(fl_print_t * const print, const f_string_t function, const f_string_static_t name, const f_string_static_t operation, const uint8_t type, const f_status_t status) { +#ifndef _di_controller_print_error_file_status_ + f_status_t controller_print_error_file_status(fl_print_t * const print, const f_string_t function, const f_string_static_t name, const f_string_static_t operation, const uint8_t type, const f_status_t status) { if (!print) return F_status_set_error(F_output_not); if (print->verbosity == f_console_verbosity_quiet_e) return F_output_not; @@ -60,10 +60,10 @@ extern "C" { return F_okay; } -#endif // _di_controller_main_print_error_file_status_ +#endif // _di_controller_print_error_file_status_ -#ifndef _di_controller_main_print_error_file_pid_exists_ - f_status_t controller_main_print_error_file_pid_exists(fl_print_t * const print, controller_thread_t * const thread, const f_string_dynamic_t path) { +#ifndef _di_controller_print_error_file_pid_exists_ + f_status_t controller_print_error_file_pid_exists(fl_print_t * const print, controller_thread_t * const thread, const f_string_dynamic_t path) { if (!print) return F_status_set_error(F_output_not); if (print->verbosity < f_console_verbosity_error_e) return F_output_not; @@ -78,10 +78,10 @@ extern "C" { return F_okay; } -#endif // _di_controller_main_print_error_file_pid_exists_ +#endif // _di_controller_print_error_file_pid_exists_ -#ifndef _di_controller_main_print_error_status_ - f_status_t controller_main_print_error_status(fl_print_t * const print, const f_string_t function, const f_status_t status) { +#ifndef _di_controller_print_error_status_ + f_status_t controller_print_error_status(fl_print_t * const print, const f_string_t function, const f_status_t status) { if (!print) return F_status_set_error(F_output_not); if (print->verbosity < f_console_verbosity_error_e) return F_output_not; @@ -90,7 +90,7 @@ extern "C" { return F_okay; } -#endif // _di_controller_main_print_error_status_ +#endif // _di_controller_print_error_status_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/print/error.h b/sources/c/main/print/error.h index fb7b032..8207d58 100644 --- a/sources/c/main/print/error.h +++ b/sources/c/main/print/error.h @@ -36,9 +36,9 @@ extern "C" { * * @see fll_error_print() */ -#ifndef _di_controller_main_print_error_ - extern f_status_t controller_main_print_error(fl_print_t * const print, const f_string_t function); -#endif // _di_controller_main_print_error_ +#ifndef _di_controller_print_error_ + extern f_status_t controller_print_error(fl_print_t * const print, const f_string_t function); +#endif // _di_controller_print_error_ /** * Print error message regarding the failsafe item failing. @@ -66,9 +66,9 @@ extern "C" { * * @see fll_error_print() */ -#ifndef _di_controller_main_print_error_failsafe_item_ - extern f_status_t controller_main_print_error_failsafe_item(fl_print_t * const print, controller_thread_t * const thread, f_string_dynamic_t * const name); -#endif // _di_controller_main_print_error_failsafe_item_ +#ifndef _di_controller_print_error_failsafe_item_ + extern f_status_t controller_print_error_failsafe_item(fl_print_t * const print, controller_thread_t * const thread, f_string_dynamic_t * const name); +#endif // _di_controller_print_error_failsafe_item_ /** * Print file related error or warning messages. @@ -99,9 +99,9 @@ extern "C" { * * @see fll_error_file_print() */ -#ifndef _di_controller_main_print_error_file_ - extern f_status_t controller_main_print_error_file(fl_print_t * const print, const f_string_t function, const f_string_static_t name, const f_string_static_t operation, const uint8_t type); -#endif // _di_controller_main_print_error_file_ +#ifndef _di_controller_print_error_file_ + extern f_status_t controller_print_error_file(fl_print_t * const print, const f_string_t function, const f_string_static_t name, const f_string_static_t operation, const uint8_t type); +#endif // _di_controller_print_error_file_ /** * Print file related error or warning messages. @@ -134,9 +134,9 @@ extern "C" { * * @see fll_error_file_print() */ -#ifndef _di_controller_main_print_error_file_status_ - extern f_status_t controller_main_print_error_file_status(fl_print_t * const print, const f_string_t function, const f_string_static_t name, const f_string_static_t operation, const uint8_t type, const f_status_t status); -#endif // _di_controller_main_print_error_file_status_ +#ifndef _di_controller_print_error_file_status_ + extern f_status_t controller_print_error_file_status(fl_print_t * const print, const f_string_t function, const f_string_static_t name, const f_string_static_t operation, const uint8_t type, const f_status_t status); +#endif // _di_controller_print_error_file_status_ /** * Print generic error message regarding a function failing in some way. @@ -160,9 +160,9 @@ extern "C" { * * @see fll_error_print() */ -#ifndef _di_controller_main_print_error_status_ - extern f_status_t controller_main_print_error_status(fl_print_t * const print, const f_string_t function, const f_status_t status); -#endif // _di_controller_main_print_error_status_ +#ifndef _di_controller_print_error_status_ + extern f_status_t controller_print_error_status(fl_print_t * const print, const f_string_t function, const f_status_t status); +#endif // _di_controller_print_error_status_ /** * Print error message regarding the pid file already existing. @@ -188,9 +188,9 @@ extern "C" { * * @see fll_error_print() */ -#ifndef _di_controller_main_print_error_file_pid_exists_ - extern f_status_t controller_main_print_error_file_pid_exists(fl_print_t * const print, controller_thread_t * const thread, const f_string_dynamic_t path); -#endif // _di_controller_main_print_error_file_pid_exists_ +#ifndef _di_controller_print_error_file_pid_exists_ + extern f_status_t controller_print_error_file_pid_exists(fl_print_t * const print, controller_thread_t * const thread, const f_string_dynamic_t path); +#endif // _di_controller_print_error_file_pid_exists_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/print/message.c b/sources/c/main/print/message.c index c04fbcf..840aa93 100644 --- a/sources/c/main/print/message.c +++ b/sources/c/main/print/message.c @@ -4,12 +4,12 @@ extern "C" { #endif -#ifndef _di_controller_main_print_message_help_ - f_status_t controller_main_print_message_help(fl_print_t * const print, const uint8_t uninterrupt) { +#ifndef _di_controller_print_message_help_ + f_status_t controller_print_message_help(fl_print_t * const print, const uint8_t uninterrupt) { if (!print || !print->custom) return F_status_set_error(F_output_not); - controller_main_t * const main = (controller_main_t *) print->custom; + controller_t * const main = (controller_t *) print->custom; f_file_stream_lock(print->to); @@ -45,7 +45,7 @@ extern "C" { return F_okay; } -#endif // _di_controller_main_print_message_help_ +#endif // _di_controller_print_message_help_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/print/message.h b/sources/c/main/print/message.h index c215bb0..2d98d17 100644 --- a/sources/c/main/print/message.h +++ b/sources/c/main/print/message.h @@ -22,7 +22,7 @@ extern "C" { * @param print * The output structure to print to. * - * This requires print.custom to be controller_main_t. + * This requires print.custom to be controller_t. * * This does not alter print.custom.setting.state.status. * @param uninterrupt @@ -43,9 +43,9 @@ extern "C" { * @see fll_program_print_help_option() * @see fll_program_print_help_usage() */ -#ifndef _di_controller_main_print_message_help_ - extern f_status_t controller_main_print_message_help(fl_print_t * const print, const uint8_t uninterrupt); -#endif // _di_controller_main_print_message_help_ +#ifndef _di_controller_print_message_help_ + extern f_status_t controller_print_message_help(fl_print_t * const print, const uint8_t uninterrupt); +#endif // _di_controller_print_message_help_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/print/rule.c b/sources/c/main/print/rule.c index ebd3627..f6557aa 100644 --- a/sources/c/main/print/rule.c +++ b/sources/c/main/print/rule.c @@ -4,8 +4,8 @@ extern "C" { #endif -#ifndef _di_controller_main_print_rule_error_ - f_status_t controller_main_print_rule_error(fl_print_t * const print, const controller_cache_action_t cache, const f_status_t status, const f_string_t function, const bool fallback, const bool item) { +#ifndef _di_controller_print_rule_error_ + f_status_t controller_print_rule_error(fl_print_t * const print, const controller_cache_action_t cache, const f_status_t status, const f_string_t function, const bool fallback, const bool item) { if (!print || !print->custom) return F_status_set_error(F_output_not); if (print->verbosity < f_console_verbosity_error_e) return F_output_not; @@ -20,16 +20,16 @@ extern "C" { f_file_stream_lock(print->to); - controller_main_print_rule_error_cache(print, cache, item); + controller_print_rule_error_cache(print, cache, item); controller_unlock_print_flush(print->to, global->thread); return F_okay; } -#endif // _di_controller_main_print_rule_error_ +#endif // _di_controller_print_rule_error_ -#ifndef _di_controller_main_print_rule_error_cache_ - f_status_t controller_main_print_rule_error_cache(fl_print_t * const print, const controller_cache_action_t cache, const bool item) { +#ifndef _di_controller_print_rule_error_cache_ + f_status_t controller_print_rule_error_cache(fl_print_t * const print, const controller_cache_action_t cache, const bool item) { if (!print) return F_status_set_error(F_output_not); if (print->verbosity < f_console_verbosity_error_e) return F_output_not; @@ -60,7 +60,7 @@ extern "C" { return F_okay; } -#endif // _di_controller_main_print_rule_error_cache_ +#endif // _di_controller_print_rule_error_cache_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/print/rule.h b/sources/c/main/print/rule.h index 06b4cb2..59798e0 100644 --- a/sources/c/main/print/rule.h +++ b/sources/c/main/print/rule.h @@ -38,11 +38,11 @@ extern "C" { * If FALSE, then this error is associated with a rule setting. * * @see fll_error_print() - * @see controller_main_print_rule_error_cache() + * @see controller_print_rule_error_cache() */ -#ifndef _di_controller_main_print_rule_error_ - extern void controller_main_print_rule_error(fl_print_t * const print, const controller_cache_action_t cache, const f_status_t status, const f_string_t function, const bool fallback, const bool item); -#endif // _di_controller_main_print_rule_error_ +#ifndef _di_controller_print_rule_error_ + extern void controller_print_rule_error(fl_print_t * const print, const controller_cache_action_t cache, const f_status_t status, const f_string_t function, const bool fallback, const bool item); +#endif // _di_controller_print_rule_error_ /** * Print additional error/warning information in addition to existing error. @@ -59,15 +59,15 @@ extern "C" { * If TRUE, then this error is associated with an item. * If FALSE, then this error is associated with a rule setting. * - * @see controller_main_rule_action_read() - * @see controller_main_rule_item_read() + * @see controller_rule_action_read() + * @see controller_rule_item_read() * @see controller_rule_items_read() - * @see controller_main_rule_read() - * @see controller_main_rule_setting_read() + * @see controller_rule_read() + * @see controller_rule_setting_read() */ -#ifndef _di_controller_main_print_rule_error_cache_ - extern void controller_main_print_rule_error_cache(fl_print_t * const print, const controller_cache_action_t cache, const bool item); -#endif // _di_controller_main_print_rule_error_cache_ +#ifndef _di_controller_print_rule_error_cache_ + extern void controller_print_rule_error_cache(fl_print_t * const print, const controller_cache_action_t cache, const bool item); +#endif // _di_controller_print_rule_error_cache_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/print/rule/action.c b/sources/c/main/print/rule/action.c index 61c0b35..e670597 100644 --- a/sources/c/main/print/rule/action.c +++ b/sources/c/main/print/rule/action.c @@ -4,8 +4,8 @@ extern "C" { #endif -#ifndef _di_controller_main_print_rule_action_error_missing_pid_ - void controller_main_print_rule_action_error_missing_pid(fl_print_t * const print, const f_string_static_t alias) { +#ifndef _di_controller_print_rule_action_error_missing_pid_ + void controller_print_rule_action_error_missing_pid(fl_print_t * const print, const f_string_static_t alias) { if (print->verbosity < f_console_verbosity_error_e) return F_output_not; @@ -13,7 +13,7 @@ extern "C" { fl_print_format(f_string_format_Q_single_s.string, print->to, print->notable, alias, print->notable); fl_print_format("%[' is not designating a pid file.%]%r", print->to, print->context, print->context, f_string_eol_s); } -#endif // _di_controller_main_print_rule_action_error_missing_pid_ +#endif // _di_controller_print_rule_action_error_missing_pid_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/print/rule/action.h b/sources/c/main/print/rule/action.h index c29843d..8a7197d 100644 --- a/sources/c/main/print/rule/action.h +++ b/sources/c/main/print/rule/action.h @@ -24,9 +24,9 @@ extern "C" { * @param alias * The rule alias of the rule that is missing the pid file designation. */ -#ifndef _di_controller_main_print_rule_action_error_missing_pid_ - extern void controller_main_print_rule_action_error_missing_pid(fl_print_t * const print, const f_string_static_t alias); -#endif // _di_controller_main_print_rule_action_error_missing_pid_ +#ifndef _di_controller_print_rule_action_error_missing_pid_ + extern void controller_print_rule_action_error_missing_pid(fl_print_t * const print, const f_string_static_t alias); +#endif // _di_controller_print_rule_action_error_missing_pid_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/print/rule/item.c b/sources/c/main/print/rule/item.c index ee0793f..0113cc1 100644 --- a/sources/c/main/print/rule/item.c +++ b/sources/c/main/print/rule/item.c @@ -4,8 +4,8 @@ extern "C" { #endif -#ifndef _di_controller_main_print_rule_item_debug_action_empty_ - f_status_t controller_main_print_rule_item_debug_action_empty(fl_print_t * const print, controller_cache_t * const cache) { +#ifndef _di_controller_print_rule_item_debug_action_empty_ + f_status_t controller_print_rule_item_debug_action_empty(fl_print_t * const print, controller_cache_t * const cache) { if (!print || !print->custom || !cache) return F_status_set_error(F_output_not); if (print->verbosity < f_console_verbosity_debug_e) return F_output_not; @@ -16,16 +16,16 @@ extern "C" { fl_print_format("%r%[%QAction is empty, nothing to do.%]%r", primt->to, f_string_eol_s, print->context, print->prefix, print->context, f_string_eol_s); - controller_main_print_rule_error_cache(print, cache->action, F_true); + controller_print_rule_error_cache(print, cache->action, F_true); controller_unlock_print_flush(print->to, global->thread); return F_okay; } -#endif // _di_controller_main_print_rule_item_debug_action_empty_ +#endif // _di_controller_print_rule_item_debug_action_empty_ -#ifndef _di_controller_main_print_rule_item_error_ - void controller_main_print_rule_item_error(fl_print_t * const print, const controller_cache_action_t cache, const bool item, const f_status_t status) { +#ifndef _di_controller_print_rule_item_error_ + void controller_print_rule_item_error(fl_print_t * const print, const controller_cache_action_t cache, const bool item, const f_status_t status) { if (!print || !print->custom) return F_status_set_error(F_output_not); if (print->verbosity < f_console_verbosity_error_e) return F_output_not; @@ -36,16 +36,16 @@ extern "C" { // fll_error_print() automatically locks, so manually handle only the mutex locking and flushing rather than calling controller_lock_print(). f_thread_mutex_lock(&global->thread->lock.print); - controller_main_print_rule_error_cache(print, cache, item); + controller_print_rule_error_cache(print, cache, item); f_file_stream_lock(print->to); controller_unlock_print_flush(print->to, global->thread); } -#endif // _di_controller_main_print_rule_item_error_ +#endif // _di_controller_print_rule_item_error_ -#ifndef _di_controller_main_print_rule_item_error_action_first_ - f_status_t controller_main_print_rule_item_error_action_first(fl_print_t * const print, controller_cache_t * const cache) { +#ifndef _di_controller_print_rule_item_error_action_first_ + f_status_t controller_print_rule_item_error_action_first(fl_print_t * const print, controller_cache_t * const cache) { if (!print || !print->custom || !cache) return F_status_set_error(F_output_not); if (print->verbosity < f_console_verbosity_error_e) return F_output_not; @@ -70,16 +70,16 @@ extern "C" { fl_print_format(f_string_format_r_single_s.string, print->to, print->notable, controller_thaw_s, print->notable, print->context); fl_print_format(f_string_format_sentence_end_quote_s.string, print->to, print->context, print->context, f_string_eol_s); - controller_main_print_rule_error_cache(print, cache->action, F_true); + controller_print_rule_error_cache(print, cache->action, F_true); controller_unlock_print_flush(print->to, global->thread); return F_okay; } -#endif // _di_controller_main_print_rule_item_error_action_first_ +#endif // _di_controller_print_rule_item_error_action_first_ -#ifndef _di_controller_main_print_rule_item_error_action_second_ - f_status_t controller_main_print_rule_item_error_action_second(fl_print_t * const print, controller_cache_t * const cache) { +#ifndef _di_controller_print_rule_item_error_action_second_ + f_status_t controller_print_rule_item_error_action_second(fl_print_t * const print, controller_cache_t * const cache) { if (!print || !print->custom || !cache) return F_status_set_error(F_output_not); if (print->verbosity < f_console_verbosity_error_e) return F_output_not; @@ -97,16 +97,16 @@ extern "C" { fl_print_format(f_string_format_r_single_s.string, print->to, print->notable, controller_thaw_s, print->notable, print->context); fl_print_format(f_string_format_sentence_end_quote_s.string, print->to, print->context, print->context, f_string_eol_s); - controller_main_print_rule_error_cache(print, cache->action, F_true); + controller_print_rule_error_cache(print, cache->action, F_true); controller_unlock_print_flush(print->to, global->thread); return F_okay; } -#endif // _di_controller_main_print_rule_item_error_action_second_ +#endif // _di_controller_print_rule_item_error_action_second_ -#ifndef _di_controller_main_print_rule_item_error_action_unknown_ - f_status_t controller_main_print_rule_item_error_action_unknown(fl_print_t * const print, controller_cache_t * const cache, const f_string_static_t name, const f_number_unsigned_t index) { +#ifndef _di_controller_print_rule_item_error_action_unknown_ + f_status_t controller_print_rule_item_error_action_unknown(fl_print_t * const print, controller_cache_t * const cache, const f_string_static_t name, const f_number_unsigned_t index) { if (!print || !print->custom || !cache) return F_status_set_error(F_output_not); if (print->verbosity < f_console_verbosity_error_e) return F_output_not; @@ -121,16 +121,16 @@ extern "C" { fl_print_format(f_string_format_Q_range_single_s.string, print->to, print->notable, cache->buffer_item, cache->content_action.array[index], print->notable); fl_print_format(f_string_format_sentence_end_quote_s.string, print->to, print->context, print->context, f_string_eol_s); - controller_main_print_rule_error_cache(print, cache->action, F_true); + controller_print_rule_error_cache(print, cache->action, F_true); controller_unlock_print_flush(print->to, global->thread); return F_okay; } -#endif // _di_controller_main_print_rule_item_error_action_unknown_ +#endif // _di_controller_print_rule_item_error_action_unknown_ -#ifndef _di_controller_main_print_rule_item_error_execute_ - void controller_main_print_rule_item_error_execute(fl_print_t * const print, controller_instance_t * const instance, const bool script_is, const f_string_static_t name, const f_status_t status) { +#ifndef _di_controller_print_rule_item_error_execute_ + void controller_print_rule_item_error_execute(fl_print_t * const print, controller_instance_t * const instance, const bool script_is, const f_string_static_t name, const f_status_t status) { if (!print || !print->custom) return F_status_set_error(F_output_not); if (print->verbosity < f_console_verbosity_error_e) return F_output_not; @@ -379,10 +379,10 @@ extern "C" { controller_unlock_print_flush(print->to, global->thread); } -#endif // _di_controller_main_print_rule_item_error_execute_ +#endif // _di_controller_print_rule_item_error_execute_ -#ifndef _di_controller_main_print_rule_item_error_need_want_wish_ - void controller_main_print_rule_item_error_need_want_wish(fl_print_t * const print, const f_string_static_t need_want_wish, const f_string_static_t value, const f_string_t why) { +#ifndef _di_controller_print_rule_item_error_need_want_wish_ + void controller_print_rule_item_error_need_want_wish(fl_print_t * const print, const f_string_static_t need_want_wish, const f_string_static_t value, const f_string_t why) { if (print->verbosity == f_console_verbosity_quiet_e) return; @@ -390,10 +390,10 @@ extern "C" { fl_print_format(f_string_format_Q_single_s.string, print->to, print->notable, value, print->notable); fl_print_format("%[' %S.%]%r", print->to, print->context, why, print->context, f_string_eol_s); } -#endif // _di_controller_main_print_rule_item_error_need_want_wish_ +#endif // _di_controller_print_rule_item_error_need_want_wish_ -#ifndef _di_controller_main_print_rule_item_error_rule_not_loaded_ - void controller_main_print_rule_item_error_rule_not_loaded(fl_print_t * const print, const f_string_static_t alias) { +#ifndef _di_controller_print_rule_item_error_rule_not_loaded_ + void controller_print_rule_item_error_rule_not_loaded(fl_print_t * const print, const f_string_static_t alias) { if (print->verbosity == f_console_verbosity_quiet_e) return; @@ -401,7 +401,7 @@ extern "C" { fl_print_format(f_string_format_Q_single_s.string, print->to, print->notable, alias, print->notable); fl_print_format("%[' is no longer loaded.%]%r", print->to, print->context, print->context, f_string_eol_s); } -#endif // _di_controller_main_print_rule_item_error_rule_not_loaded_ +#endif // _di_controller_print_rule_item_error_rule_not_loaded_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/print/rule/item.h b/sources/c/main/print/rule/item.h index 7e1db6b..6c8f960 100644 --- a/sources/c/main/print/rule/item.h +++ b/sources/c/main/print/rule/item.h @@ -38,12 +38,12 @@ extern "C" { * @see fll_error_print() * * @see controller_lock_print() - * @see controller_main_print_rule_error_cache() + * @see controller_print_rule_error_cache() * @see controller_unlock_print_flush() */ -#ifndef _di_controller_main_print_rule_item_debug_action_empty_ - extern f_status_t controller_main_print_rule_item_debug_action_empty(fl_print_t * const print, controller_cache_t * const cache); -#endif // _di_controller_main_print_rule_item_debug_action_empty_ +#ifndef _di_controller_print_rule_item_debug_action_empty_ + extern f_status_t controller_print_rule_item_debug_action_empty(fl_print_t * const print, controller_cache_t * const cache); +#endif // _di_controller_print_rule_item_debug_action_empty_ /** * Print additional error/warning information in addition to existing error. @@ -60,11 +60,11 @@ extern "C" { * @param status * The status code representing the failure (without the error bit set). * - * @see controller_main_print_rule_error_cache() + * @see controller_print_rule_error_cache() */ -#ifndef _di_controller_main_print_rule_item_error_ - extern void controller_main_print_rule_item_error(fl_print_t * const print, const controller_cache_action_t cache, const bool item, const f_status_t status); -#endif // _di_controller_main_print_rule_item_error_ +#ifndef _di_controller_print_rule_item_error_ + extern void controller_print_rule_item_error(fl_print_t * const print, const controller_cache_action_t cache, const bool item, const f_status_t status); +#endif // _di_controller_print_rule_item_error_ /** * Print rule error message about the first rule item action parameter being invalid. @@ -88,12 +88,12 @@ extern "C" { * @see fll_error_print() * * @see controller_lock_print() - * @see controller_main_print_rule_error_cache() + * @see controller_print_rule_error_cache() * @see controller_unlock_print_flush() */ -#ifndef _di_controller_main_print_rule_item_error_action_first_ - extern f_status_t controller_main_print_rule_item_error_action_first(fl_print_t * const print, controller_cache_t * const cache); -#endif // _di_controller_main_print_rule_item_error_action_first_ +#ifndef _di_controller_print_rule_item_error_action_first_ + extern f_status_t controller_print_rule_item_error_action_first(fl_print_t * const print, controller_cache_t * const cache); +#endif // _di_controller_print_rule_item_error_action_first_ /** * Print rule error message about the second rule item action parameter being invalid. @@ -117,12 +117,12 @@ extern "C" { * @see fll_error_print() * * @see controller_lock_print() - * @see controller_main_print_rule_error_cache() + * @see controller_print_rule_error_cache() * @see controller_unlock_print_flush() */ -#ifndef _di_controller_main_print_rule_item_error_action_second_ - extern f_status_t controller_main_print_rule_item_error_action_second(fl_print_t * const print, controller_cache_t * const cache); -#endif // _di_controller_main_print_rule_item_error_action_second_ +#ifndef _di_controller_print_rule_item_error_action_second_ + extern f_status_t controller_print_rule_item_error_action_second(fl_print_t * const print, controller_cache_t * const cache); +#endif // _di_controller_print_rule_item_error_action_second_ /** * Print rule error message about the rule item action being unknown. @@ -150,12 +150,12 @@ extern "C" { * @see fll_error_print() * * @see controller_lock_print() - * @see controller_main_print_rule_error_cache() + * @see controller_print_rule_error_cache() * @see controller_unlock_print_flush() */ -#ifndef _di_controller_main_print_rule_item_error_action_unknown_ - extern f_status_t controller_main_print_rule_item_error_action_unknown(fl_print_t * const print, controller_cache_t * const cache, const f_string_static_t name, const f_number_unsigned_t index); -#endif // _di_controller_main_print_rule_item_error_action_unknown_ +#ifndef _di_controller_print_rule_item_error_action_unknown_ + extern f_status_t controller_print_rule_item_error_action_unknown(fl_print_t * const print, controller_cache_t * const cache, const f_string_static_t name, const f_number_unsigned_t index); +#endif // _di_controller_print_rule_item_error_action_unknown_ /** * Print an error or warning message related to the failed execution of some program or script. @@ -178,9 +178,9 @@ extern "C" { * @param status * The status code representing the failure (without the error bit set). */ -#ifndef _di_controller_main_print_rule_item_error_execute_ - extern void controller_main_print_rule_item_error_execute(fl_print_t * const print, controller_instance_t * const instance, const bool script_is, const f_string_static_t name, const f_status_t status); -#endif // _di_controller_main_print_rule_item_error_execute_ +#ifndef _di_controller_print_rule_item_error_execute_ + extern void controller_print_rule_item_error_execute(fl_print_t * const print, controller_instance_t * const instance, const bool script_is, const f_string_static_t name, const f_status_t status); +#endif // _di_controller_print_rule_item_error_execute_ /** * Print an error or warning message related to need/want/wish settings of some rule. @@ -195,9 +195,9 @@ extern "C" { * @param why * A short explanation on why this is an error or warning. */ -#ifndef _di_controller_main_print_rule_item_error_need_want_wish_ - extern void controller_main_print_rule_item_error_need_want_wish(fl_print_t * const print, const f_string_static_t need_want_wish, const f_string_static_t value, const f_string_t why); -#endif // _di_controller_main_print_rule_item_error_need_want_wish_ +#ifndef _di_controller_print_rule_item_error_need_want_wish_ + extern void controller_print_rule_item_error_need_want_wish(fl_print_t * const print, const f_string_static_t need_want_wish, const f_string_static_t value, const f_string_t why); +#endif // _di_controller_print_rule_item_error_need_want_wish_ /** * Print an error or warning message about some rule not being loaded. @@ -207,9 +207,9 @@ extern "C" { * @param alias * The rule alias of the rule that is not loaded. */ -#ifndef _di_controller_main_print_rule_item_error_rule_not_loaded_ - extern void controller_main_print_rule_item_error_rule_not_loaded(fl_print_t * const print, const f_string_static_t alias); -#endif // _di_controller_main_print_rule_item_error_rule_not_loaded_ +#ifndef _di_controller_print_rule_item_error_rule_not_loaded_ + extern void controller_print_rule_item_error_rule_not_loaded(fl_print_t * const print, const f_string_static_t alias); +#endif // _di_controller_print_rule_item_error_rule_not_loaded_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/print/rule/setting.c b/sources/c/main/print/rule/setting.c index 87977fe..104dd70 100644 --- a/sources/c/main/print/rule/setting.c +++ b/sources/c/main/print/rule/setting.c @@ -4,13 +4,13 @@ extern "C" { #endif -#ifndef _di_controller_main_print_rule_setting_read_error_ - void controller_main_print_rule_setting_read_error(fl_print_t * const print, const f_string_t message, const f_number_unsigned_t index, const f_number_unsigned_t line_item, controller_thread_t * const thread, controller_cache_t * const cache) { +#ifndef _di_controller_print_rule_setting_read_error_ + void controller_print_rule_setting_read_error(fl_print_t * const print, const f_string_t message, const f_number_unsigned_t index, const f_number_unsigned_t line_item, controller_thread_t * const thread, controller_cache_t * const cache) { if (!print->custom) return; if (print->verbosity == f_console_verbosity_quiet_e) return; - controller_main_t * const main = (controller_main_t *) print->custom; + controller_t * const main = (controller_t *) print->custom; f_state_t state = f_state_t_initialize; @@ -24,19 +24,19 @@ extern "C" { fl_print_format("%r%[%QRule setting %S.%]%r", print->to, f_string_eol_s, print->context, print->prefix, message, print->context, f_string_eol_s); - controller_main_print_rule_error_cache(print, cache->action, F_false); + controller_print_rule_error_cache(print, cache->action, F_false); controller_unlock_print_flush(print->to, thread); } -#endif // _di_controller_main_print_rule_setting_read_error_ +#endif // _di_controller_print_rule_setting_read_error_ -#ifndef _di_controller_main_print_rule_setting_read_error_with_range_ - void controller_main_print_rule_setting_read_error_with_range(fl_print_t * const print, const f_string_t before, const f_range_t range, const f_string_t after, const f_number_unsigned_t index, const f_number_unsigned_t line_item, controller_thread_t * const thread, controller_cache_t * const cache) { +#ifndef _di_controller_print_rule_setting_read_error_with_range_ + void controller_print_rule_setting_read_error_with_range(fl_print_t * const print, const f_string_t before, const f_range_t range, const f_string_t after, const f_number_unsigned_t index, const f_number_unsigned_t line_item, controller_thread_t * const thread, controller_cache_t * const cache) { if (!print->custom) return; if (print->verbosity == f_console_verbosity_quiet_e) return; - controller_main_t * const main = (controller_main_t *) print->custom; + controller_t * const main = (controller_t *) print->custom; f_state_t state = f_state_t_initialize; @@ -52,14 +52,14 @@ extern "C" { fl_print_format(f_string_format_Q_range_single_s.string, print->to, print->notable, cache->buffer_item, range, print->notable); fl_print_format("%['%S.%]%r", print->to, print->context, after, print->context, f_string_eol_s); - controller_main_print_rule_error_cache(print, cache->action, F_false); + controller_print_rule_error_cache(print, cache->action, F_false); controller_unlock_print_flush(print->to, thread); } -#endif // _di_controller_main_print_rule_setting_read_error_with_range_ +#endif // _di_controller_print_rule_setting_read_error_with_range_ -#ifndef _di_controller_main_print_rule_setting_read_mapping_ - void controller_main_print_rule_setting_read_mapping(const controller_global_t global, const f_string_static_t name, const f_string_map_t map) { +#ifndef _di_controller_print_rule_setting_read_mapping_ + void controller_print_rule_setting_read_mapping(const controller_global_t global, const f_string_static_t name, const f_string_map_t map) { if (global.main->program.error.verbosity != f_console_verbosity_debug_e) { if (!(global.main->program.error.verbosity == f_console_verbosity_verbose_e && (global.main->program.parameters.array[controller_parameter_simulate_e].result & f_console_result_found_e))) { @@ -75,10 +75,10 @@ extern "C" { controller_unlock_print_flush(global.main->program.output.to, global.thread); } -#endif // _di_controller_main_print_rule_setting_read_mapping_ +#endif // _di_controller_print_rule_setting_read_mapping_ -#ifndef _di_controller_main_print_rule_setting_read_value_ - void controller_main_print_rule_setting_read_value(const controller_global_t global, const f_string_static_t name, const f_string_static_t name_sub, const f_string_static_t value, const f_string_t suffix) { +#ifndef _di_controller_print_rule_setting_read_value_ + void controller_print_rule_setting_read_value(const controller_global_t global, const f_string_static_t name, const f_string_static_t name_sub, const f_string_static_t value, const f_string_t suffix) { if (global.main->program.error.verbosity != f_console_verbosity_debug_e) { if (!(global.main->program.error.verbosity == f_console_verbosity_verbose_e && (global.main->program.parameters.array[controller_parameter_simulate_e].result & f_console_result_found_e))) { @@ -102,10 +102,10 @@ extern "C" { controller_unlock_print_flush(global.main->program.output.to, global.thread); } -#endif // _di_controller_main_print_rule_setting_read_value_ +#endif // _di_controller_print_rule_setting_read_value_ -#ifndef _di_controller_main_print_rule_setting_read_values_ - void controller_main_print_rule_setting_read_values(const controller_global_t global, const f_string_static_t name, const f_number_unsigned_t index, controller_cache_t * const cache) { +#ifndef _di_controller_print_rule_setting_read_values_ + void controller_print_rule_setting_read_values(const controller_global_t global, const f_string_static_t name, const f_number_unsigned_t index, controller_cache_t * const cache) { if (global.main->program.error.verbosity != f_console_verbosity_debug_e) { if (!(global.main->program.error.verbosity == f_console_verbosity_verbose_e && (global.main->program.parameters.array[controller_parameter_simulate_e].result & f_console_result_found_e))) { @@ -137,7 +137,7 @@ extern "C" { controller_unlock_print_flush(global.main->program.output.to, global.thread); } -#endif // _di_controller_main_print_rule_setting_read_value_ +#endif // _di_controller_print_rule_setting_read_value_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/print/rule/setting.h b/sources/c/main/print/rule/setting.h index f409767..a7d99f7 100644 --- a/sources/c/main/print/rule/setting.h +++ b/sources/c/main/print/rule/setting.h @@ -19,7 +19,7 @@ extern "C" { /** * Print a message about a rule setting problem. * - * This is intended to be explicitly called by controller_main_rule_setting_read(). + * This is intended to be explicitly called by controller_rule_setting_read(). * This is intended only to be used for simple messages. * * @param print @@ -35,16 +35,16 @@ extern "C" { * @param cache * A structure for containing and caching relevant data. * - * @see controller_main_rule_setting_read() + * @see controller_rule_setting_read() */ -#ifndef _di_controller_main_print_rule_setting_read_error_ - extern void controller_main_print_rule_setting_read_error(fl_print_t * const print, const f_string_t message, const f_number_unsigned_t index, const f_number_unsigned_t line_item, controller_thread_t * const thread, controller_cache_t * const cache); -#endif // _di_controller_main_print_rule_setting_read_error_ +#ifndef _di_controller_print_rule_setting_read_error_ + extern void controller_print_rule_setting_read_error(fl_print_t * const print, const f_string_t message, const f_number_unsigned_t index, const f_number_unsigned_t line_item, controller_thread_t * const thread, controller_cache_t * const cache); +#endif // _di_controller_print_rule_setting_read_error_ /** * Print a message about a rule setting problem, with additional messages about the value. * - * This is intended to be explicitly called by controller_main_rule_setting_read(). + * This is intended to be explicitly called by controller_rule_setting_read(). * This is intended only to be used for simple messages. * * @param print @@ -64,11 +64,11 @@ extern "C" { * @param cache * A structure for containing and caching relevant data. * - * @see controller_main_rule_setting_read() + * @see controller_rule_setting_read() */ -#ifndef _di_controller_main_print_rule_setting_read_error_with_range_ - extern void controller_main_print_rule_setting_read_error_with_range(fl_print_t * const print, const f_string_t before, const f_range_t range, const f_string_t after, const f_number_unsigned_t index, const f_number_unsigned_t line_item, controller_thread_t * const thread, controller_cache_t * const cache); -#endif // _di_controller_main_print_rule_setting_read_error_with_range_ +#ifndef _di_controller_print_rule_setting_read_error_with_range_ + extern void controller_print_rule_setting_read_error_with_range(fl_print_t * const print, const f_string_t before, const f_range_t range, const f_string_t after, const f_number_unsigned_t index, const f_number_unsigned_t line_item, controller_thread_t * const thread, controller_cache_t * const cache); +#endif // _di_controller_print_rule_setting_read_error_with_range_ /** * Print message regarding the mapping of a setting when in simulation or verbose mode. @@ -80,9 +80,9 @@ extern "C" { * @param map * The map being applied. */ -#ifndef _di_controller_main_print_rule_setting_read_mapping_ - extern void controller_main_print_rule_setting_read_mapping(const controller_global_t global, const f_string_static_t name, const f_string_map_t map); -#endif // _di_controller_main_print_rule_setting_read_mapping_ +#ifndef _di_controller_print_rule_setting_read_mapping_ + extern void controller_print_rule_setting_read_mapping(const controller_global_t global, const f_string_static_t name, const f_string_map_t map); +#endif // _di_controller_print_rule_setting_read_mapping_ /** * Print message regarding the population of a setting when in simulation or verbose mode. @@ -99,9 +99,9 @@ extern "C" { * @param suffix * An additional message to append at the end (before the final period). */ -#ifndef _di_controller_main_print_rule_setting_read_value_ - extern void controller_main_print_rule_setting_read_value(const controller_global_t global, const f_string_static_t name, const f_string_static_t name_sub, const f_string_static_t value, const f_string_t suffix); -#endif // _di_controller_main_print_rule_setting_read_value_ +#ifndef _di_controller_print_rule_setting_read_value_ + extern void controller_print_rule_setting_read_value(const controller_global_t global, const f_string_static_t name, const f_string_static_t name_sub, const f_string_static_t value, const f_string_t suffix); +#endif // _di_controller_print_rule_setting_read_value_ /** * Print message regarding the population of a setting when in simulation or verbose mode. @@ -117,9 +117,9 @@ extern "C" { * @param cache * A structure for containing and caching relevant data. */ -#ifndef _di_controller_main_print_rule_setting_read_values_ - extern void controller_main_print_rule_setting_read_values(const controller_global_t global, const f_string_static_t name, const f_number_unsigned_t index, controller_cache_t * const cache); -#endif // _di_controller_main_print_rule_setting_read_values_ +#ifndef _di_controller_print_rule_setting_read_values_ + extern void controller_print_rule_setting_read_values(const controller_global_t global, const f_string_static_t name, const f_number_unsigned_t index, controller_cache_t * const cache); +#endif // _di_controller_print_rule_setting_read_values_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/process.c b/sources/c/main/process.c index 1a09fa5..20e4130 100644 --- a/sources/c/main/process.c +++ b/sources/c/main/process.c @@ -4,8 +4,8 @@ extern "C" { #endif -#ifndef _di_controller_main_process_ - void controller_main_process(controller_main_t * const main, controller_program_t * const program) { +#ifndef _di_controller_process_ + void controller_process(controller_t * const main, controller_program_t * const program) { if (!main || !program || F_status_is_error(main->setting.state.status)) return; @@ -13,7 +13,7 @@ extern "C" { if (main->setting.flag & controller_main_flag_version_copyright_help_e) { if (main->setting.flag & controller_main_flag_help_e) { - controller_main_print_message_help(&main->program.message, F_false); + controller_print_message_help(&main->program.message, F_false); } else if (main->setting.flag & controller_main_flag_version_e) { fll_program_print_version(&main->program.message, controller_program_version_s); @@ -37,26 +37,26 @@ extern "C" { message.custom = output.custom = error.custom = warning.custom = debug.custom = (void *) &global; // The global locks must be initialized, but only once, so initialize immediately upon allocation. - f_status_t status = controller_main_lock_create(&thread.lock); + f_status_t status = controller_lock_create(&thread.lock); if (F_status_is_error(status)) { - controller_main_print_error_status(&main->program.error, macro_controller_f(controller_main_lock_create), status); + controller_print_error_status(&main->program.error, macro_controller_f(controller_lock_create), status); } else { status = f_memory_array_increase(controller_allocation_small_d, sizeof(controller_instance_t), (void **) &thread.instances.array, &thread.instances.used, &thread.instances.size); if (F_status_is_error(status)) { - controller_main_print_error_status(&main->program.error, macro_controller_f(f_memory_array_increase), status); + controller_print_error_status(&main->program.error, macro_controller_f(f_memory_array_increase), status); } } if (F_status_is_error_not(status)) { - status = f_thread_create(0, &thread.id_signal, &controller_main_thread_signal_normal, (void *) &global); + status = f_thread_create(0, &thread.id_signal, &controller_thread_signal_normal, (void *) &global); } if (F_status_is_error(status)) { thread.id_signal = 0; - controller_main_print_error_status(&main->program.error, macro_controller_f(f_thread_create), status); + controller_print_error_status(&main->program.error, macro_controller_f(f_thread_create), status); } else { if (main->setting.flag & controller_main_flag_daemon_e) { @@ -66,17 +66,17 @@ extern "C" { status = F_status_set_error(F_available_not); program->ready = controller_program_ready_abort_e; - controller_main_print_error_file_pid_exists(&main->program.error, &thread, program->path_pid); + controller_print_error_file_pid_exists(&main->program.error, &thread, program->path_pid); } } else if (program->name_entry.used) { - status = f_thread_create(0, &thread.id_entry, &controller_main_thread_entry, (void *) &global); + status = f_thread_create(0, &thread.id_entry, &controller_thread_entry, (void *) &global); if (F_status_is_error(status)) { - controller_main_print_error_status(&main->program.error, macro_controller_f(f_thread_create), status); + controller_print_error_status(&main->program.error, macro_controller_f(f_thread_create), status); } else { - controller_main_thread_join(&thread.id_entry); + controller_thread_join(&thread.id_entry); status = thread.status; thread.id_entry = 0; @@ -89,22 +89,22 @@ extern "C" { if (!(main->setting.flag & controller_main_flag_validate_e)) { // Wait for the entry thread to complete before starting the rule thread. - controller_main_thread_join(&thread.id_rule); + controller_thread_join(&thread.id_rule); if (thread.enabled && program->mode == controller_program_mode_service_e) { - status = f_thread_create(0, &thread.id_rule, &controller_main_thread_rule, (void *) &global); + status = f_thread_create(0, &thread.id_rule, &controller_thread_rule, (void *) &global); if (F_status_is_error(status)) { thread.id_rule = 0; } else { - status = f_thread_create(0, &thread.id_cleanup, &controller_main_thread_cleanup, (void *) &global); + status = f_thread_create(0, &thread.id_cleanup, &controller_thread_cleanup, (void *) &global); } if (F_status_is_error(status)) { thread.id_cleanup = 0; - controller_main_print_error_status(&main->program.error, macro_controller_f(f_thread_create), status); + controller_print_error_status(&main->program.error, macro_controller_f(f_thread_create), status); } } } @@ -118,18 +118,18 @@ extern "C" { return; } - if (F_status_is_error_not(status) && status != F_failure && !(main->setting.flag & controller_main_flag_validate_e) && controller_main_thread_is_enabled(F_true, &thread)) { + if (F_status_is_error_not(status) && status != F_failure && !(main->setting.flag & controller_main_flag_validate_e) && controller_thread_is_enabled(F_true, &thread)) { if (program->mode == controller_program_mode_service_e) { - controller_main_thread_join(&thread.id_signal); + controller_thread_join(&thread.id_signal); } else if (program->mode == controller_program_mode_helper_e || program->mode == controller_program_mode_program_e) { - status = controller_main_rule_wait_all(global, F_true, F_false); + status = controller_rule_wait_all(&global, F_true, F_false); } } - controller_main_thread_instance_cancel(global, F_true, controller_thread_cancel_call_e); + controller_thread_instance_cancel(&global, F_true, controller_thread_cancel_call_e); - controller_main_thread_instance_exit(&global); + controller_thread_instance_exit(&global); if (thread.id_signal) f_thread_join(thread.id_signal, 0); if (thread.id_cleanup) f_thread_join(thread.id_cleanup, 0); @@ -154,12 +154,13 @@ extern "C" { fll_program_print_signal_received(&main->program.warning, main->program.signal_received); - return F_status_set_error(F_interrupt); + main->setting.state.status = F_status_set_error(F_interrupt); + } + else { + main->setting.state.status = F_status_is_error(status) ? F_status_set_error(F_failure) : F_okay; } - - return F_status_is_error(status) ? F_status_set_error(F_failure) : F_okay; } -#endif // _di_controller_main_process_ +#endif // _di_controller_process_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/process.h b/sources/c/main/process.h index 626aeff..0928595 100644 --- a/sources/c/main/process.h +++ b/sources/c/main/process.h @@ -9,8 +9,8 @@ * * This is auto-included and should not need to be explicitly included. */ -#ifndef _controller_main_process_h -#define _controller_main_process_h +#ifndef _controller_process_h +#define _controller_process_h #ifdef __cplusplus extern "C" { @@ -44,12 +44,12 @@ extern "C" { * * Must not be NULL. */ -#ifndef controller_main_process - extern void controller_main_process(controller_main_t * const main, controller_program_t * const program); -#endif // controller_main_process +#ifndef controller_process + extern void controller_process(controller_t * const main, controller_program_t * const program); +#endif // controller_process #ifdef __cplusplus } // extern "C" #endif -#endif // _controller_main_process_h +#endif // _controller_process_h diff --git a/sources/c/main/rule.c b/sources/c/main/rule.c index b396231..d3faf04 100644 --- a/sources/c/main/rule.c +++ b/sources/c/main/rule.c @@ -15,7 +15,7 @@ extern "C" { f_number_unsigned_t i = 0; - for (; i < controller_main_rule_action_type__enum_size_e; ++i) { + for (; i < controller_rule_action_type__enum_size_e; ++i) { destination->status[i] = source.status[i]; } // for @@ -145,8 +145,8 @@ extern "C" { controller_rule_item_t *item_source = 0; controller_rule_item_t *item_destination = 0; - controller_main_rule_action_t *action_source = 0; - controller_main_rule_action_t *action_destination = 0; + controller_rule_action_t *action_source = 0; + controller_rule_action_t *action_destination = 0; if (source.items.used > destination->items.size) { status = f_memory_arrays_resize(source.items.used, sizeof(controller_rule_item_t), (void **) &destination->items.array, &destination->items.used, &destination->items.size, &controller_rule_items_delete_callback); @@ -161,7 +161,7 @@ extern "C" { item_destination = &destination->items.array[i]; if (item_source->actions.used > item_destination->actions.size) { - status = f_memory_arrays_resize(item_source->actions.used, sizeof(controller_main_rule_action_t), (void **) &item_destination->actions.array, &item_destination->actions.used, &item_destination->actions.size, &controller_main_rule_actions_delete_callback); + status = f_memory_arrays_resize(item_source->actions.used, sizeof(controller_rule_action_t), (void **) &item_destination->actions.array, &item_destination->actions.used, &item_destination->actions.size, &controller_rule_actions_delete_callback); if (F_status_is_error(status)) return status; } @@ -173,7 +173,7 @@ extern "C" { status = f_string_dynamic_append(item_source->pid_file, &item_destination->pid_file); if (F_status_is_error(status)) return status; - for (j = 0; j < controller_main_rule_action_execute_type__enum_size_e; ++j) { + for (j = 0; j < controller_rule_action_execute_type__enum_size_e; ++j) { item_destination->reruns[j].is = item_source->reruns[j].is; item_destination->reruns[j].failure.count = item_source->reruns[j].failure.count; @@ -242,7 +242,7 @@ extern "C" { f_status_t status = f_string_dynamic_partial_append_nulless(source, directory, alias); if (F_status_is_error(status)) { - controller_main_print_error_status(&global->main->program.error, macro_controller_f(f_string_dynamic_partial_append_nulless), F_status_set_fine(status)); + controller_print_error_status(&global->main->program.error, macro_controller_f(f_string_dynamic_partial_append_nulless), F_status_set_fine(status)); return status; } @@ -250,7 +250,7 @@ extern "C" { status = f_string_dynamic_append(f_path_separator_s, alias); if (F_status_is_error(status)) { - controller_main_print_error_status(&global->main->program.error, macro_controller_f(f_string_dynamic_append), F_status_set_fine(status)); + controller_print_error_status(&global->main->program.error, macro_controller_f(f_string_dynamic_append), F_status_set_fine(status)); return status; } @@ -258,7 +258,7 @@ extern "C" { status = f_string_dynamic_partial_append_nulless(source, basename, alias); if (F_status_is_error(status)) { - controller_main_print_error_status(&global->main->program.error, macro_controller_f(f_string_dynamic_partial_append_nulless), F_status_set_fine(status)); + controller_print_error_status(&global->main->program.error, macro_controller_f(f_string_dynamic_partial_append_nulless), F_status_set_fine(status)); return status; } diff --git a/sources/c/main/rule/action.c b/sources/c/main/rule/action.c index 60e099e..3f6538f 100644 --- a/sources/c/main/rule/action.c +++ b/sources/c/main/rule/action.c @@ -4,42 +4,42 @@ extern "C" { #endif -#ifndef _di_controller_main_rule_action_method_name_ - f_string_static_t controller_main_rule_action_method_name(const uint8_t type) { +#ifndef _di_controller_rule_action_method_name_ + f_string_static_t controller_rule_action_method_name(const uint8_t type) { - if (type == controller_main_rule_action_method_extended_e) return controller_main_rule_action_method_extended_s; - if (type == controller_main_rule_action_method_extended_list_e) return controller_main_rule_action_method_extended_list_s; + if (type == controller_rule_action_method_extended_e) return controller_rule_action_method_extended_s; + if (type == controller_rule_action_method_extended_list_e) return controller_rule_action_method_extended_list_s; return f_string_empty_s; } -#endif // _di_controller_main_rule_action_method_name_ - -#ifndef _di_controller_main_rule_action_type_to_action_execute_type_ - uint8_t controller_main_rule_action_type_to_action_execute_type(const uint8_t type) { - - if (type == controller_main_rule_action_type_freeze_e) return controller_main_rule_action_execute_type_freeze_e; - if (type == controller_main_rule_action_type_kill_e) return controller_main_rule_action_execute_type_kill_e; - if (type == controller_main_rule_action_type_pause_e) return controller_main_rule_action_execute_type_pause_e; - if (type == controller_main_rule_action_type_reload_e) return controller_main_rule_action_execute_type_reload_e; - if (type == controller_main_rule_action_type_restart_e) return controller_main_rule_action_execute_type_restart_e; - if (type == controller_main_rule_action_type_resume_e) return controller_main_rule_action_execute_type_resume_e; - if (type == controller_main_rule_action_type_start_e) return controller_main_rule_action_execute_type_start_e; - if (type == controller_main_rule_action_type_stop_e) return controller_main_rule_action_execute_type_stop_e; - if (type == controller_main_rule_action_type_thaw_e) return controller_main_rule_action_execute_type_thaw_e; - - return controller_main_rule_action_execute_type__enum_size_e; +#endif // _di_controller_rule_action_method_name_ + +#ifndef _di_controller_rule_action_type_to_action_execute_type_ + uint8_t controller_rule_action_type_to_action_execute_type(const uint8_t type) { + + if (type == controller_rule_action_type_freeze_e) return controller_rule_action_execute_type_freeze_e; + if (type == controller_rule_action_type_kill_e) return controller_rule_action_execute_type_kill_e; + if (type == controller_rule_action_type_pause_e) return controller_rule_action_execute_type_pause_e; + if (type == controller_rule_action_type_reload_e) return controller_rule_action_execute_type_reload_e; + if (type == controller_rule_action_type_restart_e) return controller_rule_action_execute_type_restart_e; + if (type == controller_rule_action_type_resume_e) return controller_rule_action_execute_type_resume_e; + if (type == controller_rule_action_type_start_e) return controller_rule_action_execute_type_start_e; + if (type == controller_rule_action_type_stop_e) return controller_rule_action_execute_type_stop_e; + if (type == controller_rule_action_type_thaw_e) return controller_rule_action_execute_type_thaw_e; + + return controller_rule_action_execute_type__enum_size_e; } -#endif // _di_controller_main_rule_action_type_to_action_execute_type_ +#endif // _di_controller_rule_action_type_to_action_execute_type_ -#ifndef _di_controller_main_rule_action_read_ - f_status_t controller_main_rule_action_read(controller_global_t * const global, const bool is_normal, const uint8_t type, const uint8_t method, controller_cache_t * const cache, controller_rule_item_t * const item, controller_main_rule_actions_t * const actions, f_range_t * const range) { +#ifndef _di_controller_rule_action_read_ + f_status_t controller_rule_action_read(controller_global_t * const global, const bool is_normal, const uint8_t type, const uint8_t method, controller_cache_t * const cache, controller_rule_item_t * const item, controller_rule_actions_t * const actions, f_range_t * const range) { if (!global || !item || !actions || !range) return F_status_set_error(F_parameter); f_status_t status = F_okay; - controller_interrupt_t custom = macro_controller_interrupt_t_initialize_1(is_normal, global->thread); - f_state_t state = macro_f_state_t_initialize_1(controller_allocation_large_d, controller_allocation_small_d, F_okay, 0, 0, 0, &controller_main_thread_signal_state_fss, 0, (void *) &custom, 0); + controller_interrupt_t custom = macro_controller_interrupt_t_initialize_1(is_normal, global); + f_state_t state = macro_f_state_t_initialize_1(controller_allocation_large_d, controller_allocation_small_d, F_okay, 0, 0, 0, &controller_thread_signal_state_fss, 0, (void *) &custom, 0); f_number_unsigned_t i = 0; @@ -63,11 +63,11 @@ extern "C" { cache->delimits.used = 0; cache->content_action.used = 0; - if (method == controller_main_rule_action_method_extended_list_e) { + if (method == controller_rule_action_method_extended_list_e) { fl_fss_extended_list_content_read(cache->buffer_item, range, &cache->content_action, &cache->delimits, &cache->comments, &state); if (F_status_is_error(status)) { - controller_main_print_error(&global->main->program.error, macro_controller_f(fl_fss_extended_list_content_read)); + controller_print_error(&global->main->program.error, macro_controller_f(fl_fss_extended_list_content_read)); return status; } @@ -76,7 +76,7 @@ extern "C" { f_fss_apply_delimit(cache->delimits, &cache->buffer_item, &state); if (F_status_is_error(status)) { - controller_main_print_error(&global->main->program.error, macro_controller_f(f_fss_apply_delimit)); + controller_print_error(&global->main->program.error, macro_controller_f(f_fss_apply_delimit)); return status; } @@ -88,7 +88,7 @@ extern "C" { status = f_memory_array_increase(controller_allocation_small_d, sizeof(f_string_dynamic_t), (void **) &actions->array[actions->used].parameters.array, &actions->array[actions->used].parameters.used, &actions->array[actions->used].parameters.size); if (F_status_is_error(status)) { - controller_main_print_error(&global->main->program.error, macro_controller_f(f_memory_array_increase)); + controller_print_error(&global->main->program.error, macro_controller_f(f_memory_array_increase)); return status; } @@ -96,7 +96,7 @@ extern "C" { status = f_memory_array_increase(controller_allocation_small_d, sizeof(f_iki_data_t), (void **) &actions->array[actions->used].ikis.array, &actions->array[actions->used].ikis.used, &actions->array[actions->used].ikis.size); if (F_status_is_error(status)) { - controller_main_print_error(&global->main->program.error, macro_controller_f(f_memory_array_increase)); + controller_print_error(&global->main->program.error, macro_controller_f(f_memory_array_increase)); return status; } @@ -108,9 +108,9 @@ extern "C" { status = f_string_dynamic_partial_append_nulless(cache->buffer_item, cache->content_action.array[0], &actions->array[actions->used].parameters.array[0]); if (F_status_is_error(status)) { - controller_main_print_error(&global->main->program.error, macro_controller_f(f_string_dynamic_append_nulless)); + controller_print_error(&global->main->program.error, macro_controller_f(f_string_dynamic_append_nulless)); - actions->array[actions->used++].status = controller_main_error_simplify(F_status_set_fine(status)); + actions->array[actions->used++].status = controller_error_simplify(F_status_set_fine(status)); return status; } @@ -118,16 +118,16 @@ extern "C" { if (actions->array[actions->used].parameters.array[0].used) { state.step_large = controller_allocation_iki_large_d; state.step_small = controller_allocation_iki_small_d; - state.interrupt = &controller_main_thread_signal_state_iki; + state.interrupt = &controller_thread_signal_state_iki; f_range_t range_iki = macro_f_range_t_initialize_2(actions->array[actions->used].parameters.array[0].used); fl_iki_read(&actions->array[actions->used].parameters.array[0], &range_iki, &actions->array[actions->used].ikis.array[0], &state); if (F_status_is_error(status)) { - controller_main_print_error(&global->main->program.error, macro_controller_f(fl_iki_read)); + controller_print_error(&global->main->program.error, macro_controller_f(fl_iki_read)); - actions->array[actions->used++].status = controller_main_error_simplify(F_status_set_fine(status)); + actions->array[actions->used++].status = controller_error_simplify(F_status_set_fine(status)); return status; } @@ -145,7 +145,7 @@ extern "C" { fll_fss_extended_read(cache->buffer_item, &cache->content_action.array[0], &cache->object_actions, &cache->content_actions, 0, 0, &cache->delimits, 0, &state); if (F_status_is_error(status)) { - controller_main_print_error(&global->main->program.error, macro_controller_f(fll_fss_extended_read)); + controller_print_error(&global->main->program.error, macro_controller_f(fll_fss_extended_read)); return status; } @@ -153,17 +153,17 @@ extern "C" { f_fss_apply_delimit(cache->delimits, &cache->buffer_item, &state); if (F_status_is_error(status)) { - controller_main_print_error(&global->main->program.error, macro_controller_f(f_fss_apply_delimit)); + controller_print_error(&global->main->program.error, macro_controller_f(f_fss_apply_delimit)); return status; } for (i = 0; i < cache->object_actions.used; ++i) { - status = f_memory_array_increase_by(controller_allocation_small_d, sizeof(controller_main_rule_action_t), (void **) &actions->array, &actions->used, &actions->size); + status = f_memory_array_increase_by(controller_allocation_small_d, sizeof(controller_rule_action_t), (void **) &actions->array, &actions->used, &actions->size); if (F_status_is_error(status)) { - controller_main_print_error(&global->main->program.error, macro_controller_f(f_memory_array_increase_by)); + controller_print_error(&global->main->program.error, macro_controller_f(f_memory_array_increase_by)); return status; } @@ -171,7 +171,7 @@ extern "C" { f_fss_count_lines(cache->buffer_item, cache->object_actions.array[i].start, &actions->array[actions->used].line, &state); if (F_status_is_error(status)) { - controller_main_print_error(&global->main->program.error, macro_controller_f(f_fss_count_lines)); + controller_print_error(&global->main->program.error, macro_controller_f(f_fss_count_lines)); return status; } @@ -180,10 +180,10 @@ extern "C" { actions->array[actions->used].line += ++item->line; actions->array[actions->used].status = F_known_not; - status = controller_main_rule_parameters_read(global, cache->buffer_item, &cache->object_actions.array[i], &cache->content_actions.array[i], &actions->array[actions->used], &state); + status = controller_rule_parameters_read(global, cache->buffer_item, &cache->object_actions.array[i], &cache->content_actions.array[i], &actions->array[actions->used], &state); if (F_status_is_error(status)) { - actions->array[actions->used++].status = controller_main_error_simplify(F_status_set_fine(status)); + actions->array[actions->used++].status = controller_error_simplify(F_status_set_fine(status)); return status; } @@ -201,58 +201,58 @@ extern "C" { fl_fss_extended_content_read(cache->buffer_item, range, &cache->content_action, 0, &cache->delimits, &state); if (F_status_is_error(status)) { - controller_main_print_error(&global->main->program.error, macro_controller_f(fll_fss_extended_content_read)); + controller_print_error(&global->main->program.error, macro_controller_f(fll_fss_extended_content_read)); } else if (status == F_fss_found_content) { f_fss_apply_delimit(cache->delimits, &cache->buffer_item, &state); if (F_status_is_error(status)) { - controller_main_print_error(&global->main->program.error, macro_controller_f(f_fss_apply_delimit)); + controller_print_error(&global->main->program.error, macro_controller_f(f_fss_apply_delimit)); } - else if (type == controller_main_rule_action_type_pid_file_e) { + else if (type == controller_rule_action_type_pid_file_e) { item->pid_file.used = 0; status = f_rip_dynamic_partial(cache->buffer_item, cache->content_action.array[0], &item->pid_file); if (F_status_is_error(status)) { - controller_main_print_error(&global->main->program.error, macro_controller_f(f_rip_dynamic_partial)); + controller_print_error(&global->main->program.error, macro_controller_f(f_rip_dynamic_partial)); } } - else if (type == controller_main_rule_action_type_rerun_e) { + else if (type == controller_rule_action_type_rerun_e) { uint8_t type_rerun = 0; if (cache->content_action.used) { if (f_compare_dynamic_partial_string(controller_freeze_s.string, cache->buffer_item, controller_freeze_s.used, cache->content_action.array[0]) == F_equal_to) { - type_rerun = controller_main_rule_action_execute_type_freeze_e; + type_rerun = controller_rule_action_execute_type_freeze_e; } if (f_compare_dynamic_partial_string(controller_kill_s.string, cache->buffer_item, controller_kill_s.used, cache->content_action.array[0]) == F_equal_to) { - type_rerun = controller_main_rule_action_execute_type_kill_e; + type_rerun = controller_rule_action_execute_type_kill_e; } else if (f_compare_dynamic_partial_string(controller_pause_s.string, cache->buffer_item, controller_pause_s.used, cache->content_action.array[0]) == F_equal_to) { - type_rerun = controller_main_rule_action_execute_type_pause_e; + type_rerun = controller_rule_action_execute_type_pause_e; } else if (f_compare_dynamic_partial_string(controller_reload_s.string, cache->buffer_item, controller_reload_s.used, cache->content_action.array[0]) == F_equal_to) { - type_rerun = controller_main_rule_action_execute_type_reload_e; + type_rerun = controller_rule_action_execute_type_reload_e; } else if (f_compare_dynamic_partial_string(controller_restart_s.string, cache->buffer_item, controller_restart_s.used, cache->content_action.array[0]) == F_equal_to) { - type_rerun = controller_main_rule_action_execute_type_restart_e; + type_rerun = controller_rule_action_execute_type_restart_e; } else if (f_compare_dynamic_partial_string(controller_resume_s.string, cache->buffer_item, controller_resume_s.used, cache->content_action.array[0]) == F_equal_to) { - type_rerun = controller_main_rule_action_execute_type_resume_e; + type_rerun = controller_rule_action_execute_type_resume_e; } else if (f_compare_dynamic_partial_string(controller_start_s.string, cache->buffer_item, controller_start_s.used, cache->content_action.array[0]) == F_equal_to) { - type_rerun = controller_main_rule_action_execute_type_start_e; + type_rerun = controller_rule_action_execute_type_start_e; } else if (f_compare_dynamic_partial_string(controller_stop_s.string, cache->buffer_item, controller_stop_s.used, cache->content_action.array[0]) == F_equal_to) { - type_rerun = controller_main_rule_action_execute_type_stop_e; + type_rerun = controller_rule_action_execute_type_stop_e; } else if (f_compare_dynamic_partial_string(controller_thaw_s.string, cache->buffer_item, controller_thaw_s.used, cache->content_action.array[0]) == F_equal_to) { - type_rerun = controller_main_rule_action_execute_type_thaw_e; + type_rerun = controller_rule_action_execute_type_thaw_e; } } if (!type_rerun) { - controller_main_print_rule_item_error_action_first(&global->main->program.error, cache); + controller_print_rule_item_error_action_first(&global->main->program.error, cache); return F_status_set_error(F_valid_not); } @@ -270,7 +270,7 @@ extern "C" { } } else { - controller_main_print_rule_item_error_action_second(&global->main->program.error, cache); + controller_print_rule_item_error_action_second(&global->main->program.error, cache); return F_status_set_error(F_valid_not); } @@ -278,22 +278,22 @@ extern "C" { for (i = 2; i < cache->content_action.used; ++i) { if (f_compare_dynamic_partial_string(controller_delay_s.string, cache->buffer_item, controller_delay_s.used, cache->content_action.array[i]) == F_equal_to) { - status = controller_main_rule_action_read_rerun_number(global, controller_delay_s.string, cache, &i, &rerun_item->delay); + status = controller_rule_action_read_rerun_number(global, controller_delay_s.string, cache, &i, &rerun_item->delay); } else if (f_compare_dynamic_partial_string(controller_max_s.string, cache->buffer_item, controller_max_s.used, cache->content_action.array[i]) == F_equal_to) { - status = controller_main_rule_action_read_rerun_number(global, controller_max_s.string, cache, &i, &rerun_item->max); + status = controller_rule_action_read_rerun_number(global, controller_max_s.string, cache, &i, &rerun_item->max); } else if (f_compare_dynamic_partial_string(controller_reset_s.string, cache->buffer_item, controller_reset_s.used, cache->content_action.array[i]) == F_equal_to) { item->reruns[type_rerun].is |= rerun_item == &item->reruns[type_rerun].failure ? controller_rule_rerun_is_failure_reset_d : controller_rule_rerun_is_success_reset_d; } else { - controller_main_print_rule_item_error_action_unknown(&global->main->program.error, cache, controller_rerun_s, i); + controller_print_rule_item_error_action_unknown(&global->main->program.error, cache, controller_rerun_s, i); return F_status_set_error(F_valid_not); } } // for } - else if (type == controller_main_rule_action_type_with_e) { + else if (type == controller_rule_action_type_with_e) { for (i = 0; i < cache->content_action.used; ++i) { if (f_compare_dynamic_partial_string(controller_full_path_s.string, cache->buffer_item, controller_full_path_s.used, cache->content_action.array[i]) == F_equal_to) { @@ -312,7 +312,7 @@ extern "C" { item->with &= ~controller_with_session_new_d; } else { - controller_main_print_rule_item_error_action_unknown(&global->main->program.error, cache, controller_with_s, i); + controller_print_rule_item_error_action_unknown(&global->main->program.error, cache, controller_with_s, i); status = F_status_set_error(F_valid_not); @@ -324,7 +324,7 @@ extern "C" { status = f_memory_array_increase(controller_allocation_small_d, sizeof(f_string_dynamic_t), (void **) &actions->array[actions->used].parameters.array, &actions->array[actions->used].parameters.used, &actions->array[actions->used].parameters.size); if (F_status_is_error(status)) { - controller_main_print_error(&global->main->program.error, macro_controller_f(f_memory_array_increase)); + controller_print_error(&global->main->program.error, macro_controller_f(f_memory_array_increase)); return status; } @@ -332,7 +332,7 @@ extern "C" { status = f_memory_array_increase(controller_allocation_small_d, sizeof(f_iki_data_t), (void **) &actions->array[actions->used].ikis.array, &actions->array[actions->used].ikis.used, &actions->array[actions->used].ikis.size); if (F_status_is_error(status)) { - controller_main_print_error(&global->main->program.error, macro_controller_f(f_memory_array_increase)); + controller_print_error(&global->main->program.error, macro_controller_f(f_memory_array_increase)); return status; } @@ -349,9 +349,9 @@ extern "C" { } // for if (F_status_is_error(status)) { - controller_main_print_error(&global->main->program.error, macro_controller_f(f_string_dynamic_partial_mash_nulless)); + controller_print_error(&global->main->program.error, macro_controller_f(f_string_dynamic_partial_mash_nulless)); - actions->array[actions->used++].status = controller_main_error_simplify(F_status_set_fine(status)); + actions->array[actions->used++].status = controller_error_simplify(F_status_set_fine(status)); return status; } @@ -359,16 +359,16 @@ extern "C" { if (actions->array[actions->used].parameters.array[0].used) { state.step_large = controller_allocation_iki_large_d; state.step_small = controller_allocation_iki_small_d; - state.interrupt = &controller_main_thread_signal_state_iki; + state.interrupt = &controller_thread_signal_state_iki; f_range_t range_iki = macro_f_range_t_initialize_2(actions->array[actions->used].parameters.array[0].used); fl_iki_read(&actions->array[actions->used].parameters.array[0], &range_iki, &actions->array[actions->used].ikis.array[0], &state); if (F_status_is_error(status)) { - controller_main_print_error(&global->main->program.error, macro_controller_f(fl_iki_read)); + controller_print_error(&global->main->program.error, macro_controller_f(fl_iki_read)); - actions->array[actions->used++].status = controller_main_error_simplify(F_status_set_fine(status)); + actions->array[actions->used++].status = controller_error_simplify(F_status_set_fine(status)); return status; } @@ -381,7 +381,7 @@ extern "C" { f_fss_count_lines(cache->buffer_item, range->start, &actions->array[actions->used].line, &state); if (F_status_is_error(status)) { - controller_main_print_error(&global->main->program.error, macro_controller_f(f_fss_count_lines)); + controller_print_error(&global->main->program.error, macro_controller_f(f_fss_count_lines)); return status; } @@ -390,10 +390,10 @@ extern "C" { actions->array[actions->used].line += ++item->line; actions->array[actions->used].status = F_known_not; - status = controller_main_rule_parameters_read(global, cache->buffer_item, 0, &cache->content_action, &actions->array[actions->used], &state); + status = controller_rule_parameters_read(global, cache->buffer_item, 0, &cache->content_action, &actions->array[actions->used], &state); if (F_status_is_error(status)) { - actions->array[actions->used++].status = controller_main_error_simplify(F_status_set_fine(status)); + actions->array[actions->used++].status = controller_error_simplify(F_status_set_fine(status)); return status; } @@ -407,15 +407,15 @@ extern "C" { } if (F_status_is_error_not(status) && status == F_data_not) { - controller_main_print_rule_item_debug_action_empty(&global->debug, cache); + controller_print_rule_item_debug_action_empty(global->debug, cache); } return status; } -#endif // _di_controller_main_rule_action_read_ +#endif // _di_controller_rule_action_read_ -#ifndef _di_controller_main_rule_action_read_rerun_number_ - f_status_t controller_main_rule_action_read_rerun_number(controller_global_t * const global, const f_string_t name, controller_cache_t * const cache, f_number_unsigned_t * const index, f_number_unsigned_t * const number) { +#ifndef _di_controller_rule_action_read_rerun_number_ + f_status_t controller_rule_action_read_rerun_number(controller_global_t * const global, const f_string_t name, controller_cache_t * const cache, f_number_unsigned_t * const index, f_number_unsigned_t * const number) { f_status_t status = F_okay; f_number_signed_t parsed = 0; @@ -427,7 +427,7 @@ extern "C" { status = fl_conversion_dynamic_partial_to_signed_detect(fl_conversion_data_base_10_c, cache->buffer_item, cache->content_action.array[++(*index)], &parsed); if (F_status_set_fine(status) == F_number_positive) { - status = fl_conversion_dynamic_partial_to_signed_detect(fl_conversion_data_base_10_c, cache->buffer_item, controller_main_range_after_number_sign(cache->buffer_item, cache->content_action.array[*index]), &parsed); + status = fl_conversion_dynamic_partial_to_signed_detect(fl_conversion_data_base_10_c, cache->buffer_item, controller_range_after_number_sign(cache->buffer_item, cache->content_action.array[*index]), &parsed); } if (status == F_data_not) { @@ -440,7 +440,7 @@ extern "C" { status = F_status_set_fine(status); if (status != F_valid_not && status != F_number && status != F_number_decimal && status != F_number_overflow && status != F_number_underflow && status != F_number_negative) { - controller_main_print_error(&global->main->program.error, macro_controller_f(fl_conversion_dynamic_partial_to_signed_detect)); + controller_print_error(&global->main->program.error, macro_controller_f(fl_conversion_dynamic_partial_to_signed_detect)); } else { controller_lock_print(global->main->program.error.to, global->thread); @@ -468,7 +468,7 @@ extern "C" { } } - controller_main_print_rule_error_cache(&global->error, &cache->action, F_true); + controller_print_rule_error_cache(global->error, cache->action, F_true); controller_unlock_print_flush(global->main->program.error.to, global->thread); } @@ -481,7 +481,7 @@ extern "C" { return F_okay; } -#endif // _di_controller_main_rule_action_read_rerun_number_ +#endif // _di_controller_rule_action_read_rerun_number_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/rule/action.h b/sources/c/main/rule/action.h index 0ad52e9..ff8cf7a 100644 --- a/sources/c/main/rule/action.h +++ b/sources/c/main/rule/action.h @@ -26,9 +26,9 @@ extern "C" { * The string with used > 0 on success. * The string with used == 0 if no match was found. */ -#ifndef _di_controller_main_rule_action_method_name_ - extern f_string_static_t controller_main_rule_action_method_name(const uint8_t type); -#endif // _di_controller_main_rule_action_method_name_ +#ifndef _di_controller_rule_action_method_name_ + extern f_string_static_t controller_rule_action_method_name(const uint8_t type); +#endif // _di_controller_rule_action_method_name_ /** * Convert the action type to an action execute type. @@ -39,11 +39,11 @@ extern "C" { * @return * The converted action type, converted into an action execute type. * - * The code controller_main_rule_action_execute_type__enum_size_e is returned for unknown types. + * The code controller_rule_action_execute_type__enum_size_e is returned for unknown types. */ -#ifndef _di_controller_main_rule_action_type_to_action_execute_type_ - extern uint8_t controller_main_rule_action_type_to_action_execute_type(const uint8_t type); -#endif // _di_controller_main_rule_action_type_to_action_execute_type_ +#ifndef _di_controller_rule_action_type_to_action_execute_type_ + extern uint8_t controller_rule_action_type_to_action_execute_type(const uint8_t type); +#endif // _di_controller_rule_action_type_to_action_execute_type_ /** * Read the content within the buffer, processing the action (or a set of within a list) for the given item. @@ -84,24 +84,24 @@ extern "C" { * @return * F_okay on success. * - * Errors (with error bit) from: controller_main_rule_parameters_read(). + * Errors (with error bit) from: controller_rule_parameters_read(). * Errors (with error bit) from: f_fss_count_lines(). * Errors (with error bit) from: f_memory_array_increase_by(). * - * @see controller_main_rule_parameters_read() + * @see controller_rule_parameters_read() * @see f_fss_count_lines() * @see f_memory_array_increase_by() */ -#ifndef _di_controller_main_rule_action_read_ - extern f_status_t controller_main_rule_action_read(controller_global_t * const global, const bool is_normal, const uint8_t type, const uint8_t method, controller_cache_t * const cache, controller_rule_item_t * const item, controller_main_rule_actions_t * const actions, f_range_t * const range); -#endif // _di_controller_main_rule_action_read_ +#ifndef _di_controller_rule_action_read_ + extern f_status_t controller_rule_action_read(controller_global_t * const global, const bool is_normal, const uint8_t type, const uint8_t method, controller_cache_t * const cache, controller_rule_item_t * const item, controller_rule_actions_t * const actions, f_range_t * const range); +#endif // _di_controller_rule_action_read_ /** * Process a number from a rule file, incrementing index as necessary. * * This prints error messages as necessary. * - * This is intended to be called by controller_main_rule_action_read(). + * This is intended to be called by controller_rule_action_read(). * * @param global * The global data. @@ -125,12 +125,12 @@ extern "C" { * * Errors (with error bit) from: fl_conversion_dynamic_partial_to_signed_detect(). * - * @see controller_main_rule_action_read() + * @see controller_rule_action_read() * @see fl_conversion_dynamic_partial_to_signed_detect() */ -#ifndef _di_controller_main_rule_action_read_rerun_number_ - extern f_status_t controller_main_rule_action_read_rerun_number(controller_global_t * const global, const f_string_t name, controller_cache_t * const cache, f_number_unsigned_t * const index, f_number_unsigned_t * const number); -#endif // _di_controller_main_rule_action_read_rerun_number_ +#ifndef _di_controller_rule_action_read_rerun_number_ + extern f_status_t controller_rule_action_read_rerun_number(controller_global_t * const global, const f_string_t name, controller_cache_t * const cache, f_number_unsigned_t * const index, f_number_unsigned_t * const number); +#endif // _di_controller_rule_action_read_rerun_number_ #ifdef __cplusplus diff --git a/sources/c/main/rule/execute.c b/sources/c/main/rule/execute.c index 7d2bbf4..bfdad92 100644 --- a/sources/c/main/rule/execute.c +++ b/sources/c/main/rule/execute.c @@ -4,8 +4,8 @@ extern "C" { #endif -#ifndef _di_controller_main_rule_execute_ - f_status_t controller_main_rule_execute(controller_global_t * const global, const uint8_t action, const uint8_t options, controller_instance_t * const instance) { +#ifndef _di_controller_rule_execute_ + f_status_t controller_rule_execute(controller_global_t * const global, const uint8_t action, const uint8_t options, controller_instance_t * const instance) { if (!global || !instance) return F_status_set_error(F_parameter); @@ -37,11 +37,11 @@ extern "C" { execute_set.as.control_group = &instance->rule.cgroup; // Make sure all required cgroup directories exist. - if (controller_main_rule_status_is_available(action, instance->rule)) { + if (controller_rule_status_is_available(action, instance->rule)) { status = fll_control_group_prepare(instance->rule.cgroup); if (F_status_is_error(status)) { - controller_main_print_error_file(&global->main->program.error, macro_controller_f(fll_control_group_prepare), instance->rule.cgroup.path, controller_print_rule_control_groups_prepare_s, fll_error_file_type_directory_e); + controller_print_error_file(&global->main->program.error, macro_controller_f(fll_control_group_prepare), instance->rule.cgroup.path, controller_print_rule_control_groups_prepare_s, fll_error_file_type_directory_e); return status; } @@ -76,7 +76,7 @@ extern "C" { status = fl_environment_load_names(instance->rule.environment, &environment); if (F_status_is_error(status)) { - controller_main_print_error_status(&global->main->program.error, macro_controller_f(fl_environment_load_names), F_status_set_fine(status)); + controller_print_error_status(&global->main->program.error, macro_controller_f(fl_environment_load_names), F_status_set_fine(status)); return status; } @@ -107,7 +107,7 @@ extern "C" { status = f_string_dynamic_append(entry->define.array[i].value, &environment.array[k].value); if (F_status_is_error(status)) { - controller_main_print_error_status(&global->main->program.error, macro_controller_f(f_string_dynamic_append), F_status_set_fine(status)); + controller_print_error_status(&global->main->program.error, macro_controller_f(f_string_dynamic_append), F_status_set_fine(status)); return status; } @@ -120,7 +120,7 @@ extern "C" { status = f_string_maps_append(entry->define.array[i], &environment); if (F_status_is_error(status)) { - controller_main_print_error_status(&global->main->program.error, macro_controller_f(f_string_maps_append), F_status_set_fine(status)); + controller_print_error_status(&global->main->program.error, macro_controller_f(f_string_maps_append), F_status_set_fine(status)); return status; } @@ -148,7 +148,7 @@ extern "C" { status = f_string_dynamic_append(instance->rule.define.array[i].value, &environment.array[k].value); if (F_status_is_error(status)) { - controller_main_print_error_status(&global->main->program.error, macro_controller_f(f_string_dynamic_append), F_status_set_fine(status)); + controller_print_error_status(&global->main->program.error, macro_controller_f(f_string_dynamic_append), F_status_set_fine(status)); return status; } @@ -161,7 +161,7 @@ extern "C" { status = f_string_maps_append(instance->rule.define.array[i], &environment); if (F_status_is_error(status)) { - controller_main_print_error_status(&global->main->program.error, macro_controller_f(f_string_maps_append), F_status_set_fine(status)); + controller_print_error_status(&global->main->program.error, macro_controller_f(f_string_maps_append), F_status_set_fine(status)); return status; } @@ -189,7 +189,7 @@ extern "C" { status = f_environment_get_all(&environment); if (F_status_is_error(status)) { - controller_main_print_error_status(&global->main->program.error, macro_controller_f(f_environment_get_all), F_status_set_fine(status)); + controller_print_error_status(&global->main->program.error, macro_controller_f(f_environment_get_all), F_status_set_fine(status)); return status; } @@ -199,7 +199,7 @@ extern "C" { status = f_string_maps_append(entry->define.array[i], &environment); if (F_status_is_error(status)) { - controller_main_print_error_status(&global->main->program.error, macro_controller_f(f_string_maps_append), F_status_set_fine(status)); + controller_print_error_status(&global->main->program.error, macro_controller_f(f_string_maps_append), F_status_set_fine(status)); return status; } @@ -210,7 +210,7 @@ extern "C" { status = f_string_maps_append(instance->rule.define.array[i], &environment); if (F_status_is_error(status)) { - controller_main_print_error_status(&global->main->program.error, macro_controller_f(f_string_maps_append), F_status_set_fine(status)); + controller_print_error_status(&global->main->program.error, macro_controller_f(f_string_maps_append), F_status_set_fine(status)); return status; } @@ -223,13 +223,13 @@ extern "C" { } } - for (i = 0; i < instance->rule.items.used && controller_main_thread_is_enabled_instance(instance, global->thread); ++i) { + for (i = 0; i < instance->rule.items.used && controller_thread_is_enabled_instance(instance); ++i) { if (instance->rule.items.array[i].type == controller_rule_item_type_settings_e) continue; for (j = 0; j < instance->rule.items.array[i].actions.used; ++j) { - if (!controller_main_thread_is_enabled_instance(instance, global->thread)) { + if (!controller_thread_is_enabled_instance(instance)) { status = F_status_set_error(F_interrupt); break; @@ -249,21 +249,21 @@ extern "C" { } if (instance->rule.items.array[i].type == controller_rule_item_type_command_e) { - status = controller_main_rule_expand(global, instance->rule.items.array[i].actions.array[j], instance); + status = controller_rule_expand(global, instance->rule.items.array[i].actions.array[j], instance); if (F_status_is_error(status)) { - controller_main_print_rule_error(&global->error, instance->cache.action, F_status_set_fine(status), "controller_main_rule_expand", F_true, F_false); + controller_print_rule_error(global->error, instance->cache.action, F_status_set_fine(status), "controller_rule_expand", F_true, F_false); break; } do { - status = controller_main_rule_execute_foreground(instance->rule.items.array[i].type, f_string_empty_s, instance->cache.expanded, options, &execute_set, instance); + status = controller_rule_execute_foreground(instance->rule.items.array[i].type, f_string_empty_s, instance->cache.expanded, options, &execute_set, instance); if (status == F_child || F_status_set_fine(status) == F_interrupt || F_status_set_fine(status) == F_lock) break; if (F_status_is_error(status) && F_status_set_fine(status) != F_failure) break; - } while (controller_main_rule_execute_rerun(controller_main_rule_action_type_to_action_execute_type(action), instance, &instance->rule.items.array[i]) > 0); + } while (controller_rule_execute_rerun(controller_rule_action_type_to_action_execute_type(action), instance, &instance->rule.items.array[i]) > 0); if (status == F_child || F_status_set_fine(status) == F_interrupt || F_status_set_fine(status) == F_lock) break; @@ -279,10 +279,10 @@ extern "C" { } } else if (instance->rule.items.array[i].type == controller_rule_item_type_script_e) { - status = controller_main_rule_expand(global, instance->rule.items.array[i].actions.array[j], instance); + status = controller_rule_expand(global, instance->rule.items.array[i].actions.array[j], instance); if (F_status_is_error(status)) { - controller_main_print_rule_error(&global->error, instance->cache.action, F_status_set_fine(status), "controller_main_rule_expand", F_true, F_false); + controller_print_rule_error(global->error, instance->cache.action, F_status_set_fine(status), "controller_rule_expand", F_true, F_false); break; } @@ -296,16 +296,16 @@ extern "C" { do { if (instance->rule.engine.used) { - status = controller_main_rule_execute_foreground(instance->rule.items.array[i].type, instance->rule.engine, instance->rule.engine_arguments, options, &execute_set, instance); + status = controller_rule_execute_foreground(instance->rule.items.array[i].type, instance->rule.engine, instance->rule.engine_arguments, options, &execute_set, instance); } else { - status = controller_main_rule_execute_foreground(instance->rule.items.array[i].type, *global->main->setting.default_engine, instance->rule.engine_arguments, options, &execute_set, instance); + status = controller_rule_execute_foreground(instance->rule.items.array[i].type, controller_default_engine_s, instance->rule.engine_arguments, options, &execute_set, instance); } if (status == F_child || F_status_set_fine(status) == F_lock) break; if (F_status_is_error(status) && F_status_set_fine(status) != F_failure) break; - } while (controller_main_rule_execute_rerun(controller_main_rule_action_type_to_action_execute_type(action), instance, &instance->rule.items.array[i]) > 0); + } while (controller_rule_execute_rerun(controller_rule_action_type_to_action_execute_type(action), instance, &instance->rule.items.array[i]) > 0); if (status == F_child || F_status_set_fine(status) == F_interrupt || F_status_set_fine(status) == F_lock) break; @@ -321,22 +321,22 @@ extern "C" { } } else if (instance->rule.items.array[i].type == controller_rule_item_type_service_e) { - status = controller_main_rule_expand(global, instance->rule.items.array[i].actions.array[j], instance); + status = controller_rule_expand(global, instance->rule.items.array[i].actions.array[j], instance); if (F_status_is_error(status)) { - controller_main_print_rule_error(&global->error, instance->cache.action, F_status_set_fine(status), "controller_main_rule_expand", F_true, F_false); + controller_print_rule_error(global->error, instance->cache.action, F_status_set_fine(status), "controller_rule_expand", F_true, F_false); break; } if (instance->rule.items.array[i].pid_file.used) { do { - status = controller_main_rule_execute_pid_with(instance->rule.items.array[i].pid_file, instance->rule.items.array[i].type, f_string_empty_s, instance->cache.expanded, options, instance->rule.items.array[i].with, &execute_set, instance); + status = controller_rule_execute_pid_with(instance->rule.items.array[i].pid_file, instance->rule.items.array[i].type, f_string_empty_s, instance->cache.expanded, options, instance->rule.items.array[i].with, &execute_set, instance); if (status == F_child || F_status_set_fine(status) == F_interrupt || F_status_set_fine(status) == F_lock) break; if (F_status_is_error(status) && F_status_set_fine(status) != F_failure) break; - } while (controller_main_rule_execute_rerun(controller_main_rule_action_type_to_action_execute_type(action), instance, &instance->rule.items.array[i]) > 0); + } while (controller_rule_execute_rerun(controller_rule_action_type_to_action_execute_type(action), instance, &instance->rule.items.array[i]) > 0); if (status == F_child || F_status_set_fine(status) == F_interrupt || F_status_set_fine(status) == F_lock) break; @@ -354,15 +354,15 @@ extern "C" { else { success = F_status_set_error(F_failure); - controller_main_print_rule_action_error_missing_pid(&global->error, instance->rule.alias); + controller_print_rule_action_error_missing_pid(global->error, instance->rule.alias); } } else if (instance->rule.items.array[i].type == controller_rule_item_type_utility_e) { if (instance->rule.items.array[i].pid_file.used) { - status = controller_main_rule_expand(global, instance->rule.items.array[i].actions.array[j], instance); + status = controller_rule_expand(global, instance->rule.items.array[i].actions.array[j], instance); if (F_status_is_error(status)) { - controller_main_print_rule_error(&global->error, instance->cache.action, F_status_set_fine(status), "controller_main_rule_expand", F_true, F_false); + controller_print_rule_error(global->error, instance->cache.action, F_status_set_fine(status), "controller_rule_expand", F_true, F_false); break; } @@ -375,12 +375,12 @@ extern "C" { } do { - status = controller_main_rule_execute_pid_with(instance->rule.items.array[i].pid_file, instance->rule.items.array[i].type, instance->rule.engine.used ? instance->rule.engine : *global->main->setting.default_engine, instance->rule.engine_arguments, options, instance->rule.items.array[i].with, &execute_set, instance); + status = controller_rule_execute_pid_with(instance->rule.items.array[i].pid_file, instance->rule.items.array[i].type, instance->rule.engine.used ? instance->rule.engine : controller_default_engine_s, instance->rule.engine_arguments, options, instance->rule.items.array[i].with, &execute_set, instance); if (status == F_child || F_status_set_fine(status) == F_interrupt || F_status_set_fine(status) == F_lock) break; if (F_status_is_error(status) && F_status_set_fine(status) != F_failure) break; - } while (controller_main_rule_execute_rerun(controller_main_rule_action_type_to_action_execute_type(action), instance, &instance->rule.items.array[i]) > 0); + } while (controller_rule_execute_rerun(controller_rule_action_type_to_action_execute_type(action), instance, &instance->rule.items.array[i]) > 0); if (status == F_child || F_status_set_fine(status) == F_interrupt || F_status_set_fine(status) == F_lock) break; @@ -398,7 +398,7 @@ extern "C" { else { success = F_status_set_error(F_failure); - controller_main_print_rule_action_error_missing_pid(&global->error, instance->rule.alias); + controller_print_rule_action_error_missing_pid(global->error, instance->rule.alias); } } else { @@ -407,7 +407,7 @@ extern "C" { fl_print_format("%r%[%QAction type is unknown, ignoring.%]%r", global->main->program.warning.to, f_string_eol_s, global->main->program.warning.context, global->main->program.warning.prefix, global->main->program.warning.context, f_string_eol_s); - controller_main_print_rule_error_cache(&global->main->program.warning, instance->cache.action, F_true); + controller_print_rule_error_cache(&global->main->program.warning, instance->cache.action, F_true); controller_unlock_print_flush(global->main->program.warning.to, global->thread); } @@ -429,13 +429,13 @@ extern "C" { // Lock failed, attempt to re-establish lock before returning. if (F_status_set_fine(status) == F_lock) { - status = controller_main_lock_read(instance, global->thread, &instance->lock); + status = controller_lock_read(instance, global->thread, &instance->lock); if (F_status_is_error(status)) return F_status_set_error(F_lock); success = F_false; } - if (!controller_main_thread_is_enabled_instance(instance, global->thread)) { + if (!controller_thread_is_enabled_instance(instance)) { return F_status_set_error(F_interrupt); } @@ -453,25 +453,25 @@ extern "C" { return F_okay; } -#endif // _di_controller_main_rule_execute_ +#endif // _di_controller_rule_execute_ -#ifndef _di_controller_main_rule_execute_foreground_ - f_status_t controller_main_rule_execute_foreground(const uint8_t type, const f_string_static_t program, const f_string_statics_t arguments, const uint8_t options, controller_execute_set_t * const execute_set, controller_instance_t * const instance) { +#ifndef _di_controller_rule_execute_foreground_ + f_status_t controller_rule_execute_foreground(const uint8_t type, const f_string_static_t program, const f_string_statics_t arguments, const uint8_t options, controller_execute_set_t * const execute_set, controller_instance_t * const instance) { if (!instance) return F_status_set_error(F_parameter); f_status_t status = F_okay; f_status_t status_lock = F_okay; - controller_main_t * const main = ((controller_global_t *) instance->global)->main; - controller_thread_t * const thread = ((controller_global_t *) instance->global)->thread; + controller_t * const main = instance->global->main; + controller_thread_t * const thread = instance->global->thread; f_execute_result_t result = f_execute_result_t_initialize; - status = controller_pids_increase(&instance->childs); + status = f_memory_array_increase(controller_allocation_small_d, sizeof(pid_t), (void **) &instance->childs.array, &instance->childs.used, &instance->childs.size); if (F_status_is_error(status)) { - controller_main_print_error_status(&main->program.error, macro_controller_f(controller_pids_increase), F_status_set_fine(status)); + controller_print_error_status(&main->program.error, macro_controller_f(f_memory_array_increase), F_status_set_fine(status)); return status; } @@ -524,17 +524,22 @@ extern "C" { // Sleep for less than a second to better show simulation of synchronous vs asynchronous. { - const f_time_spec_t delay = controller_main_time_milliseconds(controller_thread_simulation_timeout_d); + f_time_spec_t delay = f_time_spec_t_initialize; - if (controller_main_time_sleep_nanoseconds((controller_global_t *) instance->global, delay) == -1) { - status = F_status_set_error(F_interrupt); + status = f_time_spec_millisecond(0, controller_thread_simulation_timeout_d, &delay); + + if (F_status_is_error(status)) { + controller_print_error_status(&main->program.error, macro_controller_f(f_time_spec_millisecond), F_status_set_fine(status)); + } + else { + status = controller_time_sleep_nanoseconds(instance->global, delay); } } if (F_status_set_fine(status) != F_interrupt) { fl_execute_parameter_t simulated_parameter = macro_fl_execute_parameter_t_initialize_1(execute_set->parameter.option, execute_set->parameter.wait, instance->rule.has & controller_rule_has_environment_d ? execute_set->parameter.environment : 0, execute_set->parameter.signals, &f_string_empty_s); - status = fll_execute_program(*main->setting.default_engine, instance->rule.engine_arguments, &simulated_parameter, &execute_set->as, (void *) &result); + status = fll_execute_program(controller_default_engine_s, instance->rule.engine_arguments, &simulated_parameter, &execute_set->as, (void *) &result); } } else { @@ -547,13 +552,13 @@ extern "C" { f_thread_unlock(&instance->lock); - status_lock = controller_main_lock_write_instance(instance, thread, &instance->lock); + status_lock = controller_lock_write_instance(instance, &instance->active); if (F_status_is_error(status_lock)) { controller_lock_print_error_critical(&main->program.error, F_status_set_fine(status_lock), F_false, thread); if (F_status_set_fine(status_lock) != F_interrupt) { - status = controller_main_lock_read_instance(instance, thread, &instance->lock); + status = controller_lock_read_instance(instance, &instance->active); if (status == F_okay) { return status_lock; @@ -568,7 +573,7 @@ extern "C" { f_thread_unlock(&instance->lock); - status_lock = controller_main_lock_read_instance(instance, thread, &instance->lock); + status_lock = controller_lock_read_instance(instance, &instance->active); if (F_status_is_error(status_lock)) { controller_lock_print_error_critical(&main->program.error, F_status_set_fine(status_lock), F_true, thread); @@ -580,7 +585,7 @@ extern "C" { waitpid(id_child, &result.status, 0); } - if (F_status_set_fine(status_lock) == F_interrupt || !controller_main_thread_is_enabled_instance(instance, thread)) { + if (F_status_set_fine(status_lock) == F_interrupt || !controller_thread_is_enabled_instance(instance)) { return status_lock == F_okay ? F_status_set_error(F_interrupt) : F_status_set_error(F_lock); } @@ -588,13 +593,13 @@ extern "C" { f_thread_unlock(&instance->lock); } - status_lock = controller_main_lock_write_instance(instance, thread, &instance->lock); + status_lock = controller_lock_write_instance(instance, &instance->active); if (F_status_is_error(status_lock)) { controller_lock_print_error_critical(&main->program.error, F_status_set_fine(status_lock), F_false, thread); if (F_status_set_fine(status_lock) != F_interrupt) { - status = controller_main_lock_read_instance(instance, thread, &instance->lock); + status = controller_lock_read_instance(instance, &instance->active); if (status == F_okay) { return status_lock; @@ -611,7 +616,7 @@ extern "C" { f_thread_unlock(&instance->lock); - status_lock = controller_main_lock_read_instance(instance, thread, &instance->lock); + status_lock = controller_lock_read_instance(instance, &instance->active); if (F_status_is_error(status_lock)) { controller_lock_print_error_critical(&main->program.error, F_status_set_fine(status_lock), F_true, thread); @@ -629,7 +634,7 @@ extern "C" { else { main->program.child = result.status; - if (!controller_main_thread_is_enabled_instance(instance, thread)) { + if (!controller_thread_is_enabled_instance(instance)) { return F_status_set_error(F_interrupt); } } @@ -653,10 +658,10 @@ extern "C" { status = F_status_set_fine(status); if ((WIFEXITED(instance->result) && WEXITSTATUS(instance->result)) || status == F_control_group || status == F_failure || status == F_limit || status == F_processor || status == F_schedule) { - controller_main_print_rule_item_error_execute(&global->error, instance, type == controller_rule_item_type_script_e, program.used ? program : arguments.array[0], status); + controller_print_rule_item_error_execute(instance->global->error, instance, type == controller_rule_item_type_script_e, program.used ? program : arguments.array[0], status); } else { - controller_main_print_error_status(&global->error, macro_controller_f(fll_execute_program), F_status_set_fine(status)); + controller_print_error_status(instance->global->error, macro_controller_f(fll_execute_program), F_status_set_fine(status)); } status = F_status_set_error(status); @@ -664,25 +669,24 @@ extern "C" { return status; } -#endif // _di_controller_main_rule_execute_foreground_ +#endif // _di_controller_rule_execute_foreground_ -#ifndef _di_controller_main_rule_execute_pid_with_ - f_status_t controller_main_rule_execute_pid_with(const f_string_dynamic_t pid_file, const uint8_t type, const f_string_static_t program, const f_string_statics_t arguments, const uint8_t options, const uint8_t with, controller_execute_set_t * const execute_set, controller_instance_t * const instance) { +#ifndef _di_controller_rule_execute_pid_with_ + f_status_t controller_rule_execute_pid_with(const f_string_dynamic_t pid_file, const uint8_t type, const f_string_static_t program, const f_string_statics_t arguments, const uint8_t options, const uint8_t with, controller_execute_set_t * const execute_set, controller_instance_t * const instance) { - if (!execute_set || !instance) return F_status_set_error(F_parameter); + if (!execute_set || !instance || !instance->global || !instance->global->main || !instance->global->thread) return F_status_set_error(F_parameter); f_status_t status = F_okay; f_status_t status_lock = F_okay; - controller_main_t * const main = ((controller_global_t *) instance->global)->main; - controller_thread_t * const thread = ((controller_global_t *) instance->global)->thread; + controller_t * const main = instance->global->main; f_execute_result_t result = f_execute_result_t_initialize; - status = controller_pids_increase(&instance->childs); + status = f_memory_array_increase(controller_allocation_small_d, sizeof(pid_t), (void **) &instance->childs.array, &instance->childs.used, &instance->childs.size); if (F_status_is_error(status)) { - controller_main_print_error_status(&main->program.error, macro_controller_f(controller_pids_increase), F_status_set_fine(status)); + controller_print_error_status(&main->program.error, macro_controller_f(f_memory_array_increase), F_status_set_fine(status)); return status; } @@ -690,7 +694,7 @@ extern "C" { status = f_memory_array_increase(controller_allocation_small_d, sizeof(f_string_dynamic_t), (void **) &instance->path_pids.array, &instance->path_pids.used, &instance->path_pids.size); if (F_status_is_error(status)) { - controller_main_print_error_status(&main->program.error, macro_controller_f(f_memory_array_increase), F_status_set_fine(status)); + controller_print_error_status(&main->program.error, macro_controller_f(f_memory_array_increase), F_status_set_fine(status)); return status; } @@ -727,7 +731,7 @@ extern "C" { status = f_file_exists(pid_file, F_true); if (F_status_is_error(status) || status == F_true) { - controller_main_print_error_file_status(&main->program.error, macro_controller_f(f_file_exists), status == F_true ? F_file_found : F_status_set_fine(status), pid_file, f_file_operation_find_s, fll_error_file_type_file_e); + controller_print_error_file_status(&main->program.error, macro_controller_f(f_file_exists), pid_file, f_file_operation_find_s, fll_error_file_type_file_e, status == F_true ? F_file_found : F_status_set_fine(status)); return status; } @@ -735,14 +739,14 @@ extern "C" { status = f_string_dynamic_append_nulless(pid_file, child_pid_file); if (F_status_is_error(status)) { - controller_main_print_error_status(&main->program.error, macro_controller_f(f_string_dynamic_append_nulless), F_status_set_fine(status)); + controller_print_error_status(&main->program.error, macro_controller_f(f_string_dynamic_append_nulless), F_status_set_fine(status)); return status; } if (options & controller_instance_option_simulate_e) { if (main->program.error.verbosity > f_console_verbosity_error_e) { - controller_lock_print(main->program.error.to, thread); + controller_lock_print(main->program.error.to, instance->global->thread); fl_print_format("%rSimulating execution of '%[", main->program.error.to, f_string_eol_s, main->program.context.set.title); @@ -767,15 +771,20 @@ extern "C" { fl_print_format("%]' from '", main->program.error.to, main->program.context.set.important); fl_print_format("%[%Q%]'.%r", main->program.error.to, main->program.context.set.notable, instance->rule.name, main->program.context.set.notable, f_string_eol_s); - controller_unlock_print_flush(main->program.error.to, thread); + controller_unlock_print_flush(main->program.error.to, instance->global->thread); } // Sleep for less than a second to better show simulation of synchronous vs asynchronous. { - const f_time_spec_t delay = controller_main_time_milliseconds(controller_thread_simulation_timeout_d); + f_time_spec_t delay = f_time_spec_t_initialize; - if (controller_main_time_sleep_nanoseconds((controller_global_t *) instance->global, delay) == -1) { - status = F_status_set_error(F_interrupt); + status = f_time_spec_millisecond(0, controller_thread_simulation_timeout_d, &delay); + + if (F_status_is_error(status)) { + controller_print_error_status(&main->program.error, macro_controller_f(f_time_spec_millisecond), F_status_set_fine(status)); + } + else { + status = controller_time_sleep_nanoseconds(instance->global, delay); } } @@ -783,7 +792,7 @@ extern "C" { const f_string_statics_t simulated_arguments = f_string_statics_t_initialize; fl_execute_parameter_t simulated_parameter = macro_fl_execute_parameter_t_initialize_1(execute_set->parameter.option, execute_set->parameter.wait, instance->rule.has & controller_rule_has_environment_d ? execute_set->parameter.environment : 0, execute_set->parameter.signals, &f_string_empty_s); - status = fll_execute_program(*main->setting.default_engine, simulated_arguments, &simulated_parameter, &execute_set->as, (void *) &result); + status = fll_execute_program(controller_default_engine_s, simulated_arguments, &simulated_parameter, &execute_set->as, (void *) &result); } } else { @@ -796,13 +805,13 @@ extern "C" { f_thread_unlock(&instance->lock); - status_lock = controller_main_lock_write_instance(instance, thread, &instance->lock); + status_lock = controller_lock_write_instance(instance, &instance->active); if (F_status_is_error(status_lock)) { - controller_lock_print_error_critical(&main->program.error, F_status_set_fine(status_lock), F_false, thread); + controller_lock_print_error_critical(&main->program.error, F_status_set_fine(status_lock), F_false, instance->global->thread); if (F_status_set_fine(status_lock) != F_interrupt) { - status = controller_main_lock_read_instance(instance, thread, &instance->lock); + status = controller_lock_read_instance(instance, &instance->active); if (status == F_okay) { return status_lock; @@ -817,10 +826,10 @@ extern "C" { f_thread_unlock(&instance->lock); - status_lock = controller_main_lock_read_instance(instance, thread, &instance->lock); + status_lock = controller_lock_read_instance(instance, &instance->active); if (F_status_is_error(status_lock)) { - controller_lock_print_error_critical(&main->program.error, F_status_set_fine(status_lock), F_true, thread); + controller_lock_print_error_critical(&main->program.error, F_status_set_fine(status_lock), F_true, instance->global->thread); } if (F_status_set_fine(status_lock) != F_interrupt) { @@ -829,7 +838,7 @@ extern "C" { waitpid(id_child, &result.status, 0); } - if (!controller_main_thread_is_enabled_instance(instance, thread)) { + if (!controller_thread_is_enabled_instance(instance)) { if (status_lock == F_okay) { return F_status_set_error(F_interrupt); } @@ -841,13 +850,13 @@ extern "C" { f_thread_unlock(&instance->lock); } - status_lock = controller_main_lock_write_instance(instance, thread, &instance->lock); + status_lock = controller_lock_write_instance(instance, &instance->active); if (F_status_is_error(status_lock)) { - controller_lock_print_error_critical(&main->program.error, F_status_set_fine(status_lock), F_false, thread); + controller_lock_print_error_critical(&main->program.error, F_status_set_fine(status_lock), F_false, instance->global->thread); if (F_status_set_fine(status_lock) != F_interrupt) { - status = controller_main_lock_read_instance(instance, thread, &instance->lock); + status = controller_lock_read_instance(instance, &instance->active); if (status == F_okay) { return status_lock; @@ -864,10 +873,10 @@ extern "C" { f_thread_unlock(&instance->lock); - status_lock = controller_main_lock_read_instance(instance, thread, &instance->lock); + status_lock = controller_lock_read_instance(instance, &instance->active); if (F_status_is_error(status_lock)) { - controller_lock_print_error_critical(&main->program.error, F_status_set_fine(status_lock), F_true, thread); + controller_lock_print_error_critical(&main->program.error, F_status_set_fine(status_lock), F_true, instance->global->thread); return F_status_set_error(F_lock); } @@ -882,7 +891,7 @@ extern "C" { else { main->program.child = result.status; - if (!controller_main_thread_is_enabled_instance(instance, thread)) { + if (!controller_thread_is_enabled_instance(instance)) { return F_status_set_error(F_interrupt); } } @@ -906,10 +915,10 @@ extern "C" { status = F_status_set_fine(status); if ((WIFEXITED(instance->result) && WEXITSTATUS(instance->result)) || status == F_control_group || status == F_failure || status == F_limit || status == F_processor || status == F_schedule) { - controller_main_print_rule_item_error_execute(&global->error, instance, type == controller_rule_item_type_utility_e, program.used ? program : arguments.array[0], status); + controller_print_rule_item_error_execute(instance->global->error, instance, type == controller_rule_item_type_utility_e, program.used ? program : arguments.array[0], status); } else { - controller_main_print_error_status(&global->error, macro_controller_f(fll_execute_program), F_status_set_fine(status)); + controller_print_error_status(instance->global->error, macro_controller_f(fll_execute_program), F_status_set_fine(status)); } return F_status_set_error(status); @@ -917,29 +926,28 @@ extern "C" { return status; } -#endif // _di_controller_main_rule_execute_pid_with_ +#endif // _di_controller_rule_execute_pid_with_ -#ifndef _di_controller_main_rule_execute_rerun_ - int8_t controller_main_rule_execute_rerun(const uint8_t action, controller_instance_t * const instance, controller_rule_item_t * const item) { +#ifndef _di_controller_rule_execute_rerun_ + int8_t controller_rule_execute_rerun(const uint8_t action, controller_instance_t * const instance, controller_rule_item_t * const item) { - if (!instance || !item) return F_status_set_error(F_parameter); + if (!instance || !instance->global || !instance->global->main || !instance->global->thread || !item) return F_false; const int result = WIFEXITED(instance->result) ? WEXITSTATUS(instance->result) : 0; if (item->reruns[action].is & (result ? controller_rule_rerun_is_failure_d : controller_rule_rerun_is_success_d)) { - controller_main_t * const main = ((controller_global_t *) instance->global)->main; - controller_thread_t * const thread = ((controller_global_t *) instance->global)->thread; - controller_rule_rerun_item_t *rerun_item = result ? &item->reruns[action].failure : &item->reruns[action].success; + controller_t * const main = instance->global->main; + controller_rule_rerun_item_t * const rerun_item = result ? &item->reruns[action].failure : &item->reruns[action].success; - if (!controller_main_thread_is_enabled_instance(instance, thread)) return -2; + if (!controller_thread_is_enabled_instance(instance)) return -2; if (!rerun_item->max || rerun_item->count < rerun_item->max) { if (main->program.error.verbosity == f_console_verbosity_debug_e) { - controller_lock_print(main->program.output.to, thread); + controller_lock_print(main->program.output.to, instance->global->thread); fl_print_format("%rRe-running '", main->program.output.to, f_string_eol_s); fl_print_format("%[%r%]' '", main->program.output.to, main->program.context.set.title, instance->rule.alias, main->program.context.set.title); - fl_print_format("%[%r%]' with a ", main->program.output.to, main->program.context.set.notable, controller_main_rule_action_execute_type_name(action), main->program.context.set.notable); + fl_print_format("%[%r%]' with a ", main->program.output.to, main->program.context.set.notable, controller_convert_rule_action_execute_type_string(action), main->program.context.set.notable); fl_print_format("%[%r%] of ", main->program.output.to, main->program.context.set.notable, controller_delay_s, main->program.context.set.notable); fl_print_format("%[%ul%] MegaTime", main->program.output.to, main->program.context.set.notable, rerun_item->delay, main->program.context.set.notable); @@ -953,17 +961,28 @@ extern "C" { fl_print_format(" with no %[%r%].%r", main->program.output.to, main->program.context.set.notable, controller_max_s, main->program.context.set.notable, f_string_eol_s); } - controller_unlock_print_flush(main->program.output.to, thread); + controller_unlock_print_flush(main->program.output.to, instance->global->thread); } if (rerun_item->delay) { - const f_time_spec_t delay = controller_main_time_milliseconds(rerun_item->delay); + f_time_spec_t delay = f_time_spec_t_initialize; + + { + const f_status_t status = f_time_spec_millisecond(0, rerun_item->delay, &delay); + + if (F_status_is_error(status)) { + controller_print_error_status(&main->program.error, macro_controller_f(f_time_spec_millisecond), F_status_set_fine(status)); + + return -1; + } + } - if (controller_main_time_sleep_nanoseconds(main, (controller_process_t *) instance->main_setting, delay) == -1) { - return -1; + { + const f_status_t status = controller_time_sleep_nanoseconds(instance->global, delay); + if (F_status_is_error(status) || status == F_interrupt) return -1; } - if (!controller_main_thread_is_enabled_instance(instance, thread)) return -2; + if (!controller_thread_is_enabled_instance(instance)) return -2; } if (item->reruns[action].is & (result ? controller_rule_rerun_is_failure_reset_d : controller_rule_rerun_is_success_reset_d)) { @@ -985,7 +1004,7 @@ extern "C" { return F_false; } -#endif // _di_controller_main_rule_execute_rerun_ +#endif // _di_controller_rule_execute_rerun_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/rule/execute.h b/sources/c/main/rule/execute.h index 50ad46a..e4f7d74 100644 --- a/sources/c/main/rule/execute.h +++ b/sources/c/main/rule/execute.h @@ -31,13 +31,13 @@ extern "C" { * The action to perform based on the action type codes. * * Only subset of the action type codes are supported: - * - controller_main_rule_action_type_kill_e - * - controller_main_rule_action_type_pause_e - * - controller_main_rule_action_type_reload_e - * - controller_main_rule_action_type_restart_e - * - controller_main_rule_action_type_resume_e - * - controller_main_rule_action_type_start_e - * - controller_main_rule_action_type_stop_e + * - controller_rule_action_type_kill_e + * - controller_rule_action_type_pause_e + * - controller_rule_action_type_reload_e + * - controller_rule_action_type_restart_e + * - controller_rule_action_type_resume_e + * - controller_rule_action_type_start_e + * - controller_rule_action_type_stop_e * @param options * Process options to consider when executing. * If bit controller_instance_option_simulate_e, then the rule execution is in simulation mode (printing a message that the rule would be executed but does not execute the rule). @@ -57,9 +57,9 @@ extern "C" { * On success and the rule is run asynchronously, then the individual status for the rule is set to F_busy. * On failure, the individual status for the rule is set to an appropriate error status. */ -#ifndef _di_controller_main_rule_execute_ - extern f_status_t controller_main_rule_execute(controller_global_t * const global, const uint8_t action, const uint8_t options, controller_instance_t * const instance); -#endif // _di_controller_main_rule_execute_ +#ifndef _di_controller_rule_execute_ + extern f_status_t controller_rule_execute(controller_global_t * const global, const uint8_t action, const uint8_t options, controller_instance_t * const instance); +#endif // _di_controller_rule_execute_ /** * Perform an execution of the given rule in the foreground. @@ -91,9 +91,9 @@ extern "C" { * * @see fll_execute_program() */ -#ifndef _di_controller_main_rule_execute_foreground_ - extern f_status_t controller_main_rule_execute_foreground(const uint8_t type, const f_string_static_t program, const f_string_statics_t arguments, const uint8_t options, controller_execute_set_t * const execute_set, controller_instance_t * const instance); -#endif // _di_controller_main_rule_execute_foreground_ +#ifndef _di_controller_rule_execute_foreground_ + extern f_status_t controller_rule_execute_foreground(const uint8_t type, const f_string_static_t program, const f_string_statics_t arguments, const uint8_t options, controller_execute_set_t * const execute_set, controller_instance_t * const instance); +#endif // _di_controller_rule_execute_foreground_ /** * Perform an execution of the given rule in the foreground or background and creating a PID file. @@ -133,9 +133,9 @@ extern "C" { * * @see fll_execute_program() */ -#ifndef _di_controller_main_rule_execute_pid_with_ - extern f_status_t controller_main_rule_execute_pid_with(const f_string_dynamic_t pid_file, const uint8_t type, const f_string_static_t program, const f_string_statics_t arguments, const uint8_t options, const uint8_t with, controller_execute_set_t * const execute_set, controller_instance_t * const instance); -#endif // _di_controller_main_rule_execute_pid_with_ +#ifndef _di_controller_rule_execute_pid_with_ + extern f_status_t controller_rule_execute_pid_with(const f_string_dynamic_t pid_file, const uint8_t type, const f_string_static_t program, const f_string_statics_t arguments, const uint8_t options, const uint8_t with, controller_execute_set_t * const execute_set, controller_instance_t * const instance); +#endif // _di_controller_rule_execute_pid_with_ /** * Determine whether or not an execute rule should be re-run, applying a delay as requested. @@ -156,9 +156,9 @@ extern "C" { * - EINVAL: Consider this having returned F_status_set_error(F_parameter); * -2 to designate exit due to signal/disabled thread. */ -#ifndef _di_controller_main_rule_execute_rerun_ - extern int8_t controller_main_rule_execute_rerun(const uint8_t action, controller_instance_t * const instance, controller_rule_item_t * const item); -#endif // _di_controller_main_rule_execute_rerun_ +#ifndef _di_controller_rule_execute_rerun_ + extern int8_t controller_rule_execute_rerun(const uint8_t action, controller_instance_t * const instance, controller_rule_item_t * const item); +#endif // _di_controller_rule_execute_rerun_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/rule/expand.c b/sources/c/main/rule/expand.c index f5cc222..71d7c70 100644 --- a/sources/c/main/rule/expand.c +++ b/sources/c/main/rule/expand.c @@ -4,16 +4,16 @@ extern "C" { #endif -#ifndef _di_controller_main_rule_expand_ - f_status_t controller_main_rule_expand(controller_global_t * const global, const controller_main_rule_action_t action, controller_instance_t * const instance) { +#ifndef _di_controller_rule_expand_ + f_status_t controller_rule_expand(controller_global_t * const global, const controller_rule_action_t action, controller_instance_t * const instance) { if (!global || !instance) return F_status_set_error(F_parameter); - process->cache.expanded.used = 0; + instance->cache.expanded.used = 0; if (!action.parameters.used) return F_okay; - f_status_t status = f_memory_array_increase_by(action.parameters.used, sizeof(f_string_dynamic_t), (void **) &process->cache.expanded.array, &process->cache.expanded.used, &process->cache.expanded.size); + f_status_t status = f_memory_array_increase_by(action.parameters.used, sizeof(f_string_dynamic_t), (void **) &instance->cache.expanded.array, &instance->cache.expanded.used, &instance->cache.expanded.size); if (F_status_is_error(status)) return status; f_number_unsigned_t i = 0; @@ -23,20 +23,20 @@ extern "C" { f_iki_data_t *iki_data = 0; f_string_dynamic_t *buffer = 0; - for (; process->cache.expanded.used < action.parameters.used; ++process->cache.expanded.used) { + for (; instance->cache.expanded.used < action.parameters.used; ++instance->cache.expanded.used) { - buffer = &process->cache.expanded.array[process->cache.expanded.used]; + buffer = &instance->cache.expanded.array[instance->cache.expanded.used]; buffer->used = 0; - if (action.ikis.array[process->cache.expanded.used].variable.used) { - iki_data = &action.ikis.array[process->cache.expanded.used]; + if (action.ikis.array[instance->cache.expanded.used].variable.used) { + iki_data = &action.ikis.array[instance->cache.expanded.used]; // Allocate enough room plus an extra buffer to help reduce reallocations. - status = f_memory_array_increase_by(action.parameters.array[process->cache.expanded.used].used + controller_allocation_large_d, sizeof(f_char_t), (void **) &buffer->string, &buffer->used, &buffer->size); + status = f_memory_array_increase_by(action.parameters.array[instance->cache.expanded.used].used + controller_allocation_large_d, sizeof(f_char_t), (void **) &buffer->string, &buffer->used, &buffer->size); // Apply the IKI delimits. for (i = 0; i < iki_data->delimits.used; ++i) { - action.parameters.array[process->cache.expanded.used].string[iki_data->delimits.array[i]] = f_iki_syntax_placeholder_s.string[0]; + action.parameters.array[instance->cache.expanded.used].string[iki_data->delimits.array[i]] = f_iki_syntax_placeholder_s.string[0]; } // for if (iki_data->variable.used) { @@ -47,11 +47,11 @@ extern "C" { range.start = first; range.stop = iki_data->variable.array[i].start - 1; - status = f_string_dynamic_partial_append_nulless(action.parameters.array[process->cache.expanded.used], range, buffer); + status = f_string_dynamic_partial_append_nulless(action.parameters.array[instance->cache.expanded.used], range, buffer); if (F_status_is_error(status)) break; } - status = controller_main_rule_expand_iki(process, action.parameters.array[process->cache.expanded.used], iki_data->vocabulary.array[i], iki_data->content.array[i], buffer); + status = controller_rule_expand_iki(instance, action.parameters.array[instance->cache.expanded.used], iki_data->vocabulary.array[i], iki_data->content.array[i], buffer); if (F_status_is_error(status)) break; first = iki_data->variable.array[i].stop + 1; @@ -60,24 +60,24 @@ extern "C" { if (F_status_is_error(status)) break; // Copy everything after the last IKI variable to the end of the content. - if (first < action.parameters.array[process->cache.expanded.used].used) { + if (first < action.parameters.array[instance->cache.expanded.used].used) { range.start = first; - range.stop = action.parameters.array[process->cache.expanded.used].used - 1; + range.stop = action.parameters.array[instance->cache.expanded.used].used - 1; - status = f_string_dynamic_partial_append(action.parameters.array[process->cache.expanded.used], range, buffer); + status = f_string_dynamic_partial_append(action.parameters.array[instance->cache.expanded.used], range, buffer); } } else { - status = f_string_dynamic_append_nulless(action.parameters.array[process->cache.expanded.used], buffer); + status = f_string_dynamic_append_nulless(action.parameters.array[instance->cache.expanded.used], buffer); } // Unapply the IKI delimits. for (i = 0; i < iki_data->delimits.used; ++i) { - action.parameters.array[process->cache.expanded.used].string[iki_data->delimits.array[i]] = f_iki_syntax_slash_s.string[0]; + action.parameters.array[instance->cache.expanded.used].string[iki_data->delimits.array[i]] = f_iki_syntax_slash_s.string[0]; } // for } else { - status = f_string_dynamic_append(action.parameters.array[process->cache.expanded.used], buffer); + status = f_string_dynamic_append(action.parameters.array[instance->cache.expanded.used], buffer); } if (F_status_is_error(status)) return status; @@ -85,12 +85,12 @@ extern "C" { return F_okay; } -#endif // _di_controller_main_rule_expand_ +#endif // _di_controller_rule_expand_ -#ifndef _di_controller_main_rule_expand_iki_ - f_status_t controller_main_rule_expand_iki(controller_instance_t * const instance, const f_string_static_t source, const f_range_t vocabulary, const f_range_t content, f_string_dynamic_t * const destination) { +#ifndef _di_controller_rule_expand_iki_ + f_status_t controller_rule_expand_iki(controller_instance_t * const instance, const f_string_static_t source, const f_range_t vocabulary, const f_range_t content, f_string_dynamic_t * const destination) { - if (!instance || !destination) return F_status_set_error(F_parameter); + if (!instance || !instance->global || !instance->global->program || !destination) return F_status_set_error(F_parameter); if (vocabulary.start > vocabulary.stop) return F_okay; if (content.start > content.stop) return F_okay; @@ -100,18 +100,18 @@ extern "C" { f_number_unsigned_t i = 0; // First check to see if the environment variable is overwritten by a "define". - for (; i < process->rule.define.used; ++i) { + for (; i < instance->rule.define.used; ++i) { - if (f_compare_dynamic_partial_string(process->rule.define.array[i].key.string, source, process->rule.define.array[i].key.used, content) == F_equal_to) { - status = f_string_dynamic_append(process->rule.define.array[i].value, destination); + if (f_compare_dynamic_partial_string(instance->rule.define.array[i].key.string, source, instance->rule.define.array[i].key.used, content) == F_equal_to) { + status = f_string_dynamic_append(instance->rule.define.array[i].value, destination); if (F_status_is_error(status)) return status; break; } } // for - if (i == process->rule.define.used) { - controller_entry_t * const entry = process->type == controller_instance_type_entry_e ? &((controller_process_t *) process->main_setting)->entry : &((controller_process_t *) process->main_setting)->exit; + if (i == instance->rule.define.used) { + controller_entry_t * const entry = instance->type == controller_instance_type_entry_e ? &instance->global->program->entry : &instance->global->program->exit; for (i = 0; i < entry->define.used; ++i) { @@ -124,11 +124,11 @@ extern "C" { } // for if (i == entry->define.used) { - i = process->rule.define.used; + i = instance->rule.define.used; } } - if (i == process->rule.define.used) { + if (i == instance->rule.define.used) { f_string_static_t buffer = f_string_static_t_initialize; buffer.used = (content.stop - content.start) + 1; @@ -137,30 +137,30 @@ extern "C" { memcpy(buffer_string, source.string + content.start, sizeof(f_char_t) * buffer.used); buffer_string[buffer.used] = 0; buffer.string = buffer_string; - process->cache.action.generic.used = 0; + instance->cache.action.generic.used = 0; - status = f_environment_get(buffer, &process->cache.action.generic); + status = f_environment_get(buffer, &instance->cache.action.generic); if (F_status_is_error(status)) return status; - status = f_string_dynamic_append(process->cache.action.generic, destination); + status = f_string_dynamic_append(instance->cache.action.generic, destination); if (F_status_is_error(status)) return status; } } else if (f_compare_dynamic_partial_string(controller_parameter_s.string, source, controller_parameter_s.used, vocabulary) == F_equal_to) { f_number_unsigned_t i = 0; - for (; i < process->rule.parameter.used; ++i) { + for (; i < instance->rule.parameter.used; ++i) { - if (f_compare_dynamic_partial_string(process->rule.parameter.array[i].key.string, source, process->rule.parameter.array[i].key.used, content) == F_equal_to) { - status = f_string_dynamic_append(process->rule.parameter.array[i].value, destination); + if (f_compare_dynamic_partial_string(instance->rule.parameter.array[i].key.string, source, instance->rule.parameter.array[i].key.used, content) == F_equal_to) { + status = f_string_dynamic_append(instance->rule.parameter.array[i].value, destination); if (F_status_is_error(status)) return status; break; } } // for - if (i == process->rule.parameter.used) { - controller_entry_t * const entry = process->type == controller_instance_type_entry_e ? &((controller_process_t *) process->main_setting)->entry : &((controller_process_t *) process->main_setting)->exit; + if (i == instance->rule.parameter.used) { + controller_entry_t * const entry = instance->type == controller_instance_type_entry_e ? &instance->global->program->entry : &instance->global->program->exit; for (i = 0; i < entry->parameter.used; ++i) { @@ -174,8 +174,8 @@ extern "C" { } } else if (f_compare_dynamic_partial_string(controller_program_s.string, source, controller_program_s.used, vocabulary) == F_equal_to) { - f_string_static_t * const argv = ((controller_main_t *) process->main_data)->program.parameters.arguments.array; - f_console_parameters_t * const parameters = &((controller_main_t *) process->main_data)->program.parameters; + f_string_static_t * const argv = instance->global->main.program.parameters.arguments.array; + f_console_parameters_t * const parameters = &instance->global->main.program.parameters; const f_string_static_t options[] = { f_console_standard_long_light_s, @@ -374,7 +374,7 @@ extern "C" { return F_okay; } -#endif // _di_controller_main_rule_expand_iki_ +#endif // _di_controller_rule_expand_iki_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/rule/expand.h b/sources/c/main/rule/expand.h index b4f5d48..a1db2cd 100644 --- a/sources/c/main/rule/expand.h +++ b/sources/c/main/rule/expand.h @@ -33,13 +33,13 @@ extern "C" { * @return * F_okay on success. * - * Errors (with error bit) from: controller_main_rule_expand_iki(). + * Errors (with error bit) from: controller_rule_expand_iki(). * - * @see controller_main_rule_expand_iki() + * @see controller_rule_expand_iki() */ -#ifndef _di_controller_main_rule_expand_ - extern f_status_t controller_main_rule_expand(controller_global_t * const global, const controller_main_rule_action_t action, controller_instance_t * const instance); -#endif // _di_controller_main_rule_expand_ +#ifndef _di_controller_rule_expand_ + extern f_status_t controller_rule_expand(controller_global_t * const global, const controller_rule_action_t action, controller_instance_t * const instance); +#endif // _di_controller_rule_expand_ /** * Expand a single IKI variable into the buffer. @@ -64,9 +64,9 @@ extern "C" { * @see f_environment_get() * @see f_string_dynamic_append() */ -#ifndef _di_controller_main_rule_expand_iki_ - extern f_status_t controller_main_rule_expand_iki(controller_instance_t * const instance, const f_string_static_t source, const f_range_t vocabulary, const f_range_t content, f_string_dynamic_t * const destination); -#endif // _di_controller_main_rule_expand_iki_ +#ifndef _di_controller_rule_expand_iki_ + extern f_status_t controller_rule_expand_iki(controller_instance_t * const instance, const f_string_static_t source, const f_range_t vocabulary, const f_range_t content, f_string_dynamic_t * const destination); +#endif // _di_controller_rule_expand_iki_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/rule/instance.c b/sources/c/main/rule/instance.c index bf54e7f..8129c73 100644 --- a/sources/c/main/rule/instance.c +++ b/sources/c/main/rule/instance.c @@ -4,21 +4,23 @@ extern "C" { #endif -#ifndef _di_controller_main_rule_instance_ - f_status_t controller_main_rule_instance(controller_global_t * const global, controller_instance_t * const instance) { +#ifndef _di_controller_rule_instance_ + f_status_t controller_rule_instance(controller_instance_t * const instance) { - if (!global || !instance) return F_status_set_error(F_parameter); + if (!instance || !instance->global) return F_status_set_error(F_parameter); + + controller_global_t * const global = instance->global; switch (instance->action) { - case controller_main_rule_action_type_freeze_e: - case controller_main_rule_action_type_kill_e: - case controller_main_rule_action_type_pause_e: - case controller_main_rule_action_type_reload_e: - case controller_main_rule_action_type_restart_e: - case controller_main_rule_action_type_resume_e: - case controller_main_rule_action_type_start_e: - case controller_main_rule_action_type_stop_e: - case controller_main_rule_action_type_thaw_e: + case controller_rule_action_type_freeze_e: + case controller_rule_action_type_kill_e: + case controller_rule_action_type_pause_e: + case controller_rule_action_type_reload_e: + case controller_rule_action_type_restart_e: + case controller_rule_action_type_resume_e: + case controller_rule_action_type_start_e: + case controller_rule_action_type_stop_e: + case controller_rule_action_type_thaw_e: break; default: @@ -26,10 +28,10 @@ extern "C" { controller_lock_print(global->main->program.error.to, global->thread); fl_print_format("%r%[%QUnsupported action type '%]", global->main->program.error.to, f_string_eol_s, global->main->program.error.context, global->main->program.error.prefix, global->main->program.error.context); - fl_print_format(f_string_format_r_single_s.string, global->main->program.error.to, global->main->program.error.notable, controller_main_rule_action_type_name(instance->action), global->main->program.error.notable); + fl_print_format(f_string_format_r_single_s.string, global->main->program.error.to, global->main->program.error.notable, controller_convert_rule_action_type_string(instance->action), global->main->program.error.notable); fl_print_format("%[' while attempting to execute rule.%]%r", global->main->program.error.to, global->main->program.error.context, global->main->program.error.context, f_string_eol_s); - controller_main_print_rule_error_cache(&global->error, instance->cache.action, F_true); + controller_print_rule_error_cache(global->error, instance->cache.action, F_true); controller_unlock_print_flush(global->main->program.error.to, global->thread); } @@ -51,7 +53,7 @@ extern "C" { } if (F_status_is_error(status)) { - controller_main_print_rule_error(&global->error, instance->cache.action, F_status_set_fine(status), "f_string_dynamic_append", F_true, F_true); + controller_print_rule_error(global->error, instance->cache.action, F_status_set_fine(status), "f_string_dynamic_append", F_true, F_true); return status; } @@ -59,7 +61,7 @@ extern "C" { status = f_string_dynamic_append(instance->rule.alias, &instance->cache.action.name_file); if (F_status_is_error(status)) { - controller_main_print_rule_error(&global->error, instance->cache.action, F_status_set_fine(status), "f_string_dynamic_append", F_true, F_true); + controller_print_rule_error(global->error, instance->cache.action, F_status_set_fine(status), "f_string_dynamic_append", F_true, F_true); return status; } @@ -71,13 +73,13 @@ extern "C" { } if (F_status_is_error(status)) { - controller_main_print_rule_error(&global->error, instance->cache.action, F_status_set_fine(status), "f_string_dynamic_append", F_true, F_true); + controller_print_rule_error(global->error, instance->cache.action, F_status_set_fine(status), "f_string_dynamic_append", F_true, F_true); return status; } if ((instance->options & controller_instance_option_simulate_e) && (instance->options & controller_instance_option_validate_e)) { - controller_main_rule_validate(global, instance->rule, instance->action, instance->options, &instance->cache); + controller_rule_validate(global, instance->rule, instance->action, instance->options, &instance->cache); } f_number_unsigned_t i = 0; @@ -118,15 +120,15 @@ extern "C" { // i==0 is need, i==1 is want, i==2 is wish. // Loop through all dependencies: wait for depedency, execute dependency, fail due to missing required dependency, or skip unrequired missing dependencies. - for (i = 0; i < 3 && controller_main_thread_is_enabled_instance(instance, global->thread); ++i) { + for (i = 0; i < 3 && controller_thread_is_enabled_instance(instance); ++i) { - for (j = 0; j < dynamics[i]->used && controller_main_thread_is_enabled_instance(instance, global->thread); ++j) { + for (j = 0; j < dynamics[i]->used && controller_thread_is_enabled_instance(instance); ++j) { id_dependency = 0; dependency = 0; found = F_false; - status_lock = controller_main_lock_read_instance(instance, global->thread, &global->thread->lock.instance); + status_lock = controller_lock_read_instance(instance, &global->thread->lock.instance); if (F_status_is_error(status_lock)) { controller_lock_print_error_critical(&global->main->program.error, F_status_set_fine(status_lock), F_true, global->thread); @@ -136,7 +138,7 @@ extern "C" { if (F_status_is_error(status)) { if (F_status_set_fine(status) == F_lock) { - if (!controller_main_thread_is_enabled_instance_type(instance->type, global->thread)) { + if (!controller_thread_is_enabled_instance_type(instance->type, global->thread)) { return F_status_set_error(F_interrupt); } } @@ -144,8 +146,8 @@ extern "C" { if (global->main->program.error.verbosity > f_console_verbosity_quiet_e) { controller_lock_print(global->main->program.error.to, global->thread); - controller_main_print_rule_item_error_rule_not_loaded(&global->main->program.error, dynamics[i]->array[j]); - controller_main_print_rule_error_cache(&global->error, instance->cache.action, F_false); + controller_print_rule_item_error_rule_not_loaded(&global->main->program.error, dynamics[i]->array[j]); + controller_print_rule_error_cache(global->error, instance->cache.action, F_false); controller_unlock_print_flush(global->main->program.error.to, global->thread); } @@ -161,7 +163,7 @@ extern "C" { dependency = global->thread->instances.array[id_dependency]; - status_lock = controller_main_lock_read_instance(instance, global->thread, &dependency->active); + status_lock = controller_lock_read_instance(instance, &dependency->active); if (F_status_is_error(status_lock)) { controller_lock_print_error_critical(&global->main->program.error, F_status_set_fine(status_lock), F_true, global->thread); @@ -174,7 +176,7 @@ extern "C" { else { f_thread_unlock(&global->thread->lock.instance); - status_lock = controller_main_lock_read_instance(instance, global->thread, &global->thread->lock.rule); + status_lock = controller_lock_read_instance(instance, &global->thread->lock.rule); if (F_status_is_error(status_lock)) { controller_lock_print_error_critical(&global->main->program.error, F_status_set_fine(status_lock), F_true, global->thread); @@ -199,8 +201,8 @@ extern "C" { if (i == 0) { controller_lock_print(global->main->program.error.to, global->thread); - controller_main_print_rule_item_error_need_want_wish(&global->main->program.error, strings[i], dynamics[i]->array[j], "is not found"); - controller_main_print_rule_error_cache(&global->error, instance->cache.action, F_true); + controller_print_rule_item_error_need_want_wish(&global->main->program.error, strings[i], dynamics[i]->array[j], "is not found"); + controller_print_rule_error_cache(global->error, instance->cache.action, F_true); controller_unlock_print_flush(global->main->program.error.to, global->thread); @@ -218,16 +220,16 @@ extern "C" { if (global->main->program.warning.verbosity == f_console_verbosity_debug_e) { controller_lock_print(global->main->program.warning.to, global->thread); - controller_main_print_rule_item_error_need_want_wish(&global->main->program.warning, strings[i], dynamics[i]->array[j], "is not found"); + controller_print_rule_item_error_need_want_wish(&global->main->program.warning, strings[i], dynamics[i]->array[j], "is not found"); - controller_main_print_rule_error_cache(&global->main->program.warning, instance->cache.action, F_true); + controller_print_rule_error_cache(&global->main->program.warning, instance->cache.action, F_true); controller_unlock_print_flush(global->main->program.warning.to, global->thread); } } } else if (found) { - status_lock = controller_main_lock_read_instance(instance, global->thread, &global->thread->lock.rule); + status_lock = controller_lock_read_instance(instance, &global->thread->lock.rule); if (F_status_is_error(status_lock)) { controller_lock_print_error_critical(&global->main->program.error, F_status_set_fine(status_lock), F_true, global->thread); @@ -251,7 +253,7 @@ extern "C" { f_thread_unlock(&global->thread->lock.rule); - status_lock = controller_main_lock_read_instance(instance, global->thread, &dependency->lock); + status_lock = controller_lock_read_instance(instance, &dependency->lock); if (F_status_is_error(status_lock)) { controller_lock_print_error_critical(&global->main->program.error, F_status_set_fine(status_lock), F_true, global->thread); @@ -261,14 +263,14 @@ extern "C" { else if (dependency->state == controller_instance_state_active_e || dependency->state == controller_instance_state_busy_e) { f_thread_unlock(&dependency->lock); - status = controller_instance_wait(global, dependency); + status = controller_instance_wait(dependency); if (F_status_is_error(status) && !(instance->options & controller_instance_option_simulate_e)) break; status = dependency->rule.status[instance->action]; } else { - status_lock = controller_main_lock_read_instance(instance, global->thread, &global->thread->lock.rule); + status_lock = controller_lock_read_instance(instance, &global->thread->lock.rule); if (F_status_is_error(status_lock)) { controller_lock_print_error_critical(&global->main->program.error, F_status_set_fine(status_lock), F_true, global->thread); @@ -277,7 +279,7 @@ extern "C" { status = status_lock; } - else if (controller_main_rule_status_is_available(instance->action, global->program->rules.array[id_rule])) { + else if (controller_rule_status_is_available(instance->action, global->program->rules.array[id_rule])) { f_thread_unlock(&global->thread->lock.rule); f_thread_unlock(&dependency->lock); @@ -292,7 +294,7 @@ extern "C" { } // Synchronously execute dependency. - status = controller_main_rule_instance_begin(global, 0, alias_other_buffer, instance->action, options_instance, instance->type, instance->stack, dependency->cache); + status = controller_rule_instance_begin(global, 0, alias_other_buffer, instance->action, options_instance, instance->type, instance->stack, dependency->cache); if (status == F_child || F_status_set_fine(status) == F_interrupt) { f_thread_unlock(&dependency->active); @@ -304,8 +306,8 @@ extern "C" { if (i == 0 || i == 1 || F_status_set_fine(status) == F_memory_not) { controller_lock_print(global->main->program.error.to, global->thread); - controller_main_print_rule_item_error_need_want_wish(&global->main->program.error, strings[i], alias_other_buffer, "failed during execution"); - controller_main_print_rule_error_cache(&global->error, instance->cache.action, F_true); + controller_print_rule_item_error_need_want_wish(&global->main->program.error, strings[i], alias_other_buffer, "failed during execution"); + controller_print_rule_error_cache(global->error, instance->cache.action, F_true); controller_unlock_print_flush(global->main->program.error.to, global->thread); @@ -319,9 +321,9 @@ extern "C" { if (global->main->program.warning.verbosity == f_console_verbosity_debug_e) { controller_lock_print(global->main->program.warning.to, global->thread); - controller_main_print_rule_item_error_need_want_wish(&global->main->program.warning, strings[i], alias_other_buffer, "failed during execution"); + controller_print_rule_item_error_need_want_wish(&global->main->program.warning, strings[i], alias_other_buffer, "failed during execution"); - controller_main_print_rule_error_cache(&global->main->program.warning, instance->cache.action, F_true); + controller_print_rule_error_cache(&global->main->program.warning, instance->cache.action, F_true); controller_unlock_print_flush(global->main->program.warning.to, global->thread); } @@ -336,14 +338,14 @@ extern "C" { } } - if (!controller_main_thread_is_enabled_instance(instance, global->thread)) { + if (!controller_thread_is_enabled_instance(instance)) { f_thread_unlock(&dependency->active); break; } if (F_status_is_error_not(status_lock)) { - status_lock = controller_main_lock_read_instance(instance, global->thread, &global->thread->lock.rule); + status_lock = controller_lock_read_instance(instance, &global->thread->lock.rule); if (F_status_is_error(status_lock)) { controller_lock_print_error_critical(&global->main->program.error, F_status_set_fine(status_lock), F_false, global->thread); @@ -352,20 +354,20 @@ extern "C" { if (F_status_is_error(status_lock)) { if (F_status_is_error(status_lock)) { - controller_main_print_rule_item_error_need_want_wish(&global->main->program.error, strings[i], alias_other_buffer, "due to lock failure"); + controller_print_rule_item_error_need_want_wish(&global->main->program.error, strings[i], alias_other_buffer, "due to lock failure"); } status = status_lock; } - else if (controller_main_rule_status_is_error(instance->action, global->program->rules.array[id_rule])) { + else if (controller_rule_status_is_error(instance->action, global->program->rules.array[id_rule])) { f_thread_unlock(&global->thread->lock.rule); if (i == 0 || i == 1) { controller_lock_print(global->main->program.error.to, global->thread); - controller_main_print_rule_item_error_need_want_wish(&global->main->program.error, strings[i], alias_other_buffer, "is in a failed state"); + controller_print_rule_item_error_need_want_wish(&global->main->program.error, strings[i], alias_other_buffer, "is in a failed state"); - controller_main_print_rule_error_cache(&global->error, instance->cache.action, F_true); + controller_print_rule_error_cache(global->error, instance->cache.action, F_true); controller_unlock_print_flush(global->main->program.error.to, global->thread); @@ -381,9 +383,9 @@ extern "C" { if (global->main->program.warning.verbosity == f_console_verbosity_debug_e) { controller_lock_print(global->main->program.warning.to, global->thread); - controller_main_print_rule_item_error_need_want_wish(&global->main->program.warning, strings[i], alias_other_buffer, "is in a failed state"); + controller_print_rule_item_error_need_want_wish(&global->main->program.warning, strings[i], alias_other_buffer, "is in a failed state"); - controller_main_print_rule_error_cache(&global->main->program.warning, instance->cache.action, F_true); + controller_print_rule_error_cache(&global->main->program.warning, instance->cache.action, F_true); controller_unlock_print_flush(global->main->program.warning.to, global->thread); } @@ -409,12 +411,12 @@ extern "C" { return status; } - if (!controller_main_thread_is_enabled_instance(instance, global->thread)) { + if (!controller_thread_is_enabled_instance(instance)) { return F_status_set_error(F_interrupt); } if ((instance->options & controller_instance_option_wait_e) && F_status_is_error_not(status) && (instance->options & controller_instance_option_validate_e)) { - status_lock = controller_main_rule_wait_all_instance_type(global, instance->type, F_false); + status_lock = controller_rule_wait_all_instance_type(global, instance->type, F_false); if (F_status_set_fine(status_lock) == F_interrupt) { return status_lock; @@ -449,7 +451,7 @@ extern "C" { fl_print_format("%r%[%QThe rule '%]", global->main->program.error.to, f_string_eol_s, global->main->program.error.context, global->main->program.error.prefix, global->main->program.error.context); fl_print_format(f_string_format_Q_single_s.string, global->main->program.error.to, global->main->program.error.notable, instance->rule.name, global->main->program.error.notable); fl_print_format("%[' has no '%]", global->main->program.error.to, global->main->program.error.context, global->main->program.error.context); - fl_print_format(f_string_format_r_single_s.string, global->main->program.error.to, global->main->program.error.notable, controller_main_rule_action_type_name(instance->action), global->main->program.error.notable); + fl_print_format(f_string_format_r_single_s.string, global->main->program.error.to, global->main->program.error.notable, controller_convert_rule_action_type_string(instance->action), global->main->program.error.notable); fl_print_format("%[' action to execute.%]%r", global->main->program.error.to, global->main->program.error.context, global->main->program.error.context, f_string_eol_s); } else { @@ -468,7 +470,7 @@ extern "C" { fl_print_format("%[') to execute.%]%r", global->main->program.error.to, global->main->program.error.context, global->main->program.error.context, f_string_eol_s); } - controller_main_print_rule_error_cache(&global->error, instance->cache.action, F_true); + controller_print_rule_error_cache(global->error, instance->cache.action, F_true); controller_unlock_print_flush(global->main->program.error.to, global->thread); } @@ -478,14 +480,14 @@ extern "C" { } if (F_status_is_error_not(status)) { - status = controller_main_rule_execute(global, instance->action, instance->options, instance); + status = controller_rule_execute(global, instance->action, instance->options, instance); if (status == F_child || F_status_set_fine(status) == F_interrupt || F_status_set_fine(status) == F_lock) { return status; } if (F_status_is_error(status)) { - controller_main_print_rule_item_error(global->error, instance->cache.action, F_true, F_status_set_fine(status)); + controller_print_rule_item_error(global->error, instance->cache.action, F_true, F_status_set_fine(status)); } } } @@ -494,13 +496,13 @@ extern "C" { f_thread_unlock(&instance->lock); - status_lock = controller_main_lock_write_instance(instance, global->thread, &instance->lock); + status_lock = controller_lock_write_instance(instance, &instance->lock); if (F_status_is_error(status_lock)) { controller_lock_print_error_critical(&global->main->program.error, F_status_set_fine(status_lock), F_false, global->thread); if (F_status_set_fine(status) != F_interrupt) { - status = controller_main_lock_read_instance(instance, global->thread, &instance->lock); + status = controller_lock_read_instance(instance, &instance->lock); if (F_status_is_error_not(status)) return status_lock; } @@ -508,20 +510,20 @@ extern "C" { } if (F_status_is_error(status)) { - instance->rule.status[instance->action] = controller_main_error_simplify(F_status_set_fine(status)); + instance->rule.status[instance->action] = controller_error_simplify(F_status_set_fine(status)); } else { instance->rule.status[instance->action] = status; } - status_lock = controller_main_lock_write_instance(instance, global->thread, &global->thread->lock.rule); + status_lock = controller_lock_write_instance(instance, &global->thread->lock.rule); if (F_status_is_error(status_lock)) { controller_lock_print_error_critical(&global->main->program.error, F_status_set_fine(status_lock), F_false, global->thread); f_thread_unlock(&instance->lock); - status = controller_main_lock_read_instance(instance, global->thread, &instance->lock); + status = controller_lock_read_instance(instance, &instance->lock); if (F_status_is_error_not(status)) return status_lock; return F_status_set_error(F_lock); @@ -551,7 +553,7 @@ extern "C" { f_thread_unlock(&global->thread->lock.rule); f_thread_unlock(&instance->lock); - status_lock = controller_main_lock_read_instance(instance, global->thread, &instance->lock); + status_lock = controller_lock_read_instance(instance, &instance->lock); if (F_status_is_error(status_lock)) { controller_lock_print_error_critical(&global->main->program.error, F_status_set_fine(status_lock), F_true, global->thread); @@ -561,14 +563,14 @@ extern "C" { return instance->rule.status[instance->action]; } -#endif // _di_controller_main_rule_instance_ +#endif // _di_controller_rule_instance_ -#ifndef _di_controller_main_rule_instance_begin_ - f_status_t controller_main_rule_instance_begin(controller_global_t * const global, const uint8_t options_force, const f_string_static_t alias_rule, const uint8_t action, const uint8_t options, const uint8_t type, const f_number_unsigneds_t stack, const controller_cache_t cache) { +#ifndef _di_controller_rule_instance_begin_ + f_status_t controller_rule_instance_begin(controller_global_t * const global, const uint8_t options_force, const f_string_static_t alias_rule, const uint8_t action, const uint8_t options, const uint8_t type, const f_number_unsigneds_t stack, const controller_cache_t cache) { if (!global) return F_status_set_error(F_parameter); - if (!controller_main_thread_is_enabled_instance_type(type, global->thread)) { + if (!controller_thread_is_enabled_instance_type(type, global->thread)) { return F_status_set_error(F_interrupt); } @@ -577,7 +579,7 @@ extern "C" { controller_instance_t *instance = 0; - status = controller_main_lock_read_instance_type(type, global->thread, &global->thread->lock.instance); + status = controller_lock_read_instance_type(type, global->thread, &global->thread->lock.instance); if (F_status_is_error(status)) { controller_lock_print_error_critical(&global->main->program.error, F_status_set_fine(status), F_true, global->thread); @@ -596,8 +598,8 @@ extern "C" { if (global->main->program.error.verbosity > f_console_verbosity_quiet_e) { controller_lock_print(global->main->program.error.to, global->thread); - controller_main_print_rule_item_error_rule_not_loaded(&global->main->program.error, alias_rule); - controller_main_print_rule_error_cache(&global->error, cache.action, F_false); + controller_print_rule_item_error_rule_not_loaded(&global->main->program.error, alias_rule); + controller_print_rule_error_cache(global->error, cache.action, F_false); controller_unlock_print_flush(global->main->program.error.to, global->thread); } @@ -607,18 +609,18 @@ extern "C" { instance = global->thread->instances.array[at]; - status = controller_main_lock_read_instance_type(type, global->thread, &instance->active); + status = controller_lock_read_instance_type(type, global->thread, &instance->active); if (F_status_is_error(status)) { controller_lock_print_error_critical(&global->main->program.error, F_status_set_fine(status), F_true, global->thread); - controller_main_print_rule_item_error(global->error, cache.action, F_false, F_status_set_fine(status)); + controller_print_rule_item_error(global->error, cache.action, F_false, F_status_set_fine(status)); f_thread_unlock(&global->thread->lock.instance); return status; } - status_lock = controller_main_lock_write_instance(instance, global->thread, &instance->lock); + status_lock = controller_lock_write_instance(instance, &instance->lock); if (F_status_is_error(status_lock)) { controller_lock_print_error_critical(&global->main->program.error, F_status_set_fine(status_lock), F_false, global->thread); @@ -642,7 +644,7 @@ extern "C" { // The thread is done, so close the thread. if (instance->state == controller_instance_state_done_e) { - controller_main_thread_join(&instance->id_thread); + controller_thread_join(&instance->id_thread); f_thread_mutex_lock(&instance->wait_lock); f_thread_condition_signal_all(&instance->wait); @@ -654,7 +656,7 @@ extern "C" { f_thread_unlock(&instance->lock); - status_lock = controller_main_lock_write_instance(instance, global->thread, &instance->lock); + status_lock = controller_lock_write_instance(instance, &instance->lock); if (F_status_is_error(status_lock)) { controller_lock_print_error_critical(&global->main->program.error, F_status_set_fine(status_lock), F_false, global->thread); @@ -669,8 +671,6 @@ extern "C" { instance->options = options; instance->type = type; - macro_f_time_simple_t_clear(instance->cache.timestamp) - instance->cache.ats.used = 0; instance->cache.stack.used = 0; instance->cache.comments.used = 0; @@ -692,6 +692,8 @@ extern "C" { instance->cache.action.generic.used = 0; instance->cache.range_action.start = 1; instance->cache.range_action.stop = 0; + instance->cache.timestamp.seconds = 0; + instance->cache.timestamp.seconds_nano = 0; instance->stack.used = 0; @@ -703,7 +705,7 @@ extern "C" { } if (F_status_is_error(status)) { - controller_main_print_error_status(&global->main->program.error, macro_controller_f(f_memory_array_resize), F_status_set_fine(status)); + controller_print_error_status(&global->main->program.error, macro_controller_f(f_memory_array_resize), F_status_set_fine(status)); } else { for (f_number_unsigned_t i = 0; i < stack.used; ++i) { @@ -725,7 +727,7 @@ extern "C" { status = f_string_dynamic_append(cache.action.name_item, &instance->cache.action.name_item); } else { - controller_main_print_error_status(&global->main->program.error, macro_controller_f(f_string_dynamic_append), F_status_set_fine(status)); + controller_print_error_status(&global->main->program.error, macro_controller_f(f_string_dynamic_append), F_status_set_fine(status)); } } @@ -734,18 +736,18 @@ extern "C" { if (F_status_is_error_not(status)) { if (instance->action && (options_force & controller_instance_option_asynchronous_e)) { if (instance->type == controller_instance_type_exit_e) { - status = f_thread_create(0, &instance->id_thread, controller_main_thread_instance_other, (void *) instance); + status = f_thread_create(0, &instance->id_thread, controller_thread_instance_other, (void *) instance); } else { - status = f_thread_create(0, &instance->id_thread, controller_main_thread_instance_normal, (void *) instance); + status = f_thread_create(0, &instance->id_thread, controller_thread_instance_normal, (void *) instance); } if (F_status_is_error(status)) { - controller_main_print_error_status(&global->main->program.error, macro_controller_f(f_thread_create), F_status_set_fine(status)); + controller_print_error_status(&global->main->program.error, macro_controller_f(f_thread_create), F_status_set_fine(status)); } } else { - status = controller_main_rule_instance_do(options_force, instance); + status = controller_rule_instance_do(options_force, instance); if (status == F_child || F_status_set_fine(status) == F_interrupt) { f_thread_unlock(&instance->active); @@ -757,7 +759,7 @@ extern "C" { if (!action || F_status_is_error(status) && (instance->state == controller_instance_state_active_e || instance->state == controller_instance_state_busy_e)) { { - status_lock = controller_main_lock_write_instance(instance, global->thread, &instance->lock); + status_lock = controller_lock_write_instance(instance, &instance->lock); if (F_status_is_error(status_lock)) { controller_lock_print_error_critical(&global->main->program.error, F_status_set_fine(status_lock), F_false, global->thread); @@ -790,32 +792,18 @@ extern "C" { return F_okay; } -#endif // _di_controller_main_rule_instance_begin_ +#endif // _di_controller_rule_instance_begin_ -#ifndef _di_controller_main_rule_instance_do_ - f_status_t controller_main_rule_instance_do(const uint8_t options_force, controller_instance_t * const instance) { +#ifndef _di_controller_rule_instance_do_ + f_status_t controller_rule_instance_do(const uint8_t options_force, controller_instance_t * const instance) { if (!instance) return F_status_set_error(F_parameter); f_status_t status_lock = F_okay; - controller_global_t global = macro_controller_global_t_initialize((controller_main_t *) instance->main_data, (controller_instance_t *) instance->main_setting, (controller_thread_t *) instance->main_thread); - - global->message = global->main->program.message; - global->output = global->main->program.output; - global->error = global->main->program.error; - global->warning = global->main->program.warning; - global->debug = global->main->program.debug; - - global->message.custom = (void *) &global; - global->output.custom = (void *) &global; - global->error.custom = (void *) &global; - global->warning.custom = (void *) &global; - global->debug.custom = (void *) &global; - // The instance and active locks shall be held for the duration of this instanceing (aside from switching between read to/from write). if (options_force & controller_instance_option_asynchronous_e) { - status_lock = controller_main_lock_read_instance(instance, global->thread, &instance->active); + status_lock = controller_lock_read_instance(instance, &instance->active); if (F_status_is_error(status_lock)) { controller_lock_print_error_critical(&global->main->program.error, F_status_set_fine(status_lock), F_true, global->thread); @@ -824,7 +812,7 @@ extern "C" { } } - status_lock = controller_main_lock_read_instance(instance, global->thread, &instance->lock); + status_lock = controller_lock_read_instance(instance, &instance->lock); if (F_status_is_error(status_lock)) { controller_lock_print_error_critical(&global->main->program.error, F_status_set_fine(status_lock), F_true, global->thread); @@ -842,7 +830,7 @@ extern "C" { const f_number_unsigned_t used_original_stack = instance->stack.used; - status_lock = controller_main_lock_read_instance(instance, global->thread, &global->thread->lock.rule); + status_lock = controller_lock_read_instance(instance, &global->thread->lock.rule); if (F_status_is_error(status_lock)) { controller_lock_print_error_critical(&global->main->program.error, F_status_set_fine(status_lock), F_true, global->thread); @@ -859,7 +847,7 @@ extern "C" { if (controller_rule_find(instance->rule.alias, global->program->rules, &id_rule) == F_true) { f_thread_unlock(&instance->lock); - status_lock = controller_main_lock_write_instance(instance, global->thread, &instance->lock); + status_lock = controller_lock_write_instance(instance, &instance->lock); if (F_status_is_error(status_lock)) { controller_lock_print_error_critical(&global->main->program.error, F_status_set_fine(status_lock), F_false, global->thread); @@ -879,7 +867,7 @@ extern "C" { f_thread_unlock(&instance->lock); - status_lock = controller_main_lock_read_instance(instance, global->thread, &instance->lock); + status_lock = controller_lock_read_instance(instance, &instance->lock); if (F_status_is_error(status_lock)) { controller_lock_print_error_critical(&global->main->program.error, F_status_set_fine(status_lock), F_true, global->thread); @@ -896,7 +884,7 @@ extern "C" { f_thread_unlock(&global->thread->lock.rule); if (F_status_is_error(status)) { - controller_main_print_error_status(&global->main->program.error, macro_controller_f(controller_rule_copy), F_status_set_fine(status)); + controller_print_error_status(&global->main->program.error, macro_controller_f(controller_rule_copy), F_status_set_fine(status)); } else if (!instance->action) { @@ -907,10 +895,10 @@ extern "C" { f_thread_unlock(&instance->active); } - return F_instance_not; + return F_process_not; } else { - for (f_number_unsigned_t i = 0; i < instance->stack.used && controller_main_thread_is_enabled_instance(instance, global->thread); ++i) { + for (f_number_unsigned_t i = 0; i < instance->stack.used && controller_thread_is_enabled_instance(instance); ++i) { if (instance->stack.array[i] == id_rule) { if (global->main->program.error.verbosity > f_console_verbosity_quiet_e) { @@ -920,7 +908,7 @@ extern "C" { fl_print_format(f_string_format_Q_single_s.string, global->main->program.error.to, global->main->program.error.notable, instance->rule.alias, global->main->program.error.notable); fl_print_format("%[' is already on the execution dependency stack, this recursion is prohibited.%]%r", global->main->program.error.to, global->main->program.error.context, global->main->program.error.context, f_string_eol_s); - controller_main_print_rule_error_cache(&global->error, instance->cache.action, F_true); + controller_print_rule_error_cache(global->error, instance->cache.action, F_true); controller_unlock_print_flush(global->main->program.error.to, global->thread); } @@ -932,7 +920,7 @@ extern "C" { } } // for - if (!controller_main_thread_is_enabled_instance(instance, global->thread)) { + if (!controller_thread_is_enabled_instance(instance)) { f_thread_unlock(&instance->lock); if (options_force & controller_instance_option_asynchronous_e) { @@ -946,12 +934,12 @@ extern "C" { status = f_memory_array_increase(controller_allocation_small_d, sizeof(f_number_unsigned_t), (void **) &instance->stack.array, &instance->stack.used, &instance->stack.size); if (F_status_is_error(status)) { - controller_main_print_error_status(&global->main->program.error, macro_controller_f(f_memory_array_increase), F_status_set_fine(status)); + controller_print_error_status(&global->main->program.error, macro_controller_f(f_memory_array_increase), F_status_set_fine(status)); } else { f_thread_unlock(&instance->lock); - status_lock = controller_main_lock_write_instance(instance, global->thread, &instance->lock); + status_lock = controller_lock_write_instance(instance, &instance->lock); if (F_status_is_error(status_lock)) { controller_lock_print_error_critical(&global->main->program.error, F_status_set_fine(status_lock), F_false, global->thread); @@ -967,7 +955,7 @@ extern "C" { f_thread_unlock(&instance->lock); - status_lock = controller_main_lock_read_instance(instance, global->thread, &instance->lock); + status_lock = controller_lock_read_instance(instance, &instance->lock); if (F_status_is_error(status_lock)) { controller_lock_print_error_critical(&global->main->program.error, F_status_set_fine(status_lock), F_true, global->thread); @@ -983,7 +971,7 @@ extern "C" { } if (F_status_is_error_not(status)) { - status = controller_main_rule_instance(global, instance); + status = controller_rule_instance(instance); } } else { @@ -994,8 +982,8 @@ extern "C" { if (global->main->program.error.verbosity > f_console_verbosity_quiet_e) { controller_lock_print(global->main->program.error.to, global->thread); - controller_main_print_rule_item_error_rule_not_loaded(&global->main->program.error, instance->rule.alias); - controller_main_print_rule_error_cache(&global->error, instance->cache.action, F_false); + controller_print_rule_item_error_rule_not_loaded(&global->main->program.error, instance->rule.alias); + controller_print_rule_error_cache(global->error, instance->cache.action, F_false); controller_unlock_print_flush(global->main->program.error.to, global->thread); } @@ -1011,7 +999,7 @@ extern "C" { return status; } - status_lock = controller_main_lock_write_instance(instance, global->thread, &global->thread->lock.rule); + status_lock = controller_lock_write_instance(instance, &global->thread->lock.rule); if (F_status_is_error(status_lock)) { controller_lock_print_error_critical(&global->main->program.error, F_status_set_fine(status_lock), F_false, global->thread); @@ -1039,7 +1027,7 @@ extern "C" { f_thread_unlock(&instance->lock); } - if (F_status_set_fine(status) == F_interrupt || F_status_set_fine(status) == F_lock && !controller_main_thread_is_enabled_instance(instance, global->thread)) { + if (F_status_set_fine(status) == F_interrupt || F_status_set_fine(status) == F_lock && !controller_thread_is_enabled_instance(instance)) { if (options_force & controller_instance_option_asynchronous_e) { f_thread_unlock(&instance->active); } @@ -1047,7 +1035,7 @@ extern "C" { return F_status_set_error(F_interrupt); } - status_lock = controller_main_lock_write_instance(instance, global->thread, &instance->lock); + status_lock = controller_lock_write_instance(instance, &instance->lock); if (F_status_is_error(status_lock)) { controller_lock_print_error_critical(&global->main->program.error, F_status_set_fine(status_lock), F_false, global->thread); @@ -1079,13 +1067,13 @@ extern "C" { f_thread_unlock(&instance->active); } - if (controller_main_thread_is_enabled_instance(instance, global->thread)) { + if (controller_thread_is_enabled_instance(instance)) { return status; } return F_status_set_error(F_interrupt); } -#endif // _di_controller_main_rule_instance_do_ +#endif // _di_controller_rule_instance_do_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/rule/instance.h b/sources/c/main/rule/instance.h index ee09ad8..e6697bb 100644 --- a/sources/c/main/rule/instance.h +++ b/sources/c/main/rule/instance.h @@ -28,15 +28,11 @@ extern "C" { * * The rule status will be updated by this function. * - * @param global - * The global data. - * - * Must not be NULL. - * - * This does not alter global.main.setting.state.status. * @param instance * The instance data for processing this rule. * + * Must not be NULL. + * * @return * F_okay on success. * F_child on child instance exiting. @@ -45,12 +41,12 @@ extern "C" { * F_interrupt (with error bit) on receiving a instance signal, such as an interrupt signal. * F_lock (with error bit) if failed to re-establish read lock on instance->lock while returning. * - * Errors (with error bit) from: controller_main_lock_read(). - * Errors (with error bit) from: controller_main_lock_write(). + * Errors (with error bit) from: controller_lock_read(). + * Errors (with error bit) from: controller_lock_write(). */ -#ifndef _di_controller_main_rule_instance_ - extern f_status_t controller_main_rule_instance(controller_global_t * const global, controller_instance_t * const instance); -#endif // _di_controller_main_rule_instance_ +#ifndef _di_controller_rule_instance_ + extern f_status_t controller_rule_instance(controller_instance_t * const instance); +#endif // _di_controller_rule_instance_ /** * Synchronously or asynchronously begin processing some rule. @@ -88,22 +84,22 @@ extern "C" { * F_interrupt (with error bit) on receiving a process signal, such as an interrupt signal. * F_recurse (with error bit) on recursion error (the instance is already on the instance stack). * - * Status from: controller_main_rule_instance(). + * Status from: controller_rule_instance(). * - * Errors (with error bit) from: controller_main_rule_instance(). + * Errors (with error bit) from: controller_rule_instance(). * Errors (with error bit) from: f_string_dynamic_append(). * Errors (with error bit) from: f_thread_create(). * - * @see controller_main_rule_instance() + * @see controller_rule_instance() * @see f_string_dynamic_append() * @see f_thread_create() */ -#ifndef _di_controller_main_rule_instance_begin_ - extern f_status_t controller_main_rule_instance_begin(controller_global_t * const global, const uint8_t options_force, const f_string_static_t alias_rule, const uint8_t action, const uint8_t options, const uint8_t type, const f_number_unsigneds_t stack, const controller_cache_t cache); -#endif // _di_controller_main_rule_instance_begin_ +#ifndef _di_controller_rule_instance_begin_ + extern f_status_t controller_rule_instance_begin(controller_global_t * const global, const uint8_t options_force, const f_string_static_t alias_rule, const uint8_t action, const uint8_t options, const uint8_t type, const f_number_unsigneds_t stack, const controller_cache_t cache); +#endif // _di_controller_rule_instance_begin_ /** - * Helper for calling controller_main_rule_instance(). + * Helper for calling controller_rule_instance(). * * This does all the preparation work that needs to be synchronously performed within the same thread. * This will copy the rule by the alias to the instance structure. @@ -124,18 +120,18 @@ extern "C" { * F_found_not (with error bit) if unable to for a instance for the given rule id. * F_interrupt (with error bit) on receiving a process signal, such as an interrupt signal. * - * Status from: controller_main_rule_instance(). + * Status from: controller_rule_instance(). * * Errors (with error bit) from: controller_rule_copy(). - * Errors (with error bit) from: controller_main_rule_instance(). + * Errors (with error bit) from: controller_rule_instance(). * * @see controller_rule_copy() - * @see controller_main_rule_instance() - * @see controller_main_rule_instance_begin() + * @see controller_rule_instance() + * @see controller_rule_instance_begin() */ -#ifndef _di_controller_main_rule_instance_do_ - extern f_status_t controller_main_rule_instance_do(const uint8_t options_force, controller_instance_t * const instance); -#endif // _di_controller_main_rule_instance_do_ +#ifndef _di_controller_rule_instance_do_ + extern f_status_t controller_rule_instance_do(const uint8_t options_force, controller_instance_t * const instance); +#endif // _di_controller_rule_instance_do_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/rule/is.c b/sources/c/main/rule/is.c index f0678af..02b6b51 100644 --- a/sources/c/main/rule/is.c +++ b/sources/c/main/rule/is.c @@ -4,19 +4,19 @@ extern "C" { #endif -#ifndef _di_controller_main_rule_status_is_available_ - f_status_t controller_main_rule_status_is_available(const uint8_t action, const controller_rule_t rule) { +#ifndef _di_controller_rule_status_is_available_ + f_status_t controller_rule_status_is_available(const uint8_t action, const controller_rule_t rule) { return F_status_is_error_not(rule.status[0]) && rule.status[action] == F_known_not; } -#endif // _di_controller_main_rule_status_is_available_ +#endif // _di_controller_rule_status_is_available_ -#ifndef _di_controller_main_rule_status_is_error_ - f_status_t controller_main_rule_status_is_error(const uint8_t action, const controller_rule_t rule) { +#ifndef _di_controller_rule_status_is_error_ + f_status_t controller_rule_status_is_error(const uint8_t action, const controller_rule_t rule) { return F_status_is_error(rule.status[0]) || F_status_is_error(rule.status[action]); } -#endif // _di_controller_main_rule_status_is_error_ +#endif // _di_controller_rule_status_is_error_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/rule/is.h b/sources/c/main/rule/is.h index 7579194..67292da 100644 --- a/sources/c/main/rule/is.h +++ b/sources/c/main/rule/is.h @@ -30,9 +30,9 @@ extern "C" { * F_true on available (status is F_known_not). * F_false on unavailable. */ -#ifndef _di_controller_main_rule_status_is_available_ - extern f_status_t controller_main_rule_status_is_available(const uint8_t action, const controller_rule_t rule); -#endif // _di_controller_main_rule_status_is_available_ +#ifndef _di_controller_rule_status_is_available_ + extern f_status_t controller_rule_status_is_available(const uint8_t action, const controller_rule_t rule); +#endif // _di_controller_rule_status_is_available_ /** * Check to see if the given Rule has status is designated as an error for the given Rule Action. @@ -48,9 +48,9 @@ extern "C" { * F_true if status represents an error. * F_false if status does not represent an error. */ -#ifndef _di_controller_main_rule_status_is_error_ - extern f_status_t controller_main_rule_status_is_error(const uint8_t action, const controller_rule_t rule); -#endif // _di_controller_main_rule_status_is_error_ +#ifndef _di_controller_rule_status_is_error_ + extern f_status_t controller_rule_status_is_error(const uint8_t action, const controller_rule_t rule); +#endif // _di_controller_rule_status_is_error_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/rule/item.c b/sources/c/main/rule/item.c index 6351e89..d3dda8d 100644 --- a/sources/c/main/rule/item.c +++ b/sources/c/main/rule/item.c @@ -4,14 +4,14 @@ extern "C" { #endif -#ifndef _di_controller_main_rule_item_read_ - f_status_t controller_main_rule_item_read(controller_global_t * const global, const bool is_normal, controller_cache_t * const cache, controller_rule_item_t * const item) { +#ifndef _di_controller_rule_item_read_ + f_status_t controller_rule_item_read(controller_global_t * const global, const bool is_normal, controller_cache_t * const cache, controller_rule_item_t * const item) { if (!global || !cache || !item) return F_status_set_error(F_parameter); f_status_t status = F_okay; - controller_interrupt_t custom = macro_controller_interrupt_t_initialize_1(is_normal, global->thread); - f_state_t state = macro_f_state_t_initialize_1(controller_allocation_large_d, controller_allocation_small_d, F_okay, 0, 0, 0, &controller_main_thread_signal_state_fss, 0, (void *) &custom, 0); + controller_interrupt_t custom = macro_controller_interrupt_t_initialize_1(is_normal, global); + f_state_t state = macro_f_state_t_initialize_1(controller_allocation_large_d, controller_allocation_small_d, F_okay, 0, 0, 0, &controller_thread_signal_state_fss, 0, (void *) &custom, 0); f_range_t range = macro_f_range_t_initialize_2(cache->buffer_item.used); f_number_unsigned_t last = 0; @@ -26,7 +26,7 @@ extern "C" { fl_fss_extended_list_object_read(cache->buffer_item, &range, &cache->range_action, &cache->delimits, &state); if (F_status_is_error(status)) { - controller_main_print_error_status(&global->main->program.error, macro_controller_f(fl_fss_extended_list_object_read), F_status_set_fine(status)); + controller_print_error_status(&global->main->program.error, macro_controller_f(fl_fss_extended_list_object_read), F_status_set_fine(status)); break; } @@ -43,7 +43,7 @@ extern "C" { fl_fss_extended_object_read(cache->buffer_item, &range, &cache->range_action, 0, &cache->delimits, &state); if (F_status_is_error(status)) { - controller_main_print_error_status(&global->main->program.error, macro_controller_f(fl_fss_extended_object_read), F_status_set_fine(status)); + controller_print_error_status(&global->main->program.error, macro_controller_f(fl_fss_extended_object_read), F_status_set_fine(status)); break; } @@ -55,7 +55,7 @@ extern "C" { f_fss_apply_delimit(cache->delimits, &cache->buffer_item, &state); if (F_status_is_error(status)) { - controller_main_print_error_status(&global->main->program.error, macro_controller_f(f_fss_apply_delimit), F_status_set_fine(status)); + controller_print_error_status(&global->main->program.error, macro_controller_f(f_fss_apply_delimit), F_status_set_fine(status)); break; } @@ -63,7 +63,7 @@ extern "C" { f_fss_count_lines(cache->buffer_item, cache->range_action.start, &cache->action.line_action, &state); if (F_status_is_error(status)) { - controller_main_print_error_status(&global->main->program.error, macro_controller_f(f_fss_count_lines), F_status_set_fine(status)); + controller_print_error_status(&global->main->program.error, macro_controller_f(f_fss_count_lines), F_status_set_fine(status)); break; } @@ -74,52 +74,52 @@ extern "C" { status = f_rip_dynamic_partial_nulless(cache->buffer_item, cache->range_action, &cache->action.name_action); if (F_status_is_error(status)) { - controller_main_print_error_status(&global->main->program.error, macro_controller_f(f_rip_dynamic_partial_nulless), F_status_set_fine(status)); + controller_print_error_status(&global->main->program.error, macro_controller_f(f_rip_dynamic_partial_nulless), F_status_set_fine(status)); break; } if (f_compare_dynamic(controller_freeze_s, cache->action.name_action) == F_equal_to) { - type = controller_main_rule_action_type_freeze_e; + type = controller_rule_action_type_freeze_e; } else if (f_compare_dynamic(controller_group_s, cache->action.name_action) == F_equal_to) { - type = controller_main_rule_action_type_group_e; + type = controller_rule_action_type_group_e; } else if (f_compare_dynamic(controller_kill_s, cache->action.name_action) == F_equal_to) { - type = controller_main_rule_action_type_kill_e; + type = controller_rule_action_type_kill_e; } else if (f_compare_dynamic(controller_pause_s, cache->action.name_action) == F_equal_to) { - type = controller_main_rule_action_type_pause_e; + type = controller_rule_action_type_pause_e; } else if (f_compare_dynamic(controller_pid_file_s, cache->action.name_action) == F_equal_to) { - type = controller_main_rule_action_type_pid_file_e; + type = controller_rule_action_type_pid_file_e; } else if (f_compare_dynamic(controller_reload_s, cache->action.name_action) == F_equal_to) { - type = controller_main_rule_action_type_reload_e; + type = controller_rule_action_type_reload_e; } else if (f_compare_dynamic(controller_rerun_s, cache->action.name_action) == F_equal_to) { - type = controller_main_rule_action_type_rerun_e; + type = controller_rule_action_type_rerun_e; } else if (f_compare_dynamic(controller_restart_s, cache->action.name_action) == F_equal_to) { - type = controller_main_rule_action_type_restart_e; + type = controller_rule_action_type_restart_e; } else if (f_compare_dynamic(controller_resume_s, cache->action.name_action) == F_equal_to) { - type = controller_main_rule_action_type_resume_e; + type = controller_rule_action_type_resume_e; } else if (f_compare_dynamic(controller_start_s, cache->action.name_action) == F_equal_to) { - type = controller_main_rule_action_type_start_e; + type = controller_rule_action_type_start_e; } else if (f_compare_dynamic(controller_stop_s, cache->action.name_action) == F_equal_to) { - type = controller_main_rule_action_type_stop_e; + type = controller_rule_action_type_stop_e; } else if (f_compare_dynamic(controller_thaw_s, cache->action.name_action) == F_equal_to) { - type = controller_main_rule_action_type_thaw_e; + type = controller_rule_action_type_thaw_e; } else if (f_compare_dynamic(controller_user_s, cache->action.name_action) == F_equal_to) { - type = controller_main_rule_action_type_user_e; + type = controller_rule_action_type_user_e; } else if (f_compare_dynamic(controller_with_s, cache->action.name_action) == F_equal_to) { - type = controller_main_rule_action_type_with_e; + type = controller_rule_action_type_with_e; } else { if (global->main->program.warning.verbosity == f_console_verbosity_debug_e) { @@ -129,7 +129,7 @@ extern "C" { fl_print_format(f_string_format_Q_single_s.string, global->main->program.warning.to, global->main->program.warning.notable, cache->action.name_action, global->main->program.warning.notable); fl_print_format(f_string_format_sentence_end_quote_s.string, global->main->program.warning.to, global->main->program.warning.context, global->main->program.warning.context, f_string_eol_s); - controller_main_print_rule_error_cache(&global->main->program.warning, cache->action, F_true); + controller_print_rule_error_cache(&global->main->program.warning, cache->action, F_true); controller_unlock_print_flush(global->main->program.warning.to, global->thread); } @@ -138,7 +138,7 @@ extern "C" { } if (multiple) { - if (type == controller_main_rule_action_type_group_e || type == controller_main_rule_action_type_pid_file_e || type == controller_main_rule_action_type_user_e) { + if (type == controller_rule_action_type_group_e || type == controller_rule_action_type_pid_file_e || type == controller_rule_action_type_user_e) { if (global->main->program.error.verbosity > f_console_verbosity_quiet_e) { controller_lock_print(global->main->program.error.to, global->thread); @@ -155,27 +155,27 @@ extern "C" { break; } - method = controller_main_rule_action_method_extended_list_e; + method = controller_rule_action_method_extended_list_e; } else { - method = controller_main_rule_action_method_extended_e; + method = controller_rule_action_method_extended_e; } - status = f_memory_array_increase_by(controller_allocation_small_d, sizeof(controller_main_rule_action_t), (void **) &item->actions.array, &item->actions.used, &item->actions.size); + status = f_memory_array_increase_by(controller_allocation_small_d, sizeof(controller_rule_action_t), (void **) &item->actions.array, &item->actions.used, &item->actions.size); if (F_status_is_error(status)) { - controller_main_print_error_status(&global->main->program.error, macro_controller_f(f_memory_array_increase_by), F_status_set_fine(status)); + controller_print_error_status(&global->main->program.error, macro_controller_f(f_memory_array_increase_by), F_status_set_fine(status)); break; } - status = controller_main_rule_action_read(global, is_normal, type, method, cache, item, &item->actions, &range); + status = controller_rule_action_read(global, is_normal, type, method, cache, item, &item->actions, &range); if (F_status_is_error(status)) break; } // for return status; } -#endif // _di_controller_main_rule_item_read_ +#endif // _di_controller_rule_item_read_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/rule/item.h b/sources/c/main/rule/item.h index 271dd4e..f491edc 100644 --- a/sources/c/main/rule/item.h +++ b/sources/c/main/rule/item.h @@ -42,13 +42,13 @@ extern "C" { * Errors (with error bit) from: f_fss_count_lines(). * Errors (with error bit) from: f_string_dynamic_partial_append_nulless(). * - * @see controller_main_rule_action_read() + * @see controller_rule_action_read() * @see f_fss_count_lines() * @see f_string_dynamic_partial_append_nulless() */ -#ifndef _di_controller_main_rule_item_read_ - extern f_status_t controller_main_rule_item_read(controller_global_t * const global, const bool is_normal, controller_cache_t * const cache, controller_rule_item_t * const item); -#endif // _di_controller_main_rule_item_read_ +#ifndef _di_controller_rule_item_read_ + extern f_status_t controller_rule_item_read(controller_global_t * const global, const bool is_normal, controller_cache_t * const cache, controller_rule_item_t * const item); +#endif // _di_controller_rule_item_read_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/rule/parameter.c b/sources/c/main/rule/parameter.c index 6f699ed..570e54e 100644 --- a/sources/c/main/rule/parameter.c +++ b/sources/c/main/rule/parameter.c @@ -4,8 +4,8 @@ extern "C" { #endif -#ifndef _di_controller_main_rule_parameters_read_ - f_status_t controller_main_rule_parameters_read(controller_global_t * const global, const f_string_static_t buffer, f_range_t * const object, f_ranges_t * const content, controller_main_rule_action_t * const action, f_state_t * const state) { +#ifndef _di_controller_rule_parameters_read_ + f_status_t controller_rule_parameters_read(controller_global_t * const global, const f_string_static_t buffer, f_range_t * const object, f_ranges_t * const content, controller_rule_action_t * const action, f_state_t * const state) { if (!global || !object || !content || !action || !state) return F_status_set_error(F_parameter); @@ -32,7 +32,7 @@ extern "C" { } if (F_status_is_error(status)) { - controller_main_print_error_status(&global->main->program.error, content ? macro_controller_f(f_memory_array_increase_by) : macro_controller_f(f_memory_array_increase), F_status_set_fine(status)); + controller_print_error_status(&global->main->program.error, content ? macro_controller_f(f_memory_array_increase_by) : macro_controller_f(f_memory_array_increase), F_status_set_fine(status)); return status; } @@ -46,7 +46,7 @@ extern "C" { status = f_string_dynamic_partial_append_nulless(buffer, *object, &action->parameters.array[0]); if (F_status_is_error(status)) { - controller_main_print_error_status(&global->main->program.error, macro_controller_f(f_string_dynamic_partial_append_nulless), F_status_set_fine(status)); + controller_print_error_status(&global->main->program.error, macro_controller_f(f_string_dynamic_partial_append_nulless), F_status_set_fine(status)); return status; } @@ -63,7 +63,7 @@ extern "C" { } if (F_status_is_error(status)) { - controller_main_print_error_status(&global->main->program.error, macro_controller_f(f_memory_array_increase_by), F_status_set_fine(status)); + controller_print_error_status(&global->main->program.error, macro_controller_f(f_memory_array_increase_by), F_status_set_fine(status)); return status; } @@ -83,7 +83,7 @@ extern "C" { status = f_string_dynamic_partial_append_nulless(buffer, content->array[i], &action->parameters.array[action->parameters.used]); if (F_status_is_error(status)) { - controller_main_print_error_status(&global->main->program.error, macro_controller_f(f_string_dynamic_partial_append_nulless), F_status_set_fine(status)); + controller_print_error_status(&global->main->program.error, macro_controller_f(f_string_dynamic_partial_append_nulless), F_status_set_fine(status)); return status; } @@ -95,7 +95,7 @@ extern "C" { fl_iki_read(&action->parameters.array[action->parameters.used], &range, &action->ikis.array[action->ikis.used], state); if (F_status_is_error(status)) { - controller_main_print_error_status(&global->main->program.error, macro_controller_f(fl_iki_read), F_status_set_fine(status)); + controller_print_error_status(&global->main->program.error, macro_controller_f(fl_iki_read), F_status_set_fine(status)); action->parameters.array[action->parameters.used].used = 0; @@ -110,7 +110,7 @@ extern "C" { return F_okay; } -#endif // _di_controller_main_rule_parameters_read_ +#endif // _di_controller_rule_parameters_read_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/rule/parameter.h b/sources/c/main/rule/parameter.h index adbf51c..ed3a7db 100644 --- a/sources/c/main/rule/parameter.h +++ b/sources/c/main/rule/parameter.h @@ -58,9 +58,9 @@ extern "C" { * @see f_memory_array_increase_by() * @see fl_iki_read() */ -#ifndef _di_controller_main_rule_parameters_read_ - extern f_status_t controller_main_rule_parameters_read(controller_global_t * const global, const f_string_static_t buffer, f_range_t * const object, f_ranges_t * const content, controller_main_rule_action_t * const action, f_state_t * const state); -#endif // _di_controller_main_rule_parameters_read_ +#ifndef _di_controller_rule_parameters_read_ + extern f_status_t controller_rule_parameters_read(controller_global_t * const global, const f_string_static_t buffer, f_range_t * const object, f_ranges_t * const content, controller_rule_action_t * const action, f_state_t * const state); +#endif // _di_controller_rule_parameters_read_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/rule/read.c b/sources/c/main/rule/read.c index 20b914f..18d63f1 100644 --- a/sources/c/main/rule/read.c +++ b/sources/c/main/rule/read.c @@ -4,8 +4,8 @@ extern "C" { #endif -#ifndef _di_controller_main_rule_read_ - f_status_t controller_main_rule_read(controller_global_t * const global, const bool is_normal, const f_string_static_t alias, controller_cache_t * const cache, controller_entry_t * const entry, controller_rule_t * const rule) { +#ifndef _di_controller_rule_read_ + f_status_t controller_rule_read(controller_global_t * const global, const bool is_normal, const f_string_static_t alias, controller_cache_t * const cache, controller_entry_t * const entry, controller_rule_t * const rule) { if (!global || !cache || !entry || !rule) return F_status_set_error(F_parameter); @@ -22,7 +22,8 @@ extern "C" { rule->user = 0; rule->nice = 0; - macro_f_time_simple_t_clear(rule->timestamp); + rule->timestamp.seconds = 0; + rule->timestamp.seconds_nano = 0; rule->alias.used = 0; rule->engine.used = 0; @@ -86,7 +87,7 @@ extern "C" { rule->cgroup.groups.array[i].used = 0; } // for - for (; i < controller_main_rule_action_type__enum_size_e; ++i) { + for (; i < controller_rule_action_type__enum_size_e; ++i) { rule->status[i] = F_known_not; } // for @@ -112,7 +113,7 @@ extern "C" { rule->items.array[i].pid_file.used = 0; rule->items.array[i].actions.used = 0; - for (j = 0; j < controller_main_rule_action_execute_type__enum_size_e; ++j) { + for (j = 0; j < controller_rule_action_execute_type__enum_size_e; ++j) { rule->items.array[i].reruns[j].is = 0; @@ -168,30 +169,30 @@ extern "C" { status = f_string_dynamic_append_nulless(alias, &rule->alias); if (F_status_is_error(status)) { - controller_main_print_error_status(&global->main->program.error, macro_controller_f(f_string_dynamic_append_nulless), F_status_set_fine(status)); + controller_print_error_status(&global->main->program.error, macro_controller_f(f_string_dynamic_append_nulless), F_status_set_fine(status)); } else { - status = controller_file_load(global, F_true, controller_rules_s, rule->alias, controller_rule_s, cache); + status = controller_file_load(global, cache, F_true, controller_rules_s, rule->alias, controller_rule_s); } if (F_status_is_error_not(status)) { rule->timestamp = cache->timestamp; if (cache->buffer_file.used) { - controller_interrupt_t custom = macro_controller_interrupt_t_initialize_1(is_normal, global->thread); - f_state_t state = macro_f_state_t_initialize_1(controller_allocation_large_d, controller_allocation_small_d, F_okay, 0, 0, 0, &controller_main_thread_signal_state_fss, 0, (void *) &custom, 0); + controller_interrupt_t custom = macro_controller_interrupt_t_initialize_1(is_normal, global); + f_state_t state = macro_f_state_t_initialize_1(controller_allocation_large_d, controller_allocation_small_d, F_okay, 0, 0, 0, &controller_thread_signal_state_fss, 0, (void *) &custom, 0); f_range_t range = macro_f_range_t_initialize_2(cache->buffer_file.used); fll_fss_basic_list_read(cache->buffer_file, &range, &cache->object_items, &cache->content_items, &cache->delimits, 0, &cache->comments, &state); if (F_status_is_error(status)) { - controller_main_print_error_status(&global->main->program.error, macro_controller_f(fll_fss_basic_list_read), F_status_set_fine(status)); + controller_print_error_status(&global->main->program.error, macro_controller_f(fll_fss_basic_list_read), F_status_set_fine(status)); } else { f_fss_apply_delimit(cache->delimits, &cache->buffer_file, &state); if (F_status_is_error(status)) { - controller_main_print_error_status(&global->main->program.error, macro_controller_f(f_fss_apply_delimit), F_status_set_fine(status)); + controller_print_error_status(&global->main->program.error, macro_controller_f(f_fss_apply_delimit), F_status_set_fine(status)); } } } @@ -203,7 +204,7 @@ extern "C" { } if (F_status_is_error(status)) { - controller_main_print_error_status(&global->main->program.error, macro_controller_f(controller_rule_items_increase_by), F_status_set_fine(status)); + controller_print_error_status(&global->main->program.error, macro_controller_f(f_memory_arrays_resize), F_status_set_fine(status)); } else { f_number_unsigned_t i = 0; @@ -241,7 +242,7 @@ extern "C" { f_fss_count_lines(cache->buffer_file, cache->object_items.array[i].start, &cache->action.line_item, &global->main->setting.state); if (F_status_is_error(status)) { - controller_main_print_error_status(&global->main->program.error, macro_controller_f(f_fss_count_lines), F_status_set_fine(status)); + controller_print_error_status(&global->main->program.error, macro_controller_f(f_fss_count_lines), F_status_set_fine(status)); break; } @@ -251,7 +252,7 @@ extern "C" { status = f_rip_dynamic_partial_nulless(cache->buffer_file, cache->object_items.array[i], &cache->action.name_item); if (F_status_is_error(status)) { - controller_main_print_error_status(&global->main->program.error, macro_controller_f(f_rip_dynamic_partial_nulless), F_status_set_fine(status)); + controller_print_error_status(&global->main->program.error, macro_controller_f(f_rip_dynamic_partial_nulless), F_status_set_fine(status)); break; } @@ -279,7 +280,7 @@ extern "C" { fl_print_format(f_string_format_Q_single_s.string, global->main->program.warning.to, global->main->program.warning.notable, cache->action.name_item, global->main->program.warning.notable); fl_print_format(f_string_format_sentence_end_quote_s.string, global->main->program.warning.to, global->main->program.warning.context, global->main->program.warning.context, f_string_eol_s); - controller_main_print_rule_error_cache(&global->main->program.warning, cache->action, F_true); + controller_print_rule_error_cache(&global->main->program.warning, cache->action, F_true); controller_unlock_print_flush(global->main->program.warning.to, global->thread); } @@ -290,7 +291,7 @@ extern "C" { status = f_string_dynamic_partial_append(cache->buffer_file, cache->content_items.array[i].array[0], &cache->buffer_item); if (F_status_is_error(status)) { - controller_main_print_error_status(&global->main->program.error, macro_controller_f(f_rip_dynamic_partial_nulless), F_status_set_fine(status)); + controller_print_error_status(&global->main->program.error, macro_controller_f(f_rip_dynamic_partial_nulless), F_status_set_fine(status)); break; } @@ -307,7 +308,7 @@ extern "C" { rule->items.array[rule->items.used].with |= controller_with_session_same_d; } - status = controller_main_rule_item_read(global, is_normal, cache, &rule->items.array[rule->items.used]); + status = controller_rule_item_read(global, is_normal, cache, &rule->items.array[rule->items.used]); if (F_status_is_error(status)) break; ++rule->items.used; @@ -315,7 +316,7 @@ extern "C" { else { for_item = F_false; - status = controller_main_rule_setting_read(global, is_normal, *global->setting, cache, rule); + status = controller_rule_setting_read(global, is_normal, *global->setting, cache, rule); if (F_status_is_error(status)) { if (F_status_set_fine(status) == F_memory_not) break; @@ -326,16 +327,16 @@ extern "C" { } if (F_status_is_error(status)) { - controller_main_print_rule_item_error(global->error, cache->action, for_item, F_status_set_fine(status)); + controller_print_rule_item_error(global->error, cache->action, for_item, F_status_set_fine(status)); - rule->status[0] = controller_main_error_simplify(F_status_set_fine(status)); + rule->status[0] = controller_error_simplify(F_status_set_fine(status)); return rule->status[0]; } return F_okay; } -#endif // _di_controller_main_rule_read_ +#endif // _di_controller_rule_read_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/rule/read.h b/sources/c/main/rule/read.h index 5e48b6d..4cdcb34 100644 --- a/sources/c/main/rule/read.h +++ b/sources/c/main/rule/read.h @@ -43,19 +43,20 @@ extern "C" { * @return * F_okay on success. * - * Simplified status (with error bit) from controller_main_error_simplify() on failure. + * Simplified status (with error bit) from controller_error_simplify() on failure. + * + * @see controller_rule_item_read(). * - * @see controller_rule_items_increase_by(). - * @see controller_main_rule_item_read(). * @see f_fss_count_lines(). * @see f_fss_apply_delimit(). + * @see f_memory_arrays_resize(). * @see f_string_dynamic_partial_append(). * @see f_string_dynamic_partial_append_nulless(). * @see fll_fss_basic_list_read(). */ -#ifndef _di_controller_main_rule_read_ - extern f_status_t controller_main_rule_read(controller_global_t * const global, const bool is_normal, const f_string_static_t alias, controller_cache_t * const cache, controller_entry_t * const entry, controller_rule_t * const rule); -#endif // _di_controller_main_rule_read_ +#ifndef _di_controller_rule_read_ + extern f_status_t controller_rule_read(controller_global_t * const global, const bool is_normal, const f_string_static_t alias, controller_cache_t * const cache, controller_entry_t * const entry, controller_rule_t * const rule); +#endif // _di_controller_rule_read_ #ifdef __cplusplus diff --git a/sources/c/main/rule/setting.c b/sources/c/main/rule/setting.c index 2d97912..d93a306 100644 --- a/sources/c/main/rule/setting.c +++ b/sources/c/main/rule/setting.c @@ -4,8 +4,89 @@ extern "C" { #endif -#ifndef _di_controller_main_rule_setting_read_ - f_status_t controller_main_rule_setting_read(controller_global_t * const global, const bool is_normal, controller_cache_t * const cache, controller_rule_t * const rule) { +#ifndef _di_controller_rule_setting_limit_type_identify_ + uint8_t controller_rule_setting_limit_type_identify(const f_string_static_t limit) { + + if (f_compare_dynamic(limit, controller_as_s) == F_equal_to) return controller_resource_limit_type_as_e; + if (f_compare_dynamic(limit, controller_core_s) == F_equal_to) return controller_resource_limit_type_core_e; + if (f_compare_dynamic(limit, controller_cpu_s) == F_equal_to) return controller_resource_limit_type_cpu_e; + if (f_compare_dynamic(limit, controller_data_s) == F_equal_to) return controller_resource_limit_type_data_e; + if (f_compare_dynamic(limit, controller_fsize_s) == F_equal_to) return controller_resource_limit_type_fsize_e; + if (f_compare_dynamic(limit, controller_locks_s) == F_equal_to) return controller_resource_limit_type_locks_e; + if (f_compare_dynamic(limit, controller_memlock_s) == F_equal_to) return controller_resource_limit_type_memlock_e; + if (f_compare_dynamic(limit, controller_msgqueue_s) == F_equal_to) return controller_resource_limit_type_msgqueue_e; + if (f_compare_dynamic(limit, controller_nice_s) == F_equal_to) return controller_resource_limit_type_nice_e; + if (f_compare_dynamic(limit, controller_nofile_s) == F_equal_to) return controller_resource_limit_type_nofile_e; + if (f_compare_dynamic(limit, controller_nproc_s) == F_equal_to) return controller_resource_limit_type_nproc_e; + if (f_compare_dynamic(limit, controller_rss_s) == F_equal_to) return controller_resource_limit_type_rss_e; + if (f_compare_dynamic(limit, controller_rtprio_s) == F_equal_to) return controller_resource_limit_type_rtprio_e; + if (f_compare_dynamic(limit, controller_rttime_s) == F_equal_to) return controller_resource_limit_type_rttime_e; + if (f_compare_dynamic(limit, controller_sigpending_s) == F_equal_to) return controller_resource_limit_type_sigpending_e; + if (f_compare_dynamic(limit, controller_stack_s) == F_equal_to) return controller_resource_limit_type_stack_e; + + return 0; + } +#endif // _di_controller_rule_setting_limit_type_identify_ + +#ifndef _di_controller_rule_setting_limit_type_name_ + f_string_static_t controller_rule_setting_limit_type_name(const uint8_t type) { + + switch (type) { + case controller_resource_limit_type_as_e: + return controller_as_s; + + case controller_resource_limit_type_core_e: + return controller_core_s; + + case controller_resource_limit_type_cpu_e: + return controller_cpu_s; + + case controller_resource_limit_type_data_e: + return controller_data_s; + + case controller_resource_limit_type_fsize_e: + return controller_fsize_s; + + case controller_resource_limit_type_locks_e: + return controller_locks_s; + + case controller_resource_limit_type_memlock_e: + return controller_memlock_s; + + case controller_resource_limit_type_msgqueue_e: + return controller_msgqueue_s; + + case controller_resource_limit_type_nice_e: + return controller_nice_s; + + case controller_resource_limit_type_nofile_e: + return controller_nofile_s; + + case controller_resource_limit_type_nproc_e: + return controller_nproc_s; + + case controller_resource_limit_type_rss_e: + return controller_rss_s; + + case controller_resource_limit_type_rtprio_e: + return controller_rtprio_s; + + case controller_resource_limit_type_rttime_e: + return controller_rttime_s; + + case controller_resource_limit_type_sigpending_e: + return controller_sigpending_s; + + case controller_resource_limit_type_stack_e: + return controller_stack_s; + } + + return f_string_empty_s; + } +#endif // _di_controller_rule_setting_limit_type_name_ + +#ifndef _di_controller_rule_setting_read_ + f_status_t controller_rule_setting_read(controller_global_t * const global, const bool is_normal, controller_cache_t * const cache, controller_rule_t * const rule) { if (!global || !cache || !rule) return F_status_set_error(F_parameter); @@ -15,13 +96,13 @@ extern "C" { f_range_t range = macro_f_range_t_initialize_2(cache->buffer_item.used); f_range_t range2 = f_range_t_initialize; - controller_interrupt_t custom = macro_controller_interrupt_t_initialize_1(is_normal, global->thread); - f_state_t state = macro_f_state_t_initialize_1(controller_allocation_large_d, controller_allocation_small_d, F_okay, 0, 0, 0, &controller_main_thread_signal_state_fss, 0, (void *) &custom, 0); + controller_interrupt_t custom = macro_controller_interrupt_t_initialize_1(is_normal, global); + f_state_t state = macro_f_state_t_initialize_1(controller_allocation_large_d, controller_allocation_small_d, F_okay, 0, 0, 0, &controller_thread_signal_state_fss, 0, (void *) &custom, 0); fll_fss_extended_read(cache->buffer_item, &range, &cache->object_actions, &cache->content_actions, 0, 0, &cache->delimits, 0, &state); if (F_status_is_error(status)) { - controller_main_print_rule_error(&global->error, cache->action, F_status_set_fine(status), "fll_fss_extended_read", F_true, F_false); + controller_print_rule_error(global->error, cache->action, F_status_set_fine(status), "fll_fss_extended_read", F_true, F_false); return status; } @@ -56,7 +137,7 @@ extern "C" { status = f_string_dynamic_partial_append_nulless(cache->buffer_item, cache->object_actions.array[i], &cache->action.name_item); if (F_status_is_error(status)) { - controller_main_print_rule_error(&global->error, cache->action, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, F_false); + controller_print_rule_error(global->error, cache->action, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, F_false); if (F_status_set_fine(status) == F_memory_not) { status_return = status; @@ -74,7 +155,7 @@ extern "C" { cache->action.line_action = ++cache->action.line_item; - controller_main_print_rule_item_error(global->error, cache->action, F_false, F_status_set_fine(status)); + controller_print_rule_item_error(global->error, cache->action, F_false, F_status_set_fine(status)); continue; } @@ -145,7 +226,7 @@ extern "C" { fl_print_format(f_string_format_Q_single_s.string, global->main->program.warning.to, global->main->program.warning.notable, cache->action.name_item, global->main->program.warning.notable); fl_print_format(f_string_format_sentence_end_quote_s.string, global->main->program.warning.to, global->main->program.warning.context, global->main->program.warning.context, f_string_eol_s); - controller_main_print_rule_error_cache(&global->main->program.warning, cache->action, F_false); + controller_print_rule_error_cache(&global->main->program.warning, cache->action, F_false); controller_unlock_print_flush(global->main->program.warning.to, global->thread); } @@ -160,7 +241,7 @@ extern "C" { status = f_string_dynamic_partial_append_nulless(cache->buffer_item, range2, &cache->action.name_action); if (F_status_is_error(status)) { - controller_main_print_rule_error(&global->error, cache->action, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, F_false); + controller_print_rule_error(global->error, cache->action, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, F_false); // Get the current line number within the settings item. cache->action.line_item = line_item; @@ -168,7 +249,7 @@ extern "C" { cache->action.line_action = ++cache->action.line_item; - controller_main_print_rule_item_error(global->error, cache->action, F_false, F_status_set_fine(status)); + controller_print_rule_item_error(global->error, cache->action, F_false, F_status_set_fine(status)); if (F_status_set_fine(status) == F_memory_not) { status_return = status; @@ -197,7 +278,7 @@ extern "C" { fl_print_format("%r%[%QEmpty rule setting.%]%r", global->main->program.warning.to, f_string_eol_s, global->main->program.warning.context, global->main->program.warning.prefix, global->main->program.warning.context, f_string_eol_s); - controller_main_print_rule_error_cache(&global->main->program.warning, cache->action, F_false); + controller_print_rule_error_cache(&global->main->program.warning, cache->action, F_false); controller_unlock_print_flush(global->main->program.warning.to, global->thread); } @@ -208,7 +289,7 @@ extern "C" { if (type == controller_rule_setting_type_affinity_e) { if (!cache->content_actions.array[i].used) { - controller_main_print_rule_setting_read_error(&global->main->program.error, "requires one or more Content", i, line_item, global->thread, cache); + controller_print_rule_setting_read_error(&global->main->program.error, "requires one or more Content", i, line_item, global->thread, cache); if (F_status_is_error_not(status_return)) { status_return = F_status_set_error(F_valid_not); @@ -226,7 +307,7 @@ extern "C" { status = f_memory_array_increase(controller_allocation_small_d, sizeof(int32_t), (void **) &rule->affinity.array, &rule->affinity.used, &rule->affinity.size); if (F_status_is_error(status)) { - controller_main_print_rule_error(&global->error, cache->action, F_status_set_fine(status), "f_memory_array_increase", F_true, F_false); + controller_print_rule_error(global->error, cache->action, F_status_set_fine(status), "f_memory_array_increase", F_true, F_false); break; } @@ -234,7 +315,7 @@ extern "C" { status = fl_conversion_dynamic_partial_to_signed_detect(fl_conversion_data_base_10_c, cache->buffer_item, cache->content_actions.array[i].array[j], &number); if (F_status_set_fine(status) == F_number_positive) { - status = fl_conversion_dynamic_partial_to_signed_detect(fl_conversion_data_base_10_c, cache->buffer_item, controller_main_range_after_number_sign(cache->buffer_item, cache->content_actions.array[i].array[j]), &number); + status = fl_conversion_dynamic_partial_to_signed_detect(fl_conversion_data_base_10_c, cache->buffer_item, controller_range_after_number_sign(cache->buffer_item, cache->content_actions.array[i].array[j]), &number); // Restore error on parameter problem. if (F_status_set_fine(status) == F_parameter) { @@ -247,13 +328,13 @@ extern "C" { if (status == F_data_not || status == F_number || status == F_number_overflow || status == F_number_underflow || status == F_number_negative || status == F_number_decimal) { if (status == F_number_underflow) { - controller_main_print_rule_setting_read_error_with_range(&global->main->program.error, " has an unsupported number", cache->content_actions.array[i].array[j], ", the number is too small for this system", i, line_item, global->thread, cache); + controller_print_rule_setting_read_error_with_range(&global->main->program.error, " has an unsupported number", cache->content_actions.array[i].array[j], ", the number is too small for this system", i, line_item, global->thread, cache); } else if (status == F_number_overflow || status == F_number_positive) { - controller_main_print_rule_setting_read_error_with_range(&global->main->program.error, " has an unsupported number", cache->content_actions.array[i].array[j], ", the number is too large for this system", i, line_item, global->thread, cache); + controller_print_rule_setting_read_error_with_range(&global->main->program.error, " has an unsupported number", cache->content_actions.array[i].array[j], ", the number is too large for this system", i, line_item, global->thread, cache); } else { - controller_main_print_rule_setting_read_error_with_range(&global->main->program.error, " has an invalid number", cache->content_actions.array[i].array[j], ", only whole numbers are allowed for an affinity value", i, line_item, global->thread, cache); + controller_print_rule_setting_read_error_with_range(&global->main->program.error, " has an invalid number", cache->content_actions.array[i].array[j], ", only whole numbers are allowed for an affinity value", i, line_item, global->thread, cache); } status = F_status_set_error(F_valid_not); @@ -263,7 +344,7 @@ extern "C" { } } else { - controller_main_print_rule_error(&global->error, cache->action, F_status_set_fine(status), "fl_conversion_dynamic_partial_to_signed_detect", F_true, F_false); + controller_print_rule_error(global->error, cache->action, F_status_set_fine(status), "fl_conversion_dynamic_partial_to_signed_detect", F_true, F_false); status = F_status_set_error(status); @@ -278,14 +359,14 @@ extern "C" { rule->affinity.array[rule->affinity.used++] = number; } // for - controller_main_print_rule_setting_read_values(global, controller_affinity_s, i, cache); + controller_print_rule_setting_read_values(global, controller_affinity_s, i, cache); continue; } if (type == controller_rule_setting_type_define_e || type == controller_rule_setting_type_parameter_e) { if (cache->content_actions.array[i].used != 2) { - controller_main_print_rule_setting_read_error(&global->main->program.error, "requires exactly two Content", i, line_item, global->thread, cache); + controller_print_rule_setting_read_error(&global->main->program.error, "requires exactly two Content", i, line_item, global->thread, cache); if (F_status_is_error_not(status_return)) { status_return = F_status_set_error(F_valid_not); @@ -304,7 +385,7 @@ extern "C" { status = f_memory_array_increase(controller_allocation_small_d, sizeof(f_string_map_t), (void **) &setting_maps->array, &setting_maps->used, &setting_maps->size); if (F_status_is_error(status)) { - controller_main_print_rule_error(&global->error, cache->action, F_status_set_fine(status), "f_memory_array_increase", F_true, F_false); + controller_print_rule_error(global->error, cache->action, F_status_set_fine(status), "f_memory_array_increase", F_true, F_false); if (F_status_set_fine(status) == F_memory_not) { status_return = status; @@ -322,7 +403,7 @@ extern "C" { cache->action.line_action = ++cache->action.line_item; - controller_main_print_rule_item_error(global->error, cache->action, F_false, F_status_set_fine(status)); + controller_print_rule_item_error(global->error, cache->action, F_false, F_status_set_fine(status)); continue; } @@ -333,7 +414,7 @@ extern "C" { status = f_string_dynamic_partial_append_nulless(cache->buffer_item, cache->content_actions.array[i].array[0], &setting_maps->array[setting_maps->used].key); if (F_status_is_error(status)) { - controller_main_print_rule_error(&global->error, cache->action, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, F_false); + controller_print_rule_error(global->error, cache->action, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, F_false); if (F_status_set_fine(status) == F_memory_not) { status_return = status; @@ -350,7 +431,7 @@ extern "C" { cache->action.line_action = ++cache->action.line_item; - controller_main_print_rule_item_error(global->error, cache->action, F_false, F_status_set_fine(status)); + controller_print_rule_item_error(global->error, cache->action, F_false, F_status_set_fine(status)); continue; } @@ -358,7 +439,7 @@ extern "C" { status = f_string_dynamic_partial_append_nulless(cache->buffer_item, cache->content_actions.array[i].array[1], &setting_maps->array[setting_maps->used].value); if (F_status_is_error(status)) { - controller_main_print_rule_error(&global->error, cache->action, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, F_false); + controller_print_rule_error(global->error, cache->action, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, F_false); if (F_status_set_fine(status) == F_memory_not) { status_return = status; @@ -376,12 +457,12 @@ extern "C" { cache->action.line_action = ++cache->action.line_item; - controller_main_print_rule_item_error(global->error, cache->action, F_false, F_status_set_fine(status)); + controller_print_rule_item_error(global->error, cache->action, F_false, F_status_set_fine(status)); continue; } - controller_main_print_rule_setting_read_mapping(global, type == controller_rule_setting_type_define_e ? controller_define_s : controller_parameter_s, setting_maps->array[setting_maps->used]); + controller_print_rule_setting_read_mapping(global, type == controller_rule_setting_type_define_e ? controller_define_s : controller_parameter_s, setting_maps->array[setting_maps->used]); ++setting_maps->used; @@ -390,7 +471,7 @@ extern "C" { if (type == controller_rule_setting_type_cgroup_e) { if (cache->content_actions.array[i].used < 2 || rule->has & controller_rule_has_cgroup_d) { - controller_main_print_rule_setting_read_error(&global->main->program.error, "requires two or more Content", i, line_item, global->thread, cache); + controller_print_rule_setting_read_error(&global->main->program.error, "requires two or more Content", i, line_item, global->thread, cache); if (F_status_is_error_not(status_return)) { status_return = F_status_set_error(F_valid_not); @@ -406,7 +487,7 @@ extern "C" { rule->cgroup.as_new = F_true; } else { - controller_main_print_rule_setting_read_error_with_range(&global->main->program.error, " has an unknown option", cache->content_actions.array[i].array[0], "", i, line_item, global->thread, cache); + controller_print_rule_setting_read_error_with_range(&global->main->program.error, " has an unknown option", cache->content_actions.array[i].array[0], "", i, line_item, global->thread, cache); if (F_status_is_error_not(status_return)) { status_return = F_status_set_error(F_valid_not); @@ -420,7 +501,7 @@ extern "C" { status = f_string_dynamic_append(global->program->path_cgroup, &rule->cgroup.path); if (F_status_is_error(status)) { - controller_main_print_rule_error(&global->error, cache->action, F_status_set_fine(status), "f_string_dynamic_append", F_true, F_false); + controller_print_rule_error(global->error, cache->action, F_status_set_fine(status), "f_string_dynamic_append", F_true, F_false); } else { rule->cgroup.groups.used = 0; @@ -430,7 +511,7 @@ extern "C" { status = f_memory_array_increase(controller_allocation_small_d, sizeof(f_string_dynamic_t), (void **) &rule->cgroup.groups.array, &rule->cgroup.groups.used, &rule->cgroup.groups.size); if (F_status_is_error(status)) { - controller_main_print_rule_error(&global->error, cache->action, F_status_set_fine(status), "f_memory_array_increase", F_true, F_false); + controller_print_rule_error(global->error, cache->action, F_status_set_fine(status), "f_memory_array_increase", F_true, F_false); break; } @@ -440,7 +521,7 @@ extern "C" { status = f_string_dynamic_partial_append_nulless(cache->buffer_item, cache->content_actions.array[i].array[j], &rule->cgroup.groups.array[rule->cgroup.groups.used]); if (F_status_is_error(status)) { - controller_main_print_rule_error(&global->error, cache->action, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, F_false); + controller_print_rule_error(global->error, cache->action, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, F_false); break; } @@ -468,21 +549,21 @@ extern "C" { cache->action.line_action = ++cache->action.line_item; - controller_main_print_rule_item_error(global->error, cache->action, F_false, F_status_set_fine(status)); + controller_print_rule_item_error(global->error, cache->action, F_false, F_status_set_fine(status)); continue; } rule->has |= controller_rule_has_cgroup_d; - controller_main_print_rule_setting_read_values(global, controller_cgroup_s, i, cache); + controller_print_rule_setting_read_values(global, controller_cgroup_s, i, cache); continue; } if (type == controller_rule_setting_type_limit_e) { if (cache->content_actions.array[i].used != 3) { - controller_main_print_rule_setting_read_error(&global->main->program.error, "requires three Content", i, line_item, global->thread, cache); + controller_print_rule_setting_read_error(&global->main->program.error, "requires three Content", i, line_item, global->thread, cache); if (F_status_is_error_not(status_return)) { status_return = F_status_set_error(F_valid_not); @@ -554,7 +635,7 @@ extern "C" { fl_print_format(f_string_format_Q_single_s.string, global->main->program.error.to, global->main->program.error.notable, cache->action.name_action, global->main->program.error.notable); fl_print_format(f_string_format_sentence_end_quote_s.string, global->main->program.error.to, global->main->program.error.context, global->main->program.error.context, f_string_eol_s); - controller_main_print_rule_error_cache(&global->error, &cache->action, F_true); + controller_print_rule_error_cache(global->error, cache->action, F_true); controller_unlock_print_flush(global->main->program.error.to, global->thread); } @@ -581,7 +662,7 @@ extern "C" { fl_print_format("%r%[%QThe resource limit type is already specified%]%r", global->main->program.error.to, f_string_eol_s, global->main->program.error.context, global->main->program.error.prefix, global->main->program.error.context, f_string_eol_s); - controller_main_print_rule_error_cache(&global->error, cache->action, F_false); + controller_print_rule_error_cache(global->error, cache->action, F_false); controller_unlock_print_flush(global->main->program.error.to, global->thread); } @@ -599,7 +680,7 @@ extern "C" { status = f_memory_array_increase(controller_allocation_small_d, sizeof(f_limit_set_t), (void **) &rule->limits.array, &rule->limits.used, &rule->limits.size); if (F_status_is_error(status)) { - controller_main_print_rule_error(&global->error, cache->action, F_status_set_fine(status), "f_memory_array_increase", F_true, F_false); + controller_print_rule_error(global->error, cache->action, F_status_set_fine(status), "f_memory_array_increase", F_true, F_false); if (F_status_set_fine(status) == F_memory_not) { status_return = status; @@ -617,7 +698,7 @@ extern "C" { cache->action.line_action = ++cache->action.line_item; - controller_main_print_rule_item_error(global->error, cache->action, F_false, F_status_set_fine(status)); + controller_print_rule_item_error(global->error, cache->action, F_false, F_status_set_fine(status)); continue; } @@ -629,7 +710,7 @@ extern "C" { status = fl_conversion_dynamic_partial_to_signed_detect(fl_conversion_data_base_10_c, cache->buffer_item, cache->content_actions.array[i].array[j], &number); if (F_status_set_fine(status) == F_number_positive) { - status = fl_conversion_dynamic_partial_to_signed_detect(fl_conversion_data_base_10_c, cache->buffer_item, controller_main_range_after_number_sign(cache->buffer_item, cache->content_actions.array[i].array[j]), &number); + status = fl_conversion_dynamic_partial_to_signed_detect(fl_conversion_data_base_10_c, cache->buffer_item, controller_range_after_number_sign(cache->buffer_item, cache->content_actions.array[i].array[j]), &number); // Restore error on parameter problem. if (F_status_set_fine(status) == F_parameter) { @@ -642,13 +723,13 @@ extern "C" { if (status == F_data_not || status == F_number || status == F_number_overflow || status == F_number_underflow || status == F_number_negative || status == F_number_positive || status == F_number_decimal) { if (status == F_number_underflow) { - controller_main_print_rule_setting_read_error_with_range(&global->main->program.error, " has an unsupported number", cache->content_actions.array[i].array[j], ", the number is too small for this system", i, line_item, global->thread, cache); + controller_print_rule_setting_read_error_with_range(&global->main->program.error, " has an unsupported number", cache->content_actions.array[i].array[j], ", the number is too small for this system", i, line_item, global->thread, cache); } else if (status == F_number_overflow) { - controller_main_print_rule_setting_read_error_with_range(&global->main->program.error, " has an unsupported number", cache->content_actions.array[i].array[j], ", the number is too large for this system", i, line_item, global->thread, cache); + controller_print_rule_setting_read_error_with_range(&global->main->program.error, " has an unsupported number", cache->content_actions.array[i].array[j], ", the number is too large for this system", i, line_item, global->thread, cache); } else { - controller_main_print_rule_setting_read_error_with_range(&global->main->program.error, " has an unsupported number", cache->content_actions.array[i].array[j], ", only whole numbers are allowed for a resource limit value", i, line_item, global->thread, cache); + controller_print_rule_setting_read_error_with_range(&global->main->program.error, " has an unsupported number", cache->content_actions.array[i].array[j], ", only whole numbers are allowed for a resource limit value", i, line_item, global->thread, cache); } status = F_status_set_error(F_valid_not); @@ -658,7 +739,7 @@ extern "C" { } } else { - controller_main_print_rule_error(&global->error, cache->action, F_status_set_fine(status), "fl_conversion_dynamic_partial_to_signed_detect", F_true, F_false); + controller_print_rule_error(global->error, cache->action, F_status_set_fine(status), "fl_conversion_dynamic_partial_to_signed_detect", F_true, F_false); status = F_status_set_error(status); @@ -682,7 +763,7 @@ extern "C" { rule->limits.array[rule->limits.used++].type = type; - controller_main_print_rule_setting_read_values(global, controller_limit_s, i, cache); + controller_print_rule_setting_read_values(global, controller_limit_s, i, cache); continue; } @@ -700,7 +781,7 @@ extern "C" { } if (setting_value->used || !cache->content_actions.array[i].used) { - controller_main_print_rule_setting_read_error(&global->main->program.error, "requires one or more Content", i, line_item, global->thread, cache); + controller_print_rule_setting_read_error(&global->main->program.error, "requires one or more Content", i, line_item, global->thread, cache); if (F_status_is_error_not(status_return)) { status_return = F_status_set_error(F_valid_not); @@ -750,7 +831,7 @@ extern "C" { cache->action.line_action = ++cache->action.line_item; - controller_main_print_rule_item_error(global->error, cache->action, F_false, F_status_set_fine(status)); + controller_print_rule_item_error(global->error, cache->action, F_false, F_status_set_fine(status)); continue; } @@ -775,7 +856,7 @@ extern "C" { fl_print_format(f_string_format_Q_single_s.string, global->main->program.error.to, global->main->program.error.notable, *setting_value, global->main->program.error.notable); fl_print_format("%[', there must be at least 1 graph character.%]%r", global->main->program.error.to, global->main->program.error.context, global->main->program.error.context, f_string_eol_s); - controller_main_print_rule_error_cache(&global->error, cache->action, F_false); + controller_print_rule_error_cache(global->error, cache->action, F_false); controller_unlock_print_flush(global->main->program.error.to, global->thread); } @@ -787,13 +868,13 @@ extern "C" { else { // This function should only return F_complete_not_utf on error. - controller_main_print_rule_error(&global->error, cache->action, F_complete_not_utf, "controller_validate_has_graph", F_true, F_false); + controller_print_rule_error(global->error, cache->action, F_complete_not_utf, "controller_validate_has_graph", F_true, F_false); if (F_status_is_error_not(status_return)) { status_return = status; } - controller_main_print_rule_item_error(global->error, cache->action, F_false, F_status_set_fine(status)); + controller_print_rule_item_error(global->error, cache->action, F_false, F_status_set_fine(status)); } setting_value->used = 0; @@ -801,13 +882,13 @@ extern "C" { continue; } - controller_main_print_rule_setting_read_value(global, type == controller_rule_setting_type_name_e ? controller_name_s : controller_engine_s, f_string_empty_s, *setting_value, 0); + controller_print_rule_setting_read_value(global, type == controller_rule_setting_type_name_e ? controller_name_s : controller_engine_s, f_string_empty_s, *setting_value, 0); } else if (type == controller_rule_setting_type_path_e) { status = f_string_dynamic_partial_append_nulless(cache->buffer_item, cache->content_actions.array[i].array[0], setting_value); if (F_status_is_error(status)) { - controller_main_print_rule_error(&global->error, cache->action, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, F_false); + controller_print_rule_error(global->error, cache->action, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, F_false); if (F_status_set_fine(status) == F_memory_not) { status_return = status; @@ -827,12 +908,12 @@ extern "C" { cache->action.line_action = ++cache->action.line_item; - controller_main_print_rule_item_error(global->error, cache->action, F_false, F_status_set_fine(status)); + controller_print_rule_item_error(global->error, cache->action, F_false, F_status_set_fine(status)); continue; } - controller_main_print_rule_setting_read_value(global, controller_path_s, f_string_empty_s, *setting_value, 0); + controller_print_rule_setting_read_value(global, controller_path_s, f_string_empty_s, *setting_value, 0); } continue; @@ -840,7 +921,7 @@ extern "C" { if (type == controller_rule_setting_type_scheduler_e) { if (cache->content_actions.array[i].used < 1 || cache->content_actions.array[i].used > 2 || rule->has & controller_rule_has_scheduler_d) { - controller_main_print_rule_setting_read_error(&global->main->program.error, "requires either one or two Content", i, line_item, global->thread, cache); + controller_print_rule_setting_read_error(&global->main->program.error, "requires either one or two Content", i, line_item, global->thread, cache); if (F_status_is_error_not(status_return)) { status_return = F_status_set_error(F_valid_not); @@ -874,7 +955,7 @@ extern "C" { rule->scheduler.priority = 49; } else { - controller_main_print_rule_setting_read_error_with_range(&global->main->program.error, " has an unknown scheduler", cache->content_actions.array[i].array[0], "", i, line_item, global->thread, cache); + controller_print_rule_setting_read_error_with_range(&global->main->program.error, " has an unknown scheduler", cache->content_actions.array[i].array[0], "", i, line_item, global->thread, cache); if (F_status_is_error_not(status_return)) { status_return = F_status_set_error(F_valid_not); @@ -891,7 +972,7 @@ extern "C" { status = fl_conversion_dynamic_partial_to_signed_detect(fl_conversion_data_base_10_c, cache->buffer_item, cache->content_actions.array[i].array[1], &number); if (F_status_set_fine(status) == F_number_positive) { - status = fl_conversion_dynamic_partial_to_signed_detect(fl_conversion_data_base_10_c, cache->buffer_item, controller_main_range_after_number_sign(cache->buffer_item, cache->content_actions.array[i].array[1]), &number); + status = fl_conversion_dynamic_partial_to_signed_detect(fl_conversion_data_base_10_c, cache->buffer_item, controller_range_after_number_sign(cache->buffer_item, cache->content_actions.array[i].array[1]), &number); // Restore error on parameter problem. if (F_status_set_fine(status) == F_parameter) { @@ -928,7 +1009,7 @@ extern "C" { fl_print_format(" allowed for the designated scheduler.%]%r", global->main->program.error.to, global->main->program.error.context, global->main->program.error.context, f_string_eol_s); - controller_main_print_rule_error_cache(&global->error, cache->action, F_false); + controller_print_rule_error_cache(global->error, cache->action, F_false); controller_unlock_print_flush(global->main->program.error.to, global->thread); } @@ -938,7 +1019,7 @@ extern "C" { } } else { - controller_main_print_rule_error(&global->error, cache->action, status, "fl_conversion_dynamic_partial_to_signed_detect", F_true, F_false); + controller_print_rule_error(global->error, cache->action, status, "fl_conversion_dynamic_partial_to_signed_detect", F_true, F_false); status = F_status_set_error(status); if (F_status_is_error_not(status_return)) { @@ -954,14 +1035,14 @@ extern "C" { rule->has |= controller_rule_has_scheduler_d; - controller_main_print_rule_setting_read_values(global, controller_scheduler_s, i, cache); + controller_print_rule_setting_read_values(global, controller_scheduler_s, i, cache); continue; } if (type == controller_rule_setting_type_timeout_e) { if (cache->content_actions.array[i].used != 2) { - controller_main_print_rule_setting_read_error(&global->main->program.error, "requires exactly two Content", i, line_item, global->thread, cache); + controller_print_rule_setting_read_error(&global->main->program.error, "requires exactly two Content", i, line_item, global->thread, cache); if (F_status_is_error_not(status_return)) { status_return = F_status_set_error(F_valid_not); @@ -996,7 +1077,7 @@ extern "C" { fl_print_format(f_string_format_Q_range_single_s.string, global->main->program.error.to, global->main->program.error.notable, cache->buffer_item, cache->content_actions.array[i].array[0], global->main->program.error.notable); fl_print_format("%[' but only supports %r, %r, and %r.%]%r", global->main->program.error.to, global->main->program.error.context, controller_kill_s, controller_start_s, controller_stop_s, global->main->program.error.context, f_string_eol_s); - controller_main_print_rule_error_cache(&global->error, cache->action, F_false); + controller_print_rule_error_cache(global->error, cache->action, F_false); controller_unlock_print_flush(global->main->program.error.to, global->thread); } @@ -1013,7 +1094,7 @@ extern "C" { status = fl_conversion_dynamic_partial_to_unsigned_detect(fl_conversion_data_base_10_c, cache->buffer_item, cache->content_actions.array[i].array[1], &number); if (F_status_set_fine(status) == F_number_positive) { - status = fl_conversion_dynamic_partial_to_unsigned_detect(fl_conversion_data_base_10_c, cache->buffer_item, controller_main_range_after_number_sign(cache->buffer_item, cache->content_actions.array[i].array[1]), &number); + status = fl_conversion_dynamic_partial_to_unsigned_detect(fl_conversion_data_base_10_c, cache->buffer_item, controller_range_after_number_sign(cache->buffer_item, cache->content_actions.array[i].array[1]), &number); // Restore error on parameter problem. if (F_status_set_fine(status) == F_parameter) { @@ -1025,10 +1106,10 @@ extern "C" { status = F_status_set_fine(status); if (status == F_number_overflow) { - controller_main_print_rule_setting_read_error_with_range(&global->main->program.error, " has an unsupported number", cache->content_actions.array[i].array[1], ", the number is too large for this system", i, line_item, global->thread, cache); + controller_print_rule_setting_read_error_with_range(&global->main->program.error, " has an unsupported number", cache->content_actions.array[i].array[1], ", the number is too large for this system", i, line_item, global->thread, cache); } else if (status == F_data_not || status == F_number || status == F_number_underflow || status == F_number_negative || status == F_number_positive || status == F_number_decimal) { - controller_main_print_rule_setting_read_error_with_range(&global->main->program.error, " has an invalid number", cache->content_actions.array[i].array[1], ", only positive whole numbers are allowed", i, line_item, global->thread, cache); + controller_print_rule_setting_read_error_with_range(&global->main->program.error, " has an invalid number", cache->content_actions.array[i].array[1], ", only positive whole numbers are allowed", i, line_item, global->thread, cache); } else { @@ -1038,7 +1119,7 @@ extern "C" { cache->action.line_action = ++cache->action.line_item; - controller_main_print_rule_error(&global->error, cache->action, status, "fl_conversion_dynamic_partial_to_signed_detect", F_true, F_false); + controller_print_rule_error(global->error, cache->action, status, "fl_conversion_dynamic_partial_to_signed_detect", F_true, F_false); } if (F_status_is_error_not(status_return)) { @@ -1071,12 +1152,12 @@ extern "C" { status = f_rip_dynamic_partial_nulless(cache->buffer_item, cache->content_actions.array[i].array[1], &cache->action.generic); if (F_status_is_error(status)) { - controller_main_print_error_status(&global->main->program.error, macro_controller_f(f_rip_dynamic_partial_nulless), F_status_set_fine(status)); + controller_print_error_status(&global->main->program.error, macro_controller_f(f_rip_dynamic_partial_nulless), F_status_set_fine(status)); break; } - controller_main_print_rule_setting_read_value(global, controller_timeout_s, name_sub, cache->action.generic, 0); + controller_print_rule_setting_read_value(global, controller_timeout_s, name_sub, cache->action.generic, 0); } } @@ -1085,7 +1166,7 @@ extern "C" { if (type == controller_rule_setting_type_capability_e || type == controller_rule_setting_type_nice_e || type == controller_rule_setting_type_user_e) { if (cache->content_actions.array[i].used != 1 || type == controller_rule_setting_type_capability_e && rule->capability || type == controller_rule_setting_type_group_e && (rule->has & controller_rule_has_group_d) || type == controller_rule_setting_type_nice_e && (rule->has & controller_rule_has_nice_d) || type == controller_rule_setting_type_user_e && (rule->has & controller_rule_has_user_d)) { - controller_main_print_rule_setting_read_error(&global->main->program.error, "requires exactly one Content", i, line_item, global->thread, cache); + controller_print_rule_setting_read_error(&global->main->program.error, "requires exactly one Content", i, line_item, global->thread, cache); if (F_status_is_error_not(status_return)) { status_return = F_status_set_error(F_valid_not); @@ -1109,9 +1190,9 @@ extern "C" { controller_lock_print(global->main->program.error.to, global->thread); - controller_main_print_rule_error(&global->error, cache->action, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, F_false); + controller_print_rule_error(global->error, cache->action, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, F_false); - controller_main_print_rule_error_cache(&global->error, cache->action, F_false); + controller_print_rule_error_cache(global->error, cache->action, F_false); controller_unlock_print_flush(global->main->program.error.to, global->thread); @@ -1139,9 +1220,9 @@ extern "C" { controller_lock_print(global->main->program.error.to, global->thread); - controller_main_print_rule_error(&global->error, cache->action, F_status_set_fine(status), "f_capability_from_text", F_true, F_false); + controller_print_rule_error(global->error, cache->action, F_status_set_fine(status), "f_capability_from_text", F_true, F_false); - controller_main_print_rule_error_cache(&global->error, cache->action, F_false); + controller_print_rule_error_cache(global->error, cache->action, F_false); controller_unlock_print_flush(global->main->program.error.to, global->thread); @@ -1150,7 +1231,7 @@ extern "C" { break; } - controller_main_print_rule_setting_read_error(&global->main->program.error, "failed to process the capabilities", i, line_item, global->thread, cache); + controller_print_rule_setting_read_error(&global->main->program.error, "failed to process the capabilities", i, line_item, global->thread, cache); if (F_status_is_error_not(status_return)) { status_return = F_status_set_error(F_valid_not); @@ -1159,7 +1240,7 @@ extern "C" { continue; } - controller_main_print_rule_setting_read_value(global, controller_capability_s, f_string_empty_s, cache->action.generic, 0); + controller_print_rule_setting_read_value(global, controller_capability_s, f_string_empty_s, cache->action.generic, 0); } else if (type == controller_rule_setting_type_nice_e) { f_number_signed_t number = 0; @@ -1167,7 +1248,7 @@ extern "C" { status = fl_conversion_dynamic_partial_to_signed_detect(fl_conversion_data_base_10_c, cache->buffer_item, cache->content_actions.array[i].array[0], &number); if (F_status_set_fine(status) == F_number_positive) { - status = fl_conversion_dynamic_partial_to_signed_detect(fl_conversion_data_base_10_c, cache->buffer_item, controller_main_range_after_number_sign(cache->buffer_item, cache->content_actions.array[i].array[0]), &number); + status = fl_conversion_dynamic_partial_to_signed_detect(fl_conversion_data_base_10_c, cache->buffer_item, controller_range_after_number_sign(cache->buffer_item, cache->content_actions.array[i].array[0]), &number); // Restore error on parameter problem. if (F_status_set_fine(status) == F_parameter) { @@ -1197,7 +1278,7 @@ extern "C" { fl_print_format("%[19%]", global->main->program.error.to, global->main->program.error.notable, global->main->program.error.notable); fl_print_format(" %[are allowed.%]%r", global->main->program.error.to, global->main->program.error.context, global->main->program.error.context, f_string_eol_s); - controller_main_print_rule_error_cache(&global->error, cache->action, F_false); + controller_print_rule_error_cache(global->error, cache->action, F_false); controller_unlock_print_flush(global->main->program.error.to, global->thread); } @@ -1207,7 +1288,7 @@ extern "C" { } } else { - controller_main_print_rule_error(&global->error, cache->action, status, "fl_conversion_dynamic_partial_to_signed_detect", F_true, F_false); + controller_print_rule_error(global->error, cache->action, status, "fl_conversion_dynamic_partial_to_signed_detect", F_true, F_false); status = F_status_set_error(status); if (F_status_is_error_not(status_return)) { @@ -1234,9 +1315,9 @@ extern "C" { controller_lock_print(global->main->program.error.to, global->thread); - controller_main_print_rule_error(&global->error, cache->action, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, F_false); + controller_print_rule_error(global->error, cache->action, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, F_false); - controller_main_print_rule_error_cache(&global->error, cache->action, F_false); + controller_print_rule_error_cache(global->error, cache->action, F_false); controller_unlock_print_flush(global->main->program.error.to, global->thread); @@ -1252,7 +1333,7 @@ extern "C" { } if (F_status_is_error_not(status)) { - controller_main_print_rule_setting_read_value(global, controller_nice_s, f_string_empty_s, cache->action.generic, 0); + controller_print_rule_setting_read_value(global, controller_nice_s, f_string_empty_s, cache->action.generic, 0); } } } @@ -1260,19 +1341,19 @@ extern "C" { else if (type == controller_rule_setting_type_user_e) { uid_t number = 0; - status = controller_get_id_user(cache->buffer_item, cache->content_actions.array[i].array[0], cache, &number); + status = controller_convert_user_id(cache->buffer_item, cache->content_actions.array[i].array[0], cache, &number); if (F_status_is_error(status)) { status = F_status_set_fine(status); if (status == F_exist_not) { - controller_main_print_rule_setting_read_error_with_range(&global->main->program.error, " has an invalid user", cache->content_actions.array[i].array[0], ", because no user was found by that name", i, line_item, global->thread, cache); + controller_print_rule_setting_read_error_with_range(&global->main->program.error, " has an invalid user", cache->content_actions.array[i].array[0], ", because no user was found by that name", i, line_item, global->thread, cache); } else if (status == F_number_too_large) { - controller_main_print_rule_setting_read_error_with_range(&global->main->program.error, " has an invalid user", cache->content_actions.array[i].array[0], ", because the given ID is too large", i, line_item, global->thread, cache); + controller_print_rule_setting_read_error_with_range(&global->main->program.error, " has an invalid user", cache->content_actions.array[i].array[0], ", because the given ID is too large", i, line_item, global->thread, cache); } else if (status == F_number) { - controller_main_print_rule_setting_read_error_with_range(&global->main->program.error, " has an invalid user", cache->content_actions.array[i].array[0], ", because the given ID is not a valid supported number", i, line_item, global->thread, cache); + controller_print_rule_setting_read_error_with_range(&global->main->program.error, " has an invalid user", cache->content_actions.array[i].array[0], ", because the given ID is not a valid supported number", i, line_item, global->thread, cache); } else { @@ -1282,9 +1363,9 @@ extern "C" { cache->action.line_action = ++cache->action.line_item; - controller_main_print_rule_error(&global->error, cache->action, status, "controller_get_id_user", F_true, F_false); + controller_print_rule_error(global->error, cache->action, status, "controller_convert_user_id", F_true, F_false); - controller_main_print_rule_item_error(global->error, cache->action, F_false, F_status_set_fine(status)); + controller_print_rule_item_error(global->error, cache->action, F_false, F_status_set_fine(status)); } if (F_status_is_error_not(status_return)) { @@ -1300,7 +1381,7 @@ extern "C" { status = f_string_dynamic_partial_append_nulless(cache->buffer_item, cache->content_actions.array[i].array[0], &cache->action.generic); - controller_main_print_rule_setting_read_value(global, controller_user_s, f_string_empty_s, cache->action.generic, 0); + controller_print_rule_setting_read_value(global, controller_user_s, f_string_empty_s, cache->action.generic, 0); } } } @@ -1310,7 +1391,7 @@ extern "C" { if (type == controller_rule_setting_type_group_e) { if (!cache->content_actions.array[i].used) { - controller_main_print_rule_setting_read_error(&global->main->program.error, "requires one or more Content", i, line_item, global->thread, cache); + controller_print_rule_setting_read_error(&global->main->program.error, "requires one or more Content", i, line_item, global->thread, cache); if (F_status_is_error_not(status_return)) { status_return = F_status_set_error(F_valid_not); @@ -1328,7 +1409,7 @@ extern "C" { status = f_memory_array_increase(controller_allocation_small_d, sizeof(f_int32s_t), (void **) &rule->groups.array, &rule->groups.used, &rule->groups.size); if (F_status_is_error(status)) { - controller_main_print_rule_error(&global->error, cache->action, F_status_set_fine(status), "f_memory_array_increase", F_true, F_false); + controller_print_rule_error(global->error, cache->action, F_status_set_fine(status), "f_memory_array_increase", F_true, F_false); if (F_status_set_fine(status) == F_memory_not) { status_return = status; @@ -1346,24 +1427,24 @@ extern "C" { cache->action.line_action = ++cache->action.line_item; - controller_main_print_rule_item_error(global->error, cache->action, F_false, F_status_set_fine(status)); + controller_print_rule_item_error(global->error, cache->action, F_false, F_status_set_fine(status)); continue; } - status = controller_get_id_group(cache->buffer_item, cache->content_actions.array[i].array[j], cache, &number); + status = controller_convert_group_id(cache->buffer_item, cache->content_actions.array[i].array[j], cache, &number); if (F_status_is_error(status)) { status = F_status_set_fine(status); if (status == F_exist_not) { - controller_main_print_rule_setting_read_error_with_range(&global->main->program.error, " has an invalid group", cache->content_actions.array[i].array[j], ", because no group was found by that name", i, line_item, global->thread, cache); + controller_print_rule_setting_read_error_with_range(&global->main->program.error, " has an invalid group", cache->content_actions.array[i].array[j], ", because no group was found by that name", i, line_item, global->thread, cache); } else if (status == F_number_too_large) { - controller_main_print_rule_setting_read_error_with_range(&global->main->program.error, " has an invalid group", cache->content_actions.array[i].array[j], ", because the given ID is too large", i, line_item, global->thread, cache); + controller_print_rule_setting_read_error_with_range(&global->main->program.error, " has an invalid group", cache->content_actions.array[i].array[j], ", because the given ID is too large", i, line_item, global->thread, cache); } else if (status == F_number) { - controller_main_print_rule_setting_read_error_with_range(&global->main->program.error, " has an invalid group", cache->content_actions.array[i].array[j], ", because the given ID is not a valid supported number", i, line_item, global->thread, cache); + controller_print_rule_setting_read_error_with_range(&global->main->program.error, " has an invalid group", cache->content_actions.array[i].array[j], ", because the given ID is not a valid supported number", i, line_item, global->thread, cache); } else { @@ -1373,9 +1454,9 @@ extern "C" { cache->action.line_action = ++cache->action.line_item; - controller_main_print_rule_error(&global->error, cache->action, status, "f_account_group_id_by_name", F_true, F_false); + controller_print_rule_error(global->error, cache->action, status, "f_account_group_id_by_name", F_true, F_false); - controller_main_print_rule_item_error(global->error, cache->action, F_false, F_status_set_fine(status)); + controller_print_rule_item_error(global->error, cache->action, F_false, F_status_set_fine(status)); } if (F_status_is_error_not(status_return)) { @@ -1393,7 +1474,7 @@ extern "C" { } } // for - controller_main_print_rule_setting_read_values(global, controller_group_s, i, cache); + controller_print_rule_setting_read_values(global, controller_group_s, i, cache); continue; } @@ -1406,7 +1487,7 @@ extern "C" { status = f_memory_array_increase(controller_allocation_small_d, sizeof(f_string_dynamic_t), (void **) &setting_values->array, &setting_values->used, &setting_values->size); if (F_status_is_error(status)) { - controller_main_print_rule_error(&global->error, cache->action, F_status_set_fine(status), "f_memory_array_increase", F_true, F_false); + controller_print_rule_error(global->error, cache->action, F_status_set_fine(status), "f_memory_array_increase", F_true, F_false); if (F_status_set_fine(status) == F_memory_not) { status_return = status; @@ -1424,7 +1505,7 @@ extern "C" { cache->action.line_action = ++cache->action.line_item; - controller_main_print_rule_item_error(global->error, cache->action, F_false, F_status_set_fine(status)); + controller_print_rule_item_error(global->error, cache->action, F_false, F_status_set_fine(status)); continue; } @@ -1434,7 +1515,7 @@ extern "C" { status = f_string_dynamic_partial_append_nulless(cache->buffer_item, cache->content_actions.array[i].array[j], &setting_values->array[setting_values->used]); if (F_status_is_error(status)) { - controller_main_print_rule_error(&global->error, cache->action, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, F_false); + controller_print_rule_error(global->error, cache->action, F_status_set_fine(status), "f_string_dynamic_partial_append_nulless", F_true, F_false); setting_values->array[setting_values->used].used = 0; @@ -1454,7 +1535,7 @@ extern "C" { cache->action.line_action = ++cache->action.line_item; - controller_main_print_rule_item_error(global->error, cache->action, F_false, F_status_set_fine(status)); + controller_print_rule_item_error(global->error, cache->action, F_false, F_status_set_fine(status)); continue; } @@ -1477,7 +1558,7 @@ extern "C" { fl_print_format(f_string_format_Q_single_s.string, global->main->program.error.to, global->main->program.error.notable, setting_values->array[setting_values->used], global->main->program.error.notable); fl_print_format(f_string_format_sentence_end_quote_s.string, global->main->program.error.to, global->main->program.error.context, global->main->program.error.context, f_string_eol_s); - controller_main_print_rule_error_cache(&global->error, cache->action, F_false); + controller_print_rule_error_cache(global->error, cache->action, F_false); controller_unlock_print_flush(global->main->program.error.to, global->thread); } @@ -1489,7 +1570,7 @@ extern "C" { else { // This function should only return F_complete_not_utf on error. - controller_main_print_rule_error(&global->error, cache->action, F_complete_not_utf, "controller_validate_environment_name", F_true, F_false); + controller_print_rule_error(global->error, cache->action, F_complete_not_utf, "controller_validate_environment_name", F_true, F_false); if (F_status_is_error_not(status_return)) { status_return = status; @@ -1498,7 +1579,7 @@ extern "C" { setting_values->array[setting_values->used].used = 0; - controller_main_print_rule_item_error(global->error, cache->action, F_false, F_status_set_fine(status)); + controller_print_rule_item_error(global->error, cache->action, F_false, F_status_set_fine(status)); continue; } @@ -1509,7 +1590,7 @@ extern "C" { rule->has |= controller_rule_has_environment_d; if (cache->content_actions.array[i].used) { - controller_main_print_rule_setting_read_values(global, controller_environment_s, i, cache); + controller_print_rule_setting_read_values(global, controller_environment_s, i, cache); } else { if (global->main->program.error.verbosity == f_console_verbosity_debug_e || (global->main->program.error.verbosity == f_console_verbosity_verbose_e && (global->main->program.parameters.array[controller_parameter_simulate_e].result & f_console_result_found_e))) { @@ -1526,7 +1607,7 @@ extern "C" { // The "on" Rule Setting. if (cache->content_actions.array[i].used != 4) { - controller_main_print_rule_setting_read_error(&global->main->program.error, "requires exactly four Content", i, line_item, global->thread, cache); + controller_print_rule_setting_read_error(&global->main->program.error, "requires exactly four Content", i, line_item, global->thread, cache); if (F_status_is_error_not(status_return)) { status_return = F_status_set_error(F_valid_not); @@ -1536,31 +1617,31 @@ extern "C" { } if (f_compare_dynamic_partial_string(controller_freeze_s.string, cache->buffer_item, controller_freeze_s.used, cache->content_actions.array[i].array[0]) == F_equal_to) { - action = controller_main_rule_action_type_freeze_e; + action = controller_rule_action_type_freeze_e; } else if (f_compare_dynamic_partial_string(controller_kill_s.string, cache->buffer_item, controller_kill_s.used, cache->content_actions.array[i].array[0]) == F_equal_to) { - action = controller_main_rule_action_type_kill_e; + action = controller_rule_action_type_kill_e; } else if (f_compare_dynamic_partial_string(controller_pause_s.string, cache->buffer_item, controller_pause_s.used, cache->content_actions.array[i].array[0]) == F_equal_to) { - action = controller_main_rule_action_type_pause_e; + action = controller_rule_action_type_pause_e; } else if (f_compare_dynamic_partial_string(controller_reload_s.string, cache->buffer_item, controller_reload_s.used, cache->content_actions.array[i].array[0]) == F_equal_to) { - action = controller_main_rule_action_type_reload_e; + action = controller_rule_action_type_reload_e; } else if (f_compare_dynamic_partial_string(controller_restart_s.string, cache->buffer_item, controller_restart_s.used, cache->content_actions.array[i].array[0]) == F_equal_to) { - action = controller_main_rule_action_type_restart_e; + action = controller_rule_action_type_restart_e; } else if (f_compare_dynamic_partial_string(controller_resume_s.string, cache->buffer_item, controller_resume_s.used, cache->content_actions.array[i].array[0]) == F_equal_to) { - action = controller_main_rule_action_type_resume_e; + action = controller_rule_action_type_resume_e; } else if (f_compare_dynamic_partial_string(controller_start_s.string, cache->buffer_item, controller_start_s.used, cache->content_actions.array[i].array[0]) == F_equal_to) { - action = controller_main_rule_action_type_start_e; + action = controller_rule_action_type_start_e; } else if (f_compare_dynamic_partial_string(controller_stop_s.string, cache->buffer_item, controller_stop_s.used, cache->content_actions.array[i].array[0]) == F_equal_to) { - action = controller_main_rule_action_type_stop_e; + action = controller_rule_action_type_stop_e; } else if (f_compare_dynamic_partial_string(controller_thaw_s.string, cache->buffer_item, controller_thaw_s.used, cache->content_actions.array[i].array[0]) == F_equal_to) { - action = controller_main_rule_action_type_thaw_e; + action = controller_rule_action_type_thaw_e; } else { if (global->main->program.error.verbosity > f_console_verbosity_quiet_e) { @@ -1580,7 +1661,7 @@ extern "C" { fl_print_format("%[' but only supports %r, %r, %r, %r, %r", global->main->program.error.to, global->main->program.error.context, controller_freeze_s, controller_kill_s, controller_pause_s, controller_reload_s, controller_restart_s); fl_print_format("%r, %r, %r, and %r.%]%r", global->main->program.error.to, controller_resume_s, controller_start_s, controller_stop_s, controller_thaw_s, global->main->program.error.context, f_string_eol_s); - controller_main_print_rule_error_cache(&global->error, cache->action, F_false); + controller_print_rule_error_cache(global->error, cache->action, F_false); controller_unlock_print_flush(global->main->program.error.to, global->thread); } @@ -1597,11 +1678,11 @@ extern "C" { } // for if (j == rule->ons.used) { - status = controller_rule_ons_increase(&rule->ons); + status = f_memory_array_increase(controller_allocation_small_d, sizeof(controller_rule_on_t), (void **) &rule->ons.array, &rule->ons.used, &rule->ons.size); } if (F_status_is_error(status)) { - controller_main_print_rule_error(&global->error, cache->action, F_status_set_fine(status), "controller_rule_ons_increase", F_true, F_false); + controller_print_rule_error(global->error, cache->action, F_status_set_fine(status), macro_controller_f(f_memory_array_increase), F_true, F_false); } else { if (f_compare_dynamic_partial_string(controller_need_s.string, cache->buffer_item, controller_need_s.used, cache->content_actions.array[i].array[1]) == F_equal_to) { @@ -1628,7 +1709,7 @@ extern "C" { fl_print_format(f_string_format_Q_range_single_s.string, global->main->program.error.to, global->main->program.error.notable, cache->buffer_item, cache->content_actions.array[i].array[1], global->main->program.error.notable); fl_print_format("%[' but only supports %r, %r, and %r.%]%r", global->main->program.error.to, global->main->program.error.context, controller_need_s, controller_want_s, controller_wish_s, global->main->program.error.context, f_string_eol_s); - controller_main_print_rule_error_cache(&global->error, cache->action, F_false); + controller_print_rule_error_cache(global->error, cache->action, F_false); controller_unlock_print_flush(global->main->program.error.to, global->thread); } @@ -1643,7 +1724,7 @@ extern "C" { status = f_memory_array_increase_by(controller_allocation_small_d, sizeof(f_string_dynamic_t), (void **) &setting_values->array, &setting_values->used, &setting_values->size); if (F_status_is_error(status)) { - controller_main_print_rule_error(&global->error, cache->action, F_status_set_fine(status), "f_memory_array_increase_by", F_true, F_false); + controller_print_rule_error(global->error, cache->action, F_status_set_fine(status), "f_memory_array_increase_by", F_true, F_false); } } @@ -1664,7 +1745,7 @@ extern "C" { cache->action.line_action = ++cache->action.line_item; - controller_main_print_rule_item_error(global->error, cache->action, F_false, F_status_set_fine(status)); + controller_print_rule_item_error(global->error, cache->action, F_false, F_status_set_fine(status)); continue; } @@ -1690,7 +1771,7 @@ extern "C" { cache->action.line_action = ++cache->action.line_item; - controller_main_print_rule_item_error(global->error, cache->action, F_false, F_status_set_fine(status)); + controller_print_rule_item_error(global->error, cache->action, F_false, F_status_set_fine(status)); continue; } @@ -1702,7 +1783,7 @@ extern "C" { if (F_status_is_error(status)) { setting_values->array[setting_values->used].used = 0; - controller_main_print_rule_error(&global->error, cache->action, F_status_set_fine(status), "f_file_name_base", F_true, F_false); + controller_print_rule_error(global->error, cache->action, F_status_set_fine(status), "f_file_name_base", F_true, F_false); if (F_status_set_fine(status) == F_memory_not) { status_return = status; @@ -1747,7 +1828,7 @@ extern "C" { return status_return; } -#endif // _di_controller_main_rule_setting_read_ +#endif // _di_controller_rule_setting_read_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/rule/setting.h b/sources/c/main/rule/setting.h index 09e9e91..a81c731 100644 --- a/sources/c/main/rule/setting.h +++ b/sources/c/main/rule/setting.h @@ -17,6 +17,34 @@ extern "C" { #endif /** + * Identify the rule item code the given name represents. + * + * @param item + * The string representing an rule action. + * + * @return + * The rule item type code on success. + * 0 if name is unknown. + */ +#ifndef _di_controller_rule_setting_limit_type_identify_ + extern uint8_t controller_rule_setting_limit_type_identify(const f_string_static_t item); +#endif // _di_controller_rule_setting_limit_type_identify_ + +/** + * Get a string representing the rule setting limit type. + * + * @param type + * The rule setting limit type code. + * + * @return + * The string with used > 0 on success. + * The string with used == 0 if no match was found. + */ +#ifndef _di_controller_rule_setting_limit_type_name_ + extern f_string_static_t controller_rule_setting_limit_type_name(const uint8_t type); +#endif // di_controller_rule_setting_limit_type_name_ + +/** * Read the content within the buffer, extracting all valid settings. * * This will perform additional FSS read functions as appropriate. @@ -57,9 +85,9 @@ extern "C" { * * @see controller_path_canonical_relative() */ -#ifndef _di_controller_main_rule_setting_read_ - extern f_status_t controller_main_rule_setting_read(controller_global_t * const global, const bool is_normal, controller_cache_t * const cache, controller_rule_t * const rule); -#endif // _di_controller_main_rule_setting_read_ +#ifndef _di_controller_rule_setting_read_ + extern f_status_t controller_rule_setting_read(controller_global_t * const global, const bool is_normal, controller_cache_t * const cache, controller_rule_t * const rule); +#endif // _di_controller_rule_setting_read_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/rule/validate.c b/sources/c/main/rule/validate.c index 8b62d91..0d91c33 100644 --- a/sources/c/main/rule/validate.c +++ b/sources/c/main/rule/validate.c @@ -4,23 +4,23 @@ extern "C" { #endif -#ifndef _di_controller_main_rule_validate_ - void controller_main_rule_validate(controller_global_t * const global, const controller_rule_t rule, const uint8_t action, const uint8_t options, controller_cache_t * const cache) { +#ifndef _di_controller_rule_validate_ + void controller_rule_validate(controller_global_t * const global, const controller_rule_t rule, const uint8_t action, const uint8_t options, controller_cache_t * const cache) { if (!global || !cache) return F_status_set_error(F_parameter); - controller_main_t * const main = global->main; + controller_t * const main = global->main; switch (action) { - case controller_main_rule_action_type_freeze_e: - case controller_main_rule_action_type_kill_e: - case controller_main_rule_action_type_pause_e: - case controller_main_rule_action_type_reload_e: - case controller_main_rule_action_type_restart_e: - case controller_main_rule_action_type_resume_e: - case controller_main_rule_action_type_start_e: - case controller_main_rule_action_type_stop_e: - case controller_main_rule_action_type_thaw_e: + case controller_rule_action_type_freeze_e: + case controller_rule_action_type_kill_e: + case controller_rule_action_type_pause_e: + case controller_rule_action_type_reload_e: + case controller_rule_action_type_restart_e: + case controller_rule_action_type_resume_e: + case controller_rule_action_type_start_e: + case controller_rule_action_type_stop_e: + case controller_rule_action_type_thaw_e: break; default: @@ -28,10 +28,10 @@ extern "C" { controller_lock_print(main->program.error.to, global->thread); fl_print_format("%r%[%QUnsupported action type '%]", main->program.error.to, f_string_eol_s, main->program.error.context, main->program.error.prefix, main->program.error.context); - fl_print_format(f_string_format_r_single_s.string, main->program.error.to, main->program.error.notable, controller_main_rule_action_type_name(action), main->program.error.notable); + fl_print_format(f_string_format_r_single_s.string, main->program.error.to, main->program.error.notable, controller_convert_rule_action_type_string(action), main->program.error.notable); fl_print_format("%[' while attempting to validate rule execution.%]%r", main->program.error.to, main->program.error.context, main->program.error.context, f_string_eol_s); - controller_main_print_rule_error_cache(&global->error, &cache->action, F_true); + controller_print_rule_error_cache(global->error, cache->action, F_true); controller_unlock_print_flush(main->program.error.to, global->thread); } @@ -64,7 +64,7 @@ extern "C" { if (rule.items.used) { fl_print_format("%rRule '", main->program.output.to, f_string_eol_s); fl_print_format("%[%Q%]' has no '", main->program.output.to, main->program.context.set.title, rule.name, main->program.context.set.title); - fl_print_format("%[%r%]' action to execute and would '", main->program.output.to, main->program.context.set.title, controller_main_rule_action_type_name(action), main->program.context.set.title); + fl_print_format("%[%r%]' action to execute and would '", main->program.output.to, main->program.context.set.title, controller_convert_rule_action_type_string(action), main->program.context.set.title); fl_print_format("%[%r%]' because it is '", main->program.output.to, main->program.context.set.important, options & controller_instance_option_require_e ? controller_fail_s : controller_succeed_s, main->program.context.set.important); fl_print_format("%[%r%]'.%r", main->program.output.to, main->program.context.set.important, options & controller_instance_option_require_e ? controller_required_s : controller_optional_s, main->program.context.set.important, f_string_eol_s); } @@ -261,31 +261,31 @@ extern "C" { { f_string_static_t action = f_string_static_t_initialize; - if (rule.ons.array[i].action == controller_main_rule_action_type_freeze_e) { + if (rule.ons.array[i].action == controller_rule_action_type_freeze_e) { action = controller_freeze_s; } - else if (rule.ons.array[i].action == controller_main_rule_action_type_kill_e) { + else if (rule.ons.array[i].action == controller_rule_action_type_kill_e) { action = controller_kill_s; } - else if (rule.ons.array[i].action == controller_main_rule_action_type_pause_e) { + else if (rule.ons.array[i].action == controller_rule_action_type_pause_e) { action = controller_pause_s; } - else if (rule.ons.array[i].action == controller_main_rule_action_type_reload_e) { + else if (rule.ons.array[i].action == controller_rule_action_type_reload_e) { action = controller_reload_s; } - else if (rule.ons.array[i].action == controller_main_rule_action_type_restart_e) { + else if (rule.ons.array[i].action == controller_rule_action_type_restart_e) { action = controller_restart_s; } - else if (rule.ons.array[i].action == controller_main_rule_action_type_resume_e) { + else if (rule.ons.array[i].action == controller_rule_action_type_resume_e) { action = controller_resume_s; } - else if (rule.ons.array[i].action == controller_main_rule_action_type_start_e) { + else if (rule.ons.array[i].action == controller_rule_action_type_start_e) { action = controller_start_s; } - else if (rule.ons.array[i].action == controller_main_rule_action_type_stop_e) { + else if (rule.ons.array[i].action == controller_rule_action_type_stop_e) { action = controller_stop_s; } - else if (rule.ons.array[i].action == controller_main_rule_action_type_thaw_e) { + else if (rule.ons.array[i].action == controller_rule_action_type_thaw_e) { action = controller_thaw_s; } @@ -326,7 +326,7 @@ extern "C" { // Items. if (rule.items.used) { - controller_main_rule_action_t *action = 0; + controller_rule_action_t *action = 0; controller_rule_item_t *item = 0; controller_rule_rerun_item_t *rerun_item = 0; @@ -369,7 +369,7 @@ extern "C" { action = &item->actions.array[j]; fl_print_format(" %[%r%] {%r", main->program.output.to, main->program.context.set.important, controller_action_s, main->program.context.set.important, f_string_eol_s); - fl_print_format(" %[%r%] %r%r", main->program.output.to, main->program.context.set.important, controller_type_s, main->program.context.set.important, controller_main_rule_action_type_name(action->type), f_string_eol_s); + fl_print_format(" %[%r%] %r%r", main->program.output.to, main->program.context.set.important, controller_type_s, main->program.context.set.important, controller_convert_rule_action_type_string(action->type), f_string_eol_s); if (item->type == controller_rule_item_type_script_e || item->type == controller_rule_item_type_utility_e) { fl_print_format(" %[%r%] {%r", main->program.output.to, main->program.context.set.important, controller_parameter_s, main->program.context.set.important, f_string_eol_s); @@ -422,7 +422,7 @@ extern "C" { // Rerun. fl_print_format(" %[%r%] {%r", main->program.output.to, main->program.context.set.important, controller_rerun_s, main->program.context.set.important, f_string_eol_s); - for (j = 0; j < controller_main_rule_action_execute_type__enum_size_e; ++j) { + for (j = 0; j < controller_rule_action_execute_type__enum_size_e; ++j) { for (k = 0; k < 2; ++k) { if (!k && (item->reruns[j].is & controller_rule_rerun_is_failure_d)) { @@ -438,39 +438,39 @@ extern "C" { fl_print_format(" %[", main->program.output.to, main->program.context.set.important); switch (j) { - case controller_main_rule_action_execute_type_freeze_e: + case controller_rule_action_execute_type_freeze_e: f_print_dynamic_raw(controller_freeze_s, main->program.output.to); break; - case controller_main_rule_action_execute_type_kill_e: + case controller_rule_action_execute_type_kill_e: f_print_dynamic_raw(controller_kill_s, main->program.output.to); break; - case controller_main_rule_action_execute_type_pause_e: + case controller_rule_action_execute_type_pause_e: f_print_dynamic_raw(controller_pause_s, main->program.output.to); break; - case controller_main_rule_action_execute_type_reload_e: + case controller_rule_action_execute_type_reload_e: f_print_dynamic_raw(controller_reload_s, main->program.output.to); break; - case controller_main_rule_action_execute_type_restart_e: + case controller_rule_action_execute_type_restart_e: f_print_dynamic_raw(controller_restart_s, main->program.output.to); break; - case controller_main_rule_action_execute_type_resume_e: + case controller_rule_action_execute_type_resume_e: f_print_dynamic_raw(controller_resume_s, main->program.output.to); break; - case controller_main_rule_action_execute_type_start_e: + case controller_rule_action_execute_type_start_e: f_print_dynamic_raw(controller_start_s, main->program.output.to); break; - case controller_main_rule_action_execute_type_stop_e: + case controller_rule_action_execute_type_stop_e: f_print_dynamic_raw(controller_stop_s, main->program.output.to); break; - case controller_main_rule_action_execute_type_thaw_e: + case controller_rule_action_execute_type_thaw_e: f_print_dynamic_raw(controller_thaw_s, main->program.output.to); break; @@ -498,7 +498,7 @@ extern "C" { controller_unlock_print_flush(main->program.output.to, global->thread); } -#endif // _di_controller_main_rule_validate_ +#endif // _di_controller_rule_validate_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/rule/validate.h b/sources/c/main/rule/validate.h index 7aa954c..1e15ddc 100644 --- a/sources/c/main/rule/validate.h +++ b/sources/c/main/rule/validate.h @@ -41,9 +41,9 @@ extern "C" { * @param cache * A structure for containing and caching relevant data. */ -#ifndef _di_controller_main_rule_validate_ - extern void controller_main_rule_validate(controller_global_t * const global, const controller_rule_t rule, const uint8_t action, const uint8_t options, controller_cache_t * const cache); -#endif // _di_controller_main_rule_validate_ +#ifndef _di_controller_rule_validate_ + extern void controller_rule_validate(controller_global_t * const global, const controller_rule_t rule, const uint8_t action, const uint8_t options, controller_cache_t * const cache); +#endif // _di_controller_rule_validate_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/rule/wait.c b/sources/c/main/rule/wait.c index aec9c57..bb08add 100644 --- a/sources/c/main/rule/wait.c +++ b/sources/c/main/rule/wait.c @@ -4,12 +4,12 @@ extern "C" { #endif -#ifndef _di_controller_main_rule_wait_all_ - f_status_t controller_main_rule_wait_all(controller_global_t * const global, const bool is_normal, const bool required) { +#ifndef _di_controller_rule_wait_all_ + f_status_t controller_rule_wait_all(controller_global_t * const global, const bool is_normal, const bool required) { if (!global) return F_status_set_error(F_parameter); - f_status_t status_lock = controller_main_lock_read(is_normal, global->thread, &global->thread->lock.instance); + f_status_t status_lock = controller_lock_read(is_normal, global->thread, &global->thread->lock.instance); if (F_status_is_error(status_lock)) { controller_lock_print_error_critical(&global->main->program.error, F_status_set_fine(status_lock), F_true, global->thread); @@ -33,7 +33,7 @@ extern "C" { // Build a list of what to wait for so that anything new after this point will not be waited for. const f_number_unsigned_t instance_total = global->thread->instances.used; - controller_data_t *instance_list[instance_total]; + controller_instance_t *instance_list[instance_total]; for (; i < instance_total; ++i) { instance_list[i] = global->thread->instances.array[i]; @@ -43,10 +43,10 @@ extern "C" { for (i = 0; i < instance_total; ++i) { - if (!controller_main_thread_is_enabled(is_normal, global->thread)) break; + if (!controller_thread_is_enabled(is_normal, global->thread)) break; // Re-establish global instance read lock to wait for or protect from the cleanup thread while checking the read instance. - status_lock = controller_main_lock_read(is_normal, global->thread, &global->thread->lock.instance); + status_lock = controller_lock_read(is_normal, global->thread, &global->thread->lock.instance); if (F_status_is_error(status_lock)) break; if (!instance_list[i]) { @@ -55,7 +55,7 @@ extern "C" { continue; } - status_lock = controller_main_lock_read(is_normal, global->thread, &instance_list[i]->active); + status_lock = controller_lock_read(is_normal, global->thread, &instance_list[i]->active); if (F_status_is_error(status_lock)) { f_thread_unlock(&global->thread->lock.instance); @@ -66,7 +66,7 @@ extern "C" { // Once the active lock is obtained, then the main instance read lock can be safely released. f_thread_unlock(&global->thread->lock.instance); - status_lock = controller_main_lock_read(is_normal, global->thread, &instance_list[i]->lock); + status_lock = controller_lock_read(is_normal, global->thread, &instance_list[i]->lock); if (F_status_is_error(status_lock)) { f_thread_unlock(&instance_list[i]->active); @@ -88,7 +88,7 @@ extern "C" { if (instance_list[i]->state == controller_instance_state_done_e) { f_thread_unlock(&instance_list[i]->lock); - status_lock = controller_main_lock_write(is_normal, global->thread, &instance_list[i]->lock); + status_lock = controller_lock_write(is_normal, global->thread, &instance_list[i]->lock); if (F_status_is_error(status_lock)) { controller_lock_print_error_critical(&global->main->program.error, F_status_set_fine(status_lock), F_false, global->thread); @@ -102,7 +102,7 @@ extern "C" { f_thread_unlock(&instance_list[i]->active); if (f_thread_lock_write_try(&instance_list[i]->active) == F_okay) { - controller_main_thread_join(&instance_list[i]->id_thread); + controller_thread_join(&instance_list[i]->id_thread); instance_list[i]->state = controller_instance_state_idle_e; @@ -113,7 +113,7 @@ extern "C" { f_thread_mutex_unlock(&instance_list[i]->wait_lock); } - status_lock = controller_main_lock_read(is_normal, global->thread, &instance_list[i]->active); + status_lock = controller_lock_read(is_normal, global->thread, &instance_list[i]->active); if (F_status_is_error(status_lock)) { f_thread_unlock(&instance_list[i]->lock); @@ -124,12 +124,12 @@ extern "C" { f_thread_unlock(&instance_list[i]->lock); - status_lock = controller_main_lock_read(is_normal, global->thread, &instance_list[i]->lock); + status_lock = controller_lock_read(is_normal, global->thread, &instance_list[i]->lock); if (F_status_is_error(status_lock)) break; } if (instance_list[i]->options & controller_instance_option_require_e) { - if (controller_main_rule_status_is_error(instance_list[i]->action, instance_list[i]->rule)) { + if (controller_rule_status_is_error(instance_list[i]->action, instance_list[i]->rule)) { status = F_status_set_error(F_require); f_thread_unlock(&instance_list[i]->lock); @@ -137,7 +137,7 @@ extern "C" { break; } - else if (controller_main_rule_status_is_available(instance_list[i]->action, instance_list[i]->rule)) { + else if (controller_rule_status_is_available(instance_list[i]->action, instance_list[i]->rule)) { required_not_run = F_true; } } @@ -150,10 +150,10 @@ extern "C" { continue; } - if (!controller_main_rule_status_is_error(instance_list[i]->action, instance_list[i]->rule) && (instance_list[i]->state == controller_instance_state_active_e || instance_list[i]->state == controller_instance_state_busy_e)) { + if (!controller_rule_status_is_error(instance_list[i]->action, instance_list[i]->rule) && (instance_list[i]->state == controller_instance_state_active_e || instance_list[i]->state == controller_instance_state_busy_e)) { f_thread_unlock(&instance_list[i]->lock); - status = controller_instance_wait(global, instance_list[i]); + status = controller_instance_wait(instance_list[i]); if (F_status_set_fine(status) == F_interrupt) { f_thread_unlock(&instance_list[i]->active); @@ -161,7 +161,7 @@ extern "C" { break; } - status_lock = controller_main_lock_read(is_normal, global->thread, &instance_list[i]->lock); + status_lock = controller_lock_read(is_normal, global->thread, &instance_list[i]->lock); if (F_status_is_error(status_lock)) { f_thread_unlock(&instance_list[i]->active); @@ -172,7 +172,7 @@ extern "C" { if ((instance_list[i]->options & controller_instance_option_require_e)) { f_thread_unlock(&instance_list[i]->lock); - if (controller_main_rule_status_is_error(instance_list[i]->action, instance_list[i]->rule)) { + if (controller_rule_status_is_error(instance_list[i]->action, instance_list[i]->rule)) { status = F_status_set_error(F_require); f_thread_unlock(&instance_list[i]->active); @@ -199,22 +199,22 @@ extern "C" { return status_lock; } - if (!controller_main_thread_is_enabled(is_normal, global->thread)) return F_status_set_error(F_interrupt); + if (!controller_thread_is_enabled(is_normal, global->thread)) return F_status_set_error(F_interrupt); if (F_status_set_fine(status) == F_require) return status; if (required_not_run) return F_require; return F_okay; } -#endif // _di_controller_main_rule_wait_all_ +#endif // _di_controller_rule_wait_all_ -#ifndef _di_controller_main_rule_wait_all_instance_type_ - f_status_t controller_main_rule_wait_all_instance_type(controller_global_t * const global, const uint8_t type, const bool required) { +#ifndef _di_controller_rule_wait_all_instance_type_ + f_status_t controller_rule_wait_all_instance_type(controller_global_t * const global, const uint8_t type, const bool required) { if (!global) return F_status_set_error(F_parameter); - return controller_main_rule_wait_all(global, type != controller_instance_type_exit_e, required); + return controller_rule_wait_all(global, type != controller_instance_type_exit_e, required); } -#endif // _di_controller_main_rule_wait_all_instance_type_ +#endif // _di_controller_rule_wait_all_instance_type_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/rule/wait.h b/sources/c/main/rule/wait.h index 1fe60ee..f5e4e7f 100644 --- a/sources/c/main/rule/wait.h +++ b/sources/c/main/rule/wait.h @@ -41,9 +41,9 @@ extern "C" { * F_interrupt (with error bit) on receiving a process signal, such as an interrupt signal. * F_require (with error bit set) if a required process is in failed status when required is TRUE. */ -#ifndef _di_controller_main_rule_wait_all_ - extern f_status_t controller_main_rule_wait_all(controller_global_t * const global, const bool is_normal, const bool required); -#endif // _di_controller_main_rule_wait_all_ +#ifndef _di_controller_rule_wait_all_ + extern f_status_t controller_rule_wait_all(controller_global_t * const global, const bool is_normal, const bool required); +#endif // _di_controller_rule_wait_all_ /** * Wait until all currently running Rule processes are complete for some process type. @@ -61,15 +61,15 @@ extern "C" { * If FALSE, process all waits, returning normally. * * @return - * Success from controller_main_rule_wait_all(). + * Success from controller_rule_wait_all(). * - * Errors (with error bit) from: controller_main_rule_wait_all(). + * Errors (with error bit) from: controller_rule_wait_all(). * - * @see controller_main_rule_wait_all() + * @see controller_rule_wait_all() */ -#ifndef _di_controller_main_rule_wait_all_instance_type_ - extern f_status_t controller_main_rule_wait_all_instance_type(controller_global_t * const global, const uint8_t type, const bool required); -#endif // _di_controller_main_rule_wait_all_instance_type_ +#ifndef _di_controller_rule_wait_all_instance_type_ + extern f_status_t controller_rule_wait_all_instance_type(controller_global_t * const global, const uint8_t type, const bool required); +#endif // _di_controller_rule_wait_all_instance_type_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/signal.c b/sources/c/main/signal.c index 1ecafde..5b3f5c6 100644 --- a/sources/c/main/signal.c +++ b/sources/c/main/signal.c @@ -4,12 +4,12 @@ extern "C" { #endif -#if !defined(_di_controller_main_signal_check_) && defined(_di_thread_support_) - f_status_t controller_main_signal_check(controller_main_t * const main) { +#if !defined(_di_controller_signal_check_) && defined(_di_thread_support_) + f_status_t controller_signal_check(controller_t * const main) { if (!main || main->program.signal.id == -1) return F_false; - if (!((++main->program.signal_check) % controller_main_signal_check_d)) { + if (!((++main->program.signal_check) % controller_signal_check_d)) { if (fll_program_standard_signal_received(&main->program)) { fll_program_print_signal_received(&main->program.warning, main->program.signal_received); @@ -23,10 +23,10 @@ extern "C" { return F_false; } -#endif // !defined(_di_controller_main_signal_check_) && defined(_di_thread_support_) +#endif // !defined(_di_controller_signal_check_) && defined(_di_thread_support_) -#if !defined(_di_controller_main_signal_check_) && !defined(_di_thread_support_) - f_status_t controller_main_signal_check(controller_main_t * const main) { +#if !defined(_di_controller_signal_check_) && !defined(_di_thread_support_) + f_status_t controller_signal_check(controller_t * const main) { if (!main || main->program.signal.id == -1) return F_false; @@ -40,10 +40,10 @@ extern "C" { return F_false; } -#endif // !defined(_di_controller_main_signal_check_) && !defined(_di_thread_support_) +#endif // !defined(_di_controller_signal_check_) && !defined(_di_thread_support_) -#if !defined(_di_controller_main_signal_handler_) && !defined(_di_thread_support_) - void controller_main_signal_handler(controller_main_t * const main) { +#if !defined(_di_controller_signal_handler_) && !defined(_di_thread_support_) + void controller_signal_handler(controller_t * const main) { if (!main) return; @@ -104,7 +104,7 @@ extern "C" { main->program.signal_received = F_signal_abort; } } -#endif // !defined(_di_controller_main_signal_handler_) && !defined(_di_thread_support_) +#endif // !defined(_di_controller_signal_handler_) && !defined(_di_thread_support_) #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/signal.h b/sources/c/main/signal.h index 404caca..4b0577e 100644 --- a/sources/c/main/signal.h +++ b/sources/c/main/signal.h @@ -9,8 +9,8 @@ * * This is auto-included and should not need to be explicitly included. */ -#ifndef _controller_main_signal_h -#define _controller_main_signal_h +#ifndef _controller_signal_h +#define _controller_signal_h #ifdef __cplusplus extern "C" { @@ -28,7 +28,7 @@ extern "C" { * - F_signal_termination * * There is a threaded and a non-threaded version of this. - * The non-threaded version checks periodically using controller_main_signal_check_d and updates main->signal_check as needed. + * The non-threaded version checks periodically using controller_signal_check_d and updates main->signal_check as needed. * The threaded version checks the flag state which is set by a separate thread that is blocking until signal is received. * * @param main @@ -40,13 +40,13 @@ extern "C" { * F_true on signal received. * F_false otherwise. * - * @see controller_main_signal_handler() + * @see controller_signal_handler() * * @see fll_program_standard_signal_received() */ -#ifndef _di_controller_main_signal_check_ - extern f_status_t controller_main_signal_check(controller_main_t * const main); -#endif // _di_controller_main_signal_check_ +#ifndef _di_controller_signal_check_ + extern f_status_t controller_signal_check(controller_t * const main); +#endif // _di_controller_signal_check_ /** * Signal handler for signals/interrupts. @@ -75,12 +75,12 @@ extern "C" { * @see f_signal_open() * @see f_signal_wait() */ -#if !defined(_di_controller_main_signal_handler_) && !defined(_di_thread_support_) - extern void controller_main_signal_handler(controller_main_t * const main); -#endif // !defined(_di_controller_main_signal_handler_) && !defined(_di_thread_support_) +#if !defined(_di_controller_signal_handler_) && !defined(_di_thread_support_) + extern void controller_signal_handler(controller_t * const main); +#endif // !defined(_di_controller_signal_handler_) && !defined(_di_thread_support_) #ifdef __cplusplus } // extern "C" #endif -#endif // _controller_main_signal_h +#endif // _controller_signal_h diff --git a/sources/c/main/thread.c b/sources/c/main/thread.c index 0029c90..50d5086 100644 --- a/sources/c/main/thread.c +++ b/sources/c/main/thread.c @@ -4,8 +4,8 @@ extern "C" { #endif -#ifndef _di_controller_main_thread_detach_ - f_status_t controller_main_thread_detach(f_thread_id_t * const id) { +#ifndef _di_controller_thread_detach_ + f_status_t controller_thread_detach(f_thread_id_t * const id) { if (!id || !*id) return F_data_not; @@ -17,10 +17,10 @@ extern "C" { return status; } -#endif // _di_controller_main_thread_detach_ +#endif // _di_controller_thread_detach_ -#ifndef _di_controller_main_thread_join_ - f_status_t controller_main_thread_join(f_thread_id_t * const id) { +#ifndef _di_controller_thread_join_ + f_status_t controller_thread_join(f_thread_id_t * const id) { if (!id || !*id) return F_data_not; @@ -32,7 +32,7 @@ extern "C" { return status; } -#endif // _di_controller_main_thread_join_ +#endif // _di_controller_thread_join_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/thread.h b/sources/c/main/thread.h index b6b9b94..a3082cb 100644 --- a/sources/c/main/thread.h +++ b/sources/c/main/thread.h @@ -32,9 +32,9 @@ * * @see f_thread_detach() */ -#ifndef _di_controller_main_thread_detach_ - extern f_status_t controller_main_thread_detach(f_thread_id_t * const id); -#endif // _di_controller_main_thread_detach_ +#ifndef _di_controller_thread_detach_ + extern f_status_t controller_thread_detach(f_thread_id_t * const id); +#endif // _di_controller_thread_detach_ /*** * Join a thread, assigning id to NULL on success. @@ -54,9 +54,9 @@ * * @see f_thread_join() */ -#ifndef _di_controller_main_thread_join_ - extern f_status_t controller_main_thread_join(f_thread_id_t * const id); -#endif // _di_controller_main_thread_join_ +#ifndef _di_controller_thread_join_ + extern f_status_t controller_thread_join(f_thread_id_t * const id); +#endif // _di_controller_thread_join_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/thread/cleanup.c b/sources/c/main/thread/cleanup.c index 9db5b18..b00c783 100644 --- a/sources/c/main/thread/cleanup.c +++ b/sources/c/main/thread/cleanup.c @@ -4,8 +4,8 @@ extern "C" { #endif -#ifndef _di_controller_main_thread_cleanup_ - void * controller_main_thread_cleanup(void * const arguments) { +#ifndef _di_controller_thread_cleanup_ + void * controller_thread_cleanup(void * const arguments) { if (!arguments) return 0; @@ -15,9 +15,9 @@ extern "C" { if (global->thread->enabled != controller_thread_enabled_e) return 0; - const f_time_spec_t delay = controller_main_time_seconds(global->main->program.parameters.array[controller_parameter_simulate_e].result & f_console_result_found_e) - ? controller_main_thread_cleanup_interval_short_d - : controller_main_thread_cleanup_interval_long_d); + const f_time_spec_t delay = controller_time_seconds(global->main->program.parameters.array[controller_parameter_simulate_e].result & f_console_result_found_e) + ? controller_thread_cleanup_interval_short_d + : controller_thread_cleanup_interval_long_d); f_status_t status = F_okay; @@ -132,7 +132,7 @@ extern "C" { // De-allocate any rules in the space that is declared to be unused. if (i >= global->thread->instances.used) { - controller_main_rule_delete(&instance->rule); + controller_rule_delete(&instance->rule); } f_thread_unlock(&instance->active); @@ -144,7 +144,7 @@ extern "C" { return 0; } -#endif // _di_controller_main_thread_cleanup_ +#endif // _di_controller_thread_cleanup_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/thread/cleanup.h b/sources/c/main/thread/cleanup.h index aa29bd9..360bc9c 100644 --- a/sources/c/main/thread/cleanup.h +++ b/sources/c/main/thread/cleanup.h @@ -28,9 +28,9 @@ extern "C" { * @return * 0, always. */ -#ifndef _di_controller_main_thread_cleanup_ - extern void * controller_main_thread_cleanup(void * const arguments); -#endif // _di_controller_main_thread_cleanup_ +#ifndef _di_controller_thread_cleanup_ + extern void * controller_thread_cleanup(void * const arguments); +#endif // _di_controller_thread_cleanup_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/thread/control.c b/sources/c/main/thread/control.c index 39627fc..26ae38f 100644 --- a/sources/c/main/thread/control.c +++ b/sources/c/main/thread/control.c @@ -4,8 +4,8 @@ extern "C" { #endif -#ifndef _di_controller_main_thread_control_ - void * controller_main_thread_control(void * const arguments) { +#ifndef _di_controller_thread_control_ + void * controller_thread_control(void * const arguments) { if (!arguments) return 0; @@ -23,12 +23,12 @@ extern "C" { // It seems that this function doesn't return to the calling thread for a forked child process, even with the "return 0;" below. controller_thread_delete_simple(global->thread); controller_process_delete(global->setting); - controller_main_delete(global->main); + controller_delete(global->main); } return 0; } -#endif // _di_controller_main_thread_control_ +#endif // _di_controller_thread_control_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/thread/control.h b/sources/c/main/thread/control.h index 4962201..f11c9f2 100644 --- a/sources/c/main/thread/control.h +++ b/sources/c/main/thread/control.h @@ -28,9 +28,9 @@ extern "C" { * @return * 0, always. */ -#ifndef _di_controller_main_thread_control_ - extern void * controller_main_thread_control(void * const arguments); -#endif // _di_controller_main_thread_control_ +#ifndef _di_controller_thread_control_ + extern void * controller_thread_control(void * const arguments); +#endif // _di_controller_thread_control_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/thread/entry.c b/sources/c/main/thread/entry.c index 2b17a0c..8479fd9 100644 --- a/sources/c/main/thread/entry.c +++ b/sources/c/main/thread/entry.c @@ -4,8 +4,8 @@ extern "C" { #endif -#ifndef _di_controller_main_thread_entry_ - void * controller_main_thread_entry(void * const arguments) { +#ifndef _di_controller_thread_entry_ + void * controller_thread_entry(void * const arguments) { if (!arguments) return 0; @@ -13,11 +13,11 @@ extern "C" { controller_global_t * const global = (controller_global_t * const) arguments; - if (!controller_main_thread_is_enabled(F_true, global->thread)) return 0; + if (!controller_thread_is_enabled(F_true, global->thread)) return 0; f_status_t * const status = &global->thread->status; - *status = controller_main_entry_read(global, F_true); + *status = controller_entry_read(global, F_true); if (F_status_set_fine(*status) == F_interrupt) { global->program->ready = controller_program_ready_abort_e; @@ -26,10 +26,10 @@ extern "C" { global->program->ready = controller_program_ready_fail_e; } else if (*status != F_child) { - *status = controller_main_entry_preprocess(global, F_true); + *status = controller_entry_preprocess(global, F_true); if ((global->main->program.parameters.array[controller_parameter_simulate_e].result & f_console_result_found_e) && (global->main->program.parameters.array[controller_parameter_validate_e].result & f_console_result_found_e)) { - controller_main_entry_setting_validate(global, F_true); + controller_entry_setting_validate(global, F_true); } } @@ -40,10 +40,10 @@ extern "C" { *status = F_status_set_error(F_available_not); global->program->ready = controller_program_ready_fail_e; - controller_main_print_error_file_pid_exists(&global->main->program.error, global->thread, global->program->path_pid); + controller_print_error_file_pid_exists(&global->main->program.error, global->thread, global->program->path_pid); } else { - *status = controller_main_entry_process(global, F_false, F_true); + *status = controller_entry_process(global, F_false, F_true); if (F_status_is_error(*status)) { global->program->ready = controller_program_ready_fail_e; @@ -62,15 +62,15 @@ extern "C" { // Restart the signal global->thread to allow for signals while operating the failsafe Items. if (!global->thread->id_signal) { - f_thread_create(0, &global->thread->id_signal, &controller_main_thread_signal_normal, (void *) global); + f_thread_create(0, &global->thread->id_signal, &controller_thread_signal_normal, (void *) global); } - const f_status_t status_failsafe = controller_main_entry_process(global, F_true, F_true); + const f_status_t status_failsafe = controller_entry_process(global, F_true, F_true); if (F_status_is_error(status_failsafe)) { *status = F_status_set_error(F_failure); - controller_main_print_error_failsafe_item(&global->main->program.error, global->thread, global->program->entry.items.array[program->failsafe_item_id].name); + controller_print_error_failsafe_item(&global->main->program.error, global->thread, global->program->entry.items.array[program->failsafe_item_id].name); } else { @@ -97,12 +97,12 @@ extern "C" { if (F_status_is_error_not(*status) && *status != F_child && global->main->program.parameters.array[controller_parameter_validate_e].result == f_console_result_none_e && global->program->mode == controller_program_mode_helper_e) { f_time_spec_t time; - time.tv_sec = controller_main_thread_exit_helper_timeout_seconds_d; - time.tv_nsec = controller_main_thread_exit_helper_timeout_nanoseconds_d; + time.tv_sec = controller_thread_exit_helper_timeout_seconds_d; + time.tv_nsec = controller_thread_exit_helper_timeout_nanoseconds_d; nanosleep(&time, 0); - controller_main_thread_instance_cancel(global, F_true, controller_thread_cancel_exit_e); + controller_thread_instance_cancel(global, F_true, controller_thread_cancel_exit_e); } } } @@ -113,7 +113,7 @@ extern "C" { // It seems that this function doesn't return to the calling thread for a forked child process, even with the "return 0;" below. controller_thread_delete(global->thread); controller_program_delete(global->program); - controller_main_delete(global->main); + controller_delete(global->main); // According to the manpages, pthread_exit() calls exit(0), which the value of global->main->program.child should be returned instead. if (global->main->program.child) exit(global->main->program.child); @@ -125,10 +125,10 @@ extern "C" { return 0; } -#endif // _di_controller_main_thread_entry_ +#endif // _di_controller_thread_entry_ -#ifndef _di_controller_main_thread_exit_ - void * controller_main_thread_exit(void * const arguments) { +#ifndef _di_controller_thread_exit_ + void * controller_thread_exit(void * const arguments) { if (!arguments) return 0; @@ -136,7 +136,7 @@ extern "C" { controller_global_t * const global = (controller_global_t * const) arguments; - controller_main_t * const main = global->main; + controller_t * const main = global->main; controller_cache_t * const cache = &global->thread->cache; f_status_t * const status = &global->thread->status; @@ -183,7 +183,7 @@ extern "C" { // Restart the signal thread to allow for signals while operating the failsafe Items. if (!global->thread->id_signal) { - f_thread_create(0, &global->thread->id_signal, &controller_main_thread_signal_other, (void *) global); + f_thread_create(0, &global->thread->id_signal, &controller_thread_signal_other, (void *) global); } } @@ -192,7 +192,7 @@ extern "C" { if (F_status_is_error(status_failsafe)) { *status = F_status_set_error(F_failure); - controller_main_print_error_failsafe_item(&global->main->program.error, global->thread, global->program->entry.items.array[program->failsafe_item_id].name); + controller_print_error_failsafe_item(&global->main->program.error, global->thread, global->program->entry.items.array[program->failsafe_item_id].name); } else { @@ -224,7 +224,7 @@ extern "C" { // It seems that this function doesn't return to the calling thread for a forked child process, even with the "return 0;" below. controller_thread_delete_simple(global->thread); controller_process_delete(global->program); - controller_main_delete(main); + controller_delete(main); return 0; } @@ -239,7 +239,7 @@ extern "C" { return 0; } -#endif // _di_controller_main_thread_exit_ +#endif // _di_controller_thread_exit_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/thread/entry.h b/sources/c/main/thread/entry.h index 23701cb..a2a2560 100644 --- a/sources/c/main/thread/entry.h +++ b/sources/c/main/thread/entry.h @@ -31,9 +31,9 @@ extern "C" { * @return * 0, always. */ -#ifndef _di_controller_main_thread_entry_ - extern void * controller_main_thread_entry(void * const arguments); -#endif // _di_controller_main_thread_entry_ +#ifndef _di_controller_thread_entry_ + extern void * controller_thread_entry(void * const arguments); +#endif // _di_controller_thread_entry_ /** * Thread for handling exit file processing. @@ -53,9 +53,9 @@ extern "C" { * @return * 0, always. */ -#ifndef _di_controller_main_thread_exit_ - extern void * controller_main_thread_exit(void * const arguments); -#endif // _di_controller_main_thread_exit_ +#ifndef _di_controller_thread_exit_ + extern void * controller_thread_exit(void * const arguments); +#endif // _di_controller_thread_exit_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/thread/instance.c b/sources/c/main/thread/instance.c index 4a87588..3cedb15 100644 --- a/sources/c/main/thread/instance.c +++ b/sources/c/main/thread/instance.c @@ -4,36 +4,36 @@ extern "C" { #endif -#ifndef _di_controller_main_thread_instance_ - void controller_main_thread_instance(const uint8_t is_normal, controller_instance_t * const instance) { +#ifndef _di_controller_thread_instance_ + void controller_thread_instance(const uint8_t is_normal, controller_instance_t * const instance) { if (!instance) return; - if (!controller_main_thread_is_enabled(is_normal, (controller_thread_t * const) instance->thread)) return; + if (!controller_thread_is_enabled(is_normal, (controller_thread_t * const) instance->thread)) return; - const f_status_t status = controller_main_rule_instance_do(controller_instance_option_asynchronous_e, instance); + const f_status_t status = controller_rule_instance_do(controller_instance_option_asynchronous_e, instance); // A forked child instance should de-allocate memory on exit. // It seems that this function doesn't return to the calling thread for a forked child instance, even with the "return 0;" below. if (status == F_child) { controller_thread_delete_simple(instance->main_thread); controller_process_delete(instance->program); - controller_main_delete(instance->main_data); + controller_delete(instance->main_data); // According to some man pages, pthread_exit() calls exit(0), so expliticly exit to ensure a non-zero code is returned when needed. if (instance->main_data->program.child) exit(instance->main_data->program.child); } } -#endif // _di_controller_main_thread_instance_ +#endif // _di_controller_thread_instance_ -#ifndef _di_controller_main_thread_instance_cancel_ - void controller_main_thread_instance_cancel(controller_instance_t * const global, const uint8_t is_normal, const uint8_t by) { +#ifndef _di_controller_thread_instance_cancel_ + void controller_thread_instance_cancel(controller_global_t * const global, const uint8_t is_normal, const uint8_t by) { if (!global) return; f_thread_mutex_lock(&global->thread->lock.cancel); // Only cancel when enabled. - if (!controller_main_thread_is_enabled(is_normal, global->thread)) { + if (!controller_thread_is_enabled(is_normal, global->thread)) { f_thread_mutex_unlock(&global->thread->lock.cancel); return; @@ -67,7 +67,7 @@ extern "C" { if (!instance->id_thread) continue; - controller_main_thread_detach(&instance->id_thread); + controller_thread_detach(&instance->id_thread); instance->id_thread = 0; } // for @@ -177,7 +177,7 @@ extern "C" { time.tv_sec = 0; time.tv_nsec = interval_nanoseconds; - f_time_sleep_spec(&time, 0); + f_time_sleep_spec(time, 0); lapsed += interval_milliseconds; } @@ -202,7 +202,7 @@ extern "C" { time.tv_sec = 0; time.tv_nsec = interval_nanoseconds; - f_time_sleep_spec(&time, 0); + f_time_sleep_spec(time, 0); lapsed += interval_milliseconds; } @@ -235,13 +235,13 @@ extern "C" { f_signal_send(F_signal_kill, instance->childs.array[j]); time.tv_sec = 0; - time.tv_nsec = controller_main_thread_exit_process_cancel_wait_d; + time.tv_nsec = controller_thread_exit_process_cancel_wait_d; instance->childs.array[j] = 0; } } // for - f_time_sleep_spec(&time, 0); + f_time_sleep_spec(time, 0); } f_thread_join(instance->id_thread, 0); @@ -309,10 +309,10 @@ extern "C" { f_thread_mutex_unlock(&global->thread->lock.cancel); } -#endif // _di_controller_main_thread_instance_cancel_ +#endif // _di_controller_thread_instance_cancel_ -#ifndef _di_controller_main_thread_instance_exit_ - void controller_main_thread_instance_exit(controller_global_t * const global) { +#ifndef _di_controller_thread_instance_exit_ + void controller_thread_instance_exit(controller_global_t * const global) { if (!global) return; @@ -330,16 +330,14 @@ extern "C" { // Restart the signal thread to allow for signals while operating the Exit. if (!global->thread->id_signal) { - f_thread_create(0, &global->thread->id_signal, &controller_main_thread_signal_other, (void *) global); + f_thread_create(0, &global->thread->id_signal, &controller_thread_signal_other, (void *) global); } - const controller_main_entry_t entry = macro_controller_main_entry_t_initialize_1(global, global->setting); - - f_status_t status = f_thread_create(0, &global->thread->id_entry, &controller_main_thread_exit, (void *) &entry); + f_status_t status = f_thread_create(0, &global->thread->id_entry, &controller_thread_exit, (void *) global); if (F_status_is_error(status)) { if (global->main->program.error.verbosity > f_console_verbosity_quiet_e) { - controller_main_print_error_status(&global->main->program.error, macro_controller_f(f_thread_create), F_status_set_fine(status)); + controller_print_error_status(&global->main->program.error, macro_controller_f(f_thread_create), F_status_set_fine(status)); } if (F_status_is_error_not(f_thread_mutex_lock(&global->thread->lock.alert))) { @@ -363,7 +361,7 @@ extern "C" { break; } - controller_main_time_now(controller_main_thread_exit_ready_timeout_seconds_d, controller_main_thread_exit_ready_timeout_nanoseconds_d, &time); + controller_time_now(controller_thread_exit_ready_timeout_seconds_d, controller_thread_exit_ready_timeout_nanoseconds_d, &time); status = f_thread_condition_wait_timed(&time, &global->thread->lock.alert_condition, &global->thread->lock.alert); @@ -391,7 +389,7 @@ extern "C" { global->thread->id_signal = 0; } - controller_main_thread_instance_cancel(*global, F_false, controller_thread_cancel_exit_e); + controller_thread_instance_cancel(global, F_false, controller_thread_cancel_exit_e); } else { if (F_status_is_error_not(f_thread_mutex_lock(&global->thread->lock.alert))) { @@ -404,33 +402,33 @@ extern "C" { } } } -#endif // _di_controller_main_thread_instance_exit_ +#endif // _di_controller_thread_instance_exit_ -#ifndef _di_controller_main_thread_instance_normal_ - void * controller_main_thread_instance_normal(void * const arguments) { +#ifndef _di_controller_thread_instance_normal_ + void * controller_thread_instance_normal(void * const arguments) { if (!arguments) return 0; f_thread_cancel_state_set(PTHREAD_CANCEL_DEFERRED, 0); - controller_main_thread_instance(F_true, (controller_instance_t * const) arguments); + controller_thread_instance(F_true, (controller_instance_t * const) arguments); return 0; } -#endif // _di_controller_main_thread_instance_normal_ +#endif // _di_controller_thread_instance_normal_ -#ifndef _di_controller_main_thread_instance_other_ - void * controller_main_thread_instance_other(void * const arguments) { +#ifndef _di_controller_thread_instance_other_ + void * controller_thread_instance_other(void * const arguments) { if (!arguments) return 0; f_thread_cancel_state_set(PTHREAD_CANCEL_DEFERRED, 0); - controller_main_thread_instance(F_false, (controller_instance_t * const) arguments); + controller_thread_instance(F_false, (controller_instance_t * const) arguments); return 0; } -#endif // _di_controller_main_thread_instance_other_ +#endif // _di_controller_thread_instance_other_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/thread/instance.h b/sources/c/main/thread/instance.h index 83d152f..64a3426 100644 --- a/sources/c/main/thread/instance.h +++ b/sources/c/main/thread/instance.h @@ -27,11 +27,11 @@ extern "C" { * * Must not be NULL. * - * @see controller_main_rule_instance_do() + * @see controller_rule_instance_do() */ -#ifndef _di_controller_main_thread_instance_ - extern void controller_main_thread_instance(const uint8_t is_normal, controller_instance_t * const instance); -#endif // _di_controller_main_thread_instance_ +#ifndef _di_controller_thread_instance_ + extern void controller_thread_instance(const uint8_t is_normal, controller_instance_t * const instance); +#endif // _di_controller_thread_instance_ /** * Cancel all process threads. @@ -52,9 +52,9 @@ extern "C" { * If controller_thread_cancel_call_e, then this was not called from within the signal handling thread, so cancel the signal thread. * If controller_thread_cancel_execute_e, then this was called from within the Entry/Exit for executing a process, so cancel the signal thread but not the Entry thread. */ -#ifndef _di_controller_main_thread_instance_cancel_ - extern void controller_main_thread_instance_cancel(controller_global_t * const global, const uint8_t is_normal, const uint8_t by); -#endif // _di_controller_main_thread_instance_cancel_ +#ifndef _di_controller_thread_instance_cancel_ + extern void controller_thread_instance_cancel(controller_global_t * const global, const uint8_t is_normal, const uint8_t by); +#endif // _di_controller_thread_instance_cancel_ /** * Process the Exit file, if applicable. @@ -66,9 +66,9 @@ extern "C" { * * This does not alter global.main.setting.state.status. */ -#ifndef _di_controller_main_thread_instance_exit_ - extern void controller_main_thread_instance_exit(controller_global_t * const global); -#endif // _di_controller_main_thread_instance_exit_ +#ifndef _di_controller_thread_instance_exit_ + extern void controller_thread_instance_exit(controller_global_t * const global); +#endif // _di_controller_thread_instance_exit_ /** * Asynchronously execute a Rule process during normal operations. @@ -82,11 +82,11 @@ extern "C" { * @return * 0, always. * - * @see controller_main_thread_instance() + * @see controller_thread_instance() */ -#ifndef _di_controller_main_thread_instance_normal_ - extern void * controller_main_thread_instance_normal(void * const global); -#endif // _di_controller_main_thread_instance_normal_ +#ifndef _di_controller_thread_instance_normal_ + extern void * controller_thread_instance_normal(void * const global); +#endif // _di_controller_thread_instance_normal_ /** * Asynchronously execute a Rule process during other operations. @@ -100,11 +100,11 @@ extern "C" { * @return * 0, always. * - * @see controller_main_thread_instance() + * @see controller_thread_instance() */ -#ifndef _di_controller_main_thread_instance_other_ - extern void * controller_main_thread_instance_other(void * const arguments); -#endif // _di_controller_main_thread_instance_other_ +#ifndef _di_controller_thread_instance_other_ + extern void * controller_thread_instance_other(void * const arguments); +#endif // _di_controller_thread_instance_other_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/thread/is.c b/sources/c/main/thread/is.c index 6132976..7df726f 100644 --- a/sources/c/main/thread/is.c +++ b/sources/c/main/thread/is.c @@ -4,30 +4,30 @@ extern "C" { #endif -#ifndef _di_controller_main_thread_is_enabled_ - f_status_t controller_main_thread_is_enabled(const uint8_t is_normal, controller_thread_t * const thread) { +#ifndef _di_controller_thread_is_enabled_ + f_status_t controller_thread_is_enabled(const uint8_t is_normal, controller_thread_t * const thread) { if (!thread) return F_false; return is_normal ? thread->enabled == controller_thread_enabled_e : thread->enabled; } -#endif // _di_controller_main_thread_is_enabled_ +#endif // _di_controller_thread_is_enabled_ -#ifndef _di_controller_main_thread_is_enabled_instance_ - f_status_t controller_main_thread_is_enabled_instance(controller_instance_t * const instance, controller_thread_t * const thread) { +#ifndef _di_controller_thread_is_enabled_instance_ + f_status_t controller_thread_is_enabled_instance(controller_instance_t * const instance) { if (!instance) return F_false; - return controller_main_thread_is_enabled_instance_type(instance->type, thread); + return controller_thread_is_enabled_instance_type(instance->type, instance->global->thread); } -#endif // _di_controller_main_thread_is_enabled_instance_ +#endif // _di_controller_thread_is_enabled_instance_ -#ifndef _di_controller_main_thread_is_enabled_instance_type_ - f_status_t controller_main_thread_is_enabled_instance_type(const uint8_t type, controller_thread_t * const thread) { +#ifndef _di_controller_thread_is_enabled_instance_type_ + f_status_t controller_thread_is_enabled_instance_type(const uint8_t type, controller_thread_t * const thread) { - return controller_main_thread_is_enabled(type != controller_instance_type_exit_e, thread); + return controller_thread_is_enabled(type != controller_instance_type_exit_e, thread); } -#endif // _di_controller_main_thread_is_enabled_instance_type_ +#endif // _di_controller_thread_is_enabled_instance_type_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/thread/is.h b/sources/c/main/thread/is.h index 2b14859..c240adb 100644 --- a/sources/c/main/thread/is.h +++ b/sources/c/main/thread/is.h @@ -31,9 +31,9 @@ extern "C" { * F_true when enabled. * F_false when disabled. */ -#ifndef _di_controller_main_thread_is_enabled_ - extern f_status_t controller_main_thread_is_enabled(const uint8_t is_normal, controller_thread_t * const thread); -#endif // _di_controller_main_thread_is_enabled_ +#ifndef _di_controller_thread_is_enabled_ + extern f_status_t controller_thread_is_enabled(const uint8_t is_normal, controller_thread_t * const thread); +#endif // _di_controller_thread_is_enabled_ /** * Check to see if thread is enabled for the normal operations like entry and control or for exit operations for some instance. @@ -42,20 +42,16 @@ extern "C" { * The instance to use when checking if thread is enabled. * * Must not be NULL. - * @param thread - * The thread data. - * - * Must not be NULL. * * @return * F_true when enabled. * F_false when disabled or when parameter is invalid.. * - * @see controller_main_thread_is_enabled_instance_type() + * @see controller_thread_is_enabled_instance_type() */ -#ifndef _di_controller_main_thread_is_enabled_instance_ - extern f_status_t controller_main_thread_is_enabled_instance(controller_instance_t * const instance, controller_thread_t * const thread); -#endif // _di_controller_main_thread_is_enabled_instance_ +#ifndef _di_controller_thread_is_enabled_instance_ + extern f_status_t controller_thread_is_enabled_instance(controller_instance_t * const instance); +#endif // _di_controller_thread_is_enabled_instance_ /** * Check to see if thread is enabled for the normal operations like entry and control or for exit operations for some instance type. @@ -68,13 +64,13 @@ extern "C" { * Must not be NULL. * * @return - * Success from controller_main_thread_is_enabled(). + * Success from controller_thread_is_enabled(). * - * @see controller_main_thread_is_enabled() + * @see controller_thread_is_enabled() */ -#ifndef _di_controller_main_thread_is_enabled_instance_type_ - extern f_status_t controller_main_thread_is_enabled_instance_type(const uint8_t type, controller_thread_t * const thread); -#endif // _di_controller_main_thread_is_enabled_instance_type_ +#ifndef _di_controller_thread_is_enabled_instance_type_ + extern f_status_t controller_thread_is_enabled_instance_type(const uint8_t type, controller_thread_t * const thread); +#endif // _di_controller_thread_is_enabled_instance_type_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/thread/rule.c b/sources/c/main/thread/rule.c index 6845ae5..9a315f1 100644 --- a/sources/c/main/thread/rule.c +++ b/sources/c/main/thread/rule.c @@ -4,8 +4,8 @@ extern "C" { #endif -#ifndef _di_controller_main_thread_rule_ - void * controller_main_thread_rule(void * const arguments) { +#ifndef _di_controller_thread_rule_ + void * controller_thread_rule(void * const arguments) { if (!arguments) return 0; @@ -13,11 +13,11 @@ extern "C" { controller_global_t * const global = (controller_global_t * const) arguments; - if (!controller_main_thread_is_enabled(F_true, global->thread)) return 0; + if (!controller_thread_is_enabled(F_true, global->thread)) return 0; return 0; } -#endif // _di_controller_main_thread_rule_ +#endif // _di_controller_thread_rule_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/thread/rule.h b/sources/c/main/thread/rule.h index 0efe6b7..b72bc9b 100644 --- a/sources/c/main/thread/rule.h +++ b/sources/c/main/thread/rule.h @@ -33,9 +33,9 @@ extern "C" { * @return * 0, always. */ -#ifndef _di_controller_main_thread_rule_ - extern void * controller_main_thread_rule(void * const arguments); -#endif // _di_controller_main_thread_rule_ +#ifndef _di_controller_thread_rule_ + extern void * controller_thread_rule(void * const arguments); +#endif // _di_controller_thread_rule_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/thread/signal.c b/sources/c/main/thread/signal.c index 65ca320..66bf139 100644 --- a/sources/c/main/thread/signal.c +++ b/sources/c/main/thread/signal.c @@ -1,23 +1,23 @@ -#include "controller.h" +#include "../controller.h" #ifdef __cplusplus extern "C" { #endif -#ifndef _di_controller_main_thread_signal_ - void controller_main_thread_signal(controller_global_t * const global, const bool is_normal) { +#ifndef _di_controller_thread_signal_ + void controller_thread_signal(controller_global_t * const global, const bool is_normal) { if (!global || !global->main || !global->thread) return; - if (!controller_main_thread_is_enabled(is_normal, global->thread)) return; + if (!controller_thread_is_enabled(is_normal, global->thread)) return; if (!(global->main->setting.flag & controller_main_flag_interruptible_e)) return; f_status_t status = F_okay; siginfo_t information; f_time_spec_t time = f_time_spec_t_initialize; - while (controller_main_thread_is_enabled(is_normal, global->thread)) { + while (controller_thread_is_enabled(is_normal, global->thread)) { - controller_main_time_now(controller_main_thread_exit_ready_timeout_seconds_d, controller_main_thread_exit_ready_timeout_nanoseconds_d, &time); + controller_time_now(controller_thread_exit_ready_timeout_seconds_d, controller_thread_exit_ready_timeout_nanoseconds_d, &time); memset((void *) &information, 0, sizeof(siginfo_t)); @@ -27,71 +27,75 @@ extern "C" { if (information.si_signo == F_signal_interrupt || information.si_signo == F_signal_abort || information.si_signo == F_signal_quit || information.si_signo == F_signal_termination) { global->thread->signal = information.si_signo; - controller_main_thread_instance_cancel(global, is_normal, controller_thread_cancel_signal_e); + controller_thread_instance_cancel(global, is_normal, controller_thread_cancel_signal_e); break; } } // while } -#endif // _di_controller_main_thread_signal_ +#endif // _di_controller_thread_signal_ -#ifndef _di_controller_main_thread_signal_state_fss_ - void controller_main_thread_signal_state_fss(f_state_t * const state, void * const internal) { +#ifndef _di_controller_thread_signal_state_fss_ + void controller_thread_signal_state_fss(f_state_t * const state, void * const internal) { if (!state || !state->custom) return; - controller_global_t * const global = (controller_global_t *) state->custom; + controller_interrupt_t * const interrupt = (controller_interrupt_t *) state->custom; - if (!controller_main_thread_is_enabled(custom->is_normal, global->thread)) { - global->main->program.signal_received = F_signal_abort; - global->main->setting.state.status = F_status_set_error(F_interrupt); + if (!interrupt->global || !interrupt->global->main || !interrupt->global->thread) return; + + if (!controller_thread_is_enabled(interrupt->is_normal, interrupt->global->thread)) { + interrupt->global->main->program.signal_received = F_signal_abort; + interrupt->global->main->setting.state.status = F_status_set_error(F_interrupt); } - else if (global->thread->signal == F_signal_interrupt || global->thread->signal == F_signal_abort || global->thread->signal == F_signal_quit || global->thread->signal == F_signal_termination) { - global->main->program.signal_received = F_signal_abort; - global->main->setting.state.status = F_status_set_error(F_interrupt); + else if (interrupt->global->thread->signal == F_signal_interrupt || interrupt->global->thread->signal == F_signal_abort || interrupt->global->thread->signal == F_signal_quit || interrupt->global->thread->signal == F_signal_termination) { + interrupt->global->main->program.signal_received = F_signal_abort; + interrupt->global->main->setting.state.status = F_status_set_error(F_interrupt); } } -#endif // _di_controller_main_thread_signal_state_fss_ +#endif // _di_controller_thread_signal_state_fss_ -#ifndef _di_controller_main_thread_signal_state_iki_ - void controller_main_thread_signal_state_iki(f_state_t * const state, void * const internal) { +#ifndef _di_controller_thread_signal_state_iki_ + void controller_thread_signal_state_iki(f_state_t * const state, void * const internal) { if (!state || !state->custom) return; - controller_global_t * const global = (controller_global_t *) state->custom; + controller_interrupt_t * const interrupt = (controller_interrupt_t *) state->custom; + + if (!interrupt->global || !interrupt->global->main || !interrupt->global->thread) return; - if (!controller_main_thread_is_enabled(custom->is_normal, global->thread)) { - global->main->program.signal_received = F_signal_abort; - global->main->setting.state.status = F_status_set_error(F_interrupt); + if (!controller_thread_is_enabled(interrupt->is_normal, interrupt->global->thread)) { + interrupt->global->main->program.signal_received = F_signal_abort; + interrupt->global->main->setting.state.status = F_status_set_error(F_interrupt); } - else if (global->thread->signal == F_signal_interrupt || global->thread->signal == F_signal_abort || global->thread->signal == F_signal_quit || global->thread->signal == F_signal_termination) { - global->main->program.signal_received = F_signal_abort; - global->main->setting.state.status = F_status_set_error(F_interrupt); + else if (interrupt->global->thread->signal == F_signal_interrupt || interrupt->global->thread->signal == F_signal_abort || interrupt->global->thread->signal == F_signal_quit || interrupt->global->thread->signal == F_signal_termination) { + interrupt->global->main->program.signal_received = F_signal_abort; + interrupt->global->main->setting.state.status = F_status_set_error(F_interrupt); } } -#endif // _di_controller_main_thread_signal_state_iki_ +#endif // _di_controller_thread_signal_state_iki_ -#ifndef _di_controller_main_thread_signal_normal_ - void * controller_main_thread_signal_normal(void * const global) { +#ifndef _di_controller_thread_signal_normal_ + void * controller_thread_signal_normal(void * const global) { f_thread_cancel_state_set(PTHREAD_CANCEL_DEFERRED, 0); - controller_main_thread_signal((controller_global_t * const) global, F_true); + controller_thread_signal((controller_global_t * const) global, F_true); return 0; } -#endif // _di_controller_main_thread_signal_normal_ +#endif // _di_controller_thread_signal_normal_ -#ifndef _di_controller_main_thread_signal_other_ - void * controller_main_thread_signal_other(void * const global) { +#ifndef _di_controller_thread_signal_other_ + void * controller_thread_signal_other(void * const global) { f_thread_cancel_state_set(PTHREAD_CANCEL_DEFERRED, 0); - controller_main_thread_signal((controller_global_t * const) global, F_false); + controller_thread_signal((controller_global_t * const) global, F_false); return 0; } -#endif // _di_controller_main_thread_signal_other_ +#endif // _di_controller_thread_signal_other_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/thread/signal.h b/sources/c/main/thread/signal.h index c363f7d..89fb752 100644 --- a/sources/c/main/thread/signal.h +++ b/sources/c/main/thread/signal.h @@ -23,9 +23,9 @@ * If TRUE, then process as if this operates during a normal operation (entry and control). * If FALSE, then process as if this operates during a an exit operation. */ -#ifndef _di_controller_main_thread_signal_ - extern void controller_main_thread_signal(controller_global_t * const global, const bool is_normal); -#endif // _di_controller_main_thread_signal_ +#ifndef _di_controller_thread_signal_ + extern void controller_thread_signal(controller_global_t * const global, const bool is_normal); +#endif // _di_controller_thread_signal_ /** * Callback passed to FSS functions for checking for interrupts. @@ -37,9 +37,9 @@ * @param internal * Not used. */ -#ifndef _di_controller_main_thread_signal_state_fss_ - extern void controller_main_thread_signal_state_fss(f_state_t * const state, void * const internal); -#endif // _di_controller_main_thread_signal_state_fss_ +#ifndef _di_controller_thread_signal_state_fss_ + extern void controller_thread_signal_state_fss(f_state_t * const state, void * const internal); +#endif // _di_controller_thread_signal_state_fss_ /** * Callback passed to IKI functions for checking for interrupts. @@ -51,9 +51,9 @@ * @param internal * Not used. */ -#ifndef _di_controller_main_thread_signal_state_iki_ - extern void controller_main_thread_signal_state_iki(f_state_t * const state, void * const internal); -#endif // _di_controller_main_thread_signal_state_iki_ +#ifndef _di_controller_thread_signal_state_iki_ + extern void controller_thread_signal_state_iki(f_state_t * const state, void * const internal); +#endif // _di_controller_thread_signal_state_iki_ /** * Thread for handling signals/interrupts during normal operations. @@ -67,11 +67,11 @@ * @return * 0, always. * - * @see controller_main_thread_signal() + * @see controller_thread_signal() */ -#ifndef _di_controller_main_thread_signal_normal_ - extern void * controller_main_thread_signal_normal(void * const global); -#endif // _di_controller_main_thread_signal_normal_ +#ifndef _di_controller_thread_signal_normal_ + extern void * controller_thread_signal_normal(void * const global); +#endif // _di_controller_thread_signal_normal_ /** * Thread for handling signals/interrupts during other operations. @@ -85,11 +85,11 @@ * @return * 0, always. * - * @see controller_main_thread_signal() + * @see controller_thread_signal() */ -#ifndef _di_controller_main_thread_signal_other_ - extern void * controller_main_thread_signal_other(void * const global); -#endif // _di_controller_main_thread_signal_other_ +#ifndef _di_controller_thread_signal_other_ + extern void * controller_thread_signal_other(void * const global); +#endif // _di_controller_thread_signal_other_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/time.c b/sources/c/main/time.c index 0a5e0c7..3595290 100644 --- a/sources/c/main/time.c +++ b/sources/c/main/time.c @@ -4,8 +4,8 @@ extern "C" { #endif -#ifndef _di_controller_main_time_now_ - void controller_main_time_now(const time_t seconds, const long nanoseconds, f_time_spec_t * const time) { +#ifndef _di_controller_time_now_ + void controller_time_now(const time_t seconds, const long nanoseconds, f_time_spec_t * const time) { { f_time_value_t now = f_time_value_t_initialize; @@ -23,39 +23,15 @@ extern "C" { time->tv_nsec -= 1000000000; } } -#endif // _di_controller_main_time_now_ +#endif // _di_controller_time_now_ -/* -#ifndef _di_controller_main_time_milliseconds_ - f_time_spec_t controller_main_time_milliseconds(const f_number_unsigned_t milliseconds) { - - f_time_spec_t time; - - f_time_spec_millisecond(0, milliseconds, &time); - - return time; - } -#endif // _di_controller_main_time_milliseconds_ - -#ifndef _di_controller_main_time_seconds_ - f_time_simple_t controller_main_time_seconds(const f_number_unsigned_t seconds) { - - f_time_spec_t time; - - f_time_spec_millisecond(seconds, 0, &time); - - return time; - } -#endif // _di_controller_main_time_seconds_ -*/ - -#ifndef _di_controller_main_time_sleep_nanoseconds_ - f_status_t controller_main_time_sleep_nanoseconds(controller_global_t * const global, const f_time_spec_t time) { +#ifndef _di_controller_time_sleep_nanoseconds_ + f_status_t controller_time_sleep_nanoseconds(controller_global_t * const global, const f_time_spec_t time) { if (!global || !global->main) return F_status_set_error(F_parameter); // When sleep is a second or more, instead wait for terminating signals if interruptible. - if ((global->main->setting.flag & controller_main_flag_interruptible_e) && time.tv_sec) { + if ((global->main->program.flag & controller_main_flag_interruptible_e) && time.tv_sec) { siginfo_t information; f_signal_t signal = f_signal_t_initialize; @@ -72,7 +48,7 @@ extern "C" { return f_time_sleep_spec(time, 0); } -#endif // _di_controller_main_time_sleep_nanoseconds_ +#endif // _di_controller_time_sleep_nanoseconds_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/time.h b/sources/c/main/time.h index 650c315..21a0cbc 100644 --- a/sources/c/main/time.h +++ b/sources/c/main/time.h @@ -9,8 +9,8 @@ * * This is auto-included and should not need to be explicitly included. */ -#ifndef _controller_main_time_h -#define _controller_main_time_h +#ifndef _controller_time_h +#define _controller_time_h /** * Get the current time, plus the given offset. @@ -24,9 +24,9 @@ * * @see f_time_of_day_get() */ -#ifndef _di_controller_main_time_now_ - extern void controller_main_time_now(const time_t seconds, const long nanoseconds, f_time_spec_t * const time); -#endif // _di_controller_main_time_now_ +#ifndef _di_controller_time_now_ + extern void controller_time_now(const time_t seconds, const long nanoseconds, f_time_spec_t * const time); +#endif // _di_controller_time_now_ /** * Sleep for the given time. @@ -51,12 +51,12 @@ * * @see f_time_of_day_get() */ -#ifndef _di_controller_main_time_sleep_nanoseconds_ - extern f_status_t controller_main_time_sleep_nanoseconds(controller_global_t * const global, const f_time_spec_t time); -#endif // _di_controller_main_time_sleep_nanoseconds_ +#ifndef _di_controller_time_sleep_nanoseconds_ + extern f_status_t controller_time_sleep_nanoseconds(controller_global_t * const global, const f_time_spec_t time); +#endif // _di_controller_time_sleep_nanoseconds_ #ifdef __cplusplus } // extern "C" #endif -#endif // _controller_main_time_h +#endif // _controller_time_h