/* -
* This is a Viewer
Controller or client implemented on the System i -
* to
work with the Model part of the MVC demonstration design. -
* -
* It's
purpose is to test the Model (server) MDLDMOSR. -
* -
* The Model portion of a MVC
design should be flexible enough to -
* work
with different client implementations. -
* -
* This program is a quick
test that the Model is running as well as -
* showing that the Model
works with a client implemented on the System i. -
* -
* Bill Blalock, 2007 -
*/
PGM PARM(&VCID &ONLYREAD &IINSTRTN &IMESSAGE +
&ONLYWRITE)
/* -
* Use the MDLI input data
structure to define those varaible ... probably -
* more
trouble that it is worth -
*/
DCLF MDLIDS01
DCL VAR(&ONLYREAD) TYPE(*LGL)
DCL VAR(&ONLYWRITE) TYPE(*LGL)
/* viewer controller id length */
DCL VAR(&VCIDL) TYPE(*DEC) LEN(3 0) VALUE(6)
/* answer from model */
DCL VAR(&ANSWER) TYPE(*CHAR) LEN(160)
/* data written to Model */
DCL VAR(&WRITEDTA) TYPE(*CHAR) LEN(102)
DCL VAR(&WRITEDTAL) TYPE(*DEC) LEN(5 0) VALUE(102)
/* data received from Model */
DCL VAR(&READDTA) TYPE(*CHAR) LEN(176)
DCL VAR(&READDTAL) TYPE(*DEC) LEN(5 0) VALUE(176)
/* sender info, keeps API happy */
DCL VAR(&SENDER) TYPE(*CHAR) LEN(44)
DCL VAR(&SENDERL) TYPE(*DEC) LEN(3 0) VALUE(0)
/* wait time ... 10 secs should do it */
DCL VAR(&WAIT) TYPE(*DEC) LEN(5 0) VALUE(10)
/* -
* Instruction &ONLYREAD
flag by passes writing the model input data queue -
* that
way any messages hung up in the queue can be read and cleared -
*/
IF COND(*NOT &ONLYREAD) THEN(DO)
/* -
* Concatinate
input params into string, same structure as data
structure -
* MDLIDS01 -
*/
CHGVAR VAR(&WRITEDTA) VALUE(&VCID *CAT &IINSTRTN +
*CAT &IMESSAGE)
/* -
* Send the input parameters
to the demonstration model / server -
*/
CALL PGM(QSNDDTAQ) PARM('MDLI' '*LIBL' +
&WRITEDTAL &WRITEDTA)
ENDDO
/* -
* If the instruction is
*ONLY_WRITE then end the program. This -
* will leave the response on
the output data queue MDLO if the model -
* is
working correctly. -
*/
IF COND(&ONLYWRITE) THEN(DO)
SNDUSRMSG MSG('Parameter ONLYWRITE set.
The model +
response is left on the output data +
queue.') MSGTYPE(*INFO)
RETURN
ENDDO
/* -
* Wait for the response for
the demonstration model / server -
*/
CALL PGM(QRCVDTAQ) PARM('MDLO' '*LIBL' +
&READDTAL &READDTA &WAIT 'EQ' &VCIDL +
&VCID &SENDERL &SENDER)
/* -
* Send the answer to the
user -
*/
IF COND(&READDTAL *EQ 0) THEN(DO)
IF COND(&ONLYREAD) THEN(SNDUSRMSG MSG('The data +
queue read timed out.
The ONLYREAD +
parameter was set for to an empty +
queue.') MSGTYPE(*INFO))
ELSE CMD(SNDUSRMSG MSG('The data queue read timed +
out. The Model must
not be working.') +
MSGTYPE(*INFO))
RETURN
ENDDO
/* -
* Extract the message from
the demonstation model answer -
* MDLODS01 -
*/
CHGVAR VAR(&ANSWER) VALUE(%SST(&READDTA 17 160))
SNDUSRMSG MSG('The answer from the Model is: ' *CAT +
&ANSWER) MSGTYPE(*INFO)
ENDPGM