comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Newbie question: Implementing a callback mechanism with Ada 83
Date: Sat, 10 Feb 2007 21:40:07 +0100
Date: 2007-02-10T21:39:48+01:00	[thread overview]
Message-ID: <1n74au9nwrn5q.7hxfg8xn4t8q.dlg@40tude.net> (raw)
In-Reply-To: 1171136299.920852.179650@v33g2000cwv.googlegroups.com

On 10 Feb 2007 11:38:19 -0800, benibilme@gmail.com wrote:

> I need to develop an Ada application which must conform to Ada83. It
> will be part of legacy system. I am very much new in Ada. The
> application I have to develop is very much event driven. As an old
> time C programmer I wanted to implement an event handling module which
> you can subscribe callback functions and trigger the events when
> necessary and unfortunately I have realized that Ada 83 does not
> support pointer to subprograms. I have read about generics with which
> defining subprograms as parameters of subprograms seems possible. On
> the other hand, I could not figure out how to do it.
> 
> I simply want to store function pointers to some data structure for
> some certain events and call them with dynamic data when the event is
> triggered.
> 
> How can I do it in Ada 83 without the support of pointers to
> subprograms. It is clear how to do this Ada95 as there is a direct
> support for pointer to subprograms.
> 
> Any help is much appreciated.

I remember that once I used access-to-task to emulate access-to-subprogram.
You can make handlers tasks and serve events in rendezvous.

Another [tedious] possibility could be a proxy subprogram:

type Call_Back_Id is (Foo_Id, Bar_Id, ...);

procedure Call_Back (Id : Call_Back_Id, <parameters>) is
begin
   case Id is
      when Foo_Id => Foo (<parameters>);
      when Bar_Id => Bar  (<parameters>);
      ...
   end case;
end Call_Back;

In the data structure you store Id.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2007-02-10 20:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-10 19:38 Newbie question: Implementing a callback mechanism with Ada 83 benibilme
2007-02-10 20:40 ` Dmitry A. Kazakov [this message]
2007-02-11  2:46 ` Jeffrey R. Carter
2007-02-11 21:40   ` benibilme
2007-02-12  5:03     ` Jeffrey R. Carter
2007-02-12 19:32     ` Adam Beneschan
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox