home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Encyclopedia 96-1
/
novell-nsepro-1996-1-cd2.iso
/
download
/
netware
/
opennv.exe
/
NVALERT.C
< prev
next >
Wrap
Text File
|
1993-04-14
|
7KB
|
221 lines
/*
** (c) Copyright 1992 Novell, Inc. All rights reserved.
**
** File: nvalert.c
**
** $Logfile: J:/cs/nma/vcs/nvalert.c_v $
** $Revision: 1.5 $
** $Date: 14 Apr 1993 16:21:52 $
** $Author: RWONG $
** $Log: J:/cs/nma/vcs/nvalert.c_v $
**
** Rev 1.5 14 Apr 1993 16:21:52 RWONG
** Change adapter type to coded graphic character set.
**
** Rev 1.4 18 Nov 1992 10:22:06 RWONG
** Change adapter type to PRINTABLESTRING
**
** Rev 1.3 16 Nov 1992 19:42:56 RWONG
** Change fully formatted alert to open failure: token ring lobe.
**
** Rev 1.2 05 Nov 1992 10:30:02 JCHOU
** Change nlm name to nlm handle for all the api call.
**
** Rev 1.1 08 Oct 1992 16:35:28 RWONG
** Changed screen name
**
** Rev 1.0 02 Oct 1992 18:56:50 RWONG
** Initial revision.
*/
/* many of these are included for function prototypes */
#include <library.h>
#include <stdio.h>
#include <process.h>
#include <signal.h>
#include <conio.h>
#include <errno.h>
#include <sys/types.h>
#include <io.h>
#include <cstypes.h>
#include <nmvtdef.h>
#include <nvapi.h>
#define MYSCREENNAME "NVALERT Sample Program"
#define APPL_NAME "NVALERT"
#define NLM_NAME "NVALERT.NLM"
/* forward declarations */
int nvalert_shutdown (void); /* NLM sigterm procedure */
/* global variables */
int testMainThreadId = 0; /* main thread ID */
int screenhdl; /* handle to i/o screen */
/* various states of this NLM */
#define TEST_INIT 0x00 /* initial state */
#define TEST_SIGNAL 0x10 /* signal main thread to cleanup */
#define TEST_UNLOAD 0x20 /* ok to unload NLM */
u32_t testStatus = TEST_INIT; /* my current status */
/*
** Data for the predefined alert we'll be sending. These are
** (dummy) runtime parameters. All runtime parameters defined
** in the alert database must be provided along with the event
** id or the error NVERR_BAD_PARMLIST will received via the
** callback function.
*/
u8_t value = 0xff;
u8_t psid1 = 0x21;
u8_t adapter_type[] = "IBM TOKEN RING BOARD";
u8_t addr[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06};
NVParm_t parms[] = {
{0x96, 0x82, 0x35, 1, PRINTABLESTRING, 20, &adapter_type},
{0x96, 0x82, 0x61, 2, OCTETSTRING, 1, &value},
{0x96, 0x82, 0x07, 3, OCTETSTRING, 1, &value},
{0x96, 0x83, 0x00, 1, OCTETSTRING, 1, &psid1},
{0x96, 0x83, 0x00, 2, OCTETSTRING, 1, &psid1},
{0x51, 0x03, 0x00, 1, OCTETSTRING, 6, &addr}
};
char prefixbuf[] = "", suffixbuf[] = "alert 1";
char bfile[] = "nvalert.btv";
NVPredefinedAlert_t predefinedalert = {
0, /* RequestId */
prefixbuf, /* EventPrefix */
suffixbuf, /* EventSuffix */
6, /* ParameterCount */
0, /* ARLCount */
0, /* HRLCount */
0, /* Reserved */
bfile, /* DBName */
NULL, /* ARL */
NULL, /* HRL */
parms /* Parameters */
};
/*
** This is the msg data for a fully formatted alert NMVT.
** This sends the same alert as the predefined alert
** defined above.
*/
u8_t msg[] = {
0x41,0x03,0x8d,0x00,0x00,0x00,0x00,0x00,0x00,0x8f,0x00,0x00,
0x23,0x10,0x00,0x20,0x11,0x03,0x13,0x00,0x11,0xF0,0xF3,0xF8,
0xF6,0x81,0x81,0x81,0x89,0x82,0xF3,0xF4,0xF5,0xF6,0xF4,0xF6,
0xF7,0x0A,0x0E,0xC9,0xC2,0xD4,0xE3,0xD6,0xD2,0xC5,0xD5,
0x0b,0x92,0x00,0x00,0x01,0x32,0x11,0x00,0x00,0x00,0x00,0x04,
0x93,0x37,0x02,0x47,0x96,0x0C,0x01,0x33,0x20,0x37,0x11,
0x34,0x34,0xF8,0xE0,0x33,0xA5,0x03,0x83,0x21,0x19,0x82,0x00,
0x35,0x11,0xC9,0xC2,0xD4,0x40,0xE3,0xD6,0xD2,0xC5,0xD5,0x40,
0xD9,0xC9,0xD5,0xC7,0x40,0xC2,0xD6,0xC1,0xD9,0xC4,0x0E,0x81,
0x10,0x09,0x33,0x01,0x20,0x10,0x31,0x01,0x32,0xC0,0x31,0xE0,
0x06,0x82,0x91,0x61,0x01,0xFF,0x06,0x82,0x01,0x07,0x00,0xFF,
0x03,0x83,0x21,0x0A,0x51,0x08,0x03,0x01,0x02,0x03,0x04,0x05,
0x06,0x08,0x01,0x5C,0x09,0x1B,0x0F,0x05,0x2A};
NVNMVT_t nmvt = {
0, /* RequestId */
0, /* reserved */
1, /* MsgCount - always one for alert NMVTs */
{151, msg} /* NVMsg_t - MsgLen, MsgData */
};
void callbackfunc (u32_t, void *);
void main (argc, argv)
int argc;
int *argv[];
{
u32_t rc;
u32_t type; /* type of alert to send */
if ((screenhdl = CreateScreen (MYSCREENNAME, 0)) == EFAILURE)
exit (0);
if (argc < 2 || argc > 2) {
printf ("usage: nvalert [1|2]\r\n");
exit (0);
}
type = atoi ((char *)argv[1]);
/* obtain NLM thread ID */
testMainThreadId = GetThreadID ();
/* registers SIGTERM handler */
if (signal (SIGTERM, nvalert_shutdown) == SIG_ERR)
exit (0);
/* tell NetView agent we want to be managed */
rc = NWNVRegister(APPL_NAME, GetNLMHandle (), (void *)callbackfunc);
/*
** If command line argument is "1" send predefined alert.
** If command line argument is "2" or something else
** send fully formatted alert.
*/
switch (type) {
case 1:
rc = NWNVSend (GetNLMHandle (), NVTYPE_PREDEFINED, (void *)&predefinedalert);
break;
case 2:
default:
rc = NWNVSend (GetNLMHandle (), NVTYPE_FORMATTED, (void *)&nmvt);
break;
}
/* wait til we get unloaded */
while (!(testStatus & TEST_SIGNAL))
SuspendThread(testMainThreadId);
/*
** Flag has been set indicating we're being unloaded.
** Inform NetView agent that we're going away.
*/
rc = NWNVDeregister(GetNLMHandle ());
testStatus |= TEST_UNLOAD; /* signal SIGTERM handler that it is OK to unload */
ExitThread (EXIT_THREAD, 0); /* terminate main thread */
}
int nvalert_shutdown()
{
signal (SIGTERM, SIG_IGN);
/* if main thread is suspended, resume it to perform cleanup */
ResumeThread (testMainThreadId);
testStatus |= TEST_SIGNAL;
/* wait for cleanup to be completed by main thread - TEST_UNLOAD bit would be set then */
while (!(testStatus & TEST_UNLOAD))
ThreadSwitch ();
return (NULL);
}
void callbackfunc (u32_t isruncmd, void *data)
{
/* make sure printf goes to our screen */
(void)SetCurrentScreen (screenhdl);
if (isruncmd)
printf ("\rruncmds not supported by this nlm\r\n");
else
printf ("\r\nalert error %x received\r\n", ((NVErrData_t*)data)->Error);
}