ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzahb_5.4.0.1/rzahb_exitprogramexample.htm

173 lines
8.3 KiB
HTML
Raw Permalink Normal View History

2024-04-02 14:02:31 +00:00
<?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="Exit program for watch for event scenario" />
<meta name="abstract" content="The code in this topic is an example for a watch for event exit program. It is written in C." />
<meta name="description" content="The code in this topic is an example for a watch for event exit program. It is written in C." />
<meta name="DC.Relation" scheme="URI" content="rzahb_eventfunction.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="rzahb_exitprogramexample" />
<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>Exit program for watch for event scenario</title>
</head>
<body id="rzahb_exitprogramexample"><a name="rzahb_exitprogramexample"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Exit program for watch for event scenario</h1>
<div><p><span><img src="./delta.gif" alt="Start of change" />The code in this topic is an example for a
watch for event exit program. It is written in C.<img src="./deltaend.gif" alt="End of change" /></span></p>
<div class="section"><p><img src="./delta.gif" alt="Start of change" />Use this exit program as a starting
point to help you create your own watch for event exit program. You can modify
the code to allow the program to perform additional functions.<img src="./deltaend.gif" alt="End of change" /></p>
<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>
<img src="./delta.gif" alt="Start of change" /><pre>/*************************************************************************
** file = mywchpgm.c
**
** Example of an Exit Program for Watch for Event.
**
** This program will be called by the watch for event support when CPF0907
** message is sent to QSYSOPR.
**
** The program will call a clean up program to free up system storage and,
** if the available storage is less than 5%, the program will perform some
** more actions (not defined)
**
**************************************************************************/
#include &lt;decimal.h&gt;
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;except.h&gt; /* _INTRPT_Hndlr_Parms_T is typedefed */
#include &lt;escwcht.h&gt; /* Include for Watch Exit Program packaged in */
/* QSYSINC/H Source Physical File */
/****************** Prototypes *******************************************/
void UNEXPECTED_HDLER (_INTRPT_Hndlr_Parms_T *errmsg);
/* Declare variables to receive parameters */
char watch_option_setting[10],
session_ID[10],
* error_detected_ptr;
typedef struct {
Qsc_Watch_For_Msg_t msg_data;
char VarData[8776]; /* variable length data */
} MsgFullData_t;
MsgFullData_t * MsgFullData;
int main (int argc, char *argv[])
{
char * cAvailStorage[4];
decimal(7,4) dAvailStorage;
/* Variables to call a command */
int rc;
char cmdtorun[128];
#define CALL_MYCLNUP "CALL PGM(MYLIB/MYCLNUP)"
/*********************************************************************/
/* Turn exception monitor on. */
/*********************************************************************/
#pragma exception_handler (UNEXPECTED_HDLER, 0, 0, _C2_MH_ESCAPE)
memcpy(watch_option_setting,argv[1],10);
memcpy(session_ID,argv[2],10);
error_detected_ptr = argv[3];
MsgFullData = (MsgFullData_t *) argv[4];
/* Verify if the exit program was called because a watched message */
/* occurred. This verification is useful if you have a watch */
/* session waiting for a message event and for a LICLog event */
if (memcmp(watch_option_setting,"*MSGID ",10)==0) {
/* Verify if the message id that occurred is CPF0907 */
/* This verification is useful if you are watching for more than */
/* one message in the same watch session */
if (memcmp(MsgFullData-&gt;msg_data.Message_ID,"CPF0907",7)==0) {
/* Call clean up program to free up space */
strcpy(cmdtorun,CALL_MYCLNUP);
rc = system(cmdtorun);
if (rc == 0) {
/* Determine if the available storage space is less than 5% */
/* to do some extra processing */
if (MsgFullData-&gt;msg_data.Length_Of_Replacement_Data &gt; 0) {
/* The remaining storage comes in the 4th field data in the */
/* message replacement variable. See CPF0907 message */
/* description for a better understanding */
memcpy(cAvailStorage,
(char *) (argv[4] +
MsgFullData-&gt;msg_data.Offset_Replacement_Data + 66),
4);
dAvailStorage = *(decimal(7,4) *) cAvailStorage;
if (dAvailStorage &lt;= 5.00) {
/* Do some extra processing */
}
}
}
else { /* Error on clean up program */
UNEXPECTED_HDLER(NULL); /* Return error and exit */
}
}
else {
/* Add code in case you are expecting any other message id */
}
}
/* Verify if the exit program was called because a LIC Log occurred */
else if (memcmp(watch_option_setting,"*LICLOG ",10)==0) {
/* Not needed for this watch session */
}
memcpy(error_detected_ptr," ",10); /* No error detected by
watch exit program, return blanks and
continue watching */
#pragma disable_handler
return (0);
}
/********************************************************************/
/* FUNCTION NAME: UNEXPECTED_HDLER */
/* */
/* FUNCTION : Handle unexpected exceptions that may occur */
/* during the invocation of this pgm. */
/* */
/********************************************************************/
void UNEXPECTED_HDLER (_INTRPT_Hndlr_Parms_T *errmsg)
{
memcpy(error_detected_ptr,"*ERROR ",10); /* An error occurred
on the watch exit program, return *ERROR
and End the watch session */
exit(EXIT_FAILURE);
}</pre><img src="./deltaend.gif" alt="End of change" />
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rzahb_eventfunction.htm" title="The watch for event function enhances your ability to detect and react to problems represented by specific messages or Licensed Internal Code log entries. The watch for event function notifies you when the specified event (message or Licensed Internal Code log entry) occurs, and then calls the specified exit program to take the desired action.">Watch for event function</a></div>
</div>
</div>
</body>
</html>