Getting Started Documentation Glish Learn More Programming Contact Us
Version 1.9 Build 1556
News FAQ
Search Home


next up previous contents index
Next: The Client Class Up: The Glish Client Library Previous: The GlishEvent Class

An Example of a Client

Figure 15.1: Glish Wrapper for FFT Client

Suppose you want to create an ``FFT server": a Glish client that when sent a numerically-valued fft event computes the FFT of the array of data and returns the result as an answer event. The result consists of a record with two fields, real and imag, arrays of the real and imaginary parts of the Fourier transform.

Assume you have a function fft available for doing the actual transformation and want to ``wrap" a Glish client interface around this function. Figure 15.1 shows how you do this.

First you create a Client object using the idiom discussed in § 15.5. You then enter the event-loop, blocking until a new event is ready (NextEvent returns a nil pointer when the client should terminate).

If the event's name is fft you then extact the event's value, convert it to double if it is not already, and extract its length into num. You then use DoublePtr to get a pointer to the actual array of double-precision elements. In order to call fft you need to also pass it arrays where it should put its results, so you create real and imag. After computing the FFT you create in r a Glish record value to hold the two arrays, and assign them to r's real and imag fields. You then send this aggregate value as a Glish event with the name answer. Now that you're done with r you Unref() it to reclaim its memory. This automatically results in real and imag's memory being reclaimed too. You don't need to Unref() the GlishEvent pointed to by e because the next call to NextEvent automatically does so.

Finally, if the event isn't fft then you inform the Client library that you don't recognize this particular event.

To compile this example you use:

    C++ -I$GLISHROOT/include -c fft_server.cc
where C++ is the local C++ compiler (typically g++ or CC) and $GLISHROOT is the path to the Glish installation directory. (See § 16.7.)

You then link the example using:

    C++ -o fft_server fft_server.o \
        -L$GLISHROOT/lib/$ARCH -lglish -lsos -lm
where $ARCH indicates the local architecture. (Again, see § 16.7.) On some platforms, other libraries may be required for things like sockets, for example under Solaris -lsocket and -lnsl are also required.


next up previous contents index
Next: The Client Class Up: The Glish Client Library Previous: The GlishEvent Class   Contents   Index
Please send questions or comments about AIPS++ to aips2-request@nrao.edu.
Copyright © 1995-2000 Associated Universities Inc., Washington, D.C.

Return to AIPS++ Home Page
2006-10-15