External Input Sources (UNIX only)

On UNIX platforms, Views allows the application to add new sources of input using file descriptors. These alternate input sources can be registered and unregistered with the IlvEventLoop methods addInput, addOutput, removeInput, and removeOutput. For backward compatibility, the old functions IlvRegisterInput, IlvRegisterOutput, IlvUnRegisterInput and IlvUnRegisterOutput are still supported; they are equivalent to:

IlvEventLoop::getEventLoop()->[add|remove][Input|Output]()

Views does not read any data from these input sources but rather monitors them and notifies the application when the file descriptor has received input or is ready for writing. When this happens, Views calls the application callback routine associated with the given source of input; this callback routine is then responsible for reading (or writing) data from (or to) the file descriptor. It is also the responsibility of the application to open the file descriptors before adding them as new input sources in Views and to close them after removing them.

Here is an example of a short Views program reading from the standard input and copying it one word per line to the standard output.

#include <strstream.h>

#include <string.h>

#include <ilviews/view.h>

 

static void MyInputCallback(int, IlAny) {

char buffer[1048];

cin >> buffer;

cout << buffer << endl;

if (!strcasecmp(buffer, "quit"))

exit(0);

}

 

int main(int, char*[]) {

IlvEventLoop::getEventLoop()->addInput(0 /*stdin*/,

MyInputCallback, 0, 0);

IlvMainLoop();

}