3.2.4 The Callback Concept



next up previous contents index
Next: 3.2.5 Portability and Configurability Up: 3.2 Architectural Design Previous: 3.2.3 Structure

3.2.4 The Callback Concept

   

The X Toolkit uses a callback concept to attach application-specific functions to widgets. Whenever a widget is activated by the user (like, e.g., by pressing a command button or by selecting an item from a list) a callback function, which has been registered by the application, is executed. The callback function can be used to influence the user interface or to perform application tasks.

The standard prototype for these callback functions is

    void callBackFunc(object, client_data, call_data);

object is the widget which caused the callback and enables the callback function to identify the caller. client_data is an application-specific data item which has been specified at callback registration. It is used for the transportation of application-specific information from the context of callback registration into the callback function. call_data is the only widget-dependent information which is passed from the X Toolkit to the application and which the application has no control of. object and client_data are constant for a given callback, whereas call_data may vary from call to call.

  
Figure 3.2: Control and data flow during callback registration and execution

As shown in Figure 3.2, the use of callbacks consists of two phases. First the callee (the application) registers a callback function (func in Figure 3.2) to the caller (the X Toolkit). During this phase, the callee is in control of program execution. The registration function terminates and execution of the callee program continues. In the second phase, when execution control has been passed to the caller, the callee's function func is activated by an object which belongs to the caller. object, client_data, and call_data are passed to func. When the callback function terminates execution of the caller is continued.

The most advantageous feature of the callback concept is the proper data and control separation of caller and callee. All information which needs to be passed within the callee from callback registration to callback execution (the client_data) is entirely opaque from the caller's point of view. On the other hand, the only information about the caller which is required on the callee's side is the object identifier.

The callback concept is closely related to the Action routines concept found in UIMS [79]. This concept is, however, not confined to the user interface. It can be generalized and applied wherever an event-driven interface between software modules is needed. This is often the case for the task level of the TCAD framework (see also Chapter 4.3). By accepting the prototype proposed by the X Toolkit as standard for callback functions, a unified concept for several purposes can be used in various places throughout the whole framework, thereby gaining in simplicity and flexibility.



next up previous contents index
Next: 3.2.5 Portability and Configurability Up: 3.2 Architectural Design Previous: 3.2.3 Structure



Martin Stiftinger
Thu Oct 13 13:51:43 MET 1994