<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html lang="en-us" xml:lang="en-us"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="security" content="public" /> <meta name="Robots" content="index,follow" /> <meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' /> <meta name="DC.Type" content="reference" /> <meta name="DC.Title" content="Example: data collection program" /> <meta name="abstract" content="This program example collects some test data and stores it in a data buffer, which Collection Services copy to the collection object." /> <meta name="description" content="This program example collects some test data and stores it in a data buffer, which Collection Services copy to the collection object." /> <meta name="DC.Relation" scheme="URI" content="rzahxcollservuserdefexample.htm" /> <meta name="DC.Relation" scheme="URI" content="rzahxcolluserdefprog.htm" /> <meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" /> <meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1998, 2006" /> <meta name="DC.Format" content="XHTML" /> <meta name="DC.Identifier" content="rzahxcolluserdefexdatacoll" /> <meta name="DC.Language" content="en-us" /> <!-- All rights reserved. Licensed Materials Property of IBM --> <!-- US Government Users Restricted Rights --> <!-- Use, duplication or disclosure restricted by --> <!-- GSA ADP Schedule Contract with IBM Corp. --> <link rel="stylesheet" type="text/css" href="./ibmdita.css" /> <link rel="stylesheet" type="text/css" href="./ic.css" /> <title>Example: data collection program</title> </head> <body id="rzahxcolluserdefexdatacoll"><a name="rzahxcolluserdefexdatacoll"><!-- --></a> <!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script> <h1 class="topictitle1">Example: data collection program</h1> <div><p>This program example collects some test data and stores it in a data buffer, which Collection Services copy to the collection object.</p> <div class="section"><div class="note"><span class="notetitle">Note:</span> By using the code examples, you agree to the terms of the <a href="codedisclaimer.htm">Code license and disclaimer information</a>.</div> </div> <div class="section"><h4 class="sectiontitle">C++ sample code</h4><pre> #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() */ </pre> </div> </div> <div> <div class="familylinks"> <div class="parentlink"><strong>Parent topic:</strong> <a href="rzahxcollservuserdefexample.htm" title="Look here for sample programs that illustrate how you can use the provided APIs to integrate customized data collections into Collection Services.">Example: Implementing user-defined categories</a></div> </div> <div class="relconcepts"><strong>Related concepts</strong><br /> <div><a href="rzahxcolluserdefprog.htm" title="Collection Services calls the data collection program once during the start of a collection cycle, once for each collection interval, and again at the end of the collection cycle.">Collection program recommendations and requirements</a></div> </div> </div> </body> </html>