Previous Page Contents Page Next Page

2 Designing and Writing LU0 Applications

The information contained in this chapter will help you write LU0 application programs. The following topics are covered:

2.1 Synchronous and Asynchronous LU0 Operation

The LU0 interface can operate in two ways:

Synchronous operation

Synchronous operation is straightforward. The application makes a function call to LU0; this function call blocks until LU0 has completed all processing for the function. Any significant events on the session are reported to the application using function return codes.

Asynchronous operation

Asynchronous operation returns control to the application immediately, so the application is free to continue with further processing (including issuing other LU0 functions). The function return code is used only to indicate whether the function call was valid, and does not report completion of the function. LU0 notifies the application of subsequent events using a callback routine supplied by the application. See Asynchronous Session Operation for more details.

Each LU0 function includes a pointer to a callback routine as one of its supplied parameters. This is used to control whether synchronous or asynchronous operation is used:

The lu0_init function, which is used to initialize a session, determines how the session operates and how session events are reported to the application:

2.1.1 Asynchronous Session Operation

To start an asynchronous session, the application issues lu0_init with a pointer to a callback routine. If this function returns successfully, LU0 returns a handle, which the application uses on all future calls for this session.

The callback routine supplied to lu0_init is a special case because it is called multiple times, to update the application on the status of the session.

  • During a normal session startup, the lu0_init callback routine is called three times:

    • When ACTLU is received

    • When BIND is received

    • When the session is active (SDT is received)

    The lu0_init is considered to be pending until the active callback (with an event value of LU0_EVENT_ACTIVE) is made. You cannot issue lu0_read or lu0_write functions for the session until this callback has been made.

  • The lu0_init callback routine also receives notifications of session failure or session events:

    • A callback with an event value of LU0_EVENT_INIT_FAILED, which can only occur while the lu0_init is pending, indicates that the initialization has failed. The handle returned on the original lu0_init is no longer valid, and no further calls can be made for the session.

    • After the session has become active, a callback with an event value of LU0_EVENT_INIT_SESS_FAIL indicates that the underlying session has failed. Any unread data already received from the host is still available, so the application can still use lu0_read calls to read it. The application must then terminate the session using lu0_term (or restart it by using lu0_init with the same handle). When it issues either of these calls, all outstanding function calls for the session are terminated.

    • Other callbacks can report changes in the session status, and affect which other LU0 function calls can be made. See the description of the event parameter in lu0_init for details.

The other LU0 functions also include callback routines. However, each of these routines is only called once, to indicate whether or not LU0 has successfully completed processing for the function: the event value either indicates completed OK or reports an error condition along with the completion status. Each callback routine always receives one callback; for example, if an lu0_read function is outstanding when a session is terminated, the callback routine supplied on the lu0_read call will be called to indicate the session termination.

The application is free to choose whether to use the same callback routine for all functions or a different callback routine for each function.

Previous Page Contents Page Top of Page Next page