#include <cx/ModuleCommand.h>void *cxInputAdd( int fd, cxInputMask condition, cxInputCallbackProc callback, void *client_data)
None
The return value of this function is an opaque handle that can be used in a subsequent call to cxInputRemove for removing the monitoring function.
When the specified condition occurs, the Control Wrapper will call the function named in the callback argument to cxInputAdd. This function is assumed to have three formal arguments, as follows:
void (*cxInputCallbackProc)( void *client_data, int fd, void *handle)
The argument client_data is the value passed in to cxInputAdd. Argument fd is the Unix file descripter that is affected. Argument handle is the return value from cxInputAdd that corresponds to this activity. It may be used in a call to cxInputRemove if conditions warrant.
The action of calling a callback procedure is not equivalent to actually firing the module. If the callback routine decides that the module should be fired based on new information resulting from the file descriptor activity, it should use cxFireASAP to schedule the future firing of the module.
Because of the synchronous nature of the firing behavior of IRIS Explorer modules, a file descripter callback procedure will never be called when the module is firing. These callbacks are only called when the module is quiescent.
This facility works for both X and non-X modules.
The following code fragment shows an example of how this routine might be used within a module:
#include <cx/Typedefs.h> #include <cx/ModuleCommand.h> ... FILE *fd; void *handle; void haveData(); ... /* * Use "popen(3E)" to start some external shell command. */ if ( (fd=popen( command, "r" )) == NULL) { cxModAlert( "Command failed." ); return; } /* * Now attach the file descripter to the scheduler. */ handle = cxInputAdd( fileno(fd), cx_InputReadMask, haveData, (void *)fd ); ... /* * User callback -- called whenever data can be read. */ void haveData( client_data, fd, handle ) void *client_data; int fd; void *handle; { char buf[BUFSIZ]; int len; len = read( fd, buf, sizeof buf ); /* * If EOF or error was encountered, close the pipe and remove the * descripter from the scheduler. */ if (len <= 0) { pclose( (FILE *)client_data ); cxInputRemove( handle ); } /* * If conditions warrent, schedule the module for firing. */ if ( /* some condition */ ) { cxFireASAP(); } }