Skip to main content
A common practice in legacy multi-value applications is/was to write controlling records to denote a user being logged in, or running a specific menu option.

A problem with that design is if the program doesn't wrap-up normally (either due to a bug or the session was logged off or perhaps dropped into the debugger and the user aborted) the control record is left in place.

jabba to the rescue!!

A very useful feature of dynamic objects (written in jabba which is an extension to the jBC language) is that if a class has a destructor method, that method will be called when jBASE wraps up the work-space/session.

Example:

WRAPUP_TEST.b
PROGRAM WRAPUP_TEST

INCLUDE JWRAPUP_SESSION.h

OPEN 'CONTROL' TO F.control ELSE STOP 201,'CONTROL'

WRITE TIMEDATE() ON F.control,@LOGNAME

LOOP
    CRT "Waiting to be killed...":
    INPUT cont,1_
    CRT "We weren't killed....don't touch the keyboard"
REPEAT

The above program will write a timestamp to the file CONTROL for the logged in user name (@LOGNAME).

It then loops waiting to be killed (LOGOFF). To be clear, the destructor would still be called if the program was written to end gracefully (but there's no fun in that for this demonstration).

Let's look at the INCLUDE JWRAPUP_SESSION.h

    CALL JWRAPUP_SUB

Not much going on there...but think big picture....this include can be placed at the top of any program you want to benefit from this proposition (and recompile/catalog). You could also put it inside an INCLUDE you already have.

Now let's look at JWRAPUP_SUB.jabba

    Subroutine JWRAPUP_SUB

    common /JWRAPUP_SESSION/ jwrapup_obj

    if unassigned(jwrapup_obj) then jwrapup_obj = ''
    if not(jwrapup_obj->$isobject()) then
        jwrapup_obj = new object('jwrapup_session')
    end

    return

Note the mixed case is just a coding style.

This jabba program is essentially jBC (BASIC) code with the significant exception that it instantiates an instance of a jwrapup_session class.
The named common - JWRAPUP_SESSION - simply helps there being just one instance of this jwrapup_session object (i.e. like a singleton class).

Finally the jwrapup_session.jabba

    method jwrapup_session::~jwrapup_session()
        open 'CONTROL' to f.control then
            delete f.control,@logname
            crt
            crt 'Cleaned up after logoff'
        end
    end method

You could feasibly have a jwrapup_session::jwrapup_session() method (i.e. the constructor) and store values in the class and/or do some file I/O. You could even open the CONTROL file to this->f.control and then in the destructor you would delete from this->f.control instead of just f.control (and of course you wouldn't need the open in the destructor).


Putting this in action:

~/playground$ CREATE-FILE CONTROL
[ 417 ] File CONTROL]D created , type = JD
[ 417 ] File CONTROL created , type = JD
~/playground$ WRAPUP_TEST
Waiting to be killed...?

Now either LOGOFF this session or in this case we will just break (using control-c) and abort

Waiting to be killed...?Interrupt signal
Source taken from /jbase/playground/BP/WRAPUP_TEST.b
0011         INPUT cont,1_
jBASE debugger->!LIST-ITEM CONTROL

PAGE    1                                                                                                08:21:15  19 MAY 2022

    pfalson
001 08:20:30  19 MAY 2022

jBASE debugger->a
jBASE debugger , ABORT

Cleaned up after logoff
~/playground$ LIST-ITEM CONTROL

 No Records selected

~/playground$

As you can see from the debugger I used !LIST-ITEM CONTROL to spawn a session and list the contents of the CONTROL file, showing "pfalson" and a single attribute with the time and date.

Next I entered a to abort the program. You can see the Cleaned up after logoff message which came from the jwrapup_session::~jwrapup_session() method.

And next the LIST-ITEM CONTROL shows our pfalson record is now gone.



------------------------------
Peter Falson
Rocket Internal - All Brands
------------------------------