# See the License for the specific language governing permissions and
# limitations under the License.
-# Module to manage standard C signals
+# ANSI C signal handling
#
# Common usage imply 5 steps:
#
#define _POSIX_SOURCE 1
#include <signal.h>
#include <stdio.h>
+ #include <unistd.h>
/*
*/
char raised; /* !=0 if has been raised */
void* handler; /* instance to receive call */
char safely; /* if !=0 then manage signal safely, otherwise react when raised */
- } nit_signals_list[32] = {0x0};
+ } nit_signals_list[32] = {{0}};
/* Receiver to all signals
If unsafe, it calls directly the Nit receiver,
nit_signals_list[signal].safely = safely;
- nit_SignalHandler_receive_signal = SignalHandler_receive_signal;
+ nit_SignalHandler_receive_signal =
+ (void (*)(void*, long))&SignalHandler_receive_signal;
}
`}
`}
end
-redef interface Object
-
- # Check signals for safe operation
- # will callback receiver of raised signals
- # can callback any instance of SignalHandler, not just this one
- protected fun check_signals: Bool is extern import SignalHandler.receive_signal `{
- int sig;
- int raised_something = 0;
-
- for (sig = 0; sig < 32; sig ++)
- if (nit_signals_list[sig].raised) {
- nit_signals_list[sig].raised = 0;
- raised_something = 1;
- SignalHandler handler = (SignalHandler)nit_signals_list[sig].handler;
- SignalHandler_receive_signal(handler, sig);
- }
+# Check signals for safe operation
+# will callback receiver of raised signals
+# can callback any instance of SignalHandler, not just this one
+fun check_signals: Bool is extern import SignalHandler.receive_signal `{
+ int sig;
+ int raised_something = 0;
+
+ for (sig = 0; sig < 32; sig ++)
+ if (nit_signals_list[sig].raised) {
+ nit_signals_list[sig].raised = 0;
+ raised_something = 1;
+ SignalHandler handler = (SignalHandler)nit_signals_list[sig].handler;
+ SignalHandler_receive_signal(handler, sig);
+ }
- return raised_something;
- `}
+ return raised_something;
+`}
- # Set alarm signal
- # can callback any instance of SignalHandler, not just this one
- protected fun set_alarm(sec: Int) `{ alarm(sec); `}
-end
+# Set alarm signal
+# can callback any instance of SignalHandler, not just this one
+fun set_alarm(sec: Int) `{ alarm(sec); `}
redef class Process
# Send a signal to the process