comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Thinking of using Ada for a job at home. Couple of questions first.
Date: Wed, 3 Mar 2010 23:20:34 +0100
Date: 2010-03-03T23:20:33+01:00	[thread overview]
Message-ID: <s04pta42qpqu.s98d2pzuprhe$.dlg@40tude.net> (raw)
In-Reply-To: 60hto51vmooku9r7j6dmviqbnglhp0pra7@4ax.com

On Wed, 03 Mar 2010 20:38:01 +0000, John McCabe wrote:

> As for the tagged Connection type, I'm not sure what you mean. Would
> you mind elaborating on that please?

I meant something like this:

type Abstract_Connection is tagged ...;
procedure On_XYZ (Link : in out Connection) is abstract;
...

task type Driver (Link : not null access Abstract_Connection'Class);

task body Driver is
begin
   loop
       -- read a message (could be polymorphic or not)
       ...
       -- process the message (usually polymorphic)
       case ... is
           when XYZ => -- XYZ is here
                Link.On_XYZ; -- Do what has to be done
           when ... =>
               ...
       end case;
   end loop;
exception
   when Shut_Down_Exception =>
        null;
   when Error : others =>
        Put ("I am dead! " & Exception_Information (Error));
end Driver;

type My_Fancy_MIDI_Connection is new Abstract_Connection with private;
overriding procedure On_XYZ (Link : in out My_Fancy_MIDI_Connection);
...

I usually have a driver task which deals with a class-wide Connection
object that implements the lower-level communication protocol (the part
that reads messages) and the higher-level semantic call-backs (the part
that reacts to the messages read).

If the communication library is built on callbacks (i.e. already has a
hidden Driver task), then I pass the connection object as user parameter to
the callback, and the loop body above is what to be done in the callback
routine.

The advantage of having Connection tagged is that I can implement layered
protocols and semantic actions incrementally. In complex cases I add
further mix-ins as access discrimnants to Connection, usually when I need
to make lower layers pluggable. But that would be over the top in your
case.

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



  parent reply	other threads:[~2010-03-03 22:20 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-03 16:19 Thinking of using Ada for a job at home. Couple of questions first John McCabe
2010-03-03 18:22 ` Jeffrey R. Carter
2010-03-03 20:09   ` John McCabe
2010-03-03 21:00     ` Simon Wright
2010-03-03 18:58 ` Hibou57 (Yannick Duchêne)
2010-03-03 20:17   ` John McCabe
2010-03-04  6:22     ` Hibou57 (Yannick Duchêne)
2010-03-04 11:39       ` John McCabe
2010-03-09 14:49         ` Warren Gay
2010-03-09 15:33           ` Jacob Sparre Andersen
2010-03-09 20:22           ` jonathan
2010-03-09 21:57             ` Charmed Snark
2010-03-09 22:54               ` jonathan
2010-03-10 17:46                 ` Charmed Snark
2010-03-10 19:12                   ` jonathan
2010-03-10 20:41                     ` Simon Wright
2010-03-10 21:00                       ` Pascal Obry
2010-03-09 20:32           ` Simon Wright
2010-03-10  6:42           ` J-P. Rosen
2010-03-03 19:17 ` Dmitry A. Kazakov
2010-03-03 20:38   ` John McCabe
2010-03-03 20:56     ` Simon Wright
2010-03-03 21:00       ` John McCabe
2010-03-03 21:10         ` John McCabe
2010-03-04  6:39         ` Hibou57 (Yannick Duchêne)
2010-03-03 21:35       ` tmoran
2010-03-04  6:43         ` Hibou57 (Yannick Duchêne)
2010-03-03 22:20     ` Dmitry A. Kazakov [this message]
2010-03-03 19:52 ` Gautier write-only
2010-03-03 20:57   ` John McCabe
replies disabled

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