Application extension which handles signals to the process and calls the
onSignal() method of all registered extensions (see ISignalExtExtension).
The extension can handle any number of different signals -- depending solely
on which signals are specified in the constructor.
Note: not only must the extension be registered with the application but its
internal ISelectClient (returned by the selectClient() method) must also be
registered with an epoll instance! Until the event is registered with epoll
and the event loop started, the signal handlers will not be called in
response to signals which have occurred.
Usage example:
1 2 importocean.util.app.Application;
3 importocean.util.app.ext.SignalExt;
4 importocean.io.select.EpollSelectDispatcher;
5 importcore.sys.posix.signal : SIGINT, SIGTERM;
6 7 // Example application class which does two things:8 // 1. Owns an instance of SignalExtension and registers some signals9 // with it.10 // 2. Implements ISignalExtExtension to be notified when registered11 // signals occur.12 13 // It's important to understand that these two things are not connected.14 // It's perfectly possible for an application class to own a SignalExt15 // but for another class (indeed other classes) elsewhere to implement16 // ISignalExtExtension to receive the notification of signals occurring.17 classMyApp : Application, ISignalExtExtension18 {
19 privateSignalExtsignal_ext;
20 21 this ( )
22 {
23 super("name", "desc");
24 25 // Construct a signal extension instance and tell it which26 // signals we're interested in. The list of signals can be27 // extended after construction via the register() method.28 autosignals = [SIGINT, SIGTERM];
29 this.signal_ext = newSignalExt(signals);
30 31 // Register the signal extension with the application class32 // (this).33 this.registerExtension(this.signal_ext);
34 35 // Register this class with the signal extension so that it will36 // be notified (via its onSignal() method, below) when one of37 // the registered signals occurs.38 this.signal_ext.registerExtension(this);
39 }
40 41 // Signal handler callback required by ISignalExtExtension. Called42 // when a signal which has been registered with the signal extension43 // occurs.44 overridevoidonSignal ( intsignum )
45 {
46 }
47 48 // Application main method required by Application.49 overrideintrun ( char[][] args )
50 {
51 // Important: onSignal() will not be called until the signal52 // extension's event has been registered with epoll!53 autoepoll = newEpollSelectDispatcher;
54 epoll.register(this.signal_ext.selectClient());
55 epoll.eventLoop();
56 57 return0;
58 }
59 }
Boost Software License Version 1.0. See LICENSE_BOOST.txt for details.
Alternatively, this file may be distributed under the terms of the Tango
3-Clause BSD License (see LICENSE_BSD.txt for details).
Application extension which handles signals to the process and calls the onSignal() method of all registered extensions (see ISignalExtExtension). The extension can handle any number of different signals -- depending solely on which signals are specified in the constructor.
Note: not only must the extension be registered with the application but its internal ISelectClient (returned by the selectClient() method) must also be registered with an epoll instance! Until the event is registered with epoll and the event loop started, the signal handlers will not be called in response to signals which have occurred.
Usage example: