× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Assuming we are talking about the same thing, a callback is a
procedure called from a procedure as a means of invoking some function
in the caller.

For example, in Scott Klements, HTTPAPI he uses callbacks to for each
time that start of a XML element and one for the end of an XML
document.

You call Scott's HTTPAPI functions and you request that the XML that
gets returned be parsed. To do that you create a procedure in your RPG
that receives a given set of parameters. One for the start <ELEMENT>
and one for the end </ELEMENT>. Each time that the XML parser sees a
start element it calls the procedure you told it to use for start
element and when it sees an end element it calls the procedure you
defined for end element.

Thus the term callback. It calls back to your program to do the
processing. Very powerful tool.

Over the years I have used them for various purposes. One was a state
transition parser. The parser would parse a FedEx string returned from
a FedEx server. Every time it found a action it needed to process
(PutChar, SaveString, etc) it would callback to the calling program to
perform the action requested.

In this example, I am invoking only the end element procedure. Note
the line %pAddr(EndTagProcessing). This tells Scott's program call
procedure EndTagProcessing each time it sees the end of an element.

// Call Scott's API to get xml.
ReturnCode = HTTP_Url_Get_XML(URL :
*Null :
%pAddr(EndTagProcessing) :
%Addr(Data) :
g_TemperatureParameters.Timeout);

The procedure that is calledback looks like this.

p EndTagProcessing...
p b
d pi
d InOutData...
d LikeDs(TD_Data)
d InDepth...
d Like(StdInt)
d Value
d InTagName...
d 1024a Varying
d Const
d InPath...
d 24567a Varying
d Const
d InTagValue...
d 65535a Varying
d Const
d InAttributeArray...
d Like(StdPtr)
d Dim(32767)

d AttributeValue...
d s 64a Varying
/Free

If InPath = '/WeatherBank/Body/Current' And
InTagName = 'Temperature';
If %Trim(InTagValue) = 'Missing';
InOutData.TemperatureMissing = cTrue;
Else;
AttributeValue = %Str(InAttributeArray(2));
If AttributeValue = InOutData.TemperatureType;
InOutData.Temperature = %Dec(%Trim(InTagValue):5:1);
InOutData.TemperatureSeen = cTrue;
EndIf;
EndIf;
EndIf;



On Mon, Oct 15, 2012 at 2:50 PM, Richard Reeve <richreeve@xxxxxxxxx> wrote:

Has anyone ever heard of a callback as it is related to the IBM i? I was asked to explain a callback during an interview and I'd never even heard of it. Can any of you explain to me what a callback is and how it is used? I tried google but didn't get a good explanation.

Thanks.

Warmest Regards,

Richard Reeve
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.