comp.lang.ada
 help / color / mirror / Atom feed
* Re: Client & Server on a generic type?
@ 1993-05-27 16:20 Mark A Biggar
  0 siblings, 0 replies; only message in thread
From: Mark A Biggar @ 1993-05-27 16:20 UTC (permalink / raw)


In article <WOODRUFF.93May26175940@EC2226.addvax.llnl.gov> WOODRUFF@EC2226.addv
ax.llnl.gov writes:
>How to make a client and server pair that provide a generic service?
>I am troubled in my attempt to build a generic package (or set of
>packages) that can implement both a server and its client operations on
>a type that contains a generic formal part. Can someone offer a
>suggestion?
>In fairly simple form, I want to make a message logging facility for a
>process control system that is distributed across several platforms
>(assume that message transmission is available).  I start with
>generic 
>  message_buf_len  : positive := 96 ;    --  and some other formals
>package log_types is
>  TYPE log_entry is 
>  --  a record type that depends on the generic formals
>end log_types ;
>Now I imagine I can write 
>Package Client is
>  Procedure Put (the_entry  : ???.Log_Entry) ;
>  -- BUT the parameter is a type I cannot name
>  -- until my user gets around to instantiating 
>  -- log_types! 
>end Client ;

One option is to make the Client package Generic with its formal part listing
every type/proc/func/const etc needed by the client.  Of course, getting the
user of that mess to instantiate it correctly is another problem.  Your example
would change to:

generic
    type foo is private;
package Client is
    procedure Put(The_entry: foo);
end Client;

Then the user would have to do two instantiations like so:

package My_log_types is new log_types(1024);
with My_log_types;
package My_client is new Client(log_types.log_entry);

>
>->  Now, I guess I wouldn't have this problem if such a thing
>->  as generic formal *packages* exist, but unfortunately I seem to need
>

Help is coming slowly as Ada9x has generic formal packages, which not only make
your problem easy to solve, but go a long way to solving the "How do I make
sure the user instantates is CORRECTLY" problem.

>Package Client is
>  Procedure Put (entry_part_1 : string) ;
>  Procedure Put (entry_kind_2 : date_time_indicator) ;
>and so on 
>--  and these Put's have to rely on generic formal procs
>--  that know about the log_types instances!

The above solution solves thsi problem as well.


>  <<  ALTERNATIVE  >>
>generic
>  message_buf_len  : positive := 96 ;
>package log is
>  TYPE log_entry is  ...
>  package Server IS
>  --  uses a file system to hold all the entries
>  package Client IS
>  --  uses network to talk to Server on behalf of my user
>end log_types ;
>
>The shortcoming that I see here is the need to elaborate both Server and
>Client in every context, and it could happen that I want to run my
>Client on a platform that doesn't own a file system.  I'm pretty opposed
>to getting <client and server soup>, so I will avoid this alternative.
>
>SO I SEEK ADVICE: 
>
>I'm in fairly deep, hiding the expectations that the client and the
>server can expect of instances of the generic log_Type.  Unless I'm
>missing something, as I put more detail into the log_entry, I need to
>make more procedures in log_types that will create and consume entry for
>client to use, and each of these procedures has to be given as a generic
>formal to client so my user can call Put.

Yeah that seem to be the currently best way to go, but be sure to document
thing to avoid the "How do I instantate it" mess.

--
Mark Biggar
mab@wdl1.wdl.loral.com

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1993-05-27 16:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1993-05-27 16:20 Client & Server on a generic type? Mark A Biggar

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