omni::application::exit_handler::attach

SYNOPSIS

Attach a delegate function to the exit handler event.

top

DESCRIPTION

When a delegate is attached to the underlying exit handler, the delegate will be invoked before the application terminates in the order it was attached.

A static framework function is registered to the std::atexit library function when omni::application::run is called; this underlying function is responsible for invoking any delegates attached to the exit event handler in the order they were attached.

Since the exit handler will be invoked when the main function of the program is returning, a call to attach can be made before or after the run context has been invoked and the handlers will be called accordingly.

top

PARAMETERS

exit_func - The omni::callback delegate function to attach.

top

RETURN VALUES

No return value.

top

ERRORS

If an exception occurs on an attached delegate, it will be handled according to omni::sync::user_thread_exception and omni::sync::unhandled_thread_exception.

top

CONSIDERATIONS

This function will only have an effect if you have explicitly called one of the omni::application::run functions to block the main thread until program completion.

top

PLATFORM SPECIFIC

Nothing platform specific to account for.

top

NOTES

Be aware that the std::atexit function will call any functions in the reverse order registered. So if omni::application::run is called after any other calls to register a function with std::atexit in user code, then the underlying exit handler event will be called accordingly in the order attached; in other words, if you were to call std::atexit(&some_function) then attach an exit handler and call omni::application::run, the Omni exit handler will be called first, then some_function last.

top

EXAMPLE
#include <omni/application>

void app_exit()
{
    std::cout << "Application exiting" << std::endl;
}

void app_shutdown()
{
    std::cout << "Application shutting down" << std::endl;
}

void app_run()
{
    std::cout << "Leaving, waiting for CTRL+C" << std::endl;
}

int main(int argc, const char* argv[])
{
    omni::application::exit_handler::attach(&app_exit);
    omni::application::shutdown_handler::attach(&app_shutdown);
    return omni::application::run(&app_run);
}
Visit the examples page for more.

top