![]() |
Home | Libraries | People | FAQ | More |
In the Boost.Application, the 'aspects handlers' is the way that you can define a custom action to response some events, that are initiated by user via SCM or SIGNALS.
Table 1.4. Pre-configured Handlers available in the library
Aspect Name |
Aspect Contract Class |
Aspect Final Class |
Aspect Functionality |
---|---|---|---|
pause_handler |
pause_handler |
pause_handler_default_behaviour |
When 'pause' event is detected, fire a user defined callback |
resume_handler |
resume_handler |
resume_handler_default_behaviour |
When 'resume' event is detected, fire a user defined callback |
termination_handler |
termination_handler |
termination_handler_default_behaviour |
When 'stop' signal/event is detected, fire a user defined callback |
limit_single_instance |
limit_single_instance |
limit_single_instance_default_behaviour |
When single instance feature is enabled, fire a user defined callback to handle it |
The user can define the handler like this:
bool stop(void)
Note that handlers must return a 'bool' to indicate to 'application mode engine', what action need be done, e.g.:
class myapp { public: // ... bool stop() { char type; do { std::cout << "Do you want to exit? [y/n]" << std::endl; std::cin >> type; } while( !std::cin.fail() && type!='y' && type!='n' ); if(type == 'y') { // return true to tell to the 'application mode engine' to stop application. // This implies: // 1. The 'application mode engine' will set the 'application 'status' aspect to status::stopped; // 2. The 'application mode engine' will signalize the 'application 'wait_for_termination_request' aspect to release. return true; } // tell the 'application mode engine' to continue application (ignore requisited action) return false; } // ... };