tips:revmedia:r49

Background Indexing Hooks

Published ByDateVersionKnowledge LevelKeywords
Revelation Technologies19 FEB 19902.XEXPERTBACKGROUND, HOOKS, INDEX.CONTROL, INDEXING

Advanced Revelation has always made efficient use of workstations on a network via background indexing. Because index updates happen during what would otherwise be idle time, the user doesn't have to wait for the updates to complete before continuing processing.

Starting with Advanced Revelation 2.0, background processing is available to you. You can either replace the normal background processing or piggyback on it.

The normal sequence of events for background indexing happens in two stages.

First, INPUT.CHAR accepts and processes all keystrokes for the system. If this routine is idle for a user-specified period of time, it calls another routine, INDEX.CONTROL, which processes index transactions. (You can set the length of the time delay between index updates using the Management-Environment-Indexes window at the Delay before indexing prompt.)

Second, INDEX.CONTROL attempts to update an index. Upon completion it waits for a keystroke. If no keystroke is found in a specified period of time, it attempts to update another index. (This second delay is the time specified in the prompt Time between index checks.) INDEX.CONTROL will continue to process index transactions until the user presses a key. If an update is in progress, it finishes. Keyboard control is then returned to the user.

Two new prompts in the Management-Environment-Indexes window allow you to call code and command sequences at specified places in the background processing.

If you enter a code and command at the Replace background prompt, that code and command will be executed instead of INDEX.CONTROL. although any code and command is valid, you would normally call a a subroutine.

Subroutines called here do not normally require user interaction. If user input is required, the program should avoid calls to MSG, INPUT.CHAR, or any other routine that might again prompt using INPUT.CHAR. There is a danger that the system will prompt for input, time out, prompt for input, time out, etc., until it runs out of memory or levels of recursion.

Once your routine finishes, control is passed back to INPUT.CHAR. In order for INPUT.CHAR to be reinitialized, you must pass it a keystroke. If your routine is not already loading the keyboard buffer (@DATA), a benign keystroke to pass is the editor toggle ([F4]). Once it has been reinitialized, INPUT.CHAR will enter its time out loop as before.

It is important to note that your subroutine is called instead of INDEX.CONTROL. Unless your subroutine in turn calls INDEX.CONTROL, no background index processing occurs.

If INDEX.CONTROL is called (either by INPUT.CHAR or by your routine), it does its work and then enters its own timeout loop. If there is a code and command in the Post index check prompt, however, it will be executed after INDEX.CONTROL has done its work, but before the system waits for input. If INDEX.CONTROL times out again, it will execute its work, then your routine.

With these two hooks there are several possibilities open to you.

  1. Normal processing:
    INPUT.CHAR --> INDEX.CONTROL
  2. Complete replacement of background indexing:
    INPUT.CHAR --> CUSTOM ROUTINE
  3. Custom processing to take place before letting the normal processing take over:
    INPUT.CHAR --> CUSTOM ROUTINE --> INDEX.CONTROL
  4. Custom processing to take place after the normal index processing:
    INPUT.CHAR --> INDEX.CONTROL --> CUSTOM ROUTINE
  5. Custom processing both before and after the normal index processing:
    INPUT.CHAR --> CUSTOM ROUTINE --> INDEX.CONTROL --> CUSTOM ROUTINE 2

Figure 1 is a program that turns off the screen and prompts for a password if the system is idle. A routine like this might be used as a security measure to guard machines if users walk away from them.

Note the use of lowercase characters and C-like comments in the source code. These are both enhancements to the compiler available in Version 2.0.

Figure 1

subroutine sleep
/****************************
A routine to prompt the user for a password if they've been away from the
machine for longer than the initial index timeout period.
Background indexing will continue.
****************************/


$insert INCLUDE, EDIT.KEYS

equ password$   to 'RTI'
equ maxtries$   to 3
equ prompts$    to '|Enter password please.||<                 >'
equ invalid$    to 'Invalid password.'
equ space$      to \20\
equ wait$       to 2


declare subroutine video.rw, index.control, sec, msg
declare function curatr

/****************************
Turn off the break key and the input echo, save off the status line, turn
off the status line, and get the current color attribute and position of the
cursor.
****************************/

break off
echo off

save_status = @status.on

@status.on  = 0
curr_attrib = curatr()
get.cursor(cur)

/****************************
Clear the screen.
****************************/

image =''
video.rw(0, 0, @crtwide - 1, @crtmaxhigh - 1, 'R', image)
video.rw(0, 0, @crtwide - 1, @crtmaxhigh - 1, 'C', )

/****************************
Get the user's logon password from the system file.
****************************/

if @account ne SYSPROG then
  /* create a qfile (synonym) called SYSTEM. The command
     as used here assumes that there is no password on SYSPROG */
  perform 'SETFILE REVBOOT SYSPROG SYSTEM SYSTEM'
end

password = xlate('SYSTEM', @username, 7, 'X')
if password else
  * no password defined for this user - encrypt and use the default
  @ans = password$
  sec(6)
  transfer @ans to password
end

/****************************
Main processing loop.
The user gets maxtries$ attempts to get the password, otherwise s/he is
logged off.
****************************/

tries = 0
msg(prompts$,'S','','')

* Position the cursor for input.

print @(int(@crtwide/2),int(@crtmaxhigh/2)):
loop
  reply =''
  * Do background indexing.
  index.control()
  input reply
  convert @lower.case to @upper.case in reply
  * Encrypt the user's input.
  @ans = reply
  sec(6)
  transfer @ans to reply
  tries = 1
until reply = password or tries = maxtries$
  * Put up the error message for wait$ seconds.
  msg(invalid$, T:wait$,'','')
repeat

if tries = maxtries$ and reply ne password then
  logoff
end

/****************************
Put everything back the way it was found.
****************************/

echo on

video.rw(0, 0, @crtwide - 1, @crtmaxhigh - 1, 'W', image)
print curr_attrib:
put.cursor(cur)
@status.on = save_status
break on
* Load keyboard buffer with [F4] to reinitialize INPUT.CHAR
@data = @move.keys<edit.toggle$>
return
  • tips/revmedia/r49.txt
  • Last modified: 2024/06/19 20:20
  • by 127.0.0.1