Replication Guide and Reference


Appendixes


Appendix A. Starting the Capture and Apply programs from within an application

Instead of using the asnccp command to start the Capture program or the asnapply command to start the Apply program, you can start the Capture and Apply programs from within your application by calling routines. To use these routines you must specify the AUTOSTOP option for the Capture program and the COPYONCE option for the Apply program because only synchronous execution is supported with this API.

This chapter describes the routines and the return codes, and it gives a sample routine that starts the Capture and Apply programs.


Starting the Capture program using a routine

You can start the Capture program from within your application by calling this routine:

#ifndef ASN_INCLUDE
#define ASN_INCLUDE
 
#define MAXASNPARMLENGTH 128
 
struct asnParm
{
  short byteCount;
  char val[MAXASNPARMLENGTH];
};
 
struct asnParms
{
  int parmCount;
  struct asnParm **parms;
};
 
int asnCapture(struct asnParms *pAsnParms);
#endif

This routine returns the following return codes:

0
The program ran successfully.

-1
The program did not run successfully.

Starting the Apply program using a routine

You can start the Apply program from within your application by calling this routine:

#ifndef ASN_INCLUDE
#define ASN_INCLUDE
 
#define MAXASNPARMLENGTH 128
 
struct asnParm
{
  short byteCount;
  char val[MAXASNPARMLENGTH];
};
 
struct asnParms
{
  int parmCount;
  struct asnParm **parms;
};
 
int asnApply(struct asnParms *pAsnParms);
 
#endif

This routine returns the following return codes:

0
The Apply program ran successfully.

1
The Apply program ran successfully; however, a conflict was detected in at least one subscription set. As a result, one or more rejected transactions were compensated.

-1
The Apply program did not run successfully.

Sample routine that starts the Capture and Apply programs

The following sample routine starts the Capture and Apply programs:

#include <stdlib.h>
#include <string.h>  /* for strcpy, strlen */
#include <asn.h>  /* replication API parameters */
 
/* helper function to dump out parameter contents */
int printParms( const struct asnParms parms )
{
   int count = 0;
   if( parms.parmCount > 0 )
   {
      for( count=0; count<parms.parmcount>val );
         printf( "    bytes = %d\n", parms.parms[count]->byteCount );
      }
      return(0);
   }
   else
      return(-1);
}
 
int main(int argc, char** argv)
{
   struct asnParms captureParms;
   struct asnParms applyParms;
   struct asnParm *currParm;
   int rc = 0;
   int count = 0;
 
   /* allocate and initialize capture parameter structure */
   captureParms.parmCount = 4;
   captureParms.parms = 
      (struct asnParm **)malloc(captureParms.parmCount * sizeof(struct asnParm*));
 
   currParm = (struct asnParm *)malloc(sizeof(struct asnParm));
   strcpy( currParm->val, "SRCESRV" );
   currParm->byteCount = strlen( currParm->val );
   captureParms.parms[0] = currParm;  /* first capture parameter */
 
   currParm = (struct asnParm *)malloc(sizeof(struct asnParm));
   strcpy( currParm->val, "WARM" );
   currParm->byteCount = strlen( currParm->val );
   captureParms.parms[1] = currParm;  /* second capture parameter */
 
   currParm = (struct asnParm *)malloc(sizeof(struct asnParm));
   strcpy( currParm->val, "NOPRUNE" );
   currParm->byteCount = strlen( currParm->val );
   captureParms.parms[2] = currParm;  /* third capture parameter */
 
   currParm = (struct asnParm *)malloc(sizeof(struct asnParm));
   strcpy( currParm->val, "AUTOSTOP" );
   currParm->byteCount = strlen( currParm->val );
   captureParms.parms[3] = currParm;  /* fourth capture parameter */
 
   rc = printParms( captureParms );   /* print parameters out to verify */
 
   rc = asnCapture(&captureParms;); 
   if( rc!=0 )
      printf("Capture failed with rc = %d\n", rc );
   else
      printf("Capture completed successfully\n" );
 
   /* allocate and initialize capture parameter structure */
   applyParms.parmCount = 3;
   applyParms.parms = 
      (struct asnParm **)malloc(applyParms.parmCount * sizeof(struct asnParm*));
 
   currParm = (struct asnParm *)malloc(sizeof(struct asnParm));
   strcpy( currParm->val, "APPLYQUAL" );
   currParm->byteCount = strlen( currParm->val );
   applyParms.parms[0] = currParm;  /* first capture parameter */
 
   currParm = (struct asnParm *)malloc(sizeof(struct asnParm));
   strcpy( currParm->val, "CNTLSRV" );
   currParm->byteCount = strlen( currParm->val );
   applyParms.parms[1] = currParm;  /* second capture parameter */
 
   currParm = (struct asnParm *)malloc(sizeof(struct asnParm));
   strcpy( currParm->val, "COPYONCE" );
   currParm->byteCount = strlen( currParm->val );
   applyParms.parms[2] = currParm;  /* third capture parameter */
 
   rc = asnApply(&applyParms;); 
   if( rc!=0 )
      printf("Apply failed with rc = %d\n", rc );
   else
      printf("Apply completed successfully\n" );
 
   for(count = 0; count<= captureParms.parmCount; count++)
      free( captureParms.parms[count] );
   free( captureParms.parms );
 
   for(count = 0; count<= applyParms.parmCount; count++)
      free( applyParms.parms[count] );
   free( applyParms.parms );
 
   return(rc);
}
 
 
 


[ Top of Page | Previous Page | Next Page ]