From: defaultuserbr@yahoo.com
Subject: Re: Some help for a C++ guy
Date: 8 Apr 2005 16:03:22 -0700
Date: 2005-04-08T16:03:22-07:00 [thread overview]
Message-ID: <1113001402.404239.275940@z14g2000cwz.googlegroups.com> (raw)
In-Reply-To: <Ttqdnflhs9cMnsrfRVn-gg@comcast.com>
tmo...@acm.org wrote:
> >That's a problem because that callback subroutine needs to be passed
to
> >a function expecting some of the type BC_Completion_Handler_T,
defined
> >as:
> >
> > type BC_Completion_Handler_T is access
> > procedure (Status : in IO_Status_T);
> >
> >Changing the that type would then break a bunch of other code.
>
> So you need to specify for a callback the particular Message_* that
> it pertains to?
Correct. Right now the very simple callback just increments a counter.
That way I can see how times a particlar message ran.
> Just make a set of wrapper routines:
> procedure Message_0_Completion_Handler(Status : in IO_Status_T)
is
> begin
> Completion_Handler(Message(0), Status);
> end Message_0_Completion_Handler;
> etc.
>
> and register the specific Message_*_Completion_Handler procedures.
> I presume this registration is done once so even if you add a new
> Message_237_Completion_Handler it's a minor addition to a single
package.
Plus an additional blurp of code to register that callback. What I
wanted to be able to do was have all the registration stuff in a loop.
So rather than a whole bunch of
Stat := M1553.Register_Message_Callback(msg_id,
Message_0_Handler.Message_Callback'access);
if Stat /= M1553.No_Errors
then
GNAT.IO.Put_Line("Error Register_Message_Callback");
end if;
Blocks, one for each message (and similar ones for the two buffers that
have to be registered), I'd have:
for i in Handlers'range loop
Stat := M1553.Register_Message_Callback(msg_id,
Handlers(i).Message_Callback'access);
if Stat /= M1553.No_Errors
then
GNAT.IO.Put_Line("Error Register_Message_Callback");
end if;
end loop;
I'd have been perfectly happy with a way to create an array of those
generic package instantiations.
> I'm presuming you want to make small changes to the existing code.
> If you want to use tagged types you are contemplating larger
architectural
> changes.
I don't want to break existing code.
> In your current code, "registering a callback" means essentially
> "note a particular routine, and a particular Message_n's data for
future
> use".
It means pass these to already written registration routines through an
established API.
> Passing an explicit tagged Handler parameter accomplishes the
> "note a particular Message_n's data" part. If the particular routine
> is not in fact dynamic, but always BC_Completion_Handler, then
instead
> of registering the procedure callback you want to register the
Message_n
> data and always call BC_Completion_Handler(Registered_Message,
Status);
Well, there will be a specific callback function dedicated the each
message. For right now, as I said above, it just tracks how many times
the message ran. Later, they'd be expanded to do more things.
So each message needs to have a distinct data buffer, status buffer,
and callback subroutine.
This is tricky in C++ as well. Usually you go for callback objects or
functors rather than trying to pass a class member function.
Brian
next prev parent reply other threads:[~2005-04-08 23:03 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-04-07 22:14 Some help for a C++ guy defaultuserbr
2005-04-07 22:51 ` Ed Falis
2005-04-07 23:18 ` defaultuserbr
2005-04-07 23:32 ` Ed Falis
2005-04-08 15:41 ` defaultuserbr
2005-04-08 5:50 ` Simon Wright
2005-04-08 15:47 ` defaultuserbr
2005-04-08 17:49 ` defaultuserbr
2005-04-08 20:42 ` tmoran
2005-04-08 21:18 ` defaultuserbr
2005-04-08 20:54 ` defaultuserbr
2005-04-08 22:20 ` tmoran
2005-04-08 23:03 ` defaultuserbr [this message]
2005-04-09 0:19 ` tmoran
2005-04-09 15:17 ` defaultuserbr
2005-04-08 4:43 ` tmoran
2005-04-08 15:55 ` defaultuserbr
2005-04-09 22:20 ` Matthew Heaney
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox