Receives the callback from system when a given signal arise

Introduced properties

fun default_signal(signal: Int)

signals :: SignalHandler :: default_signal

Set default action for the signal
fun handle_signal(signal: Int, safely: Bool)

signals :: SignalHandler :: handle_signal

Set the receiver as the handler of the signal
fun ignore_signal(signal: Int)

signals :: SignalHandler :: ignore_signal

Set to ignore the signal
fun receive_signal(signal: Int)

signals :: SignalHandler :: receive_signal

Invoked after a call to check_signals if a signal has been raised
fun receive_signal_unsafe(signal: Int)

signals :: SignalHandler :: receive_signal_unsafe

Called immediatly on receiving an unsafe signal (should be redefed by subclasses)

Redefined properties

redef type SELF: SignalHandler

signals $ SignalHandler :: SELF

Type of this instance, automatically specialized in every class

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
fun default_signal(signal: Int)

signals :: SignalHandler :: default_signal

Set default action for the signal
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun handle_signal(signal: Int, safely: Bool)

signals :: SignalHandler :: handle_signal

Set the receiver as the handler of the signal
fun hash: Int

core :: Object :: hash

The hash code of the object.
fun ignore_signal(signal: Int)

signals :: SignalHandler :: ignore_signal

Set to ignore the signal
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun receive_signal(signal: Int)

signals :: SignalHandler :: receive_signal

Invoked after a call to check_signals if a signal has been raised
fun receive_signal_unsafe(signal: Int)

signals :: SignalHandler :: receive_signal_unsafe

Called immediatly on receiving an unsafe signal (should be redefed by subclasses)
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
package_diagram signals::SignalHandler SignalHandler core::Object Object signals::SignalHandler->core::Object

Parents

interface Object

core :: Object

The root of the class hierarchy.

Class definitions

signals $ SignalHandler
# Receives the callback from system when a given signal arise
interface SignalHandler
	# Invoked after a call to `check_signals` if a signal has been raised
	# (should be redefed by subclasses)
	#
	# Should be used by most signals except `sigkill` and `sigstop` since they
	# cannot be caught, blocked or ignored.
	#
	#     class MyReceiver
	#         super SignalHandler
	#
	#         redef fun receive_signal(signal) do print "received safely {signal}"
	#     end
	#
	#     var r = new MyReceiver
	#     r.handle_signal(sigint, true) # will call back when "check_signals" is called
	#     # ...
	#     check_signals # if a signal was received, it will invoke `r.receive_signal`
	fun receive_signal(signal: Int) do end

	# Called immediatly on receiving an unsafe signal (should be redefed by subclasses)
	#
	# Should be used for `sigkill` and `sigstop` since they cannot be caught,
	# blocked or ignored.
	#
	# You should consider this methods as being fragile. It should be implemented in C
	# and you should not do too much callbacks to Nit.
	#
	#     class MyReceiver
	#         super SignalHandler
	#
	#         redef fun receive_signal_unsafe(signal) do print "received unsafely {signal}"
	#     end
	#
	#     var r = new MyReceiver
	#     r.handle_signal(sigsegv, false) # `r.receive_signal_unsafe` will be invoked on sigsegv
	fun receive_signal_unsafe(signal: Int) do end

	# Set the receiver as the handler of the signal
	#
	# If `safely`, receiver will be called when `check_signals` in invoked
	# otherwise the receiver is invoked when the signal is raised, it may
	# crash the Nit system but is unavoidable for unstoppable signals.
	fun handle_signal(signal: Int, safely: Bool) import receive_signal `{
		if (signal < 32 && signal >=0) {
			struct sigaction act;
			sigemptyset(&act.sa_mask);
			act.sa_flags = 0;
			act.sa_handler = receiver;

			sigaction(signal, &act, NULL);

		#ifdef SignalHandler_decr_ref
			SignalHandler last_handler = (SignalHandler)nit_signals_list[signal].handler;
			if (last_handler != NULL)
				SignalHandler_decr_ref(last_handler);
		#endif

			nit_signals_list[signal].handler = self;

		#ifdef SignalHandler_incr_ref
			SignalHandler_incr_ref(self);
		#endif

			nit_signals_list[signal].safely = safely;

			nit_SignalHandler_receive_signal =
				(void (*)(void*, long))&SignalHandler_receive_signal;
		}
	`}

	# Set to ignore the signal
	fun ignore_signal(signal: Int) `{
		if (signal < 32 && signal >=0) {
			struct sigaction act;
			sigemptyset(&act.sa_mask);
			act.sa_flags = 0;
			act.sa_handler = SIG_IGN;
			sigaction(signal, &act, NULL);

		#ifdef SignalHandler_decr_ref
			SignalHandler last_handler = (SignalHandler)nit_signals_list[signal].handler;
			if (last_handler != NULL)
				SignalHandler_decr_ref(last_handler);
		#endif
		}
	`}

	# Set default action for the signal
	fun default_signal(signal: Int) `{
		if (signal < 32 && signal >=0) {
			struct sigaction act;
			sigemptyset(&act.sa_mask);
			act.sa_flags = 0;
			act.sa_handler = SIG_DFL;
			sigaction(signal, &act, NULL);

		#ifdef SignalHandler_decr_ref
			SignalHandler last_handler = (SignalHandler)nit_signals_list[signal].handler;
			if (last_handler != NULL)
				SignalHandler_decr_ref(last_handler);
		#endif
		}
	`}
end
lib/signals/signals.nit:101,1--205,3