Guardian Programmer's Guide

Table Of Contents
Communicating With Processes
Guardian Programmer’s Guide 421922-014
6 - 51
Programming the Server
Programming the Server
The server program reads and processes messages that arrive in the $RECEIVE file.
Each message contains a function code that the server process uses to determine
what action to take. If the action involves writing a record to the database, then the
message also contains the database record to be written. The possible functions are:
Read-approximate record
Read the next record
Read the exact record
Update an existing record
Write a new record
The MAIN procedure of the server process calls the INIT procedure and then reads the
incoming message. It then calls another procedure depending on the value of the
received function code.
The INIT procedure disposes of the startup messages. It also opens the home
terminal and the data file for the program. The data file is identified by a CLASS
MAP DEFINE. You must create the CLASS MAP DEFINE as follows:
1> SET DEFINE CLASS MAP, FILE $APPL.SUBAPPL.RECFILE
2> ADD DEFINE =PARTFILE
The READ^APPROX^RECORD procedure is called when a requester process
makes its first of a sequence of read requests. This procedure uses the part
number supplied in the message as the primary key. If no such key exists, then
the procedure reads the record with the next higher key. The procedure then
returns this record to the message sender.
The READ^NEXT^RECORD procedure is called when the requester process asks
to read the next record in a sequence that started with an approximate read. This
procedure uses the part number supplied in the message as the primary key and
reads the record with the next higher key. The server then returns this record to
the message sender.
The READ^EXACT^RECORD procedure is called when a requester process wants
to update a database record. It uses the part number supplied in the message as
the primary key and returns the corresponding record to the requester process. If
no such key exists, the server returns an error condition instead of the record.
The UPDATE^RECORD procedure is called when a requester wants to update a
database record. The procedure uses the part number supplied in the message as
the primary key to the database file, then it overwrites the corresponding database
record using the database record also supplied in the message.
Note that to update a record, the requester invokes the server twice: once to read
the record and once to update it. When making the update request, the requester
sends the read record back to the server so that UPDATE^RECORD can compare