Hitachi

JP1 Version 12 JP1/Base Function Reference


B.1 Details of the sample source files

This section gives details of the sample source files.

Organization of this subsection

(1) Events handled by the sample source files

Table B‒1: Events handled by the sample source files

Attribute type

Item

Attribute name

Description

Basic attribute

Event ID

--

0x00000001

Message

--

Starts the SAMPLE application.

Extended attributes (common attributes)

Event level

SEVERITY

Notice

User name

USER_NAME

Name of the user who executes the application.

Product name

PRODUCT_NAME

/COMPANY/APP1/SAMPLE_PRODUCT (product name)

Object type

OBJECT_TYPE

SAMPLE

Object name

OBJECT_NAME

SAMPLE_NAME

Root object type

ROOT_OBJECT_TYPE

ROOT_SAMPLE

Root object name

ROOT_OBJECT_NAME

ROOT_SAMPLE_NAME

Object ID

OBJECT_ID

SAMPLE_ID

Occurrence

OCCURRENCE

START

Start time

START_TIME

Start time of the SAMPLE application. The number of seconds from 00:00:00 UTC on 1970-01-01.

Platform

PLATFORM

NT

Version information

ACTION_VERSION

0600

Extended attributes (user-specific attributes)

SAMPLE common attribute 1

COMMON_ATTR1

NATIVE

SAMPLE common attribute 2

COMMON_ATTR2

TRUE

SAMPLE start attributes 1

START_ATTR1

SAMPLE1

SAMPLE start attributes 2

START_ATTR2

SAMPLE2

(2) Coding of sample source files

(a) sender.c code

#include <stdio.h>
#include <time.h>
#include "JevApi.h"
 
int regist_start_event()
{
      int rc;                    /* Return code */
      long status = 0;           /* Detailed error code */
      const char* server;        /* Event server name */
      long baseID;               /* Event ID */
      const char* message;       /* Message */
      char starttime[32];
      const char* extattrs[16]; /* Array for storing extended attributes */
 
      /* Set the destination event server name. */
      server = NULL;
 
      /* Set the event ID. */
      baseID = 0x00000001;
 
      /* Set the message. */
      message = "Starts the SAMPLE application.";
 
      /* Set the extended attributes. */
      extattrs[0]  = "SEVERITY=Notice";
      extattrs[1]  = "USER_NAME=SAMPLE_USER";
      extattrs[2] = "PRODUCT_NAME=/COMPANY/APP1/SAMPLE_PRODUCT";
      extattrs[3]  = "OBJECT_TYPE=SAMPLE";
      extattrs[4]  = "OBJECT_NAME=SAMPLE_NAME";
      extattrs[5]  = "OBJECT_ROOT_TYPE=ROOT_SAMPLE";
      extattrs[6]  = "OBJECT_ROOT_NAME=ROOT_SAMPLE_NAME";
      extattrs[7]  = "OBJECT_ID=SAMPLE_ID";
      extattrs[8]  = "OCCURRENCE=START";
      sprintf(starttime, "START_TIME=%ld", time(NULL));
      extattrs[9]  = starttime;
      extattrs[10] = "PLATFORM=NT";
      extattrs[11] = "VERSION=0600";
      extattrs[12] = "COMMON_ATTR1=NATIVE";
      extattrs[13] = "COMMON_ATTR2=TRUE";
      extattrs[14] = "START_ATTR1=SAMPLE1";
      extattrs[15] = "START_ATTR2=SAMPLE2";
 
      /* Register the JP1 event. */
      rc = JevRegistEvent(&status,
                          server,
                          baseID,
                          message,
                          extattrs,
                          16);
      if(rc < 0) {
          fprintf(stderr,
                  "JevRegistEvent() failed. status = %ld\n",
                   status);
          return -1;
      }
 
      return 0;
}
 
int main()
{
      return regist_start_event();
}

(b) receiver.c code

#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 00000001\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;
}
 
int main()
{
      return get_start_event();
}