Tags:
create new tag
view all tags

Advanced Topics

Now that you understand the technique described above, there are some existing and soon to be released features to make the process a little easier. Any new ideas that could add to this development are welcome. Just address your new ideas to the APPX Development team.

Foundation Processes

This is a new concept added to the APPX 3.1 environment. You can write an output process that acts like a template for other output processes. You can define generic page headings and footers in the foundation process. Then any output process that includes this foundation process will automatically pick up the standard page frames. This allows you to write ONE standard HTML header and footer for ALL of your HTML generation processes. If you decided to change the HTML header of you pages, you do it ONCE. You can point any output process to a foundation process by editing the Additional Attributes of the output process.

Named Pipes

If you want to have a copy of APPX already running (to bypass the APPX load time) that your CGI script can talk to, you can use Named Pipes. These are permanent pipes that look like data files. They have filenames and can be opened and processed pretty much like a file. This limitation here is that you have ONE process responding to all of your requests. No multi-threading goin on here.

Here is a rather crude example of using Named Pipes. The subroutine will act as a server process. It will listen to a NAMED-PIPE until it gets a connection. Once a connection is established from another process, the subroutine will read data blocks from the pipe until it reaches EOF. It will then loop back and sleep until a new connection is made. A data block is delimited by a NewLine character. So, for most CGI applications, there will be one data block containing the entire CGI data stream. This script is expecting a HEADER data block also that is used as the filename of the calling processes open pipe. The calling process needs to create a pipe, send the name as the first data block, send the CGI data as the second data block, and then listen on the new PIPE for the reply data. The calling process may then close and remove it's pipe.

The server pipe that is opened by this subroutine can be created from the unix prompt and left there, or may be created from within the subroutine itself. The command to create a pipe is 'mkfifo' and will create a disk filename in the specified directory as named-pipe. A named pipe looks just like a file, but has the leftmost security bit of 'p'. This subroutine assumes that the pipe has already been created outside of APPX.

NOTE: This example uses the older ,RT style calls to open stream files. Refer to .STREAM OPEN, .STREAM READ and .STREAM CLOSE for the current method of working with streams (Release 5.1 & up).

#!/bin/ksh
SERVER_PIPE=/src/pete/312/server.pipe
RETURN_PIPE=/tmp/$RANDOM.pipe
mkfifo $RETURN_PIPE
echo "$RETURN_PIPE\n'cat -'" >>$SERVER_PIPE
cat $RETURN_PIPE
rm $RETURN_PIPE
      *
      CNV BIN  --- CDF HEX00                  =      0
      CNV BIN  --- CDF HEX0A                  =      10
      *
      *        Endlessly loop.  The PIPE open will BLOCK until it gets an
      *        active sender on the other end.
      *
      BEG LOOP AI = 000 TO 001  STEP 000
      *
      *        Open our input PIPE as READONLY
      *        -------------------------------
      *        TEMP 80 = Filename of pipe
      *        TEMP 4  = Open mode (r=readonly)
      *        PI      = Pointer to open pipe (filled in by function call)
      *
      SET      --- TEMP 80                    =      /src/pete/312/server.
      APPEND   --- TEMP 80                    0      pipe
      APPEND   --- TEMP 80                    0  --- CDF HEX00
      SET      --- TEMP 4                     =      r
      APPEND   --- TEMP 4                     0  --- CDF HEX00
      SET      --- PI                         =      0
      *
      PASS     --- TEMP 80                    FIELD            SHARE? Y
      PASS     --- TEMP 4                     FIELD            SHARE? Y
      PASS     --- PI                         FIELD            SHARE? Y
      CALL         ,RT_OPEN_STREAM            RESIDENT? Y  END? N  FAIL 0
      *
      IF       --- RETURN CODE                EQ     0
T     CANCEL   Failed to open named pipe!
      *
      *        Initialize the filename to use as a return path to the
      *        process on the other end of the pipe.  This is used to
      *        open a second channel back to the other process for sending
      *        it information.
      *
      SET      --- TEMP 132                   =
      *
      *        Process information from pipe.  Loop endlessly  UNTIL the
      *        RETURN CODE value indicates EOF
      *
      BEG LOOP BI = 000 TO 001  STEP 000
      SET      --- TEMP 32K                   =
      SET      --- LI                         =      32767
      *
      PASS     --- TEMP 32K                   FIELD            SHARE? Y
      PASS     --- LI                         FIELD            SHARE? Y
      PASS     --- PI                         FIELD            SHARE? Y
      CALL         ,RT_READ_STREAM            RESIDENT? Y  END? N  FAIL 0
      *
      *        Do Something with the data until EOF reached on pipe
      *        The first READ will BLOCK until the PIPE is closed by the 
      *        sender process.  EOF is signalled by a RETURN CODE of 0
      *
      *        We are expecting the sender to give us a filename of a new
      *        pipe that it is listening on for our reply, as the first
      *        data block.  Data Block are seperated by a NewLine.  Each
      *        call to rt_read_stream will return one data block.
      *
      IF       --- RETURN CODE                EQ     1
T     GOSUB        :STRIP TRAILER
T     IF       --- TEMP 132                   EQ
TT    SET      --- TEMP 132                   =  --- TEMP 32K
TF    GOSUB        :PROCESS DATA
T     END LOOP BI
      *
      *        Close the pipe
      *
      PASS     --- PI                         FIELD            SHARE? Y
      CALL         ,RT_CLOSE_STREAM           RESIDENT? Y  END? N  FAIL 0
      *
      *        Copy the reply (print file data) back to the named pipe of
      *        the other process.
      *
      SET      --- TEMP 256                   =      cat
      APPEND   --- TEMP 256                   1  --- PRINT FILE PATHNAME
      APPEND   --- TEMP 256                   1      >
      APPEND   --- TEMP 256                   0  --- TEMP 132
      APPEND   --- TEMP 256                   0      ;rm
      APPEND   --- TEMP 256                   1  --- PRINT FILE PATHNAME
      SET      --- NEW PAGE AFTER             =      N
      RUN      --- TEMP 256                                END? N  FAIL 0
      *
      END LOOP AI
      *
      END
      *
      *        ===========================================================
      LABEL    :STRIP TRAILER
      *        -----------------------------------------------------------
      *        Data returned by RT_READ_STREAM is NULL terminated to show
      *        the actual number of characters read from the stream.  Any
      *        characters beyond this NULL are untouched by the function.
      *
      *        Just before the NULL, there may also be a 0x0A depending on
      *        how the data was written to the stream.
      *
      *        This routine will replace both with 0x32 (space) and return
      *        the true length of the data in LI.
      *        ===========================================================
      IF       --- TEMP 32K                   IN --- CDF HEX00
T     SET      --- LI                         =  --- TEXT AT POSITION
T     SET TEMP 32K   AT LI  FOR 001 FROM 001 OF
      *
      IF       --- TEMP 32K                   IN --- CDF HEX0A
T     SET      --- LI                         =  --- TEXT AT POSITION
T     SET TEMP 32K   AT LI  FOR 001 FROM 001 OF
      *
      COMPUTE  --- LI                         -      1
      *
      RETURN
      *        ==========================================================
      LABEL    :PROCESS DATA
      *        ----------------------------------------------------------
      *        Do whatever data processing needs to be done on this data 
      *        ==========================================================
      SET      AAA WORK ALPHA 32K RELATED     =  --- TEMP 32K
      SET      --- PRINT ON SCREEN            =      N
      SET      --- PRINT MODE                 =      KEEP
      SET      --- PRINT FILE DISPOSITION     =      SAVE
      SET      --- PRINT FORM ID              =      NO-PAGEBREAKS
      OUTPUT   AAA PROCESS DATA                RELATED      END? N  FAIL 0
      RETURN
      *        ==========================================================

-- JoeOrtagus - 2012-02-13

Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r2 - 2016-04-05 - JeanNeron
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback