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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,ec06888ca495a8ff X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!wns14feed!worldnet.att.net!attbi_s21.POSTED!53ab2750!not-for-mail From: "Jeffrey R. Carter" User-Agent: Thunderbird 1.5.0.9 (Windows/20061207) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Newbie question: Implementing a callback mechanism with Ada 83 References: <1171136299.920852.179650@v33g2000cwv.googlegroups.com> In-Reply-To: <1171136299.920852.179650@v33g2000cwv.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: NNTP-Posting-Host: 12.201.97.213 X-Complaints-To: abuse@mchsi.com X-Trace: attbi_s21 1171161976 12.201.97.213 (Sun, 11 Feb 2007 02:46:16 GMT) NNTP-Posting-Date: Sun, 11 Feb 2007 02:46:16 GMT Organization: AT&T ASP.att.net Date: Sun, 11 Feb 2007 02:46:16 GMT Xref: g2news2.google.com comp.lang.ada:9244 Date: 2007-02-11T02:46:16+00:00 List-Id: 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. Why do you want to register callbacks for the events? Does the processing for a given event change during execution? If not, there's no need for callbacks. The handling for a given event can know what subprogram to call. If they do, you no doubt have a fixed set of subprograms that can be needed for a given event, under a fixed set of conditions. You could have the handling for a given event test the condition and call the appropriate subprogram for the current condition. If you have a need to decouple the detection/generation of events from their handling, then the event package can add the events to a queue as they're detected, and the handling package can remove them from the queue and call the appropriate handling operation, which can test the condition and call the appropriate subprogram. If your system is concurrent, the queue can allow the caller to block when the queue is empty. This is often preferable to polling. If none of these will work, then I don't understand enough to make a meaningful comment. More detail from you might help alleviate that. -- Jeff Carter "C's solution to this [variable-sized array parameters] has real problems, and people who are complaining about safety definitely have a point." Dennis Ritchie 25