home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / samples / sysmgt / errlog / errlog2 / errlog2.c next >
C/C++ Source or Header  |  1999-05-11  |  8KB  |  197 lines

  1. /****************************************************************************************/
  2. /* The following example demonstrates the use of the event notification functions.      */
  3. /* This program does the following things:                                              */
  4. /* 1. Opens event notification without specifying a filter                              */
  5. /* 2. Calls LogWaitEvent which will cause the program to wait until an entry is put     */
  6. /*    in the log.  Since a filter was not specified, any entry put in the log will      */
  7. /*    trigger this event.  You can use the FFSTProbe example program to put an          */
  8. /*    entry in the log.                                                                 */
  9. /* 3. Issues a LogChangeEventFilter to filter on records where vendor tag = IBM-PSP or  */
  10. /*    severity > 2.                                                                     */
  11. /* 4. Issues another LogWaitEvent call to wait for an entry being put in the log based  */
  12. /*    on the new filter criteria.  Again, you can use the FFSTProbe sample program to   */
  13. /*    place an entry in the log which will satisfy the filter criteria.                 */
  14. /* 5. Closes event notification for this program                                        */
  15. /****************************************************************************************/
  16.  
  17. #define INCL_LOGGING
  18. #include <unidef.h>
  19. #include <os2.h>
  20. #include <stdio.h>
  21. #include <lfdef.h>
  22. #define ERROR_LOG_FILE_ID 1
  23. #define BUFFER_LENGTH 4096
  24. #define SAMPLE_SEVERITY 2
  25.                  
  26. int main()
  27. {
  28.  
  29.  APIRET rc;
  30.  ULONG service;
  31.  ULONG notification_ID;
  32.  
  33.  /* LogOpenEventNotification variables */
  34.  ULONG severity = SAMPLE_SEVERITY;
  35.  LOENREQUEST open_event_packet;
  36.  UniChar manufacturer_name[8] = L"IBM-PSP";
  37.  
  38.  /* variables for LogCloseEventNotification */
  39.  LCENREQUEST close_event_packet;
  40.  
  41.  /* variables for LogWaitEvent */
  42.  LWEREQUEST log_wait_event_packet;
  43.  EVENTKEY EventKey;
  44.  BYTE  log_entry_buffer[BUFFER_LENGTH];
  45.  ULONG log_entry_buffer_length = BUFFER_LENGTH;
  46.  UniChar pathname[512];
  47.  ULONG pathname_length = sizeof(pathname);
  48.  
  49.  /* variables for LogChangeEventFilter */
  50.  LCEFREQUEST change_event_filter_packet;
  51.  SUBBLOCK subblock1, subblock2;
  52.  HEADERBLOCK headerblock1, headerblock2;
  53.  FILTERBLOCK filter;
  54.  
  55.  service = ERROR_LOGGING_SERVICE;
  56.  
  57.  /**************************************************************/
  58.  /* OpenEventNotification                                      */
  59.  /**************************************************************/
  60.  
  61.  /* Construct the LogOpenEventNotification parameter packet.*/
  62.  open_event_packet.packet_size = sizeof(LOENREQUEST);
  63.  open_event_packet.packet_revision_number = LF_UNI_API;
  64.  open_event_packet.log_file_ID = ERROR_LOG_FILE_ID;
  65.  open_event_packet.pLogNotify = ¬ification_ID;
  66.  open_event_packet.pFilter = NULL;   /* This will cause a notification on all records */
  67.  open_event_packet.read_flags = 0;
  68.  
  69.  rc = LogOpenEventNotification(service, &open_event_packet);
  70.  
  71.  if (rc == 0)
  72.    printf("LogOpenEventNotification was successful\n");
  73.  else {
  74.    printf("LogOpenEventNotification error: return code = %d",rc);
  75.    return rc;
  76.  }
  77.  
  78.  /**************************************************************/
  79.  /* LogWaitEvent                                               */
  80.  /**************************************************************/
  81.  
  82.  /* Construct the LogWaitEvent parameter packet  */
  83.  log_wait_event_packet.packet_size = sizeof(LWEREQUEST);
  84.  log_wait_event_packet.packet_revision_number = LF_UNI_API;
  85.  log_wait_event_packet.LogNotify = notification_ID;
  86.  log_wait_event_packet.pEventKey  = &EventKey;
  87.  log_wait_event_packet.pLogEntryBuffer = &log_entry_buffer;
  88.  log_wait_event_packet.log_entry_buffer_length = &log_entry_buffer_length;
  89.  log_wait_event_packet.timeout = 0;
  90.  log_wait_event_packet.queue_flags = 0;
  91.  log_wait_event_packet.pathname_length = &pathname_length;
  92.  log_wait_event_packet.pathname = pathname;
  93.  
  94.  printf("Waiting for an event now\n");
  95.  
  96.  rc = LogWaitEvent(service, &log_wait_event_packet);
  97.  
  98.  if (rc == 0)
  99.    printf("LogWaitEvent detected an event\n");
  100.  else {
  101.    printf("LogWaitEvent error: return code = %d",rc);
  102.    return rc;
  103.  }
  104.  
  105.  /**************************************************************/
  106.  /* LogChangeEventFilter                                       */
  107.  /**************************************************************/
  108.  
  109.  /*  Construct an event notification filter  */
  110.  
  111.  filter.packet_size = sizeof(FILTERBLOCK);
  112.  filter.packet_revision_number = LF_UNI_API;
  113.  filter.header_block = &headerblock1;
  114.  
  115.  /*-------------construct headerblock1---------------------*/
  116.  headerblock1.pSubblock = &subblock1;
  117.  headerblock1.pNextBlock = &headerblock2;
  118.  
  119.  /*construct subblock1 of headerblock1*/
  120.  subblock1.entry_attribute_ID = LOG_ERROR_DMI_VENDOR_TAG;
  121.  subblock1.comparison_operator_ID = LOG_ERROR_EQUAL;
  122.  subblock1.comparison_data_ptr = &manufacturer_name;
  123.  subblock1.comparison_data_length = UniStrlen(manufacturer_name)*2;
  124.  subblock1.next_subblock = NULL;
  125.  
  126.  /*------------construct headerblock2----------------------*/
  127.  headerblock2.pSubblock = &subblock2;
  128.  headerblock2.pNextBlock = NULL;
  129.  
  130.  /*construct subblock2 of headerblock2*/
  131.  subblock2.entry_attribute_ID = LOG_ERROR_SEVERITY;
  132.  subblock2.comparison_operator_ID = LOG_ERROR_GREATER_THAN;
  133.  subblock2.comparison_data_ptr = &severity;
  134.  subblock2.comparison_data_length = sizeof(ULONG);
  135.  subblock2.next_subblock = NULL;
  136.  
  137.  /* Construct the LogChangeEventFilter parameter packet  */
  138.  change_event_filter_packet.packet_size = sizeof(LCEFREQUEST);
  139.  change_event_filter_packet.packet_revision_number = LF_UNI_API;
  140.  change_event_filter_packet.purge_flags = PURGE_EVENT_NOTIFICATION;
  141.  change_event_filter_packet.LogNotify = notification_ID;
  142.  change_event_filter_packet.pFilter = &filter;
  143.  
  144.  rc = LogChangeEventFilter(service, &change_event_filter_packet);
  145.  
  146.  if (rc == 0)
  147.    printf("LogChangeEventFilter completed successfully\n");
  148.  else {
  149.    printf("LogChangeEventFilter error: return code = %d",rc);
  150.    return rc;
  151.  }
  152.  
  153.  /**************************************************************/
  154.  /* LogWaitEvent using new filter                              */
  155.  /**************************************************************/
  156.  
  157.  /* Construct the LogWaitEvent parameter packet  */
  158.  log_wait_event_packet.packet_size = sizeof(LWEREQUEST);
  159.  log_wait_event_packet.packet_revision_number = LF_UNI_API;
  160.  log_wait_event_packet.LogNotify = notification_ID;
  161.  log_wait_event_packet.pEventKey  = &EventKey;
  162.  log_wait_event_packet.pLogEntryBuffer = &log_entry_buffer;
  163.  log_wait_event_packet.timeout = 0;         /* wait indefinately */
  164.  log_wait_event_packet.queue_flags = 0;
  165.  log_wait_event_packet.pathname_length = &pathname_length;
  166.  log_wait_event_packet.pathname = pathname;
  167.  
  168.  printf("Waiting for an event now\n");
  169.  
  170.  rc = LogWaitEvent(service, &log_wait_event_packet);
  171.  
  172.  if (rc == 0)
  173.    printf("LogWaitEvent detected an event\n");
  174.  else {
  175.    printf("LogWaitEvent error: return code = %d",rc);
  176.    return rc;
  177.  }
  178.  
  179.  /**************************************************************/
  180.  /* LogCloseEventNotification                                  */
  181.  /**************************************************************/
  182.  
  183.  /* Construct the LogCloseEventNotification parameter packet  */
  184.  close_event_packet.packet_size = sizeof(LCENREQUEST);
  185.  close_event_packet.packet_revision_number = LF_UNI_API;
  186.  close_event_packet.LogNotify = notification_ID;
  187.  
  188.  rc =  LogCloseEventNotification(service, &close_event_packet);
  189.  
  190.  if (rc == 0)
  191.    printf("LogCloseEventNotification was successful\n");
  192.  else 
  193.    printf("LogCloseEventNotification error: return code = %d",rc);
  194.  
  195.  return rc;
  196. }
  197.