ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzaik_5.4.0.1/rzaiksvcapiuseex.htm

147 lines
6.6 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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: Using iSeries Access for Windows Serviceability APIs" />
<meta name="abstract" content="The following example uses the iSeries Access for Windows Serviceability APIs to log a message string to theiSeries Access for Windows History Log." />
<meta name="description" content="The following example uses the iSeries Access for Windows Serviceability APIs to log a message string to theiSeries Access for Windows History Log." />
<meta name="DC.Relation" scheme="URI" content="rzaikappsv.htm" />
<meta name="copyright" content="(C) Copyright IBM Corporation 1999, 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1999, 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="svcapiuseex" />
<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: Using iSeries Access for Windows Serviceability
APIs</title>
</head>
<body id="svcapiuseex"><a name="svcapiuseex"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Example: Using <span class="keyword">iSeries Access for Windows</span> Serviceability
APIs</h1>
<div><p>The following example uses the <span class="keyword">iSeries™ Access for Windows<sup>®</sup></span> Serviceability
APIs to log a message string to the<span class="keyword">iSeries Access for Windows</span> History
Log.</p>
<div class="example"> <pre>#include &lt;stdio.h&gt;
#include "CWBSV.H"
unsigned int logMessageText(char *msgtxt)
/* Write a message to the active message log. */
{
cwbSV_MessageTextHandle messageTextHandle;
unsigned int rc;
/* Create a handle to a message text object, so that we may write */
/* message text to the active message log. */
if ((rc = cwbSV_CreateMessageTextHandle("ProductID", "ComponentID",
&amp;messageTextHandle)) != CWB_OK)
return(rc);
/* Log the supplied message text to the active message log. */
rc = cwbSV_LogMessageText(messageTextHandle, msgtxt, strlen(msgtxt));
/* Delete the message text object identified by the handle provided.*/
cwbSV_DeleteMessageTextHandle(messageTextHandle);
return(rc);
}
unsigned int readMessageText(char **bufptr, cwbSV_ErrHandle errorHandle)
/* Read a message from the active message log. */
{
cwbSV_ServiceFileHandle serviceFileHandle;
cwbSV_ServiceRecHandle serviceRecHandle;
static char buffer[BUFSIZ];
unsigned int rc;
/* Retrieve the fully-qualified path and file name of the active */
/* message log. */
if ((rc = cwbSV_GetServiceFileName(CWBSV_HISTORY_LOG, buffer, BUFSIZ,
NULL)) != CWB_OK)
return(rc);
/* Open the active message log for READ access and return a handle */
/* to it. */
if ((rc = cwbSV_OpenServiceFile(buffer, &amp;serviceFileHandle, errorHandle))
!= CWB_OK)
return(rc);
/* Create a service record object and return a handle to it. */
if ((rc = cwbSV_CreateServiceRecHandle(&amp;serviceRecHandle)) != CWB_OK) {
cwbSV_CloseServiceFile(serviceFileHandle, 0);
return(rc);
}
/* Read the newest record in the active message log into the */
/* record handle provided. */
if ((rc = cwbSV_ReadNewestRecord(serviceFileHandle, serviceRecHandle,
errorHandle)) != CWB_OK) {
cwbSV_DeleteServiceRecHandle(serviceRecHandle);
cwbSV_CloseServiceFile(serviceFileHandle, 0);
return(rc);
}
/* Retrieve the message text portion of the service record object */
/* identified by the handle provided. */
if ((rc = cwbSV_GetMessageText(serviceRecHandle, buffer, BUFSIZ, NULL))
== CWB_OK || rc == CWB_BUFFER_OVERFLOW) {
*bufptr = buffer;
rc = CWB_OK;
}
/* Delete the service record object identified by the */
/* handle provided. */
cwbSV_DeleteServiceRecHandle(serviceRecHandle);
/* Close the active message log identified by the handle provided.*/
cwbSV_CloseServiceFile(serviceFileHandle, errorHandle);
return(rc);
}
void main(int argc, char *argv[ [)
{
cwbSV_ErrHandle errorHandle;
char *msgtxt = NULL, errbuf[BUFSIZ];
unsigned int rc;
/* Write a message to the active message log. */
if (logMessageText("Sample message text") != CWB_OK)
return;
/* Create an error message object and return a handle to it. */
cwbSV_CreateErrHandle(&amp;errorHandle);
/* Read a message from the active message log. */
if (readMessageText(&amp;msgtxt, errorHandle) != CWB_OK) {
if ((rc = cwbSV_GetErrText(errorHandle, errbuf, BUFSIZ, NULL)) ==
CWB_OK || rc == CWB_BUFFER_OVERFLOW)
fprintf(stdout, "%s\n", errbuf);
}
else if (msgtxt)
fprintf(stdout, "Message text: \"%s\"\n", msgtxt);
/* Delete the error message object identified by the */
/* handle provided. */
cwbSV_DeleteErrHandle(errorHandle);
}</pre>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rzaikappsv.htm" title="The iSeries Access for Windows Serviceability application programming interfaces (APIs) allow you to log service file messages and events within your program.">iSeries Access for Windows Serviceability APIs</a></div>
</div>
</div>
</body>
</html>