Hitachi

JP1 Version 12 JP1/Base Function Reference


2.2.2 Procedure for acquiring JP1 events

To acquire JP1 events:

  1. Determine the types and attributes of the JP1 events you want to acquire.

  2. Define an event acquisition filter to specify the JP1 events to acquire.

  3. Write code that uses JP1 event acquisition functions.

  4. Compile the source files.

Organization of this subsection

(1) Determining the types and attributes of the JP1 events to be acquired

JP1/Base registers a wide variety of event types to the event database as JP1 events. Therefore, you must first determine the types of events you want to acquire from the event database.

Next, determine the event attributes to acquire from these JP1 events. When you are deciding which event attributes to acquire, consider the information you need to know about the application in question. Determine the event attributes of all JP1 events being acquired for each application in advance.

The following explanations are based on acquiring the startup events listed in 2.2.1(1) Determining the types and attributes of the JP1 events to be issued that are issued as JP1 events in the application SAMPLE.

(2) Defining an event acquisition filter to specify the JP1 events to acquire

To select only the JP1 events you want to acquire, you must define an event acquisition filter. For details about the syntax of event acquisition filters, see the section on filter syntax in the manual JP1/Base User's Guide. This subsection provides an example of an event acquisition filter for acquiring the startup events listed in 2.2.1(1) Determining the types and attributes of the JP1 events to be issued that are coded in the application SAMPLE.

To acquire startup events, you must first consider how to create an event acquisition filter with the following conditions:

A filter targeting JP1 events that satisfy the above conditions can be used to acquire startup events. The following is an example of such an event acquisition filter:

B.ID IN 00000001
E.SEVERITY IN Notice
E.PRODUCT_NAME IN /COMPANY/APP1/ SAMPLE_PRODUCT
Note:
  • If you specify a Japanese string for a condition of an event acquisition filter, make sure that the character set matches the locale information (such as the LANG environment variable) used for execution of JP1 event acquisition functions. If the character set for the string specified for a condition of an event acquisition filter differs from the locale information used for execution of JP1 event acquisition functions, JP1 events cannot be acquired.

  • If you define an exclusion condition in an event acquisition filter, connect to an event server of version 09-00 or later. An error occurs (JEV_S_FILTER_ERROR) if you connect to an event server of version 08-00 or earlier.

(3) Writing code that uses JP1 event acquisition functions

JP1 event acquisition functions are used when a JP1 program or user application acquires JP1 events. The following explains how to issue JP1 event acquisition functions to acquire JP1 events from the event database of JP1/Base.

To issue JP1 event acquisition functions:

  1. Issue a function that requests starting the acquisition of JP1 events.

    Issue the JevGetOpen function to the event server to request starting the acquisition of JP1 events, and to connect a JP1 program or user application to the event server. Note that the user who requests starting the acquisition of JP1 events must be preconfigured in the users parameter in the event server settings file (conf) for JP1/Base.

  2. Issue functions that request acquisition of JP1 events.

    Use various functions to acquire JP1 events and the attributes set in the JP1 events.

  3. Issue a function that reports ending the acquisition of JP1 events.

    Issue the JevGetClose function to the event server to notify the server of the end of JP1 event acquisition, and to disconnect the JP1 program or user application from the event server.

For details about JP1 event acquisition functions, see Chapter 3. Functions. For details about what types of event attributes can be acquired, see Appendix A. Criteria for Setting JP1 Event Attributes.

The following is a coding example for acquiring the startup events listed in 2.2.1(1) Determining the types and attributes of the JP1 events to be issued that are coded in the application SAMPLE.

#include <stdio.h>
#include <string.h>
#include "JevApi.h"
 
int get_start_event()
{
    int rc;               /* Return code */
    long position;       /* Sequence number within the event database */
    long status;          /* Status code address */
    char filter[256];     /* Filter statement buffer */
    const char *server;   /* Event server name */
    const char *message;  /* Pointer to the message */
    const char *name;  /* Pointer to the extended attribute name */
    const char *value; /* Pointer to the extended attribute value */
    JEVGETKEY key;        /* Handle for acquiring JP1 events */
    JP1EVENT event;       /* Handle for accessing JP1 events */
    JEVACCESSTYPE access; /* Action when no JP1 event exists*/
 
  /* Set the filter statement to acquire JP1 events. */
    strcpy(filter, "B.ID IN 0x00000001\n");
    strcat(filter, "E.SEVERITY IN Notice\n");
    strcat(filter,
           "E.PRODUCT_NAME IN /COMPANY/APP1/SAMPLE_PRODUCT");
 
    /* Connect to the event server of the physical host. */
    status = 0;
    /* Event server of the physical host to connect to */
    server = NULL;
/* Acquisition starts with sequence number 0 within the event database. */
    position = 0;
    key = JevGetOpen(&status, server, filter, position);
    if(key == NULL){
        fprintf(stderr,
                "JevGetOpen() failed. Status = %ld\n",
                status);
        return -1;
    }
 
/* Acquire all the JP1 events which match the filter condition. */
    while(1) {
        status = 0;
   /* Error return when no JP1 event matches the filter condition */
        access = JEVGET_NOWAIT;
        event = JevGetEvent(&status, key, access);
        if(event == NULL){
            if(status == JEV_S_NO_EVENT) {
   /* No more JP1 event matches the filter condition. */
                break;
            }
            else {
      /* Error occurred while acquiring JP1 events. */
                fprintf(stderr,
                        "JevGetEvent() failed. Status = %ld\n",
                        status);
                JevGetClose(&status, key);
                return -1;
            }
        }
 
        /* Acquire a message. */
        status = 0;
        rc = JevGetMessage(&status, event, &message);
        if(rc < 0){
            fprintf(stderr,
                    "JevGetMessage() failed. Status = %ld\n",
                    status);
            JevFreeEvent(&status, event);
            JevGetClose(&status, key);
            return -1;
        }
        else{
            printf("JevGetMessage() message = %s\n", message);
        }
 
        /* Acquire the (first) extended attribute. */
        status = 0;
        rc = JevGetFirstExtAttr(&status, event, &name, &value);
        if(rc < 0){
            fprintf(stderr,
                    "JevGetFirstExtAttr() failed. Status = %ld\n",
                    status);
            JevFreeEvent(&status, event);
            JevGetClose(&status, key);
            return -1;
        }
        else{
            printf("JevGetFirstExtAttr() name = %s\n", name);
            printf("JevGetFirstExtAttr() value = %s\n", value);
        }
 
        /* Acquire the (subsequent) extended attribute. */
        while(1) {
            status = 0;
            rc = JevGetNextExtAttr(&status, event, &name, &value);
            if(rc < 0 ){
                if(status == JEV_S_EXTATTR_EOD) {
                /* No more extended attribute exists.  */
                    break;
                }
                else {
   /* Error occurred while acquiring extended attributes. */
                    fprintf(stderr,
                            "JevGetNextExtAttr() failed.
                            Status = %ld\n", status);
                    JevFreeEvent(&status, event);
                    JevGetClose(&status, key);
                    return -1;
                }
            }
            else {
                printf("JevGetNextExtAttr() name = %s\n", name);
                printf("JevGetNextExtAttr() value = %s\n", value);
            }
        }
 
        /* Release the memory allocated for the acquired JP1 events. */
        rc = JevFreeEvent(&status, event);
        if(rc < 0){
            fprintf(stderr,
                    "JevFreeEvent() failed. Status = %ld\n",
                    status);
            JevGetClose(&status, key);
            return -1;
        }
    }
 
    /* Disconnect the event server.*/
    rc = JevGetClose(&status, key);
    if(rc < 0){
        fprintf(stderr,
                "JevGetClose() failed. Status = %ld\n",
                status);
        return -1;
    }
 
    return 0;
}