From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,740e91341085efe3 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!z14g2000cwz.googlegroups.com!not-for-mail From: defaultuserbr@yahoo.com Newsgroups: comp.lang.ada Subject: Re: Some help for a C++ guy Date: 8 Apr 2005 16:03:22 -0700 Organization: http://groups.google.com Message-ID: <1113001402.404239.275940@z14g2000cwz.googlegroups.com> References: <1112993665.945046.278360@f14g2000cwb.googlegroups.com> NNTP-Posting-Host: 130.76.96.17 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1113001406 12836 127.0.0.1 (8 Apr 2005 23:03:26 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 8 Apr 2005 23:03:26 +0000 (UTC) In-Reply-To: User-Agent: G2/0.2 Complaints-To: groups-abuse@google.com Injection-Info: z14g2000cwz.googlegroups.com; posting-host=130.76.96.17; posting-account=jWLFKg0AAAA9UYjCwxeOEw3zdPk7tNz5 Xref: g2news1.google.com comp.lang.ada:10357 Date: 2005-04-08T16:03:22-07:00 List-Id: 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