ILE C/C++ Programmer's Guide


Obtaining Feedback Information

You can obtain additional information about the program devices associated with your application by using OS/400 system feedback areas.

Example:

The following example uses the _Riofbk() function.

  1. To create the display file T1520DDF using the DDS source shown below, enter:

    CRTDSPF FILE(MYLIB/T1520DDF) SRCFILE(QCPPLE/QADDSSRC) MAXDEV(2)

    Figure 145. T1520DDF -- DDS Source for a Feedback Display


    
    
    A DSPSIZ(24 80 *DS3)
    A R EXAMPLE
    A OUTPUT 5A O 5 20
    A INPUT 20A I 7 20
    A 5 10'OUTPUT:'
    A 7 10'INPUT:'
  2. To override the file STDOUT with the printer file QPRINT, enter:

    OVRPRTF FILE(STDOUT) TOFILE(QPRINT)
  3. To create the program T1520FBK using the source shown below, enter:

    CRTBNDC PGM(MYLIB/T1520FBK) SRCFILE(QCPPLE/QACSRC)

    Figure 146. T1520FBK -- ILE C Source to Use Feedback Information


    
    
    /* This program illustrates how to use the _Riofbk function to access */
    /* the I/O feedback area. */ 
    #include <stdio.h>
    #include <recio.h>
    #include <signal.h>
    #include <xxfdbk.h>
    #include <stdlib.h>
    #include <string.h>
    static void handler (int);
     
    _RFILE *fp;/* Signal handler for _Racquire exceptions */
     
    static void handler (int sig)
    {
    _XXIOFB_T *io_feedbk;
    _XXIOFB_DSP_ICF_T *dsp_io_feedbk;
     
    signal ( SIGIO, handler );
     
    io_feedbk = _Riofbk ( fp );
    dsp_io_feedbk = (_XXIOFB_DSP_ICF_T *)( (char *)(io_feedbk) +
    io_feedbk->file_dep_fb_offset );
    printf ( "Acquire failed\n" );
    printf ( "Major code: %2.2s\tMinor code: %2.2s\n",
    dsp_io_feedbk->major_ret_code,dsp_io_feedbk->minor_ret_code );
    exit ( 1 );
    }
    int main(void)
    {
    char buf[20];
    _RIOFB_T *rfb;
     
    if (( fp = _Ropen ( "*LIBL/T1520DDF", "ar+") ) == NULL )
    {
    printf ( "Could not open the display file\n" );
    exit ( 2 );
    }
    signal ( SIGIO, handler );
     
    _Racquire ( fp, "DEVICE1" );/*Acquire the device. DEVICE1 is */
    /* now the default program device. */
    /* NOTE : If the device is not */
    /* acquired, exceptions are issued. */
    _Rformat ( fp, "EXAMPLE" ); /* Select the record format. */ 
    _Rwrite ( fp, "Hello", 5 ); /* Write to default program device. */
     
    /* Read from default program device. */ 
    rfb = _Rreadn ( fp, buf, 21, __DFT );
     
    printf ( "user entered: %20.20s\n", buf );
     
    _Rclose ( fp );
    return(0);
    }

    This program uses two typedefs _XXIOFB_T for common I/O feedback, and _XXIOFB_DSP_ICF_T for display file specific I/O feedback. A pointer to the I/O feedback is returned by _Riofbk (fp).

  4. To run the program T1520FBK, enter:

    CALL PGM(MYLIB/T1520FBK)

    The output is as follows:

    +--------------------------------------------------------------------------------+
    |                                                                                |
    |                                                                                |
    |                                                                                |
    |        OUTPUT:   Hello                                                         |
    |                                                                                |
    |        INPUT:                                                                  |
    |                                                                                |
    |                                                                                |
    |                                                                                |
    |                                                                                |
    |                                                                                |
    |                                                                                |
    |                                                                                |
    |                                                                                |
    |                                                                                |
    |                                                                                |
    +--------------------------------------------------------------------------------+

    The signal() function is called before an error to establish a signal handler. If an exception occurs during the acquire operation, the signal handler is called to write the major/minor return code to stdout.

    +--------------------------------------------------------------------------------+
    |Acquire failed                                                                  |
    |Major code: 82 Minor code: AA                                                   |
    +--------------------------------------------------------------------------------+


[ Top of Page | Previous Page | Next Page | Table of Contents ]