#include <xtd/console>
#include <xtd/environment>
#include <xtd/startup>
namespace environment_cancel_sgnal_example {
public:
static auto main() {
console::write_line("A {} signal occured!", e.signal());
e.cancel(cancel);
};
show_help();
console::treat_control_c_as_input(true);
while (true) {
if (console::key_available()) {
auto key_info = console::read_key(true);
if (key_info.modifiers() == console_modifiers::none && key_info.key() == console_key::escape) exit();
else if (key_info.modifiers() == console_modifiers::control && key_info.key() == console_key::c) generate_signal(signal::interrupt);
else switch (key_info.key_char()) {
case 'a': generate_signal(signal::abnormal_termination); break;
case 'c': generate_signal(signal::interrupt); break;
case 'e': exit(); break;
case 'f': generate_signal(signal::floating_point_exception); break;
case 'h': show_help(); break;
case 'i': generate_signal(signal::illegal_instruction); break;
case 't': generate_signal(signal::software_termination); break;
case 'u': cancel = !cancel; show_help(); break;
case 'v': generate_signal(signal::segmentation_violation); break;
default: break;
}
}
}
}
private:
static void exit() {
console::write_line("Exit");
environment::exit(exit_status::success);
}
console::write_line(
"Generate {} signal",
signal);
}
static void show_help() {
console::clear();
console::write_line("Select a key :");
console::write_line(" a : Generate abort signal");
console::write_line(" c : (or ctrl-c) Generate interrupt signal");
console::write_line(" e : (or Escape) Exit example");
console::write_line(" f : Generate floating point exception signal");
console::write_line(" h : Display this help");
console::write_line(" i : Generate illegal instruction signal");
console::write_line(" t : Generate software termination signal");
console::write_line(" u : Update cancel signal status");
console::write_line(" v : Generate segmentation violation signal");
console::write_line("The signal will {}be cancelled!", cancel ? "" : "not ");
}
inline static bool cancel = true;
};
}
startup_(environment_cancel_sgnal_example::program::main);
Provides data for the environment signal event. This class cannot be inherited.
Definition signal_cancel_event_args.h:18
#define static_
This keyword is use to represent a static object. A static object can't be instantiated (constructors...
Definition static.h:37
#define startup_(main_method)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.h:175
signal
Specifies signals that can interrupt the current process.
Definition signal.h:18
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10