Low-Level Services Examples

Low-Level Services Example--1

The sample ILE C program in Figure 1 shows how to use the Write Data (QsnWrtDta), Get AID (QsnGetAID), and Roll Up (QsnRollUp) APIs. The program writes a line at the bottom of the screen and if F3 is not pressed, rolls the screen up and writes a new line at the bottom of the screen. The roll area for the QsnRollUp API is defined to be from row 1 to 24 and one line is rolled up. If F3 is pressed, the program ends. A partial screen display is shown in Figure 2.

Figure 1. Program to Roll Text on Screen

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "qsnapi.h"

int main(void)
{
    long i;
    char s[100];

    QsnClrScr('0', 0, 0, NULL);
    for (i = 1; ; ++i) {
        sprintf(s, "Line %2.d.   Press Enter to roll, F3 to quit.", i);
        QsnWrtDta(s, strlen(s), 0, 24, 2, QSN_SA_NORM, QSN_SA_NORM,
                  QSN_SA_NORM, QSN_SA_NORM, 0, 0, NULL);
        if (QsnGetAID(NULL, 0, NULL) == QSN_F3)
            break;
        QsnRollUp(1, 1, 24, 0, 0, NULL);
    }
}


Figure 2. Screen Output from Roll Text Program

+--------------------------------------------------------------------------------+
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|  Line 1.   Press Enter to roll, F3 to quit.                                    |
|  Line 2.   Press Enter to roll, F3 to quit.                                    |
|  Line 3.   Press Enter to roll, F3 to quit.                                    |
|  Line 4.   Press Enter to roll, F3 to quit.                                    |
|  Line 5.   Press Enter to roll, F3 to quit.                                    |
|  Line 6.   Press Enter to roll, F3 to quit.                                    |
|  Line 7.   Press Enter to roll, F3 to quit.                                    |
|  Line 8.   Press Enter to roll, F3 to quit.                                    |
|                                                                                |
+--------------------------------------------------------------------------------+


Low-Level Services Example--2

Figure 3 shows how to use the Query 5250 (QsnQry5250) API. A sample display is shown in Figure 4.

Figure 3. Program Using the Query 5250 (QsnQry5250) API

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "qsnapi.h"

#define    TRUE    1
#define    FALSE   0

int main(void)
{
    Qsn_Qry_5250_T qry5250;
    Qsn_WSC_display_T *dsp = (Qsn_WSC_display_T *)(qry5250.WSC_display);
    char s[100];
    Q_Bin4 row;
    Qsn_Cmd_Buf_T buf;

    QsnQry5250(&qry5250, sizeof(qry5250), NULL);
    buf = QsnCrtCmdBuf(100, 20, 0, NULL, NULL);
    QsnClrScr('0', buf, Q_NO_HANDLE, NULL);
    sprintf(s, "Query status is %c, num input fields: %d, color: %c, wide: %c",
            qry5250.query_status, qry5250.num_input_capable,
            (QsnQryColorSup(NULL, Q_NO_HANDLE, NULL) == TRUE ? 'Y' : 'N'),
            (dsp->scr_size == 3 ? 'Y' : 'N'));
    QsnWrtDta(s, strlen(s), 0, row=5, 5, QSN_SA_NORM, QSN_SA_NORM,
                 QSN_SA_NORM, QSN_SA_NORM, buf, Q_NO_HANDLE, NULL);
    sprintf(s, "GUI display: %d, GUI support: %d",
               dsp->GUI_display, dsp->GUI_support);
    QsnWrtDta(s, strlen(s), 0, row+=2, 5, QSN_SA_NORM, QSN_SA_NORM,
                 QSN_SA_NORM, QSN_SA_NORM, buf, Q_NO_HANDLE, NULL);
    sprintf(s, "Move cursor: %d, Row1/Col1: %d, ReadMDTImmAlt: %d",
               dsp->move_csr_order, dsp->row1_col1, dsp->Read_MDT_Imm_Alt);
    QsnWrtDta(s, strlen(s), 0, row +=2, 5, QSN_SA_NORM, QSN_SA_NORM,
                 QSN_SA_NORM, QSN_SA_NORM, buf, Q_NO_HANDLE, NULL);
    sprintf(s, "Extended primary attributes: %d, DBCS: %x",
               dsp->extended_pri_atr_DP, dsp->DBCS);
    QsnWrtDta(s, strlen(s), 0, row +=2, 5, QSN_SA_NORM, QSN_SA_NORM,
                 QSN_SA_NORM, QSN_SA_NORM, buf, Q_NO_HANDLE, NULL);
    sprintf(s, "Wide mode on: %c",
               QsnRtvMod(NULL, Q_NO_HANDLE, NULL) == QSN_DSP04 ? 'y' : 'n');
    QsnWrtDta(s, strlen(s), 0, row +=2, 5, QSN_SA_NORM, QSN_SA_NORM,
                 QSN_SA_NORM, QSN_SA_NORM, buf, Q_NO_HANDLE, NULL);
    sprintf(s, "Wide mode allowed: %c",
               QsnQryModSup(QSN_DSP04, NULL, Q_NO_HANDLE, NULL) ==
                                                    TRUE ? 'y' : 'n');
    QsnWrtDta(s, strlen(s), 0, 13, 5, QSN_SA_NORM, QSN_SA_NORM,
                 QSN_SA_NORM, QSN_SA_NORM, buf, Q_NO_HANDLE, NULL);
    QsnPutBuf(buf, Q_NO_HANDLE, NULL);
    QsnGetAID(NULL, Q_NO_HANDLE, NULL);
}



Figure 4. Screen Output from QsnQry5250 API Program

+--------------------------------------------------------------------------------+
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|     Query status is 1, num input fields: 500, color: Y, wide: Y                |
|                                                                                |
|     GUI display: 1, GUI support: 1                                             |
|                                                                                |
|     Move cursor: 0, Extended primary attributes: 0                             |
|                                                                                |
|     Wide mode on: n                                                            |
|                                                                                |
|     Wide mode allowed: y                                                       |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
+--------------------------------------------------------------------------------+


Low-Level Services Example--3

The sample program in Figure 5 shows how to use the Read Modified Fields (QsnReadMDT) API in conjunction with the buffer query APIs. The resulting screen display before and after the input operations is shown in Figure 6 and Figure 7, respectively.

Figure 5. Program Using Read Modified Fields (QsnReadMDT) API

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "qsnapi.h"

#define    TRUE     1
#define    FALSE    0

int main(void)
{
    Q_Bin4 i, t1, t2, t3, numflds;
    const Q_Uchar cc1=QSN_CC1_MDTALL_CLRALL, cc2=QSN_CC2_UNLOCKBD;
    const Q_Uchar nosa = QSN_NO_SA, norm = QSN_SA_NORM, saul = QSN_SA_UL;
    char pad = ' ';
    Qsn_Cmd_Buf_T cmdbuf, cmdbuf2;
    Qsn_Inp_Buf_T inpbuf;
    Qsn_Fld_Inf_T fldqry;
    Qsn_Read_Inf_T rdqry;
    char msg[100];
    Q_Fdbk_T fdbk = { sizeof(Q_Fdbk_T) };

    cmdbuf = QsnCrtCmdBuf(100, 50, 0, NULL, NULL);
    cmdbuf2 = QsnCrtCmdBuf(100, 50, 0, NULL, NULL);
    inpbuf = QsnCrtInpBuf(200, 50, 0, NULL, NULL);
    QsnClrScr('0', 0, 0, NULL);
    QsnWTD(cc1, cc2, cmdbuf, 0, NULL);
    while (TRUE) {
        QsnSetFld(0, 10, 3, 2, QSN_FFW_ALPHA_SHIFT, NULL, 0, saul,
                    saul, cmdbuf, 0, NULL);
        QsnSetFld(0, 10, 5, 2, QSN_FFW_ALPHA_SHIFT, NULL, 0, saul,
                    saul, cmdbuf, 0, NULL);
        QsnSetFld(0, 10, 7, 2, QSN_FFW_ALPHA_SHIFT, NULL, 0, saul,
                    saul, cmdbuf, 0, NULL);
        numflds = QsnReadMDT(QSN_CC1_NULL, QSN_CC1_NULL, NULL,
                             inpbuf, cmdbuf, 0, NULL);
        if (QsnRtvReadAID(inpbuf, NULL, NULL) == QSN_F3)
            break;
        QsnPutBuf(cmdbuf2, 0, NULL);
        QsnClrBuf(cmdbuf2, NULL);
        QsnClrBuf(cmdbuf, NULL);
        QsnWTD(cc1, cc2, cmdbuf, 0, NULL);
        sprintf(msg, "Num Fields Change: %d", numflds);
        QsnWrtDta(msg, strlen(msg), 0, 2, 30, norm, norm, norm, norm,
                  cmdbuf, 0, NULL);
        for (i = 1; i <= numflds; i++) {
            fldqry.len = 0;
            if (QsnRtvFldInf(inpbuf, i, &fldqry, sizeof(fldqry),
                                0, &fdbk) != QSN_FAIL) {
                sprintf(msg,
                        "Field# %d, row %d, col %d, len %d, value %.*s",
                        i, fldqry.row, fldqry.col, fldqry.len,
                        fldqry.len, fldqry.data);
                QsnWrtDta(msg, t1=strlen(msg), 0,
                     t2=i+3, t3=30, norm, norm, norm, norm,
                     cmdbuf, 0, NULL);
                QsnWrtPad(pad, t1, 0, t2, t3, cmdbuf2, 0, NULL);
            } else {
                sprintf(msg, "Field query failed");
                QsnWrtDta(msg, t1=strlen(msg), 0,
                     t2=4, t3=30, norm, norm, norm, norm,
                     cmdbuf, 0, NULL);
                QsnWrtPad(pad, t1, 0, t2, t3, cmdbuf2, 0, NULL);
            }
        }
        QsnRtvReadInf(inpbuf, &rdqry, sizeof(rdqry), 0, NULL);
        sprintf(msg, "Read information:");
        QsnWrtDta(msg, strlen(msg), 0, t2=10, t3=2, norm, norm,
                  norm, norm, cmdbuf, 0, NULL);
        QsnWrtPadAdr(pad, -1, -1, t2, t3, cmdbuf2, 0, NULL);
        sprintf(msg, "Bytes returned %d, available: %d",
                rdqry.bytes_returned, rdqry.bytes_available);
        QsnWrtDta(msg, strlen(msg), 0, ++t2, t3+2, norm, norm,
                norm, norm, cmdbuf, 0, NULL);
        sprintf(msg, "First data byte: %p", rdqry.dta);
        QsnWrtDta(msg, strlen(msg), 0, ++t2, t3+2, norm, norm,
                norm, norm, cmdbuf, 0, NULL);
        sprintf(msg, "First field byte: %p", rdqry.fld_dta);
        QsnWrtDta(msg, strlen(msg), 0, ++t2, t3+4, norm, norm,
                norm, norm, cmdbuf, 0, NULL);
        sprintf(msg, "Diff: %d", rdqry.fld_dta-rdqry.dta);
        QsnWrtDta(msg, strlen(msg), 0, ++t2, t3+4, norm, norm,
                norm, norm,   cmdbuf, 0, NULL);
        sprintf(msg,
           "Read len: %d, data len: %d, field data len: %d,\
                num fields: %d",
                rdqry.read_len, rdqry.dta_len, rdqry.fld_dta_len,
                rdqry.num_flds);
        QsnWrtDta(msg, strlen(msg), 0, ++t2, t3+2, norm, norm,
                norm, norm, cmdbuf, 0, NULL);
        sprintf(msg, "Read row: %d, col: %d, aid: %x",
                rdqry.read_row, rdqry.read_col, rdqry.AID);
        QsnWrtDta(msg, strlen(msg), 0, ++t2, t3+2, norm, norm,
                norm, norm, cmdbuf, 0, NULL);
    }
}



Figure 6. Display Screen before Input Operation

+--------------------------------------------------------------------------------+
|                                                                                |
|                                                                                |
|  field 1                                                                       |
|                                                                                |
|    field 2                                                                     |
|                                                                                |
|  field 3                                                                       |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
+--------------------------------------------------------------------------------+


Figure 7. Display Screen after Input Operation

+--------------------------------------------------------------------------------+
|                                                                                |
|                             Num Fields Change: 3                               |
|   __________                                                                   |
|                              Field# 1, row 3, col 2, len 7, value field 1      |
|   __________                 Field# 2, row 5, col 2, len 9, value field 2      |
|                              Field# 3, row 7, col 2, len 7, value field 3      |
|   __________                                                                   |
|                                                                                |
|                                                                                |
|  Read information:                                                             |
|    Bytes returned 80, available: 80                                            |
|    First data byte: SPP:0000 :1aefQPADEV0010JENNIFER  002600 :19b:0:d42        |
|      First field byte: SPP:0000 :1aefQPADEV0010JENNIFER  002600 :19e:1:d42     |
|      Diff: 3                                                                   |
|    Read len: 35, data len: 35, field data len: 32, num fields: 3               |
|    Read row: 3, col: 2, aid: f1                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
|                                                                                |
+--------------------------------------------------------------------------------+


Low-Level Services Example--4

The sample program in Figure 8 shows how to use the QsnWrtSFMaj and QsnWrtSFMin APIs to display a window on the screen using the 5250 Create Window command. See the 5494 Remote Control Unit Functions Reference R3.1, SC30-3533-04, for more information. This book can be viewed online through the IBM Publications CenterLink outside Information Center.

Figure 8. Program Using Read QsnWrtSFMaj and QsnWrtSFMin APIs

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "qsnapi.h"

#define STRUCTURED_FIELD                '\xd9'
#define CREATE_WIN_STRUCTURED_FIELD     '\x51'
#define WINDOW_CURSOR_RESTRICT          '\x80'
#define WINDOW_PULL_DOWN                '\x40'
#define WINDOW_BORDER_MINOR             '\x01'
#define WINDOW_TITLE_MINOR              '\x10'

typedef _Packed struct {
    Q_Bin2 length;
    Q_Uchar class;
    Q_Uchar type;
    Q_Uchar flag1;
    Q_Uchar flag2;
    Q_Uchar reserved;
    Q_Uchar num_rows;
    Q_Uchar num_cols;
} create_window_major;

typedef _Packed struct {
    Q_Uchar length;
    Q_Uchar type;
    Q_Uchar flag1;
    Q_Uchar mono_attr;
    Q_Uchar color_attr;
    Q_Uchar ul;
    Q_Uchar top;
    Q_Uchar ur;
    Q_Uchar left;
    Q_Uchar right;
    Q_Uchar ll;
    Q_Uchar bottom;
    Q_Uchar lr;
} create_window_border_minor;

typedef _Packed struct {
    Q_Uchar length;
    Q_Uchar type;
    Q_Uchar flag1;
    Q_Uchar mono_attr;
    Q_Uchar color_attr;
    Q_Uchar reserved;
} create_window_title_minor;

int main(void)
{
    create_window_major win;
    create_window_border_minor win_border;
    create_window_title_minor win_title;
    Qsn_Cmd_Buf_T cmdbuf;
    Q_Uchar c1;
    char title_text[] = "Title";

    cmdbuf = QsnCrtCmdBuf( 300, 20, 0, NULL, NULL);

    /* setup Create window command major structure */
    win.length = sizeof(win);
    win.class = STRUCTURED_FIELD;
    win.type = CREATE_WIN_STRUCTURED_FIELD;
    win.flag1 = WINDOW_CURSOR_RESTRICT;
    win.flag2 = '\x00';
    win.reserved = '\x00';
    win.num_rows = 10;
    win.num_cols = 10;

    /* write Create window command major structure to command buffer */
    QsnWrtSFMaj((char *)(&win), sizeof(win), 0, 9, 22, cmdbuf, 0, NULL);

    /* setup border presentation minor structure */
    win_border.length = sizeof(win_border);
    win_border.type = WINDOW_BORDER_MINOR;
    win_border.flag1 = '\x00';
    win_border.mono_attr = QSN_SA_RI;
    win_border.color_attr = QSN_SA_PNK;
    win_border.ul = '+';
    win_border.top = '*';
    win_border.ur = '+';
    win_border.left = '-';
    win_border.right = '|';
    win_border.ll = '+';
    win_border.bottom = '*';
    win_border.lr = '+';

    /* write border presentation minor structure to command buffer */
    QsnWrtSFMin((char *)(&win_border), sizeof(win_border), cmdbuf, 0, NULL);

    /* setup window title minor structure */
    win_title.length = sizeof(win_title) + strlen(title_text);
    win_title.type = WINDOW_TITLE_MINOR;
    win_title.flag1 = '\x00';
    win_title.mono_attr = QSN_SA_BL;
    win_title.color_attr = QSN_SA_RED;
    win_title.reserved = '\x00';

    /* write window title minor structure to command buffer */
    QsnWrtSFMin((char *)(&win_title), sizeof(win_title), cmdbuf, 0, NULL);

    /* write title text to command buffer */
    QsnWrtDta(title_text, strlen(title_text), 0, 0, 0,
              QSN_NO_SA, QSN_NO_SA, QSN_NO_SA, QSN_NO_SA, cmdbuf, 0, NULL);

    /* write command buffer to screen and wait for key-press */
    QsnPutBuf(cmdbuf, 0, NULL);
    QsnGetAID(NULL, 0, NULL);
}



Top | Dynamic Screen Manager APIs | APIs by category