![]() |
![]() |
![]() |
![]() |
12 Adding Status and Interrupt Controls
AVS/Express provides a status and interrupt facility that enables you to monitor and control the execution of your application. This chapter describes the status and interrupt facility, including its underlying Scheduler object. It contains the following sections:
- Status and Interrupt Capabilities
- The Scheduler
- Connecting a User Interface to the Scheduler
- Declaring a Module's Behavior
- Setting and Querying Information from an Update Function
The status and interrupt facility enables you to monitor and control how users execute your application. It provides you with the ability to provide selected status information to users, and manage when and how users interrupt the application.
You can provide users with the following status information:
- Module name: the name of the currently executing module
- Percent completion: the work that a module has completed, as a percentage of the total work to be performed
You control how the module name and the percent-completion fields are displayed to the user by customizing the user interface of the control panel.
In order for the system to show status information for a module's method, you must:
- Set the status property on the method
- Instrument the code of the method to update the percent-done variable that it is executing
While a method executes, you can also change the current module field to display a text message to the user about what operation is proceeding.
You use the interrupt capabilities to determine how and when users interrupt your application. The following capabilities are available:
- Disable: prevent interruptible methods from executing once the current method completes
- Interrupt: allow an executing, interruptible method to query whether the user has requested an interrupt (by default, a method is interruptible, but it can declare through an object property that it is not interruptible)
You control interrupt information, whether a module is interruptible, and when and how a module reacts to an interrupt request by customizing the user interface of the control panel.
This section describes an AVS/Express object called the Scheduler. It, and subsequent sections, frequently refers to C API routines. For information on equivalent C++ API and FORTRAN API routines, see Chapter 9, Object Manager APIs.
Underpinning the status and interrupt facility is a special AVS/Express object called the Scheduler, which is located immediately under Root in the object hierarchy. An application must interact with the Scheduler to utilize the available status and interrupt capabilities. Interaction is through user-interface connections to the Scheduler's four external-user subobjects:
For example, if you want to display the current module to the user, you typically connect a UItext widget to the Scheduler.current_mod subobject.
See Connecting a User Interface to the Scheduler on page 12-5.
Detailed descriptions of the Schedule subobjects are as follows:
Table L-1
For more information on setting Scheduler.percent_done and Scheduler.current_mod, see Setting and Querying Information from an Update Function on page 12-8.
You can connect your application to the Scheduler either from the standard user interface or from a custom interface that you build.
AVS/Express supplies a standard user interface for displaying the information in the Scheduler as part of the SingleWindowApp and MultiWindowApp DataViewers. This interface, which appears below the Module panel, consists of simple User Interface widgets attached to Scheduler.percent_done, Scheduler.current_mod, Scheduler.interrupt, and Scheduler.disable subobjects.
Note that you can also access a control panel interface to the Scheduler from the control menu on a ModuleStack.
You can display Scheduler information in a user interface customized for your application. Simply build the user interface as you would build any user interface, inserting appropriate widgets for the Scheduler subobjects that you want to display.
To use your custom interface, connect each widget's value, label, or set subobject to the appropriate subobject in the Scheduler. Note that the Scheduler does not appear in the Network Object, hence you cannot draw a connection line to the appropriate subobject. Instead, you must enter a connection in the widget subobject's value box. For example, to refer to Scheduler.interrupt, enter the connection operator followed by Scheduler.interrupt:
Most widgets have no special execution priority. When the user interacts with a widget, the Object Manager executes the widget's update method after it handles any other methods already in the queue. However, when the user selects the interrupt toggle, it is desirable for the Scheduler.interrupt subobject to be updated immediately. An executing module's function can then query Scheduler.interrupt (by calling OMstatus_check) and take the appropriate action.
To enable an immediate update, connect a UIdynamic_toggle widget rather than a UItoggle widget to the Schedule.interrupt subobject. UIdynamic_toggle is similar to UItoggle, except that the Object Manager executes its update method immediately.
AVS/Express can use UIdynamic_toggle for immediate updates because it contains a subobject of type UImake_dyn_wind (dyn_wind stands for dynamic window), whose handle subobject is connected to UIdynamic_toggle's handle subobject. You can customize any widget in the same way to achieve the same affect.
CAUTION: Be extremely cautious about where and when you use UIdynamic_toggle and/or implement immediate updating. The UIdynamic_toggle widget works correctly in the context of the Scheduler because it is connected to Scheduler.interrupt (and possibly Scheduler.disable), and access to these Scheduler subobjects is controlled.
A module's update method uses object properties to declare whether the Object Manager should display status information for the module and whether the module is interruptible.
By default, a method does not display status information. You enable and disable its display by setting the method object's status property in the Properties Editor. The following values are allowed:
By default, a method can be interrupted and disabled. You enable and disable interruptibility by setting the method object's interruptible property in the Properties Editor. The following values are allowed:
Disabling interruptibility allows a method to continue to execute even when the system is disabled. You might want to do this in order to allow user interface objects to continue to provide feedback in those circumstances.
The update function associated with a method can call Object Manager API routines to set and query Scheduler information. This section describes the C API routines; for information on equivalent C++ API and FORTRAN API routines, see Chapter 9, Object Manager APIs.
A function can do the following by calling the OMstatus_check routine:
For a description of OMstatus_check, see the AVS/Express online help system.
A function can also normalize Scheduler.percent_done; see the next section for details.
A function sets Scheduler.percent_done by calling the OMstatus_check routine. By indicating in advance a percent range, it can also normalize this subobject. For example, suppose that it does the following:
The Object Manager then normalizes Scheduler.percent_done to 5; that is, 25 percent of 20.
To specify a percent range, a function calls the OMpush_status_range routine and pushes the range onto a stack that the Object Manager maintains. Note that you are not restricted to pushing a single range onto the stack: you can push and pop multiple percent ranges onto and off the Object Manager's stack. (To pop a range off the stack, the function calls OMpop_status_range.) When the Object Manager normalizes, it uses the top range in the stack. This feature is useful when the work of an update function is split among several other functions that the update function calls: the update function uses the push and pop functionality to set percent ranges for the other functions.
For descriptions of OMpush_status_range and OMpop_status_range, see the AVS/Express online help system.
The following example module code illustrates pushing and popping ranges onto and off the Object Manager's stack.
int
get_random_values(int arr[], int size)
{
int i, stop;
for (i = 0; i < size; i++) {
if (!(i & 0xff)) { /* do only every so often... */
(void) OMstatus_check(i * 100 / size, NULL, &stop);
if (stop) return(0); /* user interrupted us */
}
arr[i] = random();
}
return(1);
}
int
update_me(OMobj_id obj_id, OMevent_mask mask, int seq_num)
{
int arr1[1000], arr2[500];
int stat;
OMpush_status_range(0,75);
stat = get_random_values(arr1,1000);
OMpop_status_range();
if (stat != 1) return(0); /* interrupted */
OMpush_status_range(75,100);
stat = get_random_values(arr2,500);
OMpop_status_range();
if (stat != 1) return(0);
... set the values in arr1 and arr2 into objects ...
The ~express/include/avs/util.h file was updated in AVS/Express 3.1 to include changes that will safeguard against memory allocation errors. The util.h file contains the following three macros for memory allocation:
These macros will execute if the pointer returned from malloc or alloc is NULL; when this happens, a dialog box titled "Memory Allocation FAILED" is displayed with a "Save State and Exit, or Retry Allocation?" message.
- Note: The message within this dialog box is a string that is passed to the macro.
If you respond by selecting YES, the current system state is saved before exiting. If you respond by selecting NO, you can perform any memory cleanup on your own and then retry the allocation.
![]() |
![]() |
![]() |
![]() |