From 95b29304c260ad4ab557101e17e2360a9ed28f16 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sat, 1 Jun 2024 18:32:11 -0500 Subject: [PATCH] Progress: Continue migrating the project. --- data/build/settings | 10 +- sources/c/controller/controller.c | 30 ---- sources/c/controller/controller.h | 38 +---- sources/c/init/init.c | 30 ---- sources/c/init/init.h | 38 +---- sources/c/main/common.c | 2 +- sources/c/main/common/define/thread.h | 4 +- sources/c/main/common/enumeration/program.h | 2 +- sources/c/main/common/enumeration/rule.h | 76 +++++----- sources/c/main/common/print.c | 1 + sources/c/main/common/print.h | 1 + sources/c/main/common/string/rule.c | 8 +- sources/c/main/common/string/rule.h | 10 +- sources/c/main/common/type.h | 24 +-- sources/c/main/common/type/cache.h | 41 ++--- sources/c/main/common/type/control.h | 23 +-- sources/c/main/common/type/defs.h | 65 ++++++++ sources/c/main/common/type/entry.h | 61 ++++---- sources/c/main/common/type/execute.h | 5 +- sources/c/main/common/type/global.h | 11 +- sources/c/main/common/type/instance.h | 63 ++++---- sources/c/main/common/type/lock.h | 17 ++- sources/c/main/common/type/program.h | 33 ++-- sources/c/main/common/type/rule.c | 18 +-- sources/c/main/common/type/rule.h | 183 +++++++++++----------- sources/c/main/common/type/thread.h | 33 ++-- sources/c/main/controller.h | 8 +- sources/c/main/lock.c | 130 ++++++++++++++++ sources/c/main/lock.h | 228 ++++++++++++++++++++++++++++ sources/c/main/print/error.c | 2 +- sources/c/main/print/error.h | 63 +------- sources/c/main/print/lock.h | 2 + sources/c/main/print/rule.h | 8 +- sources/c/main/print/rule/item.h | 8 + sources/c/main/print/rule/setting.h | 8 +- sources/c/main/process.c | 29 ++-- sources/c/main/process.h | 2 +- sources/c/main/rule.c | 10 +- sources/c/main/rule/action.c | 90 +++++------ sources/c/main/rule/action.h | 40 ++--- sources/c/main/rule/execute.c | 100 ++++++------ sources/c/main/rule/execute.h | 39 ++--- sources/c/main/rule/expand.c | 14 +- sources/c/main/rule/expand.h | 17 ++- sources/c/main/rule/instance.c | 128 ++++++++-------- sources/c/main/rule/instance.h | 40 ++--- sources/c/main/rule/is.c | 12 +- sources/c/main/rule/is.h | 12 +- sources/c/main/rule/item.c | 44 +++--- sources/c/main/rule/item.h | 9 +- sources/c/main/rule/parameter.c | 6 +- sources/c/main/rule/parameter.h | 7 +- sources/c/main/rule/read.c | 14 +- sources/c/main/rule/read.h | 9 +- sources/c/main/rule/setting.c | 24 +-- sources/c/main/rule/setting.h | 7 +- sources/c/main/rule/validate.c | 70 ++++----- sources/c/main/rule/validate.h | 7 +- sources/c/main/rule/wait.c | 42 ++--- sources/c/main/rule/wait.h | 20 +-- sources/c/main/thread.c | 93 +++--------- sources/c/main/thread.h | 91 ++++------- sources/c/main/thread/cleanup.c | 151 ++++++++++++++++++ sources/c/main/thread/cleanup.h | 39 +++++ sources/c/main/thread/control.h | 1 + sources/c/main/thread/entry.c | 36 ++--- sources/c/main/thread/entry.h | 2 + sources/c/main/thread/instance.c | 14 +- sources/c/main/thread/instance.h | 7 +- sources/c/main/thread/is.h | 4 + sources/c/main/thread/rule.h | 1 + sources/c/main/thread/signal.c | 98 ++++++++++++ sources/c/main/thread/signal.h | 98 ++++++++++++ sources/c/main/time.c | 24 +-- sources/c/main/time.h | 15 +- 75 files changed, 1684 insertions(+), 1066 deletions(-) create mode 100644 sources/c/main/common/type/defs.h create mode 100644 sources/c/main/lock.c create mode 100644 sources/c/main/lock.h create mode 100644 sources/c/main/thread/cleanup.c create mode 100644 sources/c/main/thread/cleanup.h create mode 100644 sources/c/main/thread/signal.c create mode 100644 sources/c/main/thread/signal.h diff --git a/data/build/settings b/data/build/settings index 64cb847..d8d1ffe 100644 --- a/data/build/settings +++ b/data/build/settings @@ -43,24 +43,24 @@ 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/path.c main/process.c +build_sources_library main/instance.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 build_sources_library main/signal.c main/time.c -build_sources_library main/thread.c main/thread/control.c main/thread/entry.c main/thread/instance.c main/thread/is.c main/thread/rule.c +build_sources_library main/thread.c main/thread/cleanup.c main/thread/control.c main/thread/entry.c main/thread/instance.c main/thread/is.c main/thread/rule.c main/thread/signal.c build_sources_headers main/common.h main/controller.h main/common/define.h main/common/enumeration.h main/common/print.h main/common/string.h main/common/thread.h main/common/type.h build_sources_headers main/common/define/control.h main/common/define/entry.h main/common/define/rule.h main/common/define/thread.h 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/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/path.h main/process.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/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 build_sources_headers main/signal.h main/time.h -build_sources_headers main/thread.h main/thread/control.h main/thread/entry.h main/thread/instance.h main/thread/is.h main/thread/rule.h +build_sources_headers main/thread.h main/thread/cleanup.h main/thread/control.h main/thread/entry.h main/thread/instance.h main/thread/is.h main/thread/rule.h main/thread/signal.h build_sources_documentation man diff --git a/sources/c/controller/controller.c b/sources/c/controller/controller.c index d6b466c..b4400f9 100644 --- a/sources/c/controller/controller.c +++ b/sources/c/controller/controller.c @@ -4,36 +4,6 @@ extern "C" { #endif -#ifndef _di_controller_controller_main_ - void controller_controller_main(controller_main_t * const main, controller_program_t * const program) { - - if (!main || !program || F_status_is_error(main->setting.state.status)) return; - - main->setting.state.status = F_okay; - - 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); - } - else if (main->setting.flag & controller_main_flag_version_e) { - fll_program_print_version(&main->program.message, controller_program_version_s); - } - else if (main->setting.flag & controller_main_flag_copyright_e) { - fll_program_print_copyright(&main->program.message, fll_program_copyright_year_author_s); - } - - return; - } - - controller_main_process(data, program); - if (main->setting.state.status == F_status_set_error(F_child)) return; - - if (main->setting.state.status == F_status_set_error(F_interrupt)) { - fll_program_print_signal_received(&main->program.warning, main->program.signal_received); - } - } -#endif // _di_controller_controller_main_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/sources/c/controller/controller.h b/sources/c/controller/controller.h index 1d3fb9a..68396e4 100644 --- a/sources/c/controller/controller.h +++ b/sources/c/controller/controller.h @@ -5,9 +5,7 @@ * API Version: 0.7 * Licenses: lgpl-2.1-or-later * - * This program provides an controller base project. - * - * This program does nothing but can be used as a starting point for new program projects. + * This program provides the base include for the controller program. */ #ifndef _controller_controller_h #define _controller_controller_h @@ -20,40 +18,6 @@ extern "C" { #endif -/** - * Execute main program. - * - * If main.signal is non-zero, then this blocks and handles the following signals: - * - F_signal_abort - * - F_signal_broken_pipe - * - F_signal_hangup - * - F_signal_interrupt - * - F_signal_quit - * - F_signal_termination - * - * @param main - * The main program data and settings. - * - * Must not be NULL. - * - * This alters main.setting.state.status: - * F_okay on success. - * F_true on success when performing verification and verify passed. - * F_false on success when performing verification and verify failed. - * F_interrupt on (exit) signal received. - * - * F_parameter (with error bit) if main is NULL or setting is NULL. - * @param program - * A pointer to the current program settings. - * - * Must not be NULL. - * - * @see controller_main_process() - */ -#ifndef _di_controller_controller_main_ - extern void controller_controller_main(controller_main_t * const main, controller_program_t * const program); -#endif // _di_controller_controller_main_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/sources/c/init/init.c b/sources/c/init/init.c index 14255cd..527b41b 100644 --- a/sources/c/init/init.c +++ b/sources/c/init/init.c @@ -4,36 +4,6 @@ extern "C" { #endif -#ifndef _di_controller_init_main_ - void controller_init_main(controller_main_t * const main, controller_program_t * const program) { - - if (!main || !program || F_status_is_error(main->setting.state.status)) return; - - main->setting.state.status = F_okay; - - 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_true); - } - else if (main->setting.flag & controller_main_flag_version_e) { - fll_program_print_version(&main->program.message, controller_program_version_s); - } - else if (main->setting.flag & controller_main_flag_copyright_e) { - fll_program_print_copyright(&main->program.message, fll_program_copyright_year_author_s); - } - - return; - } - - controller_main_process(data, program); - if (main->setting.state.status == F_status_set_error(F_child)) return; - - if (main->setting.state.status == F_status_set_error(F_interrupt)) { - fll_program_print_signal_received(&main->program.warning, main->program.signal_received); - } - } -#endif // _di_controller_init_main_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/sources/c/init/init.h b/sources/c/init/init.h index 244a568..6b48703 100644 --- a/sources/c/init/init.h +++ b/sources/c/init/init.h @@ -5,9 +5,7 @@ * API Version: 0.7 * Licenses: lgpl-2.1-or-later * - * This program provides an controller base project. - * - * This program does nothing but can be used as a starting point for new program projects. + * This program provides the base include for the init program. */ #ifndef _controller_init_h #define _controller_init_h @@ -20,40 +18,6 @@ extern "C" { #endif -/** - * Execute main program. - * - * @todo this may or may not be needed. For now controller_main_process() is being written as a complete replacement to this. - * - * If main.signal is non-zero, then this blocks and handles the following signals: - * - F_signal_abort - * - F_signal_broken_pipe - * - F_signal_hangup - * - F_signal_interrupt - * - F_signal_quit - * - F_signal_termination - * - * @param main - * The main program data and settings. - * - * This alters main.setting.state.status: - * F_okay on success. - * F_true on success when performing verification and verify passed. - * F_false on success when performing verification and verify failed. - * F_interrupt on (exit) signal received. - * - * F_parameter (with error bit) if main is NULL or setting is NULL. - * @param program - * A pointer to the current program settings. - * - * Must not be NULL. - * - * @see controller_main_process() - */ -#ifndef _di_controller_init_main_ - extern void controller_init_main(controller_main_t * const main, controller_program_t * const program); -#endif // _di_controller_init_main_ - #ifdef __cplusplus } // extern "C" #endif diff --git a/sources/c/main/common.c b/sources/c/main/common.c index 7a114ac..ff52c3e 100644 --- a/sources/c/main/common.c +++ b/sources/c/main/common.c @@ -282,7 +282,7 @@ extern "C" { main->setting.flag &= ~controller_main_flag_interruptible_e; } - if (main->program.parameters.array[f_console_standard_parameter_daemon_e].result & f_console_result_found_e) { + if (main->program.parameters.array[controller_parameter_daemon_e].result & f_console_result_found_e) { main->setting.flag |= controller_main_flag_daemon_e; } diff --git a/sources/c/main/common/define/thread.h b/sources/c/main/common/define/thread.h index 40474db..88873a3 100644 --- a/sources/c/main/common/define/thread.h +++ b/sources/c/main/common/define/thread.h @@ -20,8 +20,8 @@ extern "C" { * Thread related defines. */ #ifndef _di_controller_thread_d_ - #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_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. diff --git a/sources/c/main/common/enumeration/program.h b/sources/c/main/common/enumeration/program.h index 1059980..0d1f19e 100644 --- a/sources/c/main/common/enumeration/program.h +++ b/sources/c/main/common/enumeration/program.h @@ -35,7 +35,7 @@ extern "C" { /** * Controller program mode enumeration. * - * controller_setting_mode_*: + * controller_program_mode_*: * - helper: Run as a helper, exiting when finished prrocess entry (and any respective exit). * - program: Run as a program, exiting when finished prrocess entry (and any respective exit). * - service: Run as a service, listening for requests after processing entry. diff --git a/sources/c/main/common/enumeration/rule.h b/sources/c/main/common/enumeration/rule.h index f7a8942..f1534b6 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_rule_action_execute_type_*_e: + * controller_main_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_rule_action_execute_type_e_ +#ifndef _di_controller_main_rule_action_execute_type_e_ enum { - 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, + 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, // Designate the largest value in the enum, the '__' is intentional. - controller_rule_action_execute_type__enum_size_e, + controller_main_rule_action_execute_type__enum_size_e, }; // enum -#endif // _di_controller_rule_action_execute_type_e_ +#endif // _di_controller_main_rule_action_execute_type_e_ /** * Controller Rule Action method enumeration. * - * controller_rule_action_method_*_e: + * controller_main_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_rule_action_method_e_ +#ifndef _di_controller_main_rule_action_method_e_ enum { - controller_rule_action_method_none_e = 0, - controller_rule_action_method_extended_e, - controller_rule_action_method_extended_list_e, + controller_main_rule_action_method_none_e = 0, + controller_main_rule_action_method_extended_e, + controller_main_rule_action_method_extended_list_e, }; // enum -#endif // _di_controller_rule_action_method_e_ +#endif // _di_controller_main_rule_action_method_e_ /** * Controller Rule Action type enumeration. * - * controller_rule_action_type_*_e: + * controller_main_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_rule_action_type_e_ +#ifndef _di_controller_main_rule_action_type_e_ enum { - 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, + 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, // Designate the largest value in the enum, the '__' is intentional. - controller_rule_action_type__enum_size_e, + controller_main_rule_action_type__enum_size_e, }; // enum -#endif // _di_controller_rule_action_type_e_ +#endif // _di_controller_main_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 6d597f4..11c9d89 100644 --- a/sources/c/main/common/print.c +++ b/sources/c/main/common/print.c @@ -6,6 +6,7 @@ extern "C" { #ifndef _di_controller_f_a_ const f_string_t controller_f_a[] = { + "controller_main_lock_create", "controller_rule_copy", "controller_rule_items_increase_by", "controller_path_canonical_relative", diff --git a/sources/c/main/common/print.h b/sources/c/main/common/print.h index dc436ad..af3773e 100644 --- a/sources/c/main/common/print.h +++ b/sources/c/main/common/print.h @@ -39,6 +39,7 @@ extern "C" { */ #ifndef _di_controller_f_e_ enum { + controller_f_controller_main_lock_create_e, controller_f_controller_rule_copy_e, controller_f_controller_rule_items_increase_by_e, controller_f_controller_path_canonical_relative_e, diff --git a/sources/c/main/common/string/rule.c b/sources/c/main/common/string/rule.c index 5484055..742f4bd 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_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_ +#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_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/common/string/rule.h b/sources/c/main/common/string/rule.h index 08e8c13..1a0c1de 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_rule_action_method_*_s: + * controller_main_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_rule_action_method_s_ +#ifndef _di_controller_main_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_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_ + 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_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/common/type.h b/sources/c/main/common/type.h index 49a69b0..6335657 100644 --- a/sources/c/main/common/type.h +++ b/sources/c/main/common/type.h @@ -22,13 +22,14 @@ extern "C" { * This is passed to the program-specific main entry point to designate program settings. * These program settings are often processed from the program arguments (often called the command line arguments). * - * flag: Flags passed to the main function. + * Properties: + * - flag: Flags passed to the main function. * - * status_signal: A status used eclusively by the threaded signal handler. - * state: The state data used when processing the FSS data. + * - status_signal: A status used eclusively by the threaded signal handler. + * - state: The state data used when processing the FSS data. * - * path_pid: The name of the program. - * path_setting: The long name of the program. + * - path_pid: The name of the program. + * - path_setting: The long name of the program. */ #ifndef _di_controller_setting_t_ typedef struct { @@ -54,15 +55,18 @@ extern "C" { /** * The main program data as a single structure. * - * program: The main program data. - * setting: The settings data. + * The typedef for this is located in the defs.h header. + * + * Properties: + * - program: The main program data. + * - setting: The settings data. */ #ifndef _di_controller_main_t_ - typedef struct { + struct controller_main_t_ { fll_program_data_t program; controller_setting_t setting; controller_cache_t cache; - } controller_main_t; + }; #define controller_main_t_initialize \ { \ @@ -73,7 +77,7 @@ extern "C" { #endif // _di_controller_main_t_ /** - * Deallocate main program data. + * De-allocate main program data. * * @param main * The main program data. diff --git a/sources/c/main/common/type/cache.h b/sources/c/main/common/type/cache.h index e541998..9bf75c8 100644 --- a/sources/c/main/common/type/cache.h +++ b/sources/c/main/common/type/cache.h @@ -61,30 +61,31 @@ extern "C" { /** * A cache intended for re-using memory while loading and processing rules whenever possible. * - * timestamp: The timestamp. + * Properties: + * - timestamp: The timestamp. * - * range_action: The Range for some Action. + * - range_action: The Range for some Action. * - * ats: Locations. - * stack: Locations within a items history used as a history stack for circular recursion prevention. + * - ats: Locations. + * - stack: Locations within a items history used as a history stack for circular recursion prevention. * - * comments: Comments associated with a buffer string. - * delimits: Delimits associated with a buffer string. + * - comments: Comments associated with a buffer string. + * - delimits: Delimits associated with a buffer string. * - * content_action: The specific Content for some Action. - * content_actions: Content for some Action. - * content_items: Content for some Item. - * object_actions: Objects for some Action. - * object_items: Objects for some Item. + * - content_action: The specific Content for some Action. + * - content_actions: Content for some Action. + * - content_items: Content for some Item. + * - object_actions: Objects for some Action. + * - object_items: Objects for some Item. * - * buffer: A generic buffer. - * buffer_file: A generic file related buffer. - * buffer_item: A generic item related buffer. - * buffer_path: A generic path related buffer. + * - buffer: A generic buffer. + * - buffer_file: A generic file related buffer. + * - buffer_item: A generic item related buffer. + * - buffer_path: A generic path related buffer. * - * expanded: An array of expanded strings, generally used by the execute functions. + * - expanded: An array of expanded strings, generally used by the execute functions. * - * action: A cache for some Action, often used by error printing for reporting where an error happened. + * - action: A cache for some Action, often used by error printing for reporting where an error happened. */ #ifndef _di_controller_cache_t_ typedef struct { @@ -137,10 +138,11 @@ extern "C" { #endif // _di_controller_cache_t_ /** - * Deallocate the Controller cache. + * De-allocate the Controller cache. * * @param cache * The cache. + * * Must not be NULL. * * @see f_memory_array_resize() @@ -150,10 +152,11 @@ extern "C" { #endif // _di_controller_cache_delete_ /** - * Deallocate the Controller action cache. + * De-allocate the Controller action cache. * * @param cache * The action cache. + * * Must not be NULL. * * @see f_memory_array_resize() diff --git a/sources/c/main/common/type/control.h b/sources/c/main/common/type/control.h index 23d1f58..64a4ad5 100644 --- a/sources/c/main/common/type/control.h +++ b/sources/c/main/common/type/control.h @@ -19,20 +19,21 @@ extern "C" { /** * Controller control data. * - * flag: Flags from controller_control_flag_*_e. - * user: The user ID, if specified. - * group: The group ID, if specified. - * mode: The file mode, if specified. + * Properties: + * - flag: Flags from controller_control_flag_*_e. + * - user: The user ID, if specified. + * - group: The group ID, if specified. + * - mode: The file mode, if specified. * - * server: The server socket connection. - * client: The client socket connection. + * - server: The server socket connection. + * - client: The client socket connection. * - * cache_1: A generic buffer used for caching control related data. - * cache_2: A generic buffer used for caching control related data. - * cache_3: A generic buffer used for caching control related data. + * - cache_1: A generic buffer used for caching control related data. + * - cache_2: A generic buffer used for caching control related data. + * - cache_3: A generic buffer used for caching control related data. * - * input: A buffer used for receiving data from the client. - * output: A buffer used for transmitting data to the client. + * - input: A buffer used for receiving data from the client. + * - output: A buffer used for transmitting data to the client. */ #ifndef _di_controller_control_t_ typedef struct { diff --git a/sources/c/main/common/type/defs.h b/sources/c/main/common/type/defs.h new file mode 100644 index 0000000..08e7dc4 --- /dev/null +++ b/sources/c/main/common/type/defs.h @@ -0,0 +1,65 @@ +/** + * FLL - Level 3 + * + * Project: Controller + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Provides the common typedefs for addressing specific cases of circular definitions. + * + * This is auto-included and should not need to be explicitly included. + */ +#ifndef _controller_main_common_type_defs_h +#define _controller_main_common_type_defs_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * The controller global typedef. + */ + #ifndef _di_controller_global_t_ + typedef struct controller_global_t_ controller_global_t; +#endif // _di_controller_global_t_ + +/** + * The controller instance typedef. + */ + #ifndef _di_controller_instance_t_ + typedef struct controller_instance_t_ controller_instance_t; +#endif // _di_controller_instance_t_ + +/** + * The controller instances typedef. + */ + #ifndef _di_controller_instances_t_ + typedef struct controller_instances_t_ controller_instances_t; +#endif // _di_controller_instances_t_ + +/** + * The controller main typedef. + */ +#ifndef _di_controller_main_t_ + typedef struct controller_main_t_ controller_main_t; +#endif // _di_controller_main_t_ + +/** + * The controller program typedef. + */ +#ifndef _di_controller_program_t_ + typedef struct controller_program_t_ controller_program_t; +#endif // _di_controller_program_t_ + +/** + * The controller thread typedef. + */ + #ifndef _di_controller_thread_t_ + typedef struct controller_thread_t_ controller_thread_t; +#endif // _di_controller_thread_t_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _controller_main_common_type_defs_h diff --git a/sources/c/main/common/type/entry.h b/sources/c/main/common/type/entry.h index 3219e70..cec9f15 100644 --- a/sources/c/main/common/type/entry.h +++ b/sources/c/main/common/type/entry.h @@ -19,13 +19,14 @@ extern "C" { /** * Controller Entry Item Action. * - * type: The type of Action. - * code: A single code or sub-type associated with the Action. - * flag: A set of flags to describe special behavior for the given type and code (flags may be different per type and code). - * line: The line number where the Entry Item begins. - * number: The unsigned number that some types use instead of the "parameters". - * status: The overall status. - * parameters: The values associated with the Action. + * Properties: + * - type: The type of Action. + * - code: A single code or sub-type associated with the Action. + * - flag: A set of flags to describe special behavior for the given type and code (flags may be different per type and code). + * - line: The line number where the Entry Item begins. + * - number: The unsigned number that some types use instead of the "parameters". + * - status: The overall status. + * - parameters: The values associated with the Action. */ #ifndef _di_controller_entry_action_t_ typedef struct { @@ -55,9 +56,10 @@ extern "C" { /** * Controller Entry Item Actions. * - * array: An array of Entry Item Actions. - * size: Total amount of allocated space. - * used: Total number of allocated spaces used. + * Properties: + * - array: An array of Entry Item Actions. + * - size: Total amount of allocated space. + * - used: Total number of allocated spaces used. */ #ifndef _di_controller_entry_actions_t_ typedef struct { @@ -77,9 +79,10 @@ extern "C" { /** * Controller Entry Item. * - * line: The line number where the Entry Item begins. - * name: The name of the Entry Item. - * actions: The Actions associated with the Entry Item. + * Properties: + * - line: The line number where the Entry Item begins. + * - name: The name of the Entry Item. + * - actions: The Actions associated with the Entry Item. */ #ifndef _di_controller_entry_item_t_ typedef struct { @@ -100,9 +103,10 @@ extern "C" { /** * Controller Entry Items. * - * array: An array of Entry Items. - * size: Total amount of allocated space. - * used: Total number of allocated spaces used. + * Properties: + * - array: An array of Entry Items. + * - size: Total amount of allocated space. + * - used: Total number of allocated spaces used. */ #ifndef _di_controller_entry_items_t_ typedef struct { @@ -130,18 +134,19 @@ extern "C" { * Entry and Exit files are essentially the same structure with minor differences in settings and behavior. * The structure is identical and due to lacking any particularly good name to represent both "entry" or "exit", the name "entry" is being used for both. * - * define: Any defines (environment variables) made available to all Rules in this entry for IKI substitution or just as environment variables. - * flag: A set of flags, primarily used to designate that timeouts are disabled. - * items: The array of entry items. - * parameter: Any parameters made available to all Rules in this entry for IKI substitution. - * pid: The PID file generation setting. - * session: The default session settings (when NULL, no default is specified). - * show: The show setting for controlling what to show when executing entry items and rules. - * status: The overall 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. - * timeout_stop: The timeout to wait relating to stopping a process. + * Properties: + * - define: Any defines (environment variables) made available to all Rules in this entry for IKI substitution or just as environment variables. + * - flag: A set of flags, primarily used to designate that timeouts are disabled. + * - items: The array of entry items. + * - parameter: Any parameters made available to all Rules in this entry for IKI substitution. + * - pid: The PID file generation setting. + * - session: The default session settings (when NULL, no default is specified). + * - show: The show setting for controlling what to show when executing entry items and rules. + * - status: The overall 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. + * - timeout_stop: The timeout to wait relating to stopping a process. */ #ifndef _di_controller_entry_t_ typedef struct { diff --git a/sources/c/main/common/type/execute.h b/sources/c/main/common/type/execute.h index 27720a6..bb9c694 100644 --- a/sources/c/main/common/type/execute.h +++ b/sources/c/main/common/type/execute.h @@ -19,8 +19,9 @@ extern "C" { /** * A structure for passing execution arguments to the execute functions. * - * parameter: All parameters sent to the program on execution. - * as: All special properties to apply, such as cpu affinity. + * Properties: + * - parameter: All parameters sent to the program on execution. + * - as: All special properties to apply, such as cpu affinity. */ #ifndef _di_controller_execute_set_t_ typedef struct { diff --git a/sources/c/main/common/type/global.h b/sources/c/main/common/type/global.h index 4e3a7aa..a1d6983 100644 --- a/sources/c/main/common/type/global.h +++ b/sources/c/main/common/type/global.h @@ -19,6 +19,8 @@ extern "C" { /** * A wrapper used for passing a common set of all data, particularly for sharing between threads. * + * The typedef for this is located in the defs.h header. + * * Properties: * - main: The main program data. * - program: The program data. @@ -31,7 +33,7 @@ extern "C" { * - debug: The output file for debug output messages, but with custom set to (controller_global_t *). */ #ifndef _di_controller_global_t_ - typedef struct { + struct controller_global_t_ { controller_main_t *main; controller_program_t *program; controller_thread_t *thread; @@ -41,7 +43,7 @@ extern "C" { fl_print_t *error; fl_print_t *warning; fl_print_t *debug; - } controller_global_t; + }; #define controller_global_t_initialize { 0, 0, 0, 0, 0, 0, 0, 0 } @@ -60,8 +62,9 @@ extern "C" { /** * A structure for passing data to the interrupt state function. * - * is_normal: Boolean designating if this is operating in a normal state. - * thread: The thread data. + * Properties: + * - is_normal: Boolean designating if this is operating in a normal state. + * - thread: The thread data. */ #ifndef _di_controller_interrupt_t_ typedef struct { diff --git a/sources/c/main/common/type/instance.h b/sources/c/main/common/type/instance.h index f0ef03c..c38c8a8 100644 --- a/sources/c/main/common/type/instance.h +++ b/sources/c/main/common/type/instance.h @@ -24,30 +24,33 @@ extern "C" { * The "cache" should only be used by the function processing/executing the process and as such should not require a write lock normally needed for thread-safety. * There must only be a single thread running any given Instance at a time, guaranteeing that the cache does not need read/write locks. * - * id: The ID of this process relative to the processes array. - * id_thread: The thread ID, a valid ID when state is "active", and an invalid ID when the state is "busy". - * - * action: The action being performed. - * options: Configuration options for this thread. - * state: The state of the process. - * type: The currently active process type (from the controller_instance_type_*_e). - * result: The last return code from an execution of a process. - * - * active: A read/write lock representing that something is currently using this (read locks = in use, write lock = begin deleting). - * lock: A read/write lock on the structure. - * wait: A thread condition to tell a process waiting process that the rule has is done being processed. - * wait_lock: A mutex lock for working with "wait". - * - * child: The process id of a child process, if one is running (when forking to execute a child process). - * path_pids: An array of paths representing PID files. - * stack: A stack used to represent dependencies as Rule ID's to avoid circular Rule dependencies (If Rule A waits on Rule B, then Rule B must not wait on Rule A). - * - * rule: A copy of the rule actively being executed. - * cache: The cache used by this Instance. - * global: The global data. + * The typedef for this is located in the defs.h header. + * + * Properties: + * - id: The ID of this process relative to the processes array. + * - id_thread: The thread ID, a valid ID when state is "active", and an invalid ID when the state is "busy". + * + * - action: The action being performed. + * - options: Configuration options for this thread. + * - state: The state of the process. + * - type: The currently active process type (from the controller_instance_type_*_e). + * - result: The last return code from an execution of a process. + * + * - active: A read/write lock representing that something is currently using this (read locks = in use, write lock = begin deleting). + * - lock: A read/write lock on the structure. + * - wait: A thread condition to tell a process waiting process that the rule has is done being processed. + * - wait_lock: A mutex lock for working with "wait". + * + * - child: The process id of a child process, if one is running (when forking to execute a child process). + * - path_pids: An array of paths representing PID files. + * - stack: A stack used to represent dependencies as Rule ID's to avoid circular Rule dependencies (If Rule A waits on Rule B, then Rule B must not wait on Rule A). + * + * - rule: A copy of the rule actively being executed. + * - cache: The cache used by this Instance. + * - global: The global data. */ #ifndef _di_controller_instance_t_ - typedef struct { + struct controller_instance_t_ { f_number_unsigned_t id; f_thread_id_t id_thread; @@ -69,7 +72,7 @@ extern "C" { controller_rule_t rule; controller_cache_t cache; controller_global_t global; - } controller_instance_t; + }; #define controller_instance_t_initialize { \ 0, \ @@ -95,19 +98,20 @@ extern "C" { /** * An array of Controller Instances. * - * This has a circular dependency with controller_thread_t. + * The typedef for this is located in the defs.h header. * - * array: An array of Instances. - * size: Total amount of allocated space. - * used: Total number of allocated spaces used. + * Properties: + * - array: An array of Instances. + * - size: Total amount of allocated space. + * - used: Total number of allocated spaces used. */ #ifndef _di_controller_instances_t_ - typedef struct { + struct controller_instances_t_ { controller_instance_t **array; f_number_unsigned_t size; f_number_unsigned_t used; - } controller_instances_t; + }; #define controller_instances_t_initialize { \ 0, \ @@ -143,6 +147,7 @@ extern "C" { * The exclusive stop position in the array to stop deleting. * @param array * The array structure to delete all values of. + * * Must not be NULL. * * @return diff --git a/sources/c/main/common/type/lock.h b/sources/c/main/common/type/lock.h index 56fb5a2..727c0f4 100644 --- a/sources/c/main/common/type/lock.h +++ b/sources/c/main/common/type/lock.h @@ -25,12 +25,13 @@ extern "C" { * The instance lock is intended to lock any activity on the instance structure. * The rule lock is intended to lock any activity on the rules structure. * - * alert: The alert mutex lock for waking up on alerts. - * cancel: The cancel mutex lock for locking the cancel operation. - * print: The print mutex lock. - * instance: The instance r/w lock. - * rule: The rule r/w lock. - * alert_condition: The condition used to trigger alerts. + * Properties: + * - alert: The alert mutex lock for waking up on alerts. + * - cancel: The cancel mutex lock for locking the cancel operation. + * - print: The print mutex lock. + * - instance: The instance r/w lock. + * - rule: The rule r/w lock. + * - alert_condition: The condition used to trigger alerts. */ #ifndef _di_controller_lock_t_ typedef struct { @@ -55,10 +56,10 @@ extern "C" { #endif // _di_controller_lock_t_ /** - * Fully deallocate all memory for the given lock without caring about return status. + * Fully de-allocate all memory for the given lock without caring about return status. * * @param lock - * The lock to deallocate. + * The lock to de-allocate. * * @see f_thread_lock_delete() * @see f_thread_mutex_delete() diff --git a/sources/c/main/common/type/program.h b/sources/c/main/common/type/program.h index 01e888e..f705531 100644 --- a/sources/c/main/common/type/program.h +++ b/sources/c/main/common/type/program.h @@ -19,25 +19,28 @@ extern "C" { /** * Controller program process data. * - * ready: State representing if the settings are all loaded and is ready to run program operations. - * mode: Controller setting mode based on the setting mode enumerator. + * The typedef for this is located in the defs.h header. * - * failsafe_item_id: The Entry Item ID to execute when failsafe execution is enabled. + * Properties: + * - ready: State representing if the settings are all loaded and is ready to run program operations. + * - mode: Controller setting mode based on the setting mode enumerator. * - * name_entry: The name of the entry file. - * path_cgroup: Directory path to the cgroup directory. - * path_control: File path to the control socket (used for printing the path). - * path_current: The current path. - * path_pid: File path to the PID file. - * path_setting: File path to the setting directory. + * - failsafe_item_id: The Entry Item ID to execute when failsafe execution is enabled. * - * control: The control socket data. - * entry: The Entry settings. - * exit: The Exit settings. - * rules: All rules and their respective settings. + * - name_entry: The name of the entry file. + * - path_cgroup: Directory path to the cgroup directory. + * - path_control: File path to the control socket (used for printing the path). + * - path_current: The current path. + * - path_pid: File path to the PID file. + * - path_setting: File path to the setting directory. + * + * - control: The control socket data. + * - entry: The Entry settings. + * - exit: The Exit settings. + * - rules: All rules and their respective settings. */ #ifndef _di_controller_program_t_ - typedef struct { + struct controller_program_t_ { uint8_t ready; uint8_t mode; @@ -54,7 +57,7 @@ extern "C" { controller_entry_t entry; controller_entry_t exit; controller_rules_t rules; - } controller_program_t; + }; #define controller_program_t_initialize { \ 0, \ diff --git a/sources/c/main/common/type/rule.c b/sources/c/main/common/type/rule.c index 0cc50ad..3872698 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_rule_action_delete_ - void controller_rule_action_delete(controller_rule_action_t * const action) { +#ifndef _di_controller_main_rule_action_delete_ + void controller_main_rule_action_delete(controller_main_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_rule_action_delete_ +#endif // _di_controller_main_rule_action_delete_ -#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) { +#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) { { - controller_rule_action_t * const controller_rule_actions = (controller_rule_action_t *) void_array; + controller_main_rule_action_t * const controller_main_rule_actions = (controller_main_rule_action_t *) void_array; for (f_number_unsigned_t i = start; i < stop; ++i) { - controller_rule_action_delete(&controller_rule_actions[i]); + controller_main_rule_action_delete(&controller_main_rule_actions[i]); } // for } return F_okay; } -#endif // _di_controller_rule_actions_delete_callback_ +#endif // _di_controller_main_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_rule_action_t), (void **) &item->actions.array, &item->actions.used, &item->actions.size, &controller_rule_actions_delete_callback); + 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); } #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 7ca3b9f..73b43d8 100644 --- a/sources/c/main/common/type/rule.h +++ b/sources/c/main/common/type/rule.h @@ -19,9 +19,10 @@ extern "C" { /** * The Rule "rerun" item for controlling re-execution. * - * count: A count of the number of executions. - * delay: The time to wait before attempting to re-run. - * max: The maximum number of times to re-run (with 0 representing re-run infinitely) for executions. + * Properties: + * - count: A count of the number of executions. + * - delay: The time to wait before attempting to re-run. + * - max: The maximum number of times to re-run (with 0 representing re-run infinitely) for executions. */ #ifndef _di_controller_rule_rerun_item_t_ typedef struct { @@ -49,13 +50,14 @@ extern "C" { /** * The Rule "rerun" values for controlling re-execution. * - * is: A bitwise set of options to designate whether rerun is enabled or not and other options. - * count_failure: A count of the number of failed executions. - * count_success: A count of the number of successful executions. - * delay_failure: The time to wait before attempting to "rerun" for failed executions. - * delay_success: The time to wait before attempting to "rerun" for successful executions. - * max_failure: The maximum number of times to "rerun" (with 0 representing "rerun" infinitely) for failed executions. - * max_success: The maximum number of times to "rerun" (with 0 representing "rerun" infinitely) for successful executions. + * Properties: + * - is: A bitwise set of options to designate whether rerun is enabled or not and other options. + * - count_failure: A count of the number of failed executions. + * - count_success: A count of the number of successful executions. + * - delay_failure: The time to wait before attempting to "rerun" for failed executions. + * - delay_success: The time to wait before attempting to "rerun" for successful executions. + * - max_failure: The maximum number of times to "rerun" (with 0 representing "rerun" infinitely) for failed executions. + * - max_success: The maximum number of times to "rerun" (with 0 representing "rerun" infinitely) for successful executions. */ #ifndef _di_controller_rule_rerun_t_ typedef struct { @@ -75,12 +77,13 @@ extern "C" { /** * Controller Rule Action. * - * type: The Rule Action type. - * line: The line number where the Rule Action begins. - * status: The last execution status of the Rule Action. - * parameters: All parameters associated with the Rule Action. + * Properties: + * - type: The Rule Action type. + * - line: The line number where the Rule Action begins. + * - status: The last execution status of the Rule Action. + * - parameters: All parameters associated with the Rule Action. */ -#ifndef _di_controller_rule_action_t_ +#ifndef _di_controller_main_rule_action_t_ typedef struct { uint8_t type; f_number_unsigned_t line; @@ -88,47 +91,49 @@ extern "C" { f_string_dynamics_t parameters; f_iki_datas_t ikis; - } controller_rule_action_t; + } controller_main_rule_action_t; - #define controller_rule_action_t_initialize { \ + #define controller_main_rule_action_t_initialize { \ 0, \ 0, \ F_known_not, \ f_string_dynamics_t_initialize, \ f_iki_datas_t_initialize, \ } -#endif // _di_controller_rule_action_t_ +#endif // _di_controller_main_rule_action_t_ /** * Controller Rule Actions. * - * array: An array of Rule Actions. - * size: Total amount of allocated space. - * used: Total number of allocated spaces used. + * Properties: + * - array: An array of Rule Actions. + * - size: Total amount of allocated space. + * - used: Total number of allocated spaces used. */ -#ifndef _di_controller_rule_actions_t_ +#ifndef _di_controller_main_rule_actions_t_ typedef struct { - controller_rule_action_t *array; + controller_main_rule_action_t *array; f_number_unsigned_t size; f_number_unsigned_t used; - } controller_rule_actions_t; + } controller_main_rule_actions_t; - #define controller_rule_actions_t_initialize { \ + #define controller_main_rule_actions_t_initialize { \ 0, \ 0, \ 0, \ } -#endif // _di_controller_rule_actions_t_ +#endif // _di_controller_main_rule_actions_t_ /** * Controller Rule Item. * - * type: The type of the Rule Item. - * with: A bitwise number representing execute "with" options. - * line: The line number where the Rule Item begins. - * reruns: An array designating rerun settings for each execution type available. - * actions: The actions associated with the Rule Item. + * Properties: + * - type: The type of the Rule Item. + * - with: A bitwise number representing execute "with" options. + * - line: The line number where the Rule Item begins. + * - reruns: An array designating rerun settings for each execution type available. + * - actions: The actions associated with the Rule Item. */ #ifndef _di_controller_rule_item_t_ typedef struct { @@ -137,8 +142,8 @@ extern "C" { f_number_unsigned_t line; f_string_dynamic_t pid_file; - controller_rule_rerun_t reruns[controller_rule_action_execute_type__enum_size_e]; - controller_rule_actions_t actions; + controller_rule_rerun_t reruns[controller_main_rule_action_execute_type__enum_size_e]; + controller_main_rule_actions_t actions; } controller_rule_item_t; #define controller_rule_item_t_initialize \ @@ -158,16 +163,17 @@ extern "C" { controller_rule_rerun_t_initialize, \ controller_rule_rerun_t_initialize, \ }, \ - controller_rule_actions_t_initialize, \ + controller_main_rule_actions_t_initialize, \ } #endif // _di_controller_rule_item_t_ /** * Controller Rule Items. * - * array: An array of Rule Items. - * size: Total amount of allocated space. - * used: Total number of allocated spaces used. + * Properties: + * - array: An array of Rule Items. + * - size: Total amount of allocated space. + * - used: Total number of allocated spaces used. */ #ifndef _di_controller_rule_items_t_ typedef struct { @@ -187,10 +193,11 @@ extern "C" { /** * The Rule "on" values for designating dependencies. * - * action: The Rule Action type this "on" dependencies are associated with. - * need: The Rule Alias for a required Rule. - * want: The Rule Alias for an optional Rule that is required to succeed if found. - * wish: The Rule Alias for an optional Rule that is not required. + * Properties: + * - action: The Rule Action type this "on" dependencies are associated with. + * - need: The Rule Alias for a required Rule. + * - want: The Rule Alias for an optional Rule that is required to succeed if found. + * - wish: The Rule Alias for an optional Rule that is not required. */ #ifndef _di_controller_rule_on_t_ typedef struct { @@ -212,9 +219,10 @@ extern "C" { /** * The Rule "on" array. * - * array: An array of Rule "on" values. - * size: Total amount of allocated space. - * used: Total number of allocated spaces used. + * Properties: + * - array: An array of Rule "on" values. + * - size: Total amount of allocated space. + * - used: Total number of allocated spaces used. */ #ifndef _di_controller_rule_ons_t_ typedef struct { @@ -234,36 +242,37 @@ extern "C" { /** * Controller Rule. * - * affinity: The cpu affinity to be used when executing the Rule. - * alias: The distinct ID (machine name) of the Rule, such as "service/ssh". - * capability: The capability setting if the Rule "has" a capability. - * cgroup: The control group setting if the Rule "has" a control group. - * define: Any defines (environment variables) made available to the Rule for IKI substitution or just as environment variables. - * engine: The program or path to the program of the scripting engine to use when processing scripts in this Rule. - * engine_arguments: Any arguments to pass to the engine program. - * environment: All environment variables allowed to be exposed to the Rule when processing. - * group: The group ID if the Rule "has" a group. - * groups: A set of group IDs to run the process with (first specified group is the primary group). - * has: Bitwise set of "has" codes representing what the Rule has. - * items: All items associated with the Rule. - * limits: The cpu/resource limits to use when executing the Rule. - * name: A human name for the Rule (does not have to be distinct), such as "Bash Script". - * nice: The niceness value if the Rule "has" nice. - * on: A set of parameters for defining dependencies and how they are needed, wanted, or wished for. - * 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_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. - * timeout_stop: The timeout to wait relating to stopping a process. - * timestamp: The timestamp when the Rule was loaded. - * user: The User ID if the Rule "has" a user. + * Properties: + * - affinity: The cpu affinity to be used when executing the Rule. + * - alias: The distinct ID (machine name) of the Rule, such as "service/ssh". + * - capability: The capability setting if the Rule "has" a capability. + * - cgroup: The control group setting if the Rule "has" a control group. + * - define: Any defines (environment variables) made available to the Rule for IKI substitution or just as environment variables. + * - engine: The program or path to the program of the scripting engine to use when processing scripts in this Rule. + * - engine_arguments: Any arguments to pass to the engine program. + * - environment: All environment variables allowed to be exposed to the Rule when processing. + * - group: The group ID if the Rule "has" a group. + * - groups: A set of group IDs to run the process with (first specified group is the primary group). + * - has: Bitwise set of "has" codes representing what the Rule has. + * - items: All items associated with the Rule. + * - limits: The cpu/resource limits to use when executing the Rule. + * - name: A human name for the Rule (does not have to be distinct), such as "Bash Script". + * - nice: The niceness value if the Rule "has" nice. + * - on: A set of parameters for defining dependencies and how they are needed, wanted, or wished for. + * - 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. + * - 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. + * - timeout_stop: The timeout to wait relating to stopping a process. + * - timestamp: The timestamp when the Rule was loaded. + * - user: The User ID if the Rule "has" a user. */ #ifndef _di_controller_rule_t_ typedef struct { - f_status_t status[controller_rule_action_type__enum_size_e]; + f_status_t status[controller_main_rule_action_type__enum_size_e]; f_number_unsigned_t timeout_kill; f_number_unsigned_t timeout_start; @@ -346,9 +355,10 @@ extern "C" { /** * Controller Rules. * - * array: An array of Rules. - * size: Total amount of allocated space. - * used: Total number of allocated spaces used. + * Properties: + * - array: An array of Rules. + * - size: Total amount of allocated space. + * - used: Total number of allocated spaces used. */ #ifndef _di_controller_rules_t_ typedef struct { @@ -366,10 +376,10 @@ extern "C" { #endif // _di_controller_rules_t_ /** - * Fully deallocate all memory for the given Rule without caring about return status. + * Fully de-allocate all memory for the given Rule without caring about return status. * * @param rule - * The rule to deallocate. + * The rule to de-allocate. * * @see f_capability_delete() * @see f_memory_array_resize() @@ -388,12 +398,12 @@ extern "C" { * @see f_memory_array_resize() * @see f_memory_arrays_resize() */ -#ifndef _di_controller_rule_action_delete_ - extern void controller_rule_action_delete(controller_rule_action_t * const action); -#endif // _di_controller_rule_action_delete_ +#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_ /** - * A callback intended to be passed to f_memory_arrays_resize() for an controller_rule_actions_t structure. + * A callback intended to be passed to f_memory_arrays_resize() for an controller_main_rule_actions_t structure. * * This is only called when shrinking the array and generally should perform de-allocations. * @@ -405,6 +415,7 @@ extern "C" { * The exclusive stop position in the array to stop deleting. * @param array * The array structure to delete all values of. + * * Must not be NULL. * * @return @@ -412,11 +423,11 @@ extern "C" { * * F_parameter (with error bit) if a parameter is invalid. * - * @see controller_rule_action_delete() + * @see controller_main_rule_action_delete() */ -#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_ +#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_ /** * Delete the Controller Rule Item data. @@ -424,7 +435,7 @@ extern "C" { * @param item * The Rule Item data. * - * @see controller_rule_actions_delete() + * @see controller_main_rule_actions_delete() * * @see f_memory_array_resize() */ @@ -444,6 +455,7 @@ extern "C" { * The exclusive stop position in the array to stop deleting. * @param array * The array structure to delete all values of. + * * Must not be NULL. * * @return @@ -482,6 +494,7 @@ extern "C" { * The exclusive stop position in the array to stop deleting. * @param array * The array structure to delete all values of. + * * Must not be NULL. * * @return diff --git a/sources/c/main/common/type/thread.h b/sources/c/main/common/type/thread.h index 918e668..e33fb0e 100644 --- a/sources/c/main/common/type/thread.h +++ b/sources/c/main/common/type/thread.h @@ -23,22 +23,25 @@ extern "C" { * * The "enabled" and "signal" utilize the lock: lock.process. * - * enabled: F_true when threads are active, FALSE when inactive and the program is essentially shutting down, no new threads should be started when F_false. - * signal: The code of any signal received. - * status: A status used by the main entry/rule processing thread for synchronous operations. + * The typedef for this is located in the defs.h header. * - * id_cleanup: The thread ID representing the Cleanup Process. - * id_control: The thread ID representing the Control Process. - * id_entry: The thread ID representing the Entry or Exit Process. - * id_rule: The thread ID representing the Rule Process. - * id_signal: The thread ID representing the Signal Process. + * Properties: + * - enabled: F_true when threads are active, FALSE when inactive and the program is essentially shutting down, no new threads should be started when F_false. + * - signal: The code of any signal received. + * - status: A status used by the main entry/rule processing thread for synchronous operations. * - * lock: A r/w lock for operating on this structure. - * instances: All Rule Instance thread data. - * cache: A cache used by the main entry/rule processing thread for synchronous operations. + * - id_cleanup: The thread ID representing the Cleanup Process. + * - id_control: The thread ID representing the Control Process. + * - id_entry: The thread ID representing the Entry or Exit Process. + * - id_rule: The thread ID representing the Rule Process. + * - id_signal: The thread ID representing the Signal Process. + * + * - lock: A r/w lock for operating on this structure. + * - instances: All Rule Instance thread data. + * - cache: A cache used by the main entry/rule processing thread for synchronous operations. */ #ifndef _di_controller_thread_t_ - typedef struct { + struct controller_thread_t_ { uint8_t enabled; int signal; f_status_t status; @@ -52,7 +55,7 @@ extern "C" { controller_lock_t lock; controller_instances_t instances; controller_cache_t cache; - } controller_thread_t; + }; #define controller_thread_t_initialize { \ controller_thread_enabled_e, \ @@ -70,10 +73,10 @@ extern "C" { #endif // _di_controller_thread_t_ /** - * Fully deallocate all memory for the given setting without caring about return status. + * Fully de-allocate all memory for the given setting without caring about return status. * * @param thread - * The thread to deallocate. + * The thread to de-allocate. * * Must not be NULL. * diff --git a/sources/c/main/controller.h b/sources/c/main/controller.h index 7dce5c6..2702008 100644 --- a/sources/c/main/controller.h +++ b/sources/c/main/controller.h @@ -96,12 +96,14 @@ #include #include #include +#include +#include #include +#include #include #include -#include -#include #include +#include #include #include #include @@ -117,11 +119,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include diff --git a/sources/c/main/lock.c b/sources/c/main/lock.c new file mode 100644 index 0000000..6d90c1e --- /dev/null +++ b/sources/c/main/lock.c @@ -0,0 +1,130 @@ +#include "controller.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_controller_main_lock_create_ + f_status_t controller_main_lock_create(controller_lock_t * const lock) { + + if (!lock) return F_status_set_error(F_parameter); + + f_status_t status = f_thread_mutex_create(0, &lock->alert); + + if (F_status_is_error_not(status)) { + status = f_thread_mutex_create(0, &lock->cancel); + } + + if (F_status_is_error_not(status)) { + status = f_thread_mutex_create(0, &lock->print); + } + + if (F_status_is_error_not(status)) { + status = f_thread_lock_create(0, &lock->instance); + } + + if (F_status_is_error_not(status)) { + status = f_thread_lock_create(0, &lock->rule); + } + + if (F_status_is_error_not(status)) { + status = f_thread_mutex_create(0, &lock->alert); + } + + if (F_status_is_error_not(status)) { + status = f_thread_condition_create(0, &lock->alert_condition); + } + + return F_status_is_error(status) ? status : F_okay; + } +#endif // _di_controller_main_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) { + + if (!thread || !lock) return F_status_set_error(F_parameter); + + f_status_t status = F_okay; + + 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); + + 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); + } + else { + break; + } + } // for + + return status; + } +#endif // _di_controller_main_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) { + + if (!thread || !lock) return F_status_set_error(F_parameter); + + return controller_main_lock_read_instance_type(instance->type, thread, lock); + } +#endif // _di_controller_main_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) { + + if (!thread || !lock) return F_status_set_error(F_parameter); + + return controller_main_lock_read(type != controller_instance_type_exit_e, thread, lock); + } +#endif // _di_controller_main_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) { + + if (!thread || !lock) return F_status_set_error(F_parameter); + + f_status_t status = F_okay; + + 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); + + 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); + } + else { + break; + } + } // for + + return status; + } +#endif // _di_controller_main_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) { + + if (!thread || !lock) return F_status_set_error(F_parameter); + + return controller_main_lock_write_instance_type(instance->type, thread, lock); + } +#endif // _di_controller_main_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) { + + if (!thread || !lock) return F_status_set_error(F_parameter); + + return controller_main_lock_write(type != controller_instance_type_exit_e, thread, lock); + } +#endif // _di_controller_main_lock_write_instance_type_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/sources/c/main/lock.h b/sources/c/main/lock.h new file mode 100644 index 0000000..65cb454 --- /dev/null +++ b/sources/c/main/lock.h @@ -0,0 +1,228 @@ +/** + * FLL - Level 3 + * + * Project: Controller + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Provides lock functionality. + * + * This is auto-included and should not need to be explicitly included. + */ +#ifndef _controller_main_lock_h +#define _controller_main_lock_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Perform the initial, required, allocation for the lock. + * + * @param lock + * The lock to allocate. + * + * Must not be NULL. + * + * @return + * F_okay on success. + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_thread_lock_delete(). + * Errors (with error bit) from: f_thread_mutex_delete(). + * + * @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_ + +/** + * Wait to get a read lock. + * + * Given a r/w lock, periodically check to see if main thread is disabled while waiting. + * + * @param is_normal + * If TRUE, then perform as if this operates during a normal operation (entry and control). + * If FALSE, then perform as if this operates during a an exit operation. + * @param thread + * The thread data used to determine if the main thread is disabled or not. + * + * Must not be NULL. + * @param lock + * The r/w lock to obtain a read lock on. + * + * Must not be NULL. + * + * @return + * F_okay on success. + * + * F_interrupt (with error bit set) on (exit) signal received, lock will not be set when this is returned. + * F_parameter (with error bit) if a parameter is invalid. + * + * Status from: f_thread_lock_read_timed(). + * + * Errors (with error bit) from: f_thread_lock_read_timed(). + * + * @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_ + +/** + * Wait to get a read lock for some instance. + * + * Given a r/w lock, periodically check to see if main thread is disabled while waiting. + * + * @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 + * The r/w lock to obtain a read lock on. + * + * Must not be NULL. + * + * @return + * Status from: controller_main_lock_read(). + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: controller_main_lock_read(). + * + * @see controller_main_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_ + +/** + * Wait to get a read lock for some instance type. + * + * Given a r/w lock, periodically check to see if main thread is disabled while waiting. + * + * @param type + * The instance type 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 + * The r/w lock to obtain a read lock on. + * + * Must not be NULL. + * + * @return + * Status from: controller_main_lock_read(). + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: controller_main_lock_read(). + * + * @see controller_main_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_ + +/** + * Wait to get a write lock. + * + * Given a r/w lock, periodically check to see if main thread is disabled while waiting. + * + * @param is_normal + * If TRUE, then perform as if this operates during a normal operation (entry and control). + * If FALSE, then perform as if this operates during a an exit operation. + * @param thread + * The thread data used to determine if the main thread is disabled or not. + * + * Must not be NULL. + * @param lock + * The r/w lock to obtain a write lock on. + * + * Must not be NULL. + * + * @return + * F_okay on success. + * + * F_interrupt (with error bit set) on (exit) signal received, lock will not be set when this is returned. + * F_parameter (with error bit) if a parameter is invalid. + * + * Status from: f_thread_lock_write_timed(). + * + * Errors (with error bit) from: f_thread_lock_write_timed(). + * + * @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_ + +/** + * Wait to get a write lock for some instance. + * + * Given a r/w lock, periodically check to see if main thread is disabled while waiting. + * + * @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 + * The r/w lock to obtain a write lock on. + * + * Must not be NULL. + * + * @return + * Status from: controller_main_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(). + * + * @see controller_main_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_ + +/** + * Wait to get a write lock for some instance type. + * + * Given a r/w lock, periodically check to see if main thread is disabled while waiting. + * + * @param type + * The instance type 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 + * The r/w lock to obtain a write lock on. + * + * Must not be NULL. + * + * @return + * Status from: controller_main_lock_write(). + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: controller_main_lock_write(). + * + * @see controller_main_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_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _controller_main_lock_h diff --git a/sources/c/main/print/error.c b/sources/c/main/print/error.c index 8e69031..8feac22 100644 --- a/sources/c/main/print/error.c +++ b/sources/c/main/print/error.c @@ -63,7 +63,7 @@ extern "C" { #endif // _di_controller_main_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, f_string_dynamic_t * const path) { + 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) { if (!print) return F_status_set_error(F_output_not); if (print->verbosity < f_console_verbosity_error_e) return F_output_not; diff --git a/sources/c/main/print/error.h b/sources/c/main/print/error.h index 46282b9..fb7b032 100644 --- a/sources/c/main/print/error.h +++ b/sources/c/main/print/error.h @@ -21,6 +21,7 @@ extern "C" { * * @param print * The output structure to print to. + * * Must not be NULL. * * This does not alter print.custom.setting.state.status. @@ -74,6 +75,7 @@ extern "C" { * * @param print * The output structure to print to. + * * Must not be NULL. * * The print.custom is expected to be of type fss_read_main_t. @@ -106,6 +108,7 @@ extern "C" { * * @param print * The output structure to print to. + * * Must not be NULL. * * The print.custom is expected to be of type fss_read_main_t. @@ -140,6 +143,7 @@ extern "C" { * * @param print * The output structure to print to. + * * Must not be NULL. * * This does not alter print.custom.setting.state.status. @@ -161,61 +165,6 @@ extern "C" { #endif // _di_controller_main_print_error_status_ /** - * Print generic error/warning information. - * - * This is essentially a wrapper to fll_error_print() that includes locking. - * - * @param thread - * The thread data. - * @param print - * Designates how printing is to be performed. - * @param cache - * The action cache. - * @param status - * The status code to process. - * Make sure this has F_status_set_fine() called if the status code has any error or warning bits. - * @param function - * The name of the function where the error happened. - * Set to 0 to disable. - * @param fallback - * Set to F_true to print the fallback error message for unknown errors. - * @param item - * If TRUE, then this error is associated with an item. - * If FALSE, then this error is associated with a rule setting. - * - * @see fll_error_print() - * @see controller_main_print_rule_error_cache() - */ -#ifndef _di_controller_main_print_rule_error_ - extern void controller_main_print_rule_error(controller_thread_t * const thread, 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_ - -/** - * Print additional error/warning information in addition to existing error. - * - * This is explicitly intended to be used in addition to the error message. - * - * This neither locks the thread nor does it check to see if output is enabled or disabled. - * - * @param print - * The error or warning output structure. - * @param cache - * A structure for containing and caching relevant data. - * @param item - * If TRUE, then this error is associated with an item. - * If FALSE, then this error is associated with a rule setting. - * - * @see controller_rule_action_read() - * @see controller_rule_item_read() - * @see controller_rule_items_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_ - -/** * Print error message regarding the pid file already existing. * * @param print @@ -231,8 +180,6 @@ extern "C" { * @param path * The path to the PID file. * - * Must not be NULL. - * * @return * F_okay on success. * F_output_not on success, but no printing is performed. @@ -242,7 +189,7 @@ 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, f_string_dynamic_t * const path); + 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_ #ifdef __cplusplus diff --git a/sources/c/main/print/lock.h b/sources/c/main/print/lock.h index bf8b41b..2d7f095 100644 --- a/sources/c/main/print/lock.h +++ b/sources/c/main/print/lock.h @@ -49,6 +49,7 @@ extern "C" { * The file stream to lock. * @param thread * (optonal) The thread containing the print mutex to lock. + * * Set to NULL to not use. * * @see f_file_stream_lock() @@ -72,6 +73,7 @@ extern "C" { * The file stream to unlock and flush. * @param thread * (optonal) The thread containing the print mutex to unlock. + * * Set to NULL to not use. * * @see f_file_stream_unlock() diff --git a/sources/c/main/print/rule.h b/sources/c/main/print/rule.h index f2a02d7..06b4cb2 100644 --- a/sources/c/main/print/rule.h +++ b/sources/c/main/print/rule.h @@ -59,11 +59,11 @@ 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_rule_action_read() - * @see controller_rule_item_read() + * @see controller_main_rule_action_read() + * @see controller_main_rule_item_read() * @see controller_rule_items_read() - * @see controller_rule_read() - * @see controller_rule_setting_read() + * @see controller_main_rule_read() + * @see controller_main_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); diff --git a/sources/c/main/print/rule/item.h b/sources/c/main/print/rule/item.h index 38d744f..7e1db6b 100644 --- a/sources/c/main/print/rule/item.h +++ b/sources/c/main/print/rule/item.h @@ -21,9 +21,11 @@ extern "C" { * * @param print * The output structure to print to. + * * Must not be NULL. * @param cache * A structure for containing and caching relevant data. + * * Must not be NULL. * * @return @@ -69,9 +71,11 @@ extern "C" { * * @param print * The output structure to print to. + * * Must not be NULL. * @param cache * A structure for containing and caching relevant data. + * * Must not be NULL. * * @return @@ -96,9 +100,11 @@ extern "C" { * * @param print * The output structure to print to. + * * Must not be NULL. * @param cache * A structure for containing and caching relevant data. + * * Must not be NULL. * * @return @@ -123,9 +129,11 @@ extern "C" { * * @param print * The output structure to print to. + * * Must not be NULL. * @param cache * A structure for containing and caching relevant data. + * * Must not be NULL. * @param name * The parameter name whose value is unknown. diff --git a/sources/c/main/print/rule/setting.h b/sources/c/main/print/rule/setting.h index 624e268..f409767 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_rule_setting_read(). + * This is intended to be explicitly called by controller_main_rule_setting_read(). * This is intended only to be used for simple messages. * * @param print @@ -35,7 +35,7 @@ extern "C" { * @param cache * A structure for containing and caching relevant data. * - * @see controller_rule_setting_read() + * @see controller_main_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); @@ -44,7 +44,7 @@ extern "C" { /** * Print a message about a rule setting problem, with additional messages about the value. * - * This is intended to be explicitly called by controller_rule_setting_read(). + * This is intended to be explicitly called by controller_main_rule_setting_read(). * This is intended only to be used for simple messages. * * @param print @@ -64,7 +64,7 @@ extern "C" { * @param cache * A structure for containing and caching relevant data. * - * @see controller_rule_setting_read() + * @see controller_main_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); diff --git a/sources/c/main/process.c b/sources/c/main/process.c index 5c5bddd..1a09fa5 100644 --- a/sources/c/main/process.c +++ b/sources/c/main/process.c @@ -25,9 +25,6 @@ extern "C" { return; } - // A custom status at this scope is used to prevent the status from being changed by any child process or sub-function. - f_status_t status = F_okay; - fl_print_t message = main->program.message; fl_print_t output = main->program.output; fl_print_t error = main->program.error; @@ -40,7 +37,7 @@ 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. - status = controller_main_lock_create(&thread.lock); + f_status_t status = controller_main_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); @@ -53,7 +50,7 @@ extern "C" { } if (F_status_is_error_not(status)) { - status = f_thread_create(0, &thread.id_signal, &controller_thread_signal_normal, (void *) &global); + status = f_thread_create(0, &thread.id_signal, &controller_main_thread_signal_normal, (void *) &global); } if (F_status_is_error(status)) { @@ -63,11 +60,11 @@ extern "C" { } else { if (main->setting.flag & controller_main_flag_daemon_e) { - program->ready = controller_setting_ready_done_e; + program->ready = controller_program_ready_done_e; if (f_file_exists(program->path_pid, F_true) == F_true) { status = F_status_set_error(F_available_not); - program->ready = controller_setting_ready_abort_e; + program->ready = controller_program_ready_abort_e; controller_main_print_error_file_pid_exists(&main->program.error, &thread, program->path_pid); } @@ -79,7 +76,7 @@ extern "C" { controller_main_print_error_status(&main->program.error, macro_controller_f(f_thread_create), status); } else { - controller_thread_join(&thread.id_entry); + controller_main_thread_join(&thread.id_entry); status = thread.status; thread.id_entry = 0; @@ -94,7 +91,7 @@ extern "C" { // Wait for the entry thread to complete before starting the rule thread. controller_main_thread_join(&thread.id_rule); - if (thread.enabled && program->mode == controller_setting_mode_service_e) { + if (thread.enabled && program->mode == controller_program_mode_service_e) { status = f_thread_create(0, &thread.id_rule, &controller_main_thread_rule, (void *) &global); if (F_status_is_error(status)) { @@ -116,23 +113,23 @@ extern "C" { if (status == F_child) { main->setting.state.status = F_child; - controller_main_thread_delete(&thread); + controller_thread_delete(&thread); return; } - 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_setting_mode_service_e) { + 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 (program->mode == controller_program_mode_service_e) { controller_main_thread_join(&thread.id_signal); } - else if (program->mode == controller_setting_mode_helper_e || program->mode == controller_setting_mode_program_e) { + 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); } } - controller_main_thread_process_cancel(global, F_true, controller_thread_cancel_call_e); + controller_main_thread_instance_cancel(global, F_true, controller_thread_cancel_call_e); - controller_main_thread_process_exit(&global); + controller_main_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); @@ -146,7 +143,7 @@ extern "C" { thread.id_rule = 0; thread.id_signal = 0; - controller_main_thread_delete(&thread); + controller_thread_delete(&thread); if (F_status_set_fine(status) == F_interrupt) { fll_program_print_signal_received(&main->program.warning, thread.signal); diff --git a/sources/c/main/process.h b/sources/c/main/process.h index e800d40..626aeff 100644 --- a/sources/c/main/process.h +++ b/sources/c/main/process.h @@ -17,7 +17,7 @@ extern "C" { #endif /** - * Execute main program process. + * Execute main program process, starting all threads, waiting on threads, and handling requests. * * If main.signal is non-zero, then this blocks and handles the following signals: * - F_signal_abort diff --git a/sources/c/main/rule.c b/sources/c/main/rule.c index 899b55a..b396231 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_rule_action_type__enum_size_e; ++i) { + for (; i < controller_main_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_rule_action_t *action_source = 0; - controller_rule_action_t *action_destination = 0; + controller_main_rule_action_t *action_source = 0; + controller_main_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_rule_action_t), (void **) &item_destination->actions.array, &item_destination->actions.used, &item_destination->actions.size, &controller_rule_actions_delete_callback); + 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); 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_rule_action_execute_type__enum_size_e; ++j) { + for (j = 0; j < controller_main_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; diff --git a/sources/c/main/rule/action.c b/sources/c/main/rule/action.c index b74dd92..60e099e 100644 --- a/sources/c/main/rule/action.c +++ b/sources/c/main/rule/action.c @@ -4,35 +4,35 @@ extern "C" { #endif -#ifndef _di_controller_rule_action_method_name_ - f_string_static_t controller_rule_action_method_name(const uint8_t type) { +#ifndef _di_controller_main_rule_action_method_name_ + f_string_static_t controller_main_rule_action_method_name(const uint8_t type) { - 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; + 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; return f_string_empty_s; } -#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_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_type_to_action_execute_type_ +#endif // _di_controller_main_rule_action_type_to_action_execute_type_ -#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) { +#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) { if (!global || !item || !actions || !range) return F_status_set_error(F_parameter); @@ -63,7 +63,7 @@ extern "C" { cache->delimits.used = 0; cache->content_action.used = 0; - if (method == controller_rule_action_method_extended_list_e) { + if (method == controller_main_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)) { @@ -160,7 +160,7 @@ extern "C" { for (i = 0; i < cache->object_actions.used; ++i) { - status = f_memory_array_increase_by(controller_allocation_small_d, sizeof(controller_rule_action_t), (void **) &actions->array, &actions->used, &actions->size); + status = f_memory_array_increase_by(controller_allocation_small_d, sizeof(controller_main_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)); @@ -180,7 +180,7 @@ extern "C" { actions->array[actions->used].line += ++item->line; actions->array[actions->used].status = F_known_not; - status = controller_rule_parameters_read(global, cache->buffer_item, &cache->object_actions.array[i], &cache->content_actions.array[i], &actions->array[actions->used], &state); + 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); if (F_status_is_error(status)) { actions->array[actions->used++].status = controller_main_error_simplify(F_status_set_fine(status)); @@ -209,7 +209,7 @@ extern "C" { if (F_status_is_error(status)) { controller_main_print_error(&global->main->program.error, macro_controller_f(f_fss_apply_delimit)); } - else if (type == controller_rule_action_type_pid_file_e) { + else if (type == controller_main_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); @@ -218,36 +218,36 @@ extern "C" { controller_main_print_error(&global->main->program.error, macro_controller_f(f_rip_dynamic_partial)); } } - else if (type == controller_rule_action_type_rerun_e) { + else if (type == controller_main_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_rule_action_execute_type_freeze_e; + type_rerun = controller_main_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_rule_action_execute_type_kill_e; + type_rerun = controller_main_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_rule_action_execute_type_pause_e; + type_rerun = controller_main_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_rule_action_execute_type_reload_e; + type_rerun = controller_main_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_rule_action_execute_type_restart_e; + type_rerun = controller_main_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_rule_action_execute_type_resume_e; + type_rerun = controller_main_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_rule_action_execute_type_start_e; + type_rerun = controller_main_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_rule_action_execute_type_stop_e; + type_rerun = controller_main_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_rule_action_execute_type_thaw_e; + type_rerun = controller_main_rule_action_execute_type_thaw_e; } } @@ -278,10 +278,10 @@ 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_rule_action_read_rerun_number(global, controller_delay_s.string, cache, &i, &rerun_item->delay); + status = controller_main_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_rule_action_read_rerun_number(global, controller_max_s.string, cache, &i, &rerun_item->max); + status = controller_main_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; @@ -293,7 +293,7 @@ extern "C" { } } // for } - else if (type == controller_rule_action_type_with_e) { + else if (type == controller_main_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) { @@ -390,7 +390,7 @@ extern "C" { actions->array[actions->used].line += ++item->line; actions->array[actions->used].status = F_known_not; - status = controller_rule_parameters_read(global, cache->buffer_item, 0, &cache->content_action, &actions->array[actions->used], &state); + status = controller_main_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)); @@ -412,10 +412,10 @@ extern "C" { return status; } -#endif // _di_controller_rule_action_read_ +#endif // _di_controller_main_rule_action_read_ -#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) { +#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) { f_status_t status = F_okay; f_number_signed_t parsed = 0; @@ -481,7 +481,7 @@ extern "C" { return F_okay; } -#endif // _di_controller_rule_action_read_rerun_number_ +#endif // _di_controller_main_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 0307966..0ad52e9 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_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_ +#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_ /** * 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_rule_action_execute_type__enum_size_e is returned for unknown types. + * The code controller_main_rule_action_execute_type__enum_size_e is returned for unknown types. */ -#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_ +#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_ /** * Read the content within the buffer, processing the action (or a set of within a list) for the given item. @@ -52,6 +52,7 @@ extern "C" { * * @param global * The global data. + * * Must not be NULL. * * This does not alter global.main.setting.state.status. @@ -64,42 +65,47 @@ extern "C" { * The action method for this action or set of actions. * @param cache * A structure for containing and caching relevant data. + * * Must not be NULL. * @param item * The processed item. + * * Must not be NULL. * @param actions * The processed actions. + * * Must not be NULL. * @param range * The current positions within the buffer being operated on. * This is expected to be set to a position immediately after a valid object read. + * * Must not be NULL. * * @return * F_okay on success. * - * Errors (with error bit) from: controller_rule_parameters_read(). + * Errors (with error bit) from: controller_main_rule_parameters_read(). * Errors (with error bit) from: f_fss_count_lines(). * Errors (with error bit) from: f_memory_array_increase_by(). * - * @see controller_rule_parameters_read() + * @see controller_main_rule_parameters_read() * @see f_fss_count_lines() * @see f_memory_array_increase_by() */ -#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_ +#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_ /** * 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_rule_action_read(). + * This is intended to be called by controller_main_rule_action_read(). * * @param global * The global data. + * * Must not be NULL. * * This does not alter global.main.setting.state.status. @@ -119,12 +125,12 @@ extern "C" { * * Errors (with error bit) from: fl_conversion_dynamic_partial_to_signed_detect(). * - * @see controller_rule_action_read() + * @see controller_main_rule_action_read() * @see fl_conversion_dynamic_partial_to_signed_detect() */ -#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_ +#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_ #ifdef __cplusplus diff --git a/sources/c/main/rule/execute.c b/sources/c/main/rule/execute.c index 35cc1e3..7d2bbf4 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_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) { +#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) { if (!global || !instance) return F_status_set_error(F_parameter); @@ -37,7 +37,7 @@ extern "C" { execute_set.as.control_group = &instance->rule.cgroup; // Make sure all required cgroup directories exist. - if (controller_rule_status_is_available(action, instance->rule)) { + if (controller_main_rule_status_is_available(action, instance->rule)) { status = fll_control_group_prepare(instance->rule.cgroup); if (F_status_is_error(status)) { @@ -249,21 +249,21 @@ extern "C" { } if (instance->rule.items.array[i].type == controller_rule_item_type_command_e) { - status = controller_rule_expand(global, instance->rule.items.array[i].actions.array[j], instance); + status = controller_main_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_rule_expand", F_true, F_false); + controller_main_print_rule_error(&global->error, instance->cache.action, F_status_set_fine(status), "controller_main_rule_expand", F_true, F_false); break; } do { - status = controller_rule_execute_foreground(instance->rule.items.array[i].type, f_string_empty_s, instance->cache.expanded, options, &execute_set, instance); + status = controller_main_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_rule_execute_rerun(controller_rule_action_type_to_action_execute_type(action), instance, &instance->rule.items.array[i]) > 0); + } while (controller_main_rule_execute_rerun(controller_main_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_rule_expand(global, instance->rule.items.array[i].actions.array[j], instance); + status = controller_main_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_rule_expand", F_true, F_false); + controller_main_print_rule_error(&global->error, instance->cache.action, F_status_set_fine(status), "controller_main_rule_expand", F_true, F_false); break; } @@ -296,16 +296,16 @@ extern "C" { do { if (instance->rule.engine.used) { - status = controller_rule_execute_foreground(instance->rule.items.array[i].type, instance->rule.engine, instance->rule.engine_arguments, options, &execute_set, instance); + status = controller_main_rule_execute_foreground(instance->rule.items.array[i].type, instance->rule.engine, instance->rule.engine_arguments, options, &execute_set, instance); } else { - status = controller_rule_execute_foreground(instance->rule.items.array[i].type, *global->main->setting.default_engine, instance->rule.engine_arguments, options, &execute_set, instance); + 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); } 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_rule_execute_rerun(controller_rule_action_type_to_action_execute_type(action), instance, &instance->rule.items.array[i]) > 0); + } while (controller_main_rule_execute_rerun(controller_main_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_rule_expand(global, instance->rule.items.array[i].actions.array[j], instance); + status = controller_main_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_rule_expand", F_true, F_false); + controller_main_print_rule_error(&global->error, instance->cache.action, F_status_set_fine(status), "controller_main_rule_expand", F_true, F_false); break; } if (instance->rule.items.array[i].pid_file.used) { do { - 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); + 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); 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_rule_execute_rerun(controller_rule_action_type_to_action_execute_type(action), instance, &instance->rule.items.array[i]) > 0); + } while (controller_main_rule_execute_rerun(controller_main_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; @@ -359,10 +359,10 @@ extern "C" { } 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_rule_expand(global, instance->rule.items.array[i].actions.array[j], instance); + status = controller_main_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_rule_expand", F_true, F_false); + controller_main_print_rule_error(&global->error, instance->cache.action, F_status_set_fine(status), "controller_main_rule_expand", F_true, F_false); break; } @@ -375,12 +375,12 @@ extern "C" { } do { - 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 : *global->main->setting.default_engine, instance->rule.engine_arguments, options, instance->rule.items.array[i].with, &execute_set, instance); + 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); 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_rule_execute_rerun(controller_rule_action_type_to_action_execute_type(action), instance, &instance->rule.items.array[i]) > 0); + } while (controller_main_rule_execute_rerun(controller_main_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; @@ -429,7 +429,7 @@ extern "C" { // Lock failed, attempt to re-establish lock before returning. if (F_status_set_fine(status) == F_lock) { - status = controller_lock_read(instance, global->thread, &instance->lock); + status = controller_main_lock_read(instance, global->thread, &instance->lock); if (F_status_is_error(status)) return F_status_set_error(F_lock); success = F_false; @@ -453,10 +453,10 @@ extern "C" { return F_okay; } -#endif // _di_controller_rule_execute_ +#endif // _di_controller_main_rule_execute_ -#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) { +#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) { if (!instance) return F_status_set_error(F_parameter); @@ -524,9 +524,9 @@ extern "C" { // Sleep for less than a second to better show simulation of synchronous vs asynchronous. { - const f_time_spec_t delay = controller_time_milliseconds(controller_thread_simulation_timeout_d); + const f_time_spec_t delay = controller_main_time_milliseconds(controller_thread_simulation_timeout_d); - if (controller_time_sleep_nanoseconds((controller_global_t *) instance->global, delay) == -1) { + if (controller_main_time_sleep_nanoseconds((controller_global_t *) instance->global, delay) == -1) { status = F_status_set_error(F_interrupt); } } @@ -547,13 +547,13 @@ extern "C" { f_thread_unlock(&instance->lock); - status_lock = controller_lock_write_process(instance, thread, &instance->lock); + status_lock = controller_main_lock_write_instance(instance, thread, &instance->lock); 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_lock_read_process(instance, thread, &instance->lock); + status = controller_main_lock_read_instance(instance, thread, &instance->lock); if (status == F_okay) { return status_lock; @@ -568,7 +568,7 @@ extern "C" { f_thread_unlock(&instance->lock); - status_lock = controller_lock_read_process(instance, thread, &instance->lock); + status_lock = controller_main_lock_read_instance(instance, thread, &instance->lock); if (F_status_is_error(status_lock)) { controller_lock_print_error_critical(&main->program.error, F_status_set_fine(status_lock), F_true, thread); @@ -588,13 +588,13 @@ extern "C" { f_thread_unlock(&instance->lock); } - status_lock = controller_lock_write_process(instance, thread, &instance->lock); + status_lock = controller_main_lock_write_instance(instance, thread, &instance->lock); 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_lock_read_process(instance, thread, &instance->lock); + status = controller_main_lock_read_instance(instance, thread, &instance->lock); if (status == F_okay) { return status_lock; @@ -611,7 +611,7 @@ extern "C" { f_thread_unlock(&instance->lock); - status_lock = controller_lock_read_process(instance, thread, &instance->lock); + status_lock = controller_main_lock_read_instance(instance, thread, &instance->lock); if (F_status_is_error(status_lock)) { controller_lock_print_error_critical(&main->program.error, F_status_set_fine(status_lock), F_true, thread); @@ -664,10 +664,10 @@ extern "C" { return status; } -#endif // _di_controller_rule_execute_foreground_ +#endif // _di_controller_main_rule_execute_foreground_ -#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) { +#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) { if (!execute_set || !instance) return F_status_set_error(F_parameter); @@ -772,9 +772,9 @@ extern "C" { // Sleep for less than a second to better show simulation of synchronous vs asynchronous. { - const f_time_spec_t delay = controller_time_milliseconds(controller_thread_simulation_timeout_d); + const f_time_spec_t delay = controller_main_time_milliseconds(controller_thread_simulation_timeout_d); - if (controller_time_sleep_nanoseconds((controller_global_t *) instance->global, delay) == -1) { + if (controller_main_time_sleep_nanoseconds((controller_global_t *) instance->global, delay) == -1) { status = F_status_set_error(F_interrupt); } } @@ -796,13 +796,13 @@ extern "C" { f_thread_unlock(&instance->lock); - status_lock = controller_lock_write_process(instance, thread, &instance->lock); + status_lock = controller_main_lock_write_instance(instance, thread, &instance->lock); 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_lock_read_process(instance, thread, &instance->lock); + status = controller_main_lock_read_instance(instance, thread, &instance->lock); if (status == F_okay) { return status_lock; @@ -817,7 +817,7 @@ extern "C" { f_thread_unlock(&instance->lock); - status_lock = controller_lock_read_process(instance, thread, &instance->lock); + status_lock = controller_main_lock_read_instance(instance, thread, &instance->lock); if (F_status_is_error(status_lock)) { controller_lock_print_error_critical(&main->program.error, F_status_set_fine(status_lock), F_true, thread); @@ -841,13 +841,13 @@ extern "C" { f_thread_unlock(&instance->lock); } - status_lock = controller_lock_write_process(instance, thread, &instance->lock); + status_lock = controller_main_lock_write_instance(instance, thread, &instance->lock); 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_lock_read_process(instance, thread, &instance->lock); + status = controller_main_lock_read_instance(instance, thread, &instance->lock); if (status == F_okay) { return status_lock; @@ -864,7 +864,7 @@ extern "C" { f_thread_unlock(&instance->lock); - status_lock = controller_lock_read_process(instance, thread, &instance->lock); + status_lock = controller_main_lock_read_instance(instance, thread, &instance->lock); if (F_status_is_error(status_lock)) { controller_lock_print_error_critical(&main->program.error, F_status_set_fine(status_lock), F_true, thread); @@ -917,10 +917,10 @@ extern "C" { return status; } -#endif // _di_controller_rule_execute_pid_with_ +#endif // _di_controller_main_rule_execute_pid_with_ -#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) { +#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) { if (!instance || !item) return F_status_set_error(F_parameter); @@ -939,7 +939,7 @@ extern "C" { 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_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_main_rule_action_execute_type_name(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); @@ -957,9 +957,9 @@ extern "C" { } if (rerun_item->delay) { - const f_time_spec_t delay = controller_time_milliseconds(rerun_item->delay); + const f_time_spec_t delay = controller_main_time_milliseconds(rerun_item->delay); - if (controller_time_sleep_nanoseconds(main, (controller_process_t *) instance->main_setting, delay) == -1) { + if (controller_main_time_sleep_nanoseconds(main, (controller_process_t *) instance->main_setting, delay) == -1) { return -1; } @@ -985,7 +985,7 @@ extern "C" { return F_false; } -#endif // _di_controller_rule_execute_rerun_ +#endif // _di_controller_main_rule_execute_rerun_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/rule/execute.h b/sources/c/main/rule/execute.h index f9fd110..50ad46a 100644 --- a/sources/c/main/rule/execute.h +++ b/sources/c/main/rule/execute.h @@ -23,6 +23,7 @@ extern "C" { * * @param global * The global data. + * * Must not be NULL. * * This does not alter global.main.setting.state.status. @@ -30,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_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 + * - 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 * @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). @@ -56,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_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_ +#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_ /** * Perform an execution of the given rule in the foreground. @@ -90,9 +91,9 @@ extern "C" { * * @see fll_execute_program() */ -#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_ +#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_ /** * Perform an execution of the given rule in the foreground or background and creating a PID file. @@ -132,9 +133,9 @@ extern "C" { * * @see fll_execute_program() */ -#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_ +#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_ /** * Determine whether or not an execute rule should be re-run, applying a delay as requested. @@ -155,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_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_ +#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_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/rule/expand.c b/sources/c/main/rule/expand.c index 6256339..f5cc222 100644 --- a/sources/c/main/rule/expand.c +++ b/sources/c/main/rule/expand.c @@ -4,8 +4,8 @@ extern "C" { #endif -#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) { +#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) { if (!global || !instance) return F_status_set_error(F_parameter); @@ -51,7 +51,7 @@ extern "C" { if (F_status_is_error(status)) break; } - status = controller_rule_expand_iki(process, action.parameters.array[process->cache.expanded.used], iki_data->vocabulary.array[i], iki_data->content.array[i], buffer); + 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); if (F_status_is_error(status)) break; first = iki_data->variable.array[i].stop + 1; @@ -85,10 +85,10 @@ extern "C" { return F_okay; } -#endif // _di_controller_rule_expand_ +#endif // _di_controller_main_rule_expand_ -#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) { +#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) { if (!instance || !destination) return F_status_set_error(F_parameter); if (vocabulary.start > vocabulary.stop) return F_okay; @@ -374,7 +374,7 @@ extern "C" { return F_okay; } -#endif // _di_controller_rule_expand_iki_ +#endif // _di_controller_main_rule_expand_iki_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/rule/expand.h b/sources/c/main/rule/expand.h index 4cb4d7b..b4f5d48 100644 --- a/sources/c/main/rule/expand.h +++ b/sources/c/main/rule/expand.h @@ -21,6 +21,7 @@ extern "C" { * * @param global * The global data. + * * Must not be NULL. * * This does not alter global.main.setting.state.status. @@ -32,13 +33,13 @@ extern "C" { * @return * F_okay on success. * - * Errors (with error bit) from: controller_rule_expand_iki(). + * Errors (with error bit) from: controller_main_rule_expand_iki(). * - * @see controller_rule_expand_iki() + * @see controller_main_rule_expand_iki() */ -#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_ +#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_ /** * Expand a single IKI variable into the buffer. @@ -63,9 +64,9 @@ extern "C" { * @see f_environment_get() * @see f_string_dynamic_append() */ -#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_ +#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_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/rule/instance.c b/sources/c/main/rule/instance.c index e0d2cad..bf54e7f 100644 --- a/sources/c/main/rule/instance.c +++ b/sources/c/main/rule/instance.c @@ -4,21 +4,21 @@ extern "C" { #endif -#ifndef _di_controller_rule_instance_ - f_status_t controller_rule_instance(controller_global_t * const global, controller_instance_t * const instance) { +#ifndef _di_controller_main_rule_instance_ + f_status_t controller_main_rule_instance(controller_global_t * const global, controller_instance_t * const instance) { if (!global || !instance) return F_status_set_error(F_parameter); switch (instance->action) { - 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: + 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: break; default: @@ -26,7 +26,7 @@ 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_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_main_rule_action_type_name(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); @@ -77,7 +77,7 @@ extern "C" { } if ((instance->options & controller_instance_option_simulate_e) && (instance->options & controller_instance_option_validate_e)) { - controller_rule_validate(global, instance->rule, instance->action, instance->options, &instance->cache); + controller_main_rule_validate(global, instance->rule, instance->action, instance->options, &instance->cache); } f_number_unsigned_t i = 0; @@ -118,15 +118,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_thread_is_enabled_instance(instance, global->thread); ++i) { + for (i = 0; i < 3 && controller_main_thread_is_enabled_instance(instance, global->thread); ++i) { - for (j = 0; j < dynamics[i]->used && controller_thread_is_enabled_instance(instance, global->thread); ++j) { + for (j = 0; j < dynamics[i]->used && controller_main_thread_is_enabled_instance(instance, global->thread); ++j) { id_dependency = 0; dependency = 0; found = F_false; - status_lock = controller_lock_read_instance(instance, global->thread, &global->thread->lock.instance); + status_lock = controller_main_lock_read_instance(instance, 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); @@ -136,7 +136,7 @@ extern "C" { if (F_status_is_error(status)) { if (F_status_set_fine(status) == F_lock) { - if (!controller_thread_is_enabled_instance_type(instance->type, global->thread)) { + if (!controller_main_thread_is_enabled_instance_type(instance->type, global->thread)) { return F_status_set_error(F_interrupt); } } @@ -174,7 +174,7 @@ extern "C" { else { f_thread_unlock(&global->thread->lock.instance); - status_lock = controller_lock_read_instance(instance, global->thread, &global->thread->lock.rule); + status_lock = controller_main_lock_read_instance(instance, global->thread, &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); @@ -227,7 +227,7 @@ extern "C" { } } else if (found) { - status_lock = controller_lock_read_instance(instance, global->thread, &global->thread->lock.rule); + status_lock = controller_main_lock_read_instance(instance, global->thread, &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 +251,7 @@ extern "C" { f_thread_unlock(&global->thread->lock.rule); - status_lock = controller_lock_read_instance(instance, global->thread, &dependency->lock); + status_lock = controller_main_lock_read_instance(instance, global->thread, &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); @@ -268,7 +268,7 @@ extern "C" { status = dependency->rule.status[instance->action]; } else { - status_lock = controller_lock_read_instance(instance, global->thread, &global->thread->lock.rule); + status_lock = controller_main_lock_read_instance(instance, global->thread, &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 +277,7 @@ extern "C" { status = status_lock; } - else if (controller_rule_status_is_available(instance->action, global->program->rules.array[id_rule])) { + else if (controller_main_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 +292,7 @@ extern "C" { } // Synchronously execute dependency. - status = controller_rule_instance_begin(global, 0, alias_other_buffer, instance->action, options_instance, instance->type, instance->stack, dependency->cache); + status = controller_main_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); @@ -336,14 +336,14 @@ extern "C" { } } - if (!controller_thread_is_enabled_instance(instance, global->thread)) { + if (!controller_main_thread_is_enabled_instance(instance, global->thread)) { f_thread_unlock(&dependency->active); break; } if (F_status_is_error_not(status_lock)) { - status_lock = controller_lock_read_instance(instance, global->thread, &global->thread->lock.rule); + status_lock = controller_main_lock_read_instance(instance, global->thread, &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); @@ -357,7 +357,7 @@ extern "C" { status = status_lock; } - else if (controller_rule_status_is_error(instance->action, global->program->rules.array[id_rule])) { + else if (controller_main_rule_status_is_error(instance->action, global->program->rules.array[id_rule])) { f_thread_unlock(&global->thread->lock.rule); if (i == 0 || i == 1) { @@ -409,12 +409,12 @@ extern "C" { return status; } - if (!controller_thread_is_enabled_instance(instance, global->thread)) { + if (!controller_main_thread_is_enabled_instance(instance, global->thread)) { 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_rule_wait_all_instance_type(global, instance->type, F_false); + status_lock = controller_main_rule_wait_all_instance_type(global, instance->type, F_false); if (F_status_set_fine(status_lock) == F_interrupt) { return status_lock; @@ -449,7 +449,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_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_main_rule_action_type_name(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 { @@ -478,7 +478,7 @@ extern "C" { } if (F_status_is_error_not(status)) { - status = controller_rule_execute(global, instance->action, instance->options, instance); + status = controller_main_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; @@ -494,13 +494,13 @@ extern "C" { f_thread_unlock(&instance->lock); - status_lock = controller_lock_write_instance(instance, global->thread, &instance->lock); + status_lock = controller_main_lock_write_instance(instance, global->thread, &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_lock_read_instance(instance, global->thread, &instance->lock); + status = controller_main_lock_read_instance(instance, global->thread, &instance->lock); if (F_status_is_error_not(status)) return status_lock; } @@ -514,14 +514,14 @@ extern "C" { instance->rule.status[instance->action] = status; } - status_lock = controller_lock_write_instance(instance, global->thread, &global->thread->lock.rule); + status_lock = controller_main_lock_write_instance(instance, global->thread, &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_lock_read_instance(instance, global->thread, &instance->lock); + status = controller_main_lock_read_instance(instance, global->thread, &instance->lock); if (F_status_is_error_not(status)) return status_lock; return F_status_set_error(F_lock); @@ -551,7 +551,7 @@ extern "C" { f_thread_unlock(&global->thread->lock.rule); f_thread_unlock(&instance->lock); - status_lock = controller_lock_read_instance(instance, global->thread, &instance->lock); + status_lock = controller_main_lock_read_instance(instance, global->thread, &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 +561,14 @@ extern "C" { return instance->rule.status[instance->action]; } -#endif // _di_controller_rule_instance_ +#endif // _di_controller_main_rule_instance_ -#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) { +#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) { if (!global) return F_status_set_error(F_parameter); - if (!controller_thread_is_enabled_instance_type(type, global->thread)) { + if (!controller_main_thread_is_enabled_instance_type(type, global->thread)) { return F_status_set_error(F_interrupt); } @@ -577,7 +577,7 @@ extern "C" { controller_instance_t *instance = 0; - status = controller_lock_read_instance_type(type, global->thread, &global->thread->lock.instance); + status = controller_main_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); @@ -607,7 +607,7 @@ extern "C" { instance = global->thread->instances.array[at]; - status = controller_lock_read_instance_type(type, global->thread, &instance->active); + status = controller_main_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); @@ -618,7 +618,7 @@ extern "C" { return status; } - status_lock = controller_lock_write_instance(instance, global->thread, &instance->lock); + status_lock = controller_main_lock_write_instance(instance, global->thread, &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 +642,7 @@ extern "C" { // The thread is done, so close the thread. if (instance->state == controller_instance_state_done_e) { - controller_thread_join(&instance->id_thread); + controller_main_thread_join(&instance->id_thread); f_thread_mutex_lock(&instance->wait_lock); f_thread_condition_signal_all(&instance->wait); @@ -654,7 +654,7 @@ extern "C" { f_thread_unlock(&instance->lock); - status_lock = controller_lock_write_instance(instance, global->thread, &instance->lock); + status_lock = controller_main_lock_write_instance(instance, global->thread, &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); @@ -745,7 +745,7 @@ extern "C" { } } else { - status = controller_rule_instance_do(options_force, instance); + status = controller_main_rule_instance_do(options_force, instance); if (status == F_child || F_status_set_fine(status) == F_interrupt) { f_thread_unlock(&instance->active); @@ -757,7 +757,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_lock_write_instance(instance, global->thread, &instance->lock); + status_lock = controller_main_lock_write_instance(instance, global->thread, &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,10 +790,10 @@ extern "C" { return F_okay; } -#endif // _di_controller_rule_instance_begin_ +#endif // _di_controller_main_rule_instance_begin_ -#ifndef _di_controller_rule_instance_do_ - f_status_t controller_rule_instance_do(const uint8_t options_force, controller_instance_t * const instance) { +#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) { if (!instance) return F_status_set_error(F_parameter); @@ -815,7 +815,7 @@ extern "C" { // 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_lock_read_instance(instance, global->thread, &instance->active); + status_lock = controller_main_lock_read_instance(instance, global->thread, &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 +824,7 @@ extern "C" { } } - status_lock = controller_lock_read_instance(instance, global->thread, &instance->lock); + status_lock = controller_main_lock_read_instance(instance, global->thread, &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 +842,7 @@ extern "C" { const f_number_unsigned_t used_original_stack = instance->stack.used; - status_lock = controller_lock_read_instance(instance, global->thread, &global->thread->lock.rule); + status_lock = controller_main_lock_read_instance(instance, global->thread, &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 +859,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_lock_write_instance(instance, global->thread, &instance->lock); + status_lock = controller_main_lock_write_instance(instance, global->thread, &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 +879,7 @@ extern "C" { f_thread_unlock(&instance->lock); - status_lock = controller_lock_read_instance(instance, global->thread, &instance->lock); + status_lock = controller_main_lock_read_instance(instance, global->thread, &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); @@ -910,7 +910,7 @@ extern "C" { return F_instance_not; } else { - for (f_number_unsigned_t i = 0; i < instance->stack.used && controller_thread_is_enabled_instance(instance, global->thread); ++i) { + for (f_number_unsigned_t i = 0; i < instance->stack.used && controller_main_thread_is_enabled_instance(instance, global->thread); ++i) { if (instance->stack.array[i] == id_rule) { if (global->main->program.error.verbosity > f_console_verbosity_quiet_e) { @@ -932,7 +932,7 @@ extern "C" { } } // for - if (!controller_thread_is_enabled_instance(instance, global->thread)) { + if (!controller_main_thread_is_enabled_instance(instance, global->thread)) { f_thread_unlock(&instance->lock); if (options_force & controller_instance_option_asynchronous_e) { @@ -951,7 +951,7 @@ extern "C" { else { f_thread_unlock(&instance->lock); - status_lock = controller_lock_write_instance(instance, global->thread, &instance->lock); + status_lock = controller_main_lock_write_instance(instance, global->thread, &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 +967,7 @@ extern "C" { f_thread_unlock(&instance->lock); - status_lock = controller_lock_read_instance(instance, global->thread, &instance->lock); + status_lock = controller_main_lock_read_instance(instance, global->thread, &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 +983,7 @@ extern "C" { } if (F_status_is_error_not(status)) { - status = controller_rule_instance(global, instance); + status = controller_main_rule_instance(global, instance); } } else { @@ -1011,7 +1011,7 @@ extern "C" { return status; } - status_lock = controller_lock_write_instance(instance, global->thread, &global->thread->lock.rule); + status_lock = controller_main_lock_write_instance(instance, global->thread, &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 +1039,7 @@ extern "C" { f_thread_unlock(&instance->lock); } - if (F_status_set_fine(status) == F_interrupt || F_status_set_fine(status) == F_lock && !controller_thread_is_enabled_instance(instance, global->thread)) { + 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 (options_force & controller_instance_option_asynchronous_e) { f_thread_unlock(&instance->active); } @@ -1047,7 +1047,7 @@ extern "C" { return F_status_set_error(F_interrupt); } - status_lock = controller_lock_write_instance(instance, global->thread, &instance->lock); + status_lock = controller_main_lock_write_instance(instance, global->thread, &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 +1079,13 @@ extern "C" { f_thread_unlock(&instance->active); } - if (controller_thread_is_enabled_instance(instance, global->thread)) { + if (controller_main_thread_is_enabled_instance(instance, global->thread)) { return status; } return F_status_set_error(F_interrupt); } -#endif // _di_controller_rule_instance_do_ +#endif // _di_controller_main_rule_instance_do_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/rule/instance.h b/sources/c/main/rule/instance.h index 5a130f3..ee09ad8 100644 --- a/sources/c/main/rule/instance.h +++ b/sources/c/main/rule/instance.h @@ -30,6 +30,7 @@ extern "C" { * * @param global * The global data. + * * Must not be NULL. * * This does not alter global.main.setting.state.status. @@ -44,18 +45,19 @@ 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_lock_read(). - * Errors (with error bit) from: controller_lock_write(). + * Errors (with error bit) from: controller_main_lock_read(). + * Errors (with error bit) from: controller_main_lock_write(). */ -#ifndef _di_controller_rule_instance_ - extern f_status_t controller_rule_instance(controller_global_t * const global, controller_instance_t * const instance); -#endif // _di_controller_rule_instance_ +#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_ /** * Synchronously or asynchronously begin processing some rule. * * @param global * The global data. + * * Must not be NULL. * * This does not alter global.main.setting.state.status. @@ -86,22 +88,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_rule_instance(). + * Status from: controller_main_rule_instance(). * - * Errors (with error bit) from: controller_rule_instance(). + * Errors (with error bit) from: controller_main_rule_instance(). * Errors (with error bit) from: f_string_dynamic_append(). * Errors (with error bit) from: f_thread_create(). * - * @see controller_rule_instance() + * @see controller_main_rule_instance() * @see f_string_dynamic_append() * @see f_thread_create() */ -#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_ +#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_ /** - * Helper for calling controller_rule_instance(). + * Helper for calling controller_main_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. @@ -122,18 +124,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_rule_instance(). + * Status from: controller_main_rule_instance(). * * Errors (with error bit) from: controller_rule_copy(). - * Errors (with error bit) from: controller_rule_instance(). + * Errors (with error bit) from: controller_main_rule_instance(). * * @see controller_rule_copy() - * @see controller_rule_instance() - * @see controller_rule_instance_begin() + * @see controller_main_rule_instance() + * @see controller_main_rule_instance_begin() */ -#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_ +#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_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/rule/is.c b/sources/c/main/rule/is.c index 02b6b51..f0678af 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_rule_status_is_available_ - f_status_t controller_rule_status_is_available(const uint8_t action, const controller_rule_t rule) { +#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) { return F_status_is_error_not(rule.status[0]) && rule.status[action] == F_known_not; } -#endif // _di_controller_rule_status_is_available_ +#endif // _di_controller_main_rule_status_is_available_ -#ifndef _di_controller_rule_status_is_error_ - f_status_t controller_rule_status_is_error(const uint8_t action, const controller_rule_t rule) { +#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) { return F_status_is_error(rule.status[0]) || F_status_is_error(rule.status[action]); } -#endif // _di_controller_rule_status_is_error_ +#endif // _di_controller_main_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 67292da..7579194 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_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_ +#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_ /** * 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_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_ +#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_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/rule/item.c b/sources/c/main/rule/item.c index ce6e457..6351e89 100644 --- a/sources/c/main/rule/item.c +++ b/sources/c/main/rule/item.c @@ -4,8 +4,8 @@ extern "C" { #endif -#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) { +#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) { if (!global || !cache || !item) return F_status_set_error(F_parameter); @@ -80,46 +80,46 @@ extern "C" { } if (f_compare_dynamic(controller_freeze_s, cache->action.name_action) == F_equal_to) { - type = controller_rule_action_type_freeze_e; + type = controller_main_rule_action_type_freeze_e; } else if (f_compare_dynamic(controller_group_s, cache->action.name_action) == F_equal_to) { - type = controller_rule_action_type_group_e; + type = controller_main_rule_action_type_group_e; } else if (f_compare_dynamic(controller_kill_s, cache->action.name_action) == F_equal_to) { - type = controller_rule_action_type_kill_e; + type = controller_main_rule_action_type_kill_e; } else if (f_compare_dynamic(controller_pause_s, cache->action.name_action) == F_equal_to) { - type = controller_rule_action_type_pause_e; + type = controller_main_rule_action_type_pause_e; } else if (f_compare_dynamic(controller_pid_file_s, cache->action.name_action) == F_equal_to) { - type = controller_rule_action_type_pid_file_e; + type = controller_main_rule_action_type_pid_file_e; } else if (f_compare_dynamic(controller_reload_s, cache->action.name_action) == F_equal_to) { - type = controller_rule_action_type_reload_e; + type = controller_main_rule_action_type_reload_e; } else if (f_compare_dynamic(controller_rerun_s, cache->action.name_action) == F_equal_to) { - type = controller_rule_action_type_rerun_e; + type = controller_main_rule_action_type_rerun_e; } else if (f_compare_dynamic(controller_restart_s, cache->action.name_action) == F_equal_to) { - type = controller_rule_action_type_restart_e; + type = controller_main_rule_action_type_restart_e; } else if (f_compare_dynamic(controller_resume_s, cache->action.name_action) == F_equal_to) { - type = controller_rule_action_type_resume_e; + type = controller_main_rule_action_type_resume_e; } else if (f_compare_dynamic(controller_start_s, cache->action.name_action) == F_equal_to) { - type = controller_rule_action_type_start_e; + type = controller_main_rule_action_type_start_e; } else if (f_compare_dynamic(controller_stop_s, cache->action.name_action) == F_equal_to) { - type = controller_rule_action_type_stop_e; + type = controller_main_rule_action_type_stop_e; } else if (f_compare_dynamic(controller_thaw_s, cache->action.name_action) == F_equal_to) { - type = controller_rule_action_type_thaw_e; + type = controller_main_rule_action_type_thaw_e; } else if (f_compare_dynamic(controller_user_s, cache->action.name_action) == F_equal_to) { - type = controller_rule_action_type_user_e; + type = controller_main_rule_action_type_user_e; } else if (f_compare_dynamic(controller_with_s, cache->action.name_action) == F_equal_to) { - type = controller_rule_action_type_with_e; + type = controller_main_rule_action_type_with_e; } else { if (global->main->program.warning.verbosity == f_console_verbosity_debug_e) { @@ -138,7 +138,7 @@ extern "C" { } if (multiple) { - if (type == controller_rule_action_type_group_e || type == controller_rule_action_type_pid_file_e || type == controller_rule_action_type_user_e) { + 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 (global->main->program.error.verbosity > f_console_verbosity_quiet_e) { controller_lock_print(global->main->program.error.to, global->thread); @@ -155,13 +155,13 @@ extern "C" { break; } - method = controller_rule_action_method_extended_list_e; + method = controller_main_rule_action_method_extended_list_e; } else { - method = controller_rule_action_method_extended_e; + method = controller_main_rule_action_method_extended_e; } - 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); + 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); 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)); @@ -169,13 +169,13 @@ extern "C" { break; } - status = controller_rule_action_read(global, is_normal, type, method, cache, item, &item->actions, &range); + status = controller_main_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_rule_item_read_ +#endif // _di_controller_main_rule_item_read_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/rule/item.h b/sources/c/main/rule/item.h index 284d87c..271dd4e 100644 --- a/sources/c/main/rule/item.h +++ b/sources/c/main/rule/item.h @@ -23,6 +23,7 @@ extern "C" { * * @param global * The global data. + * * Must not be NULL. * * This does not alter global.main.setting.state.status. @@ -41,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_rule_action_read() + * @see controller_main_rule_action_read() * @see f_fss_count_lines() * @see f_string_dynamic_partial_append_nulless() */ -#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_ +#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_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/rule/parameter.c b/sources/c/main/rule/parameter.c index 91d056d..6f699ed 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_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) { +#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) { if (!global || !object || !content || !action || !state) return F_status_set_error(F_parameter); @@ -110,7 +110,7 @@ extern "C" { return F_okay; } -#endif // _di_controller_rule_parameters_read_ +#endif // _di_controller_main_rule_parameters_read_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/rule/parameter.h b/sources/c/main/rule/parameter.h index 8be0998..adbf51c 100644 --- a/sources/c/main/rule/parameter.h +++ b/sources/c/main/rule/parameter.h @@ -23,6 +23,7 @@ extern "C" { * * @param global * The global data. + * * Must not be NULL. * * This does not alter global.main.setting.state.status. @@ -57,9 +58,9 @@ extern "C" { * @see f_memory_array_increase_by() * @see fl_iki_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_ +#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_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/rule/read.c b/sources/c/main/rule/read.c index fa2b181..20b914f 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_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) { +#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) { if (!global || !cache || !entry || !rule) return F_status_set_error(F_parameter); @@ -86,7 +86,7 @@ extern "C" { rule->cgroup.groups.array[i].used = 0; } // for - for (; i < controller_rule_action_type__enum_size_e; ++i) { + for (; i < controller_main_rule_action_type__enum_size_e; ++i) { rule->status[i] = F_known_not; } // for @@ -112,7 +112,7 @@ extern "C" { rule->items.array[i].pid_file.used = 0; rule->items.array[i].actions.used = 0; - for (j = 0; j < controller_rule_action_execute_type__enum_size_e; ++j) { + for (j = 0; j < controller_main_rule_action_execute_type__enum_size_e; ++j) { rule->items.array[i].reruns[j].is = 0; @@ -307,7 +307,7 @@ extern "C" { rule->items.array[rule->items.used].with |= controller_with_session_same_d; } - status = controller_rule_item_read(global, is_normal, cache, &rule->items.array[rule->items.used]); + status = controller_main_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 +315,7 @@ extern "C" { else { for_item = F_false; - status = controller_rule_setting_read(global, is_normal, *global->setting, cache, rule); + status = controller_main_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; @@ -335,7 +335,7 @@ extern "C" { return F_okay; } -#endif // _di_controller_rule_read_ +#endif // _di_controller_main_rule_read_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/rule/read.h b/sources/c/main/rule/read.h index 75c69c4..5e48b6d 100644 --- a/sources/c/main/rule/read.h +++ b/sources/c/main/rule/read.h @@ -21,6 +21,7 @@ extern "C" { * * @param global * The global data. + * * Must not be NULL. * * This does not alter global.main.setting.state.status. @@ -45,16 +46,16 @@ extern "C" { * Simplified status (with error bit) from controller_main_error_simplify() on failure. * * @see controller_rule_items_increase_by(). - * @see controller_rule_item_read(). + * @see controller_main_rule_item_read(). * @see f_fss_count_lines(). * @see f_fss_apply_delimit(). * @see f_string_dynamic_partial_append(). * @see f_string_dynamic_partial_append_nulless(). * @see fll_fss_basic_list_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_ +#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_ #ifdef __cplusplus diff --git a/sources/c/main/rule/setting.c b/sources/c/main/rule/setting.c index 196289c..2d97912 100644 --- a/sources/c/main/rule/setting.c +++ b/sources/c/main/rule/setting.c @@ -4,8 +4,8 @@ extern "C" { #endif -#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) { +#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) { if (!global || !cache || !rule) return F_status_set_error(F_parameter); @@ -1536,31 +1536,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_rule_action_type_freeze_e; + action = controller_main_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_rule_action_type_kill_e; + action = controller_main_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_rule_action_type_pause_e; + action = controller_main_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_rule_action_type_reload_e; + action = controller_main_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_rule_action_type_restart_e; + action = controller_main_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_rule_action_type_resume_e; + action = controller_main_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_rule_action_type_start_e; + action = controller_main_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_rule_action_type_stop_e; + action = controller_main_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_rule_action_type_thaw_e; + action = controller_main_rule_action_type_thaw_e; } else { if (global->main->program.error.verbosity > f_console_verbosity_quiet_e) { @@ -1747,7 +1747,7 @@ extern "C" { return status_return; } -#endif // _di_controller_rule_setting_read_ +#endif // _di_controller_main_rule_setting_read_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/rule/setting.h b/sources/c/main/rule/setting.h index a8b07e1..09e9e91 100644 --- a/sources/c/main/rule/setting.h +++ b/sources/c/main/rule/setting.h @@ -26,6 +26,7 @@ extern "C" { * * @param global * The global data. + * * Must not be NULL. * * This does not alter global.main.setting.state.status. @@ -56,9 +57,9 @@ extern "C" { * * @see controller_path_canonical_relative() */ -#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_ +#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_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/rule/validate.c b/sources/c/main/rule/validate.c index d189c05..8b62d91 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_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) { +#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) { if (!global || !cache) return F_status_set_error(F_parameter); controller_main_t * const main = global->main; switch (action) { - 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: + 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: break; default: @@ -28,7 +28,7 @@ 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_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_main_rule_action_type_name(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); @@ -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_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_main_rule_action_type_name(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_rule_action_type_freeze_e) { + if (rule.ons.array[i].action == controller_main_rule_action_type_freeze_e) { action = controller_freeze_s; } - else if (rule.ons.array[i].action == controller_rule_action_type_kill_e) { + else if (rule.ons.array[i].action == controller_main_rule_action_type_kill_e) { action = controller_kill_s; } - else if (rule.ons.array[i].action == controller_rule_action_type_pause_e) { + else if (rule.ons.array[i].action == controller_main_rule_action_type_pause_e) { action = controller_pause_s; } - else if (rule.ons.array[i].action == controller_rule_action_type_reload_e) { + else if (rule.ons.array[i].action == controller_main_rule_action_type_reload_e) { action = controller_reload_s; } - else if (rule.ons.array[i].action == controller_rule_action_type_restart_e) { + else if (rule.ons.array[i].action == controller_main_rule_action_type_restart_e) { action = controller_restart_s; } - else if (rule.ons.array[i].action == controller_rule_action_type_resume_e) { + else if (rule.ons.array[i].action == controller_main_rule_action_type_resume_e) { action = controller_resume_s; } - else if (rule.ons.array[i].action == controller_rule_action_type_start_e) { + else if (rule.ons.array[i].action == controller_main_rule_action_type_start_e) { action = controller_start_s; } - else if (rule.ons.array[i].action == controller_rule_action_type_stop_e) { + else if (rule.ons.array[i].action == controller_main_rule_action_type_stop_e) { action = controller_stop_s; } - else if (rule.ons.array[i].action == controller_rule_action_type_thaw_e) { + else if (rule.ons.array[i].action == controller_main_rule_action_type_thaw_e) { action = controller_thaw_s; } @@ -326,7 +326,7 @@ extern "C" { // Items. if (rule.items.used) { - controller_rule_action_t *action = 0; + controller_main_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_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_main_rule_action_type_name(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_rule_action_execute_type__enum_size_e; ++j) { + for (j = 0; j < controller_main_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_rule_action_execute_type_freeze_e: + case controller_main_rule_action_execute_type_freeze_e: f_print_dynamic_raw(controller_freeze_s, main->program.output.to); break; - case controller_rule_action_execute_type_kill_e: + case controller_main_rule_action_execute_type_kill_e: f_print_dynamic_raw(controller_kill_s, main->program.output.to); break; - case controller_rule_action_execute_type_pause_e: + case controller_main_rule_action_execute_type_pause_e: f_print_dynamic_raw(controller_pause_s, main->program.output.to); break; - case controller_rule_action_execute_type_reload_e: + case controller_main_rule_action_execute_type_reload_e: f_print_dynamic_raw(controller_reload_s, main->program.output.to); break; - case controller_rule_action_execute_type_restart_e: + case controller_main_rule_action_execute_type_restart_e: f_print_dynamic_raw(controller_restart_s, main->program.output.to); break; - case controller_rule_action_execute_type_resume_e: + case controller_main_rule_action_execute_type_resume_e: f_print_dynamic_raw(controller_resume_s, main->program.output.to); break; - case controller_rule_action_execute_type_start_e: + case controller_main_rule_action_execute_type_start_e: f_print_dynamic_raw(controller_start_s, main->program.output.to); break; - case controller_rule_action_execute_type_stop_e: + case controller_main_rule_action_execute_type_stop_e: f_print_dynamic_raw(controller_stop_s, main->program.output.to); break; - case controller_rule_action_execute_type_thaw_e: + case controller_main_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_rule_validate_ +#endif // _di_controller_main_rule_validate_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/rule/validate.h b/sources/c/main/rule/validate.h index 4479a9e..7aa954c 100644 --- a/sources/c/main/rule/validate.h +++ b/sources/c/main/rule/validate.h @@ -25,6 +25,7 @@ extern "C" { * * @param global * The global data. + * * Must not be NULL. * * This does not alter global.main.setting.state.status. @@ -40,9 +41,9 @@ extern "C" { * @param cache * A structure for containing and caching relevant data. */ -#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_ +#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_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/rule/wait.c b/sources/c/main/rule/wait.c index f625427..aec9c57 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_rule_wait_all_ - f_status_t controller_rule_wait_all(controller_global_t * const global, const bool is_normal, const bool required) { +#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) { if (!global) return F_status_set_error(F_parameter); - f_status_t status_lock = controller_lock_read(is_normal, global->thread, &global->thread->lock.instance); + f_status_t status_lock = controller_main_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); @@ -31,7 +31,7 @@ extern "C" { f_number_unsigned_t i = 0; f_number_unsigned_t j = 0; - // Vuild a list of what to wait for so that anything new after this point will not be waited for. + // 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]; @@ -46,7 +46,7 @@ extern "C" { if (!controller_main_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_lock_read(is_normal, global->thread, &global->thread->lock.instance); + status_lock = controller_main_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_lock_read(is_normal, global->thread, &instance_list[i]->active); + status_lock = controller_main_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_lock_read(is_normal, global->thread, &instance_list[i]->lock); + status_lock = controller_main_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_lock_write(is_normal, global->thread, &instance_list[i]->lock); + status_lock = controller_main_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_thread_join(&instance_list[i]->id_thread); + controller_main_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_lock_read(is_normal, global->thread, &instance_list[i]->active); + status_lock = controller_main_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_lock_read(is_normal, global->thread, &instance_list[i]->lock); + status_lock = controller_main_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_rule_status_is_error(instance_list[i]->action, instance_list[i]->rule)) { + if (controller_main_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_rule_status_is_available(instance_list[i]->action, instance_list[i]->rule)) { + else if (controller_main_rule_status_is_available(instance_list[i]->action, instance_list[i]->rule)) { required_not_run = F_true; } } @@ -150,7 +150,7 @@ extern "C" { continue; } - 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)) { + 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)) { f_thread_unlock(&instance_list[i]->lock); status = controller_instance_wait(global, instance_list[i]); @@ -161,7 +161,7 @@ extern "C" { break; } - status_lock = controller_lock_read(is_normal, global->thread, &instance_list[i]->lock); + status_lock = controller_main_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_rule_status_is_error(instance_list[i]->action, instance_list[i]->rule)) { + if (controller_main_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); @@ -205,16 +205,16 @@ extern "C" { return F_okay; } -#endif // _di_controller_rule_wait_all_ +#endif // _di_controller_main_rule_wait_all_ -#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) { +#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) { if (!global) return F_status_set_error(F_parameter); - return controller_rule_wait_all(global, type != controller_instance_type_exit_e, required); + return controller_main_rule_wait_all(global, type != controller_instance_type_exit_e, required); } -#endif // _di_controller_rule_wait_all_instance_type_ +#endif // _di_controller_main_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 9c2f474..1fe60ee 100644 --- a/sources/c/main/rule/wait.h +++ b/sources/c/main/rule/wait.h @@ -21,6 +21,7 @@ extern "C" { * * @param global * The global data. + * * Must not be NULL. * * This does not alter global.main.setting.state.status. @@ -40,15 +41,16 @@ 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_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_ +#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_ /** * Wait until all currently running Rule processes are complete for some process type. * * @param global * The global data. + * * Must not be NULL. * * This does not alter global.main.setting.state.status. @@ -59,15 +61,15 @@ extern "C" { * If FALSE, process all waits, returning normally. * * @return - * Success from controller_rule_wait_all(). + * Success from controller_main_rule_wait_all(). * - * Errors (with error bit) from: controller_rule_wait_all(). + * Errors (with error bit) from: controller_main_rule_wait_all(). * - * @see controller_rule_wait_all() + * @see controller_main_rule_wait_all() */ -#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_ +#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_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/thread.c b/sources/c/main/thread.c index 27c3339..0029c90 100644 --- a/sources/c/main/thread.c +++ b/sources/c/main/thread.c @@ -4,94 +4,35 @@ 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_main_thread_detach_ + f_status_t controller_main_thread_detach(f_thread_id_t * const id) { - if (!global || !global->main || !global->thread) return; - if (!controller_main_thread_is_enabled(is_normal, global->thread)) return; - if (!(global->main->setting.flag & controller_main_flag_interruptible_e)) return; + if (!id || !*id) return F_data_not; - f_status_t status = F_okay; - siginfo_t information; - f_time_spec_t time = f_time_spec_t_initialize; + const f_status_t status = f_thread_detach(*id); - while (controller_main_thread_is_enabled(is_normal, global->thread)) { - - controller_time_now(controller_main_thread_exit_ready_timeout_seconds_d, controller_main_thread_exit_ready_timeout_nanoseconds_d, &time); - - memset((void *) &information, 0, sizeof(siginfo_t)); - - status = f_signal_wait_until(&global->main->program.signal.set, &time, &information); - if (status == F_time_out) continue; - - 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); - - break; - } - } // while - } -#endif // _di_controller_main_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) { - - if (!state || !state->custom) return; - - controller_global_t * const global = (controller_global_t *) state->custom; - - if (!controller_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); - } - 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); + if (F_status_is_error_not(status) || F_status_set_fine(status) == F_found_not) { + *id = 0; } - } -#endif // _di_controller_main_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) { - - if (!state || !state->custom) return; - controller_global_t * const global = (controller_global_t *) state->custom; - - if (!controller_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); - } - 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); - } + return status; } -#endif // _di_controller_main_thread_signal_state_iki_ +#endif // _di_controller_main_thread_detach_ -#ifndef _di_controller_main_thread_signal_normal_ - void * controller_main_thread_signal_normal(void * const global) { +#ifndef _di_controller_main_thread_join_ + f_status_t controller_main_thread_join(f_thread_id_t * const id) { - f_thread_cancel_state_set(PTHREAD_CANCEL_DEFERRED, 0); + if (!id || !*id) return F_data_not; - controller_main_thread_signal((controller_global_t * const) global, F_true); + const f_status_t status = f_thread_join(*id, 0); - return 0; - } -#endif // _di_controller_main_thread_signal_normal_ - -#ifndef _di_controller_main_thread_signal_other_ - void * controller_main_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); + if (F_status_is_error_not(status) || F_status_set_fine(status) == F_found_not) { + *id = 0; + } - return 0; + return status; } -#endif // _di_controller_main_thread_signal_other_ +#endif // _di_controller_main_thread_join_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/thread.h b/sources/c/main/thread.h index b558856..b6b9b94 100644 --- a/sources/c/main/thread.h +++ b/sources/c/main/thread.h @@ -12,84 +12,51 @@ #ifndef _controller_main_thread_h #define _controller_main_thread_h -/** - * Thread for handling signals/interrupts. +/*** + * Detach a thread, assigning id to NULL on success. * - * @param global - * The global data. + * If the ID is not found, then it is also set to NULL. * - * Must not be NULL. - * @param is_normal - * 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_ - -/** - * Callback passed to FSS functions for checking for interrupts. + * This should be called for asynchronous processes. * - * @param state - * The state data. + * @param id + * The thread ID. * - * Must not be NULL. - * @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_ - -/** - * Callback passed to IKI functions for checking for interrupts. + * @return + * F_okay on success. + * F_data_not if id is NULL or the value of id is 0. * - * @param state - * The state data. + * Success from: f_thread_detach(). * - * Must not be NULL. - * @param internal - * Not used. + * Errors (with error bit) from: f_thread_detach(). + * + * @see f_thread_detach() */ -#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_main_thread_detach_ + extern f_status_t controller_main_thread_detach(f_thread_id_t * const id); +#endif // _di_controller_main_thread_detach_ -/** - * Thread for handling signals/interrupts during normal operations. +/*** + * Join a thread, assigning id to NULL on success. * - * @param global - * The global structure. - * Must be of type controller_global_t. + * If the ID is not found, then it is also set to NULL. * - * Must not be NULL. + * @param id + * The thread ID. * * @return - * 0, always. - * - * @see controller_main_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_ - -/** - * Thread for handling signals/interrupts during other operations. + * F_okay on success. + * F_data_not if id is NULL or the value of id is 0. * - * @param global - * The global structure. - * Must be of type controller_global_t. + * Success from: f_thread_join(). * - * Must not be NULL. - * - * @return - * 0, always. + * Errors (with error bit) from: f_thread_join(). * - * @see controller_main_thread_signal() + * @see f_thread_join() */ -#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_main_thread_join_ + extern f_status_t controller_main_thread_join(f_thread_id_t * const id); +#endif // _di_controller_main_thread_join_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/thread/cleanup.c b/sources/c/main/thread/cleanup.c new file mode 100644 index 0000000..9db5b18 --- /dev/null +++ b/sources/c/main/thread/cleanup.c @@ -0,0 +1,151 @@ +#include "../controller.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_controller_main_thread_cleanup_ + void * controller_main_thread_cleanup(void * const arguments) { + + if (!arguments) return 0; + + f_thread_cancel_state_set(PTHREAD_CANCEL_DEFERRED, 0); + + controller_global_t * const global = (controller_global_t * const) arguments; + + 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); + + f_status_t status = F_okay; + + while (global->thread->enabled == controller_thread_enabled_e) { + + f_time_sleep_spec(delay, 0); + + if (global->thread->enabled != controller_thread_enabled_e) break; + + if (f_thread_lock_write_try(&global->thread->lock.instance) == F_okay) { + controller_instance_t *instance = 0; + + f_number_unsigned_t i = 0; + + for (; i < global->thread->instances.size && global->thread->enabled == controller_thread_enabled_e; ++i) { + + if (!global->thread->instances.array[i]) continue; + + instance = global->thread->instances.array[i]; + + // If "active" has a read lock, then do not attempt to clean it. + if (f_thread_lock_write_try(&instance->active) != F_okay) continue; + + // If "lock" has a read or write lock, then do not attempt to clean it. + if (f_thread_lock_write_try(&instance->lock) != F_okay) { + f_thread_unlock(&instance->active); + + continue; + } + + // If instance is active or busy, then do not attempt to clean it. + if (instance->state == controller_process_state_active_e || instance->state == controller_process_state_busy_e) { + f_thread_unlock(&instance->active); + f_thread_unlock(&instance->lock); + + continue; + } + + // If instance has a PID file, then it is running in the background, only cleanup if the PID file no longer exists. + if (instance->path_pids.used) { + f_number_unsigned_t j = 0; + + for (; j < instance->path_pids.used; ++j) { + + if (instance->path_pids.array[j].used && f_file_exists(instance->path_pids.array[j], F_true) == F_true) { + break; + } + } // for + + if (j < instance->path_pids.used) { + f_thread_unlock(&instance->active); + f_thread_unlock(&instance->lock); + + continue; + } + } + + f_thread_unlock(&instance->lock); + + // Close any still open thread. + if (instance->id_thread) { + status = f_thread_join(instance->id_thread, 0); + + if (F_status_is_error_not(status) || F_status_set_fine(status) == F_found_not) { + status = f_thread_lock_write(&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); + + f_thread_unlock(&instance->active); + + continue; + } + + instance->state = controller_process_state_idle_e; + instance->id_thread = 0; + + f_thread_mutex_lock(&instance->wait_lock); + f_thread_condition_signal_all(&instance->wait); + f_thread_mutex_unlock(&instance->wait_lock); + + f_thread_unlock(&instance->lock); + } + else { + f_thread_unlock(&instance->active); + + continue; + } + } + + // De-allocate dynamic portions of the structure that are only ever needed while the instance is running. + controller_cache_delete_simple(&instance->cache); + f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &instance->stack.array, &instance->stack.used, &instance->stack.size); + + // Shrink the childs array. + if (instance->childs.used) { + for (; instance->childs.used; --instance->childs.used) { + if (instance->childs.array[instance->childs.used]) break; + } // for + + if (instance->childs.used < instance->childs.size) { + f_memory_array_resize(instance->childs.used, sizeof(pid_t), (void **) &instance->childs.array, &instance->childs.used, &instance->childs.size); + } + } + + // De-allocate the PID files. + if (instance->path_pids.used) { + instance->path_pids.used = 0; + + f_memory_arrays_resize(0, sizeof(f_string_dynamic_t), (void **) &instance->path_pids.array, &instance->path_pids.used, &instance->path_pids.size, &f_string_dynamics_delete_callback); + } + + // 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); + } + + f_thread_unlock(&instance->active); + } // for + + f_thread_unlock(&global->thread->lock.instance); + } + } // while + + return 0; + } +#endif // _di_controller_main_thread_cleanup_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/sources/c/main/thread/cleanup.h b/sources/c/main/thread/cleanup.h new file mode 100644 index 0000000..aa29bd9 --- /dev/null +++ b/sources/c/main/thread/cleanup.h @@ -0,0 +1,39 @@ +/** + * FLL - Level 3 + * + * Project: Controller + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Provides the thread "cleanup" functionality. + * + * This is auto-included and should not need to be explicitly included. + */ +#ifndef _controller_main_thread_cleanup_h +#define _controller_main_thread_cleanup_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Thread for periodically cleaning up data when not busy. + * + * @param arguments + * The thread arguments. + * Must be of type controller_global_t. + * + * Must not be NULL. + * + * @return + * 0, always. + */ +#ifndef _di_controller_main_thread_cleanup_ + extern void * controller_main_thread_cleanup(void * const arguments); +#endif // _di_controller_main_thread_cleanup_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _controller_main_thread_cleanup_h diff --git a/sources/c/main/thread/control.h b/sources/c/main/thread/control.h index 207d761..4962201 100644 --- a/sources/c/main/thread/control.h +++ b/sources/c/main/thread/control.h @@ -22,6 +22,7 @@ extern "C" { * @param arguments * The global data. * Must be of type controller_global_t. + * * Must not be NULL. * * @return diff --git a/sources/c/main/thread/entry.c b/sources/c/main/thread/entry.c index 4fcd809..2b17a0c 100644 --- a/sources/c/main/thread/entry.c +++ b/sources/c/main/thread/entry.c @@ -20,10 +20,10 @@ extern "C" { *status = controller_main_entry_read(global, F_true); if (F_status_set_fine(*status) == F_interrupt) { - global->program->ready = controller_setting_ready_abort_e; + global->program->ready = controller_program_ready_abort_e; } else if (F_status_is_error(*status)) { - global->program->ready = controller_setting_ready_fail_e; + global->program->ready = controller_program_ready_fail_e; } else if (*status != F_child) { *status = controller_main_entry_preprocess(global, F_true); @@ -38,7 +38,7 @@ extern "C" { if (global->program->entry.pid == controller_entry_pid_require_e && f_file_exists(global->program->path_pid, F_true) == F_true) { *status = F_status_set_error(F_available_not); - global->program->ready = controller_setting_ready_fail_e; + 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); } @@ -46,7 +46,7 @@ extern "C" { *status = controller_main_entry_process(global, F_false, F_true); if (F_status_is_error(*status)) { - global->program->ready = controller_setting_ready_fail_e; + global->program->ready = controller_program_ready_fail_e; if ((F_status_set_fine(*status) == F_execute || F_status_set_fine(*status) == F_require) && (program->flag & controller_setting_flag_failsafe_e)) { const uint8_t original_enabled = global->thread->enabled; @@ -88,31 +88,31 @@ extern "C" { } } else if (F_status_set_fine(*status) == F_interrupt) { - global->program->ready = controller_setting_ready_abort_e; + global->program->ready = controller_program_ready_abort_e; } else if (*status != F_child) { - global->program->ready = controller_setting_ready_done_e; + global->program->ready = controller_program_ready_done_e; } } - 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_setting_mode_helper_e) { + 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; nanosleep(&time, 0); - controller_main_thread_process_cancel(global, F_true, controller_thread_cancel_exit_e); + controller_main_thread_instance_cancel(global, F_true, controller_thread_cancel_exit_e); } } } if (*status == F_child) { - // A forked child process should deallocate memory on exit. + // A forked child process should de-allocate memory on exit. // It seems that this function doesn't return to the calling thread for a forked child process, even with the "return 0;" below. - controller_main_thread_delete(global->thread); - controller_main_program_delete(global->program); + controller_thread_delete(global->thread); + controller_program_delete(global->program); controller_main_delete(global->main); // According to the manpages, pthread_exit() calls exit(0), which the value of global->main->program.child should be returned instead. @@ -143,13 +143,13 @@ extern "C" { *status = controller_entry_read(global, F_false); if (F_status_set_fine(*status) == F_interrupt) { - global->program->ready = controller_setting_ready_abort_e; + global->program->ready = controller_program_ready_abort_e; } else if (F_status_is_error(*status)) { - global->program->ready = controller_setting_ready_fail_e; + global->program->ready = controller_program_ready_fail_e; } else if (*status == F_file_found_not) { - global->program->ready = controller_setting_ready_done_e; + global->program->ready = controller_program_ready_done_e; } else if (*status != F_child) { *status = controller_entry_preprocess(global, F_false, cache); @@ -165,7 +165,7 @@ extern "C" { *status = controller_entry_process(global, F_false, F_false); if (F_status_is_error(*status)) { - global->program->ready = controller_setting_ready_fail_e; + global->program->ready = controller_program_ready_fail_e; if ((F_status_set_fine(*status) == F_execute || F_status_set_fine(*status) == F_require) && (global->program->flag & controller_setting_flag_failsafe_e)) { @@ -210,17 +210,17 @@ extern "C" { } } else if (F_status_set_fine(*status) == F_interrupt) { - global->program->ready = controller_setting_ready_abort_e; + global->program->ready = controller_program_ready_abort_e; } else if (*status != F_child) { - global->program->ready = controller_setting_ready_done_e; + global->program->ready = controller_program_ready_done_e; } } } if (*status == F_child) { - // A forked child process should deallocate memory on exit. + // A forked child process should de-allocate memory on exit. // 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); diff --git a/sources/c/main/thread/entry.h b/sources/c/main/thread/entry.h index 6c35f29..23701cb 100644 --- a/sources/c/main/thread/entry.h +++ b/sources/c/main/thread/entry.h @@ -25,6 +25,7 @@ extern "C" { * @param arguments * The global data. * Must be of type controller_instance_t. + * * Must not be NULL. * * @return @@ -46,6 +47,7 @@ extern "C" { * @param arguments * The global data. * Must be of type controller_instance_t. + * * Must not be NULL. * * @return diff --git a/sources/c/main/thread/instance.c b/sources/c/main/thread/instance.c index 9bb2d78..4a87588 100644 --- a/sources/c/main/thread/instance.c +++ b/sources/c/main/thread/instance.c @@ -10,9 +10,9 @@ extern "C" { if (!instance) return; if (!controller_main_thread_is_enabled(is_normal, (controller_thread_t * const) instance->thread)) return; - const f_status_t status = controller_rule_instance_do(controller_instance_option_asynchronous_e, instance); + const f_status_t status = controller_main_rule_instance_do(controller_instance_option_asynchronous_e, instance); - // A forked child instance should deallocate memory on exit. + // 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); @@ -55,7 +55,7 @@ extern "C" { time.tv_sec = 0; time.tv_nsec = interval_nanoseconds; - if (global->program->mode == controller_setting_mode_helper_e && global->main->program.parameters.array[controller_parameter_validate_e].result == f_console_result_none_e) { + if (global->program->mode == controller_program_mode_helper_e && global->main->program.parameters.array[controller_parameter_validate_e].result == f_console_result_none_e) { int value = 0; f_number_unsigned_t lapsed = 0; @@ -67,7 +67,7 @@ extern "C" { if (!instance->id_thread) continue; - controller_thread_detach(&instance->id_thread); + controller_main_thread_detach(&instance->id_thread); instance->id_thread = 0; } // for @@ -118,7 +118,7 @@ extern "C" { global->thread->id_signal = 0; } - if (global->program->mode == controller_setting_mode_helper_e && global->main->program.parameters.array[controller_parameter_validate_e].result == f_console_result_none_e) { + if (global->program->mode == controller_program_mode_helper_e && global->main->program.parameters.array[controller_parameter_validate_e].result == f_console_result_none_e) { f_thread_mutex_unlock(&global->thread->lock.cancel); return; @@ -318,7 +318,7 @@ extern "C" { if (global->thread->enabled != controller_thread_enabled_exit_e) return; - if (global->program->ready == controller_setting_ready_done_e) { + if (global->program->ready == controller_program_ready_done_e) { // The exit processing runs using the entry thread. if (global->thread->id_entry) { @@ -363,7 +363,7 @@ extern "C" { break; } - controller_time(controller_main_thread_exit_ready_timeout_seconds_d, controller_main_thread_exit_ready_timeout_nanoseconds_d, &time); + controller_main_time_now(controller_main_thread_exit_ready_timeout_seconds_d, controller_main_thread_exit_ready_timeout_nanoseconds_d, &time); status = f_thread_condition_wait_timed(&time, &global->thread->lock.alert_condition, &global->thread->lock.alert); diff --git a/sources/c/main/thread/instance.h b/sources/c/main/thread/instance.h index 6cdcd23..83d152f 100644 --- a/sources/c/main/thread/instance.h +++ b/sources/c/main/thread/instance.h @@ -24,9 +24,10 @@ extern "C" { * If F_false, then process as if this operates during a an exit operation. * @param instance * The instance data. + * * Must not be NULL. * - * @see controller_rule_instance_do() + * @see controller_main_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); @@ -37,6 +38,7 @@ extern "C" { * * @param global * The global data. + * * Must not be NULL. * * This does not alter global.main.setting.state.status. @@ -59,6 +61,7 @@ extern "C" { * * @param global * The global data. + * * Must not be NULL. * * This does not alter global.main.setting.state.status. @@ -73,6 +76,7 @@ extern "C" { * @param arguments * The thread arguments. * Must be of type controller_global_t. + * * Must not be NULL. * * @return @@ -89,6 +93,7 @@ extern "C" { * * @param arguments * The thread arguments. + * * Must not be NULL. * Must be of type controller_instance_t. * diff --git a/sources/c/main/thread/is.h b/sources/c/main/thread/is.h index 95461ec..2b14859 100644 --- a/sources/c/main/thread/is.h +++ b/sources/c/main/thread/is.h @@ -24,6 +24,7 @@ extern "C" { * If FALSE, then instance as if this operates during a an exit operation. * @param thread * The thread data. + * * Must not be NULL. * * @return @@ -39,9 +40,11 @@ extern "C" { * * @param instance * The instance to use when checking if thread is enabled. + * * Must not be NULL. * @param thread * The thread data. + * * Must not be NULL. * * @return @@ -61,6 +64,7 @@ extern "C" { * The instance type to use when checking if thread is enabled. * @param thread * The thread data. + * * Must not be NULL. * * @return diff --git a/sources/c/main/thread/rule.h b/sources/c/main/thread/rule.h index 262397d..0efe6b7 100644 --- a/sources/c/main/thread/rule.h +++ b/sources/c/main/thread/rule.h @@ -27,6 +27,7 @@ extern "C" { * @param arguments * The global data. * Must be of type controller_global_t. + * * Must not be NULL. * * @return diff --git a/sources/c/main/thread/signal.c b/sources/c/main/thread/signal.c new file mode 100644 index 0000000..65ca320 --- /dev/null +++ b/sources/c/main/thread/signal.c @@ -0,0 +1,98 @@ +#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) { + + if (!global || !global->main || !global->thread) return; + if (!controller_main_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)) { + + controller_main_time_now(controller_main_thread_exit_ready_timeout_seconds_d, controller_main_thread_exit_ready_timeout_nanoseconds_d, &time); + + memset((void *) &information, 0, sizeof(siginfo_t)); + + status = f_signal_wait_until(&global->main->program.signal.set, &time, &information); + if (status == F_time_out) continue; + + 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); + + break; + } + } // while + } +#endif // _di_controller_main_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) { + + if (!state || !state->custom) return; + + controller_global_t * const global = (controller_global_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); + } + 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); + } + } +#endif // _di_controller_main_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) { + + if (!state || !state->custom) return; + + controller_global_t * const global = (controller_global_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); + } + 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); + } + } +#endif // _di_controller_main_thread_signal_state_iki_ + +#ifndef _di_controller_main_thread_signal_normal_ + void * controller_main_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); + + return 0; + } +#endif // _di_controller_main_thread_signal_normal_ + +#ifndef _di_controller_main_thread_signal_other_ + void * controller_main_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); + + return 0; + } +#endif // _di_controller_main_thread_signal_other_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/sources/c/main/thread/signal.h b/sources/c/main/thread/signal.h new file mode 100644 index 0000000..c363f7d --- /dev/null +++ b/sources/c/main/thread/signal.h @@ -0,0 +1,98 @@ +/** + * FLL - Level 3 + * + * Project: Controller + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Provides thread "signal" functionality. + * + * This is auto-included and should not need to be explicitly included. + */ +#ifndef _controller_main_thread_signal_h +#define _controller_main_thread_signal_h + +/** + * Thread for handling signals/interrupts. + * + * @param global + * The global data. + * + * Must not be NULL. + * @param is_normal + * 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_ + +/** + * Callback passed to FSS functions for checking for interrupts. + * + * @param state + * The state data. + * + * Must not be NULL. + * @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_ + +/** + * Callback passed to IKI functions for checking for interrupts. + * + * @param state + * The state data. + * + * Must not be NULL. + * @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_ + +/** + * Thread for handling signals/interrupts during normal operations. + * + * @param global + * The global structure. + * Must be of type controller_global_t. + * + * Must not be NULL. + * + * @return + * 0, always. + * + * @see controller_main_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_ + +/** + * Thread for handling signals/interrupts during other operations. + * + * @param global + * The global structure. + * Must be of type controller_global_t. + * + * Must not be NULL. + * + * @return + * 0, always. + * + * @see controller_main_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_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _controller_main_thread_signal_h diff --git a/sources/c/main/time.c b/sources/c/main/time.c index 19ee1cd..0a5e0c7 100644 --- a/sources/c/main/time.c +++ b/sources/c/main/time.c @@ -4,8 +4,8 @@ extern "C" { #endif -#ifndef _di_controller_time_now_ - void controller_time_now(const time_t seconds, const long nanoseconds, f_time_spec_t * const time) { +#ifndef _di_controller_main_time_now_ + void controller_main_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,11 +23,11 @@ extern "C" { time->tv_nsec -= 1000000000; } } -#endif // _di_controller_time_now_ +#endif // _di_controller_main_time_now_ /* -#ifndef _di_controller_time_milliseconds_ - f_time_spec_t controller_time_milliseconds(const f_number_unsigned_t milliseconds) { +#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; @@ -35,10 +35,10 @@ extern "C" { return time; } -#endif // _di_controller_time_milliseconds_ +#endif // _di_controller_main_time_milliseconds_ -#ifndef _di_controller_time_seconds_ - f_time_simple_t controller_time_seconds(const f_number_unsigned_t seconds) { +#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; @@ -46,11 +46,11 @@ extern "C" { return time; } -#endif // _di_controller_time_seconds_ +#endif // _di_controller_main_time_seconds_ */ -#ifndef _di_controller_time_sleep_nanoseconds_ - f_status_t controller_time_sleep_nanoseconds(controller_global_t * const global, const f_time_spec_t time) { +#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) { if (!global || !global->main) return F_status_set_error(F_parameter); @@ -72,7 +72,7 @@ extern "C" { return f_time_sleep_spec(time, 0); } -#endif // _di_controller_time_sleep_nanoseconds_ +#endif // _di_controller_main_time_sleep_nanoseconds_ #ifdef __cplusplus } // extern "C" diff --git a/sources/c/main/time.h b/sources/c/main/time.h index 651b6bc..650c315 100644 --- a/sources/c/main/time.h +++ b/sources/c/main/time.h @@ -24,15 +24,16 @@ * * @see f_time_of_day_get() */ -#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_ +#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_ /** * Sleep for the given time. * * @param global * The global data. + * * Must not be NULL. * * This does not alter global.main.setting.state.status. @@ -43,16 +44,16 @@ * Success from: f_signal_wait_until(). * Success from: f_time_of_day_get(). * - * F_parameter (with error bit) on invalid parameter. + * F_parameter (with error bit) if a parameter is invalid. * * Errors (with error bit) from: f_signal_wait_until(). * Errors (with error bit) from: f_time_of_day_get(). * * @see f_time_of_day_get() */ -#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_ +#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_ #ifdef __cplusplus } // extern "C" -- 1.8.3.1