From: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
Subject: Re: Handling signals in ADA
Date: Thu, 15 Mar 2001 19:27:21 -0600
Date: 2001-03-15T19:27:21-06:00 [thread overview]
Message-ID: <YZds6.3394$25.1574196@newsrump.sjc.telocity.net> (raw)
In-Reply-To: 87y9u6k7s6.fsf@deneb.enyo.de
"Florian Weimer" <fw@deneb.enyo.de> wrote in message
news:87y9u6k7s6.fsf@deneb.enyo.de...
> Tomas Hlavaty <hlavaty@labe.felk.cvut.cz> writes:
>
> > Hi, could you help me with translating following C code to ADA?
>
> The programming language is called 'Ada'.
>
> > -- How to translate it to ADA?
>
> The standard Ada library does not support signals. Typical Ada
> programs use other communication mechanisms, and a verbatim
> translation is not possible. If you need signal handling because it's
> required by your environment, have a look at POSIX.5.
This answer is just plain wrong. The following program demonstrates
the use of signals in Ada, using only language-defined units.
Now. to be sure, because Ada restricts interrupt handlers to being
parameterless protected procedures, it is not possible to
pass parameter like what can be done under UNIX with the
standard C runtime, for example.
But the "standard Ada library" _DOES_ support signals.
-- begin source code
package body Signal_Handlers
is
SIG_INT_Received : Boolean := False;
function SIGINT_RECEIVED return BOOLEAN
is
begin
return SIG_INT_Received;
end SIGINT_Received;
protected body Signals
is
procedure Handle_SIGINT
is
begin
Ada.Text_IO.Put_Line ("SIGINT received..; Terminating.");
SIG_INT_Received := True;
end Handle_SIGINT;
procedure Handle_SIGUSR1
is
begin
Ada.Text_IO.Put_Line ("SIGUSR1 received and handled.");
end Handle_SIGUSR1;
procedure Handle_SIGUSR2
is
begin
Ada.Text_IO.Put_Line ("SIGUSR2 received and handled.");
end Handle_SIGUSR2;
end Signals;
end Signal_Handlers;
with Ada.Interrupts.Names;
with Ada.Text_IO;
package Signal_Handlers
is
pragma Unreserve_All_Interrupts;
function SIGINT_Received return Boolean;
protected Signals is
procedure Handle_SIGINT;
procedure Handle_SIGUSR1;
procedure Handle_SIGUSR2;
private
pragma Attach_Handler
(Handle_SIGINT, Ada.Interrupts.Names.SIGINT);
pragma Attach_Handler
(Handle_SIGUSR1, Ada.Interrupts.Names.SIGUSR1);
pragma Attach_Handler
(Handle_SIGUSR2, Ada.Interrupts.Names.SIGUSR2);
end Signals;
end Signal_Handlers;
with Ada.Text_IO;
with Signal_Handlers;
procedure Test_Signal_Handler
is
begin
loop
exit when Signal_Handlers.SIGINT_Received;
Ada.Text_IO.Put_Line ("I'm alive...");
delay 1.0;
end loop;
end Test_Signal_Handler;
.
next prev parent reply other threads:[~2001-03-16 1:27 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-03-13 11:09 Handling signals in ADA Tomas Hlavaty
2001-03-15 5:21 ` DuckE
2001-03-15 18:48 ` David Starner
2001-03-16 17:17 ` Robert A Duff
2001-03-15 22:05 ` Florian Weimer
2001-03-15 23:42 ` Ed Falis
2001-03-16 1:27 ` David C. Hoos, Sr. [this message]
2001-03-16 1:48 ` Jeffrey Carter
2001-03-16 21:06 ` Florian Weimer
2001-03-17 1:00 ` David C. Hoos, Sr.
2001-03-16 3:06 ` (null)
2001-03-16 13:10 ` Tomas Hlavaty
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox