JP1/Base 関数リファレンス
- <この項の構成>
- (1) サンプルソースファイルで扱うイベント
- (2) サンプルソースファイルのコーディング内容
(1) サンプルソースファイルで扱うイベント
サンプルソースファイルで扱うイベントは次のとおりです。
表B-2 サンプルソースファイルで扱うイベント
属性の種別 項目 属性名 内容 基本属性 イベントID − 0x00000001 メッセージ − 「Starts the SAMPLE application.」 拡張属性(共通情報) 重大度 SEVERITY Notice ユーザー名 USER_NAME アプリケーション実行ユーザー名 プロダクト名 PRODUCT_NAME /COMPANY/APP1/SAMPLE_PRODUCT(プロダクトの名称) オブジェクトタイプ OBJECT_TYPE SAMPLE オブジェクト名 OBJECT_NAME SAMPLE_NAME 登録名タイプ ROOT_OBJECT_TYPE ROOT_SAMPLE 登録名 ROOT_OBJECT_NAME ROOT_SAMPLE_NAME オブジェクトID OBJECT_ID SAMPLE_ID 事象種別 OCCURRENCE START 開始時刻 START_TIME SAMPLEアプリケーションの開始時刻。UTC 1970年1月1日00:00:00からの秒数。 プラットフォーム PLATFORM NT バージョン情報 ACTION_VERSION 0600 拡張属性(固有情報) SAMPLE共通属性1 COMMON_ATTR1 NATIVE SAMPLE共通属性2 COMMON_ATTR2 TRUE SAMPLE開始属性1 START_ATTR1 SAMPLE1 SAMPLE開始属性2 START_ATTR2 SAMPLE2
(2) サンプルソースファイルのコーディング内容
sender.c,receiver.cそれぞれのコーディング内容を次に示します。
#include <stdio.h> #include <time.h> #include "JevApi.h" int regist_start_event() { int rc; /* リターンコード */ long status = 0; /* 詳細エラーコード */ const char* server; /* イベントサーバ名 */ long baseID; /* イベントID */ const char* message; /* メッセージ */ char starttime[32]; const char* extattrs[16]; /* 拡張属性を格納するための配列 */ /* 登録先イベントサーバ名を設定します */ server = NULL; /* イベントIDを設定します */ baseID = 0x00000001; /* メッセージを設定します */ message = "Starts the SAMPLE application."; /* 拡張属性を設定します */ 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"; /* JP1イベントを登録します */ 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(); }#include <stdio.h> #include <string.h> #include "JevApi.h" int get_start_event() { int rc; /* リターンコード */ long position; /* イベントDB内の通し番号 */ long status; /* 状態コードアドレス */ char filter[256]; /* フィルター文バッファー */ const char *server; /* イベントサーバ名 */ const char *message; /* メッセージへのポインターのアドレス */ const char *name; /* 拡張属性名へのポインターのアドレス */ const char *value; /* 拡張属性値へのポインターのアドレス */ JEVGETKEY key; /* JP1イベント取得用ハンドル */ JP1EVENT event; /* JP1イベントアクセス用ハンドル */ JEVACCESSTYPE access; /* JP1イベントが存在しない場合の動作 */ /* 必要なJP1イベントを取得するためのフィルター文を設定します */ strcpy(filter, "B.ID IN 00000001\n"); strcat(filter, "E.SEVERITY IN Notice\n"); strcat(filter, "E.PRODUCT_NAME IN /COMPANY/APP1/SAMPLE_PRODUCT"); /* 物理ホストのイベントサーバに接続します */ status = 0; /* 接続先は物理ホストのイベントサーバ */ server = NULL; /* 取得の基点はイベントDB内の通し番号0以降から */ position = 0; key = JevGetOpen(&status, server, filter, position); if(key == NULL){ fprintf(stderr, "JevGetOpen() failed. Status = %ld\n", status); return -1; } /* フィルターに合致するJP1イベントを全件取得します */ while(1) { status = 0; /* 該当するJP1イベントがなければエラーリターン */ access = JEVGET_NOWAIT; event = JevGetEvent(&status, key, access); if(event == NULL){ if(status == JEV_S_NO_EVENT) { /* 該当するJP1イベントはこれ以上存在しません */ break; } else { /* JP1イベント取得時にエラーが発生しました */ fprintf(stderr, "JevGetEvent() failed. Status = %ld\n", status); JevGetClose(&status, key); return -1; } } /* メッセージを取得します */ 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); } /* (最初の)拡張属性を取得します */ 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); } /* (継続の)拡張属性を取得します */ while(1) { status = 0; rc = JevGetNextExtAttr(&status, event, &name, &value); if(rc < 0 ){ if(status == JEV_S_EXTATTR_EOD) { /* 拡張属性はこれ以上存在しません */ break; } else { /* 拡張属性の取得でエラーが発生しました */ 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); } } /* 取得したJP1イベント用メモリーを解放します */ rc = JevFreeEvent(&status, event); if(rc < 0){ fprintf(stderr, "JevFreeEvent() failed. Status = %ld\n", status); JevGetClose(&status, key); return -1; } } /* イベントサーバから切断します */ 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(); }
All Rights Reserved. Copyright (C) 2009, 2011, Hitachi, Ltd.