omni::application::startup_handler::attach
NAME

omni::application::startup_handler::attach

A function of omni::application::startup_handler

#include <omni/application.hpp>
void omni::application::startup_handler::attach(const omni::callback& start_func)

SYNOPSIS

Attaches an omni::callback delegate to the application startup handler.

top

DESCRIPTION

Attaching an omni::callback will register the delegate with the application startup event. The startup event is called immediately before any user supplied thread functions and before the underlying base application loop runs. The run context is blocked and will not continue (thus not calling the user thread functions or main loop) until all attached handlers have been invoked and return.

top

PARAMETERS

start_func - The omni::callback to attach to the startup event.

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


NOTES

Calling this function after the run context has entered the main application loop will have no effect on the startup handler since it will have already been called.

top


EXAMPLE

#include <omni/application>

void app_start()
{
    std::cout << "Application starting up" << std::endl;
}

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::startup_handler::attach(&app_start);
    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