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 >
Text File  |  1993-04-14  |  7KB  |  221 lines

  1. /*
  2. ** (c) Copyright 1992 Novell, Inc. All rights reserved.
  3. **
  4. ** File: nvalert.c
  5. **
  6. ** $Logfile:   J:/cs/nma/vcs/nvalert.c_v  $
  7. ** $Revision:   1.5  $
  8. ** $Date:   14 Apr 1993 16:21:52  $
  9. ** $Author:   RWONG  $
  10. ** $Log:   J:/cs/nma/vcs/nvalert.c_v  $
  11. ** 
  12. **    Rev 1.5   14 Apr 1993 16:21:52   RWONG
  13. ** Change adapter type to coded graphic character set.
  14. ** 
  15. **    Rev 1.4   18 Nov 1992 10:22:06   RWONG
  16. ** Change adapter type to PRINTABLESTRING
  17. ** 
  18. **    Rev 1.3   16 Nov 1992 19:42:56   RWONG
  19. ** Change fully formatted alert to open failure: token ring lobe.
  20. ** 
  21. **    Rev 1.2   05 Nov 1992 10:30:02   JCHOU
  22. ** Change nlm name to nlm handle for all the api call.
  23. ** 
  24. **    Rev 1.1   08 Oct 1992 16:35:28   RWONG
  25. ** Changed screen name
  26. ** 
  27. **    Rev 1.0   02 Oct 1992 18:56:50   RWONG
  28. ** Initial revision.
  29. */
  30.  
  31. /* many of these are included for function prototypes */
  32. #include <library.h>
  33. #include <stdio.h> 
  34. #include <process.h>
  35. #include <signal.h>
  36. #include <conio.h>
  37. #include <errno.h>
  38. #include <sys/types.h>
  39. #include <io.h>
  40.  
  41. #include <cstypes.h>
  42. #include <nmvtdef.h>
  43. #include <nvapi.h>
  44.  
  45. #define MYSCREENNAME "NVALERT Sample Program"
  46. #define APPL_NAME    "NVALERT"
  47. #define NLM_NAME     "NVALERT.NLM"
  48.  
  49. /*  forward declarations  */
  50. int            nvalert_shutdown (void);     /* NLM sigterm procedure */
  51.  
  52. /*  global variables  */
  53. int            testMainThreadId = 0;        /* main thread ID */
  54. int            screenhdl;                   /* handle to i/o screen */
  55.  
  56. /*  various states of this NLM  */
  57. #define        TEST_INIT          0x00      /* initial state */
  58. #define        TEST_SIGNAL        0x10      /* signal main thread to cleanup */
  59. #define        TEST_UNLOAD        0x20      /* ok to unload NLM */
  60. u32_t          testStatus = TEST_INIT;      /* my current status */
  61.  
  62. /*
  63. ** Data for the predefined alert we'll be sending.  These are
  64. ** (dummy) runtime parameters.  All runtime parameters defined
  65. ** in the alert database must be provided along with the event
  66. ** id or the error NVERR_BAD_PARMLIST will received via the
  67. ** callback function.
  68. */
  69.  
  70. u8_t  value = 0xff;
  71. u8_t  psid1 = 0x21;
  72. u8_t  adapter_type[] = "IBM TOKEN RING BOARD";
  73. u8_t  addr[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06};
  74.  
  75. NVParm_t parms[] = {
  76. {0x96, 0x82, 0x35, 1, PRINTABLESTRING, 20, &adapter_type},
  77. {0x96, 0x82, 0x61, 2, OCTETSTRING, 1, &value},
  78. {0x96, 0x82, 0x07, 3, OCTETSTRING, 1, &value},
  79. {0x96, 0x83, 0x00, 1, OCTETSTRING, 1, &psid1},
  80. {0x96, 0x83, 0x00, 2, OCTETSTRING, 1, &psid1},
  81. {0x51, 0x03, 0x00, 1, OCTETSTRING, 6, &addr}
  82. };
  83.  
  84. char prefixbuf[] = "", suffixbuf[] = "alert 1";
  85. char bfile[] = "nvalert.btv";
  86.  
  87. NVPredefinedAlert_t predefinedalert = {
  88. 0,                      /* RequestId */
  89. prefixbuf,              /* EventPrefix */
  90. suffixbuf,              /* EventSuffix */
  91. 6,                      /* ParameterCount */
  92. 0,                      /* ARLCount */
  93. 0,                      /* HRLCount */
  94. 0,                      /* Reserved */
  95. bfile,                  /* DBName */
  96. NULL,                   /* ARL */
  97. NULL,                   /* HRL */
  98. parms                   /* Parameters */
  99. };
  100.  
  101. /*
  102. ** This is the msg data for a fully formatted alert NMVT.
  103. ** This sends the same alert as the predefined alert
  104. ** defined above.
  105. */
  106.  
  107. u8_t  msg[] = {
  108. 0x41,0x03,0x8d,0x00,0x00,0x00,0x00,0x00,0x00,0x8f,0x00,0x00,
  109. 0x23,0x10,0x00,0x20,0x11,0x03,0x13,0x00,0x11,0xF0,0xF3,0xF8,
  110. 0xF6,0x81,0x81,0x81,0x89,0x82,0xF3,0xF4,0xF5,0xF6,0xF4,0xF6,
  111. 0xF7,0x0A,0x0E,0xC9,0xC2,0xD4,0xE3,0xD6,0xD2,0xC5,0xD5,
  112. 0x0b,0x92,0x00,0x00,0x01,0x32,0x11,0x00,0x00,0x00,0x00,0x04,
  113. 0x93,0x37,0x02,0x47,0x96,0x0C,0x01,0x33,0x20,0x37,0x11,  
  114. 0x34,0x34,0xF8,0xE0,0x33,0xA5,0x03,0x83,0x21,0x19,0x82,0x00,
  115. 0x35,0x11,0xC9,0xC2,0xD4,0x40,0xE3,0xD6,0xD2,0xC5,0xD5,0x40,
  116. 0xD9,0xC9,0xD5,0xC7,0x40,0xC2,0xD6,0xC1,0xD9,0xC4,0x0E,0x81,  
  117. 0x10,0x09,0x33,0x01,0x20,0x10,0x31,0x01,0x32,0xC0,0x31,0xE0,
  118. 0x06,0x82,0x91,0x61,0x01,0xFF,0x06,0x82,0x01,0x07,0x00,0xFF,
  119. 0x03,0x83,0x21,0x0A,0x51,0x08,0x03,0x01,0x02,0x03,0x04,0x05,  
  120. 0x06,0x08,0x01,0x5C,0x09,0x1B,0x0F,0x05,0x2A};
  121.  
  122. NVNMVT_t nmvt = {
  123. 0,                      /* RequestId */
  124. 0,                      /* reserved */
  125. 1,                      /* MsgCount - always one for alert NMVTs */
  126. {151, msg}              /* NVMsg_t - MsgLen, MsgData */
  127. };
  128.  
  129. void  callbackfunc (u32_t, void *);
  130.  
  131.  
  132. void main (argc, argv)
  133. int argc;
  134. int *argv[];
  135. {
  136.    u32_t rc;
  137.    u32_t type;          /* type of alert to send */
  138.  
  139.    if ((screenhdl = CreateScreen (MYSCREENNAME, 0)) == EFAILURE)
  140.       exit (0);
  141.  
  142.    if (argc < 2 || argc > 2) {
  143.       printf ("usage: nvalert [1|2]\r\n");
  144.       exit (0);
  145.    }
  146.  
  147.    type = atoi ((char *)argv[1]);
  148.  
  149.    /* obtain NLM thread ID */
  150.    testMainThreadId = GetThreadID ();
  151.  
  152.    /* registers SIGTERM handler  */
  153.    if (signal (SIGTERM, nvalert_shutdown) == SIG_ERR)
  154.       exit (0);
  155.  
  156.    /* tell NetView agent we want to be managed */
  157.    rc = NWNVRegister(APPL_NAME, GetNLMHandle (), (void *)callbackfunc);
  158.  
  159.    /*
  160.    ** If command line argument is "1" send predefined alert.
  161.    ** If command line argument is "2" or something else 
  162.    ** send fully formatted alert.
  163.    */
  164.    switch (type) {
  165.       case 1:
  166.          rc = NWNVSend (GetNLMHandle (), NVTYPE_PREDEFINED, (void *)&predefinedalert);
  167.          break;
  168.  
  169.       case 2:
  170.       default:
  171.          rc = NWNVSend (GetNLMHandle (), NVTYPE_FORMATTED, (void *)&nmvt);
  172.          break;
  173.  
  174.    }
  175.  
  176.    /* wait til we get unloaded */         
  177.    while (!(testStatus & TEST_SIGNAL))
  178.       SuspendThread(testMainThreadId);
  179.  
  180.    /* 
  181.    ** Flag has been set indicating we're being unloaded.
  182.    ** Inform NetView agent that we're going away.
  183.    */
  184.    rc = NWNVDeregister(GetNLMHandle ());
  185.      
  186.    testStatus |= TEST_UNLOAD;         /*  signal SIGTERM handler that it is OK to unload  */
  187.    ExitThread (EXIT_THREAD, 0);       /*  terminate main thread  */
  188.  
  189. }
  190.  
  191.  
  192. int nvalert_shutdown()
  193. {
  194.    signal (SIGTERM, SIG_IGN);
  195.  
  196.    /*  if main thread is suspended, resume it to perform cleanup  */
  197.    ResumeThread (testMainThreadId);
  198.  
  199.    testStatus |= TEST_SIGNAL;
  200.  
  201.    /*  wait for cleanup to be completed by main thread - TEST_UNLOAD bit would be set then  */
  202.    while (!(testStatus & TEST_UNLOAD))
  203.       ThreadSwitch ();
  204.  
  205.    return (NULL);
  206. }
  207.  
  208.  
  209.  
  210. void callbackfunc (u32_t isruncmd, void *data)
  211. {
  212.    /* make sure printf goes to our screen */
  213.    (void)SetCurrentScreen (screenhdl);
  214.   
  215.    if (isruncmd)
  216.       printf ("\rruncmds not supported by this nlm\r\n");
  217.    else
  218.       printf ("\r\nalert error %x received\r\n", ((NVErrData_t*)data)->Error);
  219. }
  220. 
  221.