Als Alternative für den Programmstart über den Befehl asnccp (beim Capture-Programm) oder über den Befehl asnapply (beim Apply-Programm) können die beiden Programme auch durch den Aufruf von Routinen aus einer Anwendung gestartet werden. Um diese Routinen verwenden zu können, müssen Sie die Option AUTOSTOP für das Capture-Programm und die Option COPYONCE für das Apply-Programm angeben, da bei diesem API nur die synchrone Ausführung unterstützt wird.
Dieses Kapitel beschreibt die Routinen und Rückkehrcodes. Ferner ist eine Beispielroutine enthalten, mit der die Programme Capture und Apply gestartet werden können.
Sie können das Capture-Programm aus Ihrer Anwendung starten, indem Sie die folgende Routine aufrufen:
#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
Diese Routine gibt die folgenden Rückkehrcodes zurück:
Sie können das Apply-Programm aus Ihrer Anwendung starten, indem Sie die folgende Routine aufrufen:
#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
Diese Routine gibt die folgenden Rückkehrcodes zurück:
Die folgende Beispielroutine startet die Programme Capture und Apply:
#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); }