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.
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:
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:
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); }