This program example collects some test data and stores it in a data buffer, which Collection Services copy to the collection object.
#include "string.h" // memcpy(), memset(), strlen() #include "stdio.h" // printf() #include "qpmdcprm.h" // data collection program interface #include "time.h" extern "C" void DCPentry( Qpm_DC_Parm_t *request, char *dataBuffer, char *workArea, int *returnCode ) { static char testData[21] = "Just some test stuff"; int i; /* Print contents of request structure */ printf( "DCP called with parameters:\n" ); printf( " format name: \"%8.8s\"; category name: \"%10.10s\";\n", request->formatName, request->categoryName ); printf( " rsvd1: %4.4X; req type: %d; req mod: %d; buffer len: %d;\n", *(short *)(request->rsvd1), request->requestType, request->requestModifier, request->dataBufferLength); printf( " prm offset: %d; prm len: %d; work len: %d; rsvd2: %8.8X;\n", request->parmOffset, request->parmLength, request->workAreaLength, *(int *)(request->rsvd2) ); printf( " rec key: \"%8.8s\"; timestamp: %8.8X %8.8X;\n", request->intervalKey, *(int *)(request->intervalTimestamp), *(int *)(request->intervalTimestamp + 4) ); printf( " return len: %d; more data: %d; rsvd3: %8.8X %8.8X;\n", request->bytesProvided, request->moreData, *(int *)(request->rsvd3), *(int *)(request->rsvd3 + 4) ); switch ( request->requestType ) { /* Write control record in the beginning of collection */ case PM_DOBEGIN: printf( "doBegin(%d)\n", request->requestModifier ); switch ( request->requestModifier) { case PM_CALL_NORMAL: memcpy( dataBuffer, testData, 20 ); *(int *)workArea = 20; request->moreData = PM_MORE_DATA; request->bytesProvided = 20; break; case PM_CALL_CONTINUE: if ( *(int *)workArea < 200 ) { memcpy( dataBuffer, testData, 20 ); *(int *)workArea += 20; request->moreData = PM_MORE_DATA; request->bytesProvided = 20; } else { *(int *)workArea = 0; request->moreData = PM_NO_MORE_DATA; request->bytesProvided = 0; } break; default: *returnCode = -1; return; } break; /* Write control record in the end of collection */ case PM_DOEND: printf( "doEnd(%d)\n", request->requestModifier ); switch ( request->requestModifier) { case PM_CALL_NORMAL: memcpy( dataBuffer, testData, 20 ); *(int *)workArea = 20; request->moreData = PM_MORE_DATA; request->bytesProvided = 20; break; case PM_CALL_CONTINUE: if ( *(int *)workArea < 200 ) { memcpy( dataBuffer, testData, 20 ); *(int *)workArea += 20; request->moreData = PM_MORE_DATA; request->bytesProvided = 20; } else { *(int *)workArea = 0; request->moreData = PM_NO_MORE_DATA; request->bytesProvided = 0; } break; default: *returnCode = -1; return; } break; /*Write interval record */ case PM_DOCOLLECT: printf( "doCollect(%d)\n", request->requestModifier ); for ( i = 0; i < 10000; i++ ) dataBuffer[i] = i % 256; request->bytesProvided = 10000; switch ( request->requestModifier) { case PM_CALL_NORMAL: *(time_t *)(workArea + 4) = time( NULL ); *(int *)workArea = 1; request->moreData = PM_MORE_DATA; break; case PM_CALL_CONTINUE: *(int *)workArea += 1; if ( *(int *)workArea < 20 ) request->moreData = PM_MORE_DATA; else { *(time_t *)(workArea + 8) = time( NULL ); printf( "doCollect() complete in %d secs (%d bytes transferred)\n", *(time_t *)(workArea + 8) - *(time_t *)(workArea + 4), 10000 * 20 ); request->moreData = PM_NO_MORE_DATA; } break; default: *returnCode = -1; return; } break; /* Clean-up and terminate */ case PM_DOSHUTDOWN: printf( "doShutdown\n" ); *returnCode = 0; return; break; default: *returnCode = -1; return; break; } }/* DCPentry() */