イベント監視機能は、「監視の開始 (STRWCH)」コマンド、または「監視の開始 (QSCSWCH)」API で開始され、指定したイベントが発生したときに出口プログラムを呼び出して、ユーザーに通知します。イベントには、メッセージ待ち行列へ送られるメッセージ、ジョブ・ログ、LIC ログ項目、または通信中やワークステーション上でディスクおよびテープ装置に生じたエラーを示す製品アクティビティー・ログ (PAL) 項目があります。
ユーザー作成の出口プログラムは、「監視オプション設定」パラメーターで指定された状況が発生すると呼び出されます。以下は、イベントの監視出口プログラムの例です。これは、C で書かれています。
この出口プログラムは、お客様のご自身のイベントの監視出口プログラムを作成するのに役立つ出発点としてご使用ください。 このコードは、プログラムが追加の機能を実行するように変更することができます。
/*************************************************************************
** 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 the history log (QHST message queue in library QSYS).
**
** The program will call a cleanup program to free system storage and,
** if the available storage is less than 5%, the program will perform some
** more actions (not defined).
**
**************************************************************************/
#include <decimal.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <except.h> /* _INTRPT_Hndlr_Parms_T is typedefed */
#include <escwcht.h> /* 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 Licensed Internal Code log 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->msg_data.Message_ID,"CPF0907",7)==0) {
/* Call cleanup program to free 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->msg_data.Length_Of_Replacement_Data > 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->msg_data.Offset_Replacement_Data + 66),
4);
dAvailStorage = *(decimal(7,4) *) cAvailStorage;
if (dAvailStorage <= 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 Licensed Internal Code 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);
}