work_proc
Description
work_proc.c is a Motif GUI source file that defines the plug_away function, which serves as an XtWorkProc (Xt Intrinsics work procedure) for the “Submetrix 2000 unraveller” application. This function is designed to perform computationally intensive tasks, such as parsing and processing Submetrix 2000 data, in the background. It allows the graphical user interface to remain responsive while data processing is ongoing. After processing data blocks, it triggers updates to the various drawing areas of the application.
Function
Boolean plug_away()
The work procedure that performs background data processing.
- Reads Data Blocks: It calls
search_for_ping_start()to find the beginning of the next data block (block_type,block_size) in theSUBX_infile. It then reads the data for that block into memory (data). - Handles Data Blocks: It calls
handle_SUBX_block()(defined inj_SUB2K.hand implemented elsewhere, likelyreadSUB2K.c) to process the contents of the newly read data block. - GUI Updates: If the processed block is of type
0x00or0x16(representing raw sonar data), it triggers updates to the application’s drawing areas:- Calls
draw_view()forDA1,DA2,DA3, andDA4to refresh their displays according to theirdisplay_state. - If
DA10.pixmapexists (meaning the bathymetry window is active), it callsdraw_bathy()to refresh the bathymetry display.
- Calls
- End of File Check: It checks if the end of the
SUBX_infilehas been reached. If so, it callsstop_parse()to remove itself as a work procedure. - Returns:
Trueif processing is complete (EOF reached),Falseotherwise (meaning it should be called again by the Xt event loop).
How It Works
plug_away is a classic example of how to keep a GUI application interactive during long computations. Instead of running the entire processing loop directly, which would block the X event loop and make the GUI unresponsive, plug_away processes a small chunk of data and then returns control to the event loop. This allows the GUI to handle events (like redraws, button clicks) before plug_away is called again. This cycle continues until plug_away signals completion by returning True.
- It relies heavily on global variables (
SUBX_infile,block_type,block_size,ateof,data,file_length,DA1,DA2,DA3,DA4,DA10,display_state) to manage file state, processing data, and GUI contexts. - The actual heavy lifting of parsing and interpreting the binary Submetrix data blocks is handled by
handle_SUBX_block().