Contents Index Monitoring and canceling synchronization Developing multi-threaded applications

UltraLite Static C++ User's Guide
  Adding Non Data Access Features to UltraLite Applications
    Adding synchronization to your application
      Monitoring and canceling synchronization

Handling synchronization status information

The callback function that monitors synchronization takes a ul_synch_status structure as parameter.

The ul_synch_status structure has the following members:

ul_synch_state    state;
ul_u_short        tableCount;
ul_u_short        tableIndex;
   struct {
      ul_u_long   bytes;
      ul_u_short  inserts;
      ul_u_short  updates;
      ul_u_short  deletes;
    }       sent;
    struct {
      ul_u_long   bytes;
      ul_u_short  inserts;
      ul_u_short  updates;
      ul_u_short  deletes;
    }       received;
p_ul_synch_info   info;
ul_bool           stop;
Example 

The following code illustrates a very simple observer function:

extern void __stdcall ObserverFunc(
    p_ul_synch_status status )
{
    printf( "UL_SYNCH_STATE is %d: ",
            status->state );
    switch( status->state ) {
        case UL_SYNCH_STATE_STARTING:
        printf( "Starting\n");
        break;
    case UL_SYNCH_STATE_CONNECTING:
        printf( "Connecting\n"  );
        break;
    case UL_SYNCH_STATE_SENDING_HEADER:
        printf( "Sending Header\n" );
        break;
    case UL_SYNCH_STATE_SENDING_TABLE:
        printf( "Sending Table %d of %d\n",
                status->tableIndex + 1,
                status->tableCount );
        break;
...

This observer produces the following output when synchronizing two tables:

UL_SYNCH_STATE is 0: Starting
UL_SYNCH_STATE is 1: Connecting
UL_SYNCH_STATE is 2: Sending Header
UL_SYNCH_STATE is 3: Sending Table 1 of 2
UL_SYNCH_STATE is 3: Sending Table 2 of 2
UL_SYNCH_STATE is 4: Receiving Upload Ack
UL_SYNCH_STATE is 5: Receiving Table 1 of 2
UL_SYNCH_STATE is 5: Receiving Table 2 of 2
UL_SYNCH_STATE is 6: Sending Download Ack
UL_SYNCH_STATE is 7: Disconnecting
UL_SYNCH_STATE is 8: Done
CustDB example 

An example of an observer function is included in the CustDB sample application. The implementation in CustDB provides a dialog that displays synchronization progress and allows the user to cancel synchronization. The user-interface component makes the observer function platform specific.

The CustDB sample code is in the Samples\UltraLite\CustDB subdirectory of your SQL Anywhere directory. The observer function is contained in the platform-specific subdirectories of the CustDB directory.


Contents Index Monitoring and canceling synchronization Developing multi-threaded applications