2.2.2 JP1イベントを取得する手順
作業の流れは次のとおりです。
-
取得するJP1イベントの種類とイベント属性を決める
-
取得するJP1イベントをイベント取得フィルターによって指定する
-
JP1イベント取得関数を使用してコーディングする
-
ソースファイルをコンパイルする
- 〈この項の構成〉
(1) 取得するJP1イベントの種類とイベント属性を決める
JP1/Baseでは,さまざまな種類の事象がJP1イベントとしてイベントDBに登録されます。まず,このイベントDBの中からどのような種類のJP1イベントを取得するかを決めます。
次に,そのJP1イベントからどのイベント属性を取得すればよいかを決めます。取得するイベント属性を決めるときは,そのアプリケーションの情報として何が必要かを考えます。アプリケーション単位で,取得するすべてのJP1イベントのイベント属性をあらかじめ決めておきます。
ここでは,「2.2.1(1) 発行するJP1イベントの種類とイベント属性を決める」でJP1イベントとして発行したSAMPLEアプリケーションの「開始イベント」の取得を例に説明します。
(2) 取得するJP1イベントをイベント取得フィルターによって指定する
必要なJP1イベントだけを取得するには,イベント取得フィルターを定義する必要があります。イベント取得フィルターの文法の詳細については,マニュアル「JP1/Base 運用ガイド」の,フィルターの文法の項を参照してください。ここでは,「2.2.1(1) 発行するJP1イベントの種類とイベント属性を決める」で示したSAMPLEアプリケーションの「開始イベント」を取得するためのイベント取得フィルターの例を次に示します。
まず,「開始イベント」を取得するために,次に示す条件を付けたイベント取得フィルターを作成することを検討します。
-
イベントID:0x00000001
-
拡張属性「SEVERITY」の値:Notice
-
拡張属性「PRODUCT_NAME」の値:/COMPANY/APP1/SAMPLE_PRODUCT
上記条件に合致するJP1イベントを取得対象にすることで,「開始イベント」が取得できるようになります。上記条件に合致するイベント取得フィルターの例を次に示します。
B.ID IN 00000001 E.SEVERITY IN Notice E.PRODUCT_NAME IN /COMPANY/APP1/ SAMPLE_PRODUCT
- 注意事項
-
-
イベント取得フィルターの条件として日本語文字列を指定する場合,その文字コードは,JP1イベント取得関数実行時のロケール情報(環境変数LANGなど)と合致させてください。イベント取得フィルターの条件として指定した文字列の文字コードとJP1イベント取得関数実行時のロケール情報(環境変数LANGなど)が異なる場合,JP1イベントは取得できません。
-
イベント取得フィルターに除外条件を定義するときは,08-50以降のイベントサーバに接続してください。08-11以前のイベントサーバに接続するとエラー(JEV_S_FILTER_ERROR)になります。
-
(3) JP1イベント取得関数を使用してコーディングする
ほかのJP1プログラムやユーザーアプリケーションがJP1イベントを取得する場合,JP1イベント取得関数を利用します。JP1/BaseのイベントDBからJP1イベントを取得するには,次の順序でJP1イベント取得関数を発行します。
-
JP1イベントの取得開始を要求する関数を発行する
イベントサーバに対して関数(JevGetOpen)を使ってJP1イベントの取得開始を要求し,イベントサーバに接続します。なお,取得開始を要求するユーザーは,あらかじめJP1/Baseのイベントサーバ設定(conf)ファイルのusersパラメーターで設定する必要があります。
-
JP1イベントの取得を要求する関数を発行する
さまざまな関数を使ってJP1イベントを取得したり,JP1イベントに設定されたさまざまなイベント属性を取得したりします。
-
JP1イベントの取得終了を通知する関数を発行する
イベントサーバに対して関数(JevGetClose)を使ってJP1イベントの取得終了を通知し,イベントサーバとの接続を切断します。
JP1イベント取得関数の詳細については,「3. 関数」を参照してください。また,取得できるイベント属性がどのようなものであるかについては,「付録A JP1イベントの属性の設定基準」を参照してください。
ここでは,「2.2.1(1) 発行するJP1イベントの種類とイベント属性を決める」に示した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 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; }