From 1bc0ecade288c226c3f5b37fc377fc6317c14a36 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Fri, 23 Sep 2005 00:11:55 +0000 Subject: [PATCH] save a reference to log name and pass around internally --- bindings/java/src/jni/win32/eventlog.c | 4 ++-- .../src/net/hyperic/sigar/win32/EventLog.java | 17 ++++++++++++++--- .../net/hyperic/sigar/win32/EventLogThread.java | 2 +- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/bindings/java/src/jni/win32/eventlog.c b/bindings/java/src/jni/win32/eventlog.c index a242581e..33609f2a 100644 --- a/bindings/java/src/jni/win32/eventlog.c +++ b/bindings/java/src/jni/win32/eventlog.c @@ -107,7 +107,7 @@ static int get_formatted_message(EVENTLOGRECORD *pevlr, char *dllfile, return 0; } -JNIEXPORT void SIGAR_JNI(win32_EventLog_open) +JNIEXPORT void SIGAR_JNI(win32_EventLog_openlog) (JNIEnv *env, jobject obj, jstring lpSourceName) { HANDLE h; @@ -164,7 +164,7 @@ JNIEXPORT jint SIGAR_JNI(win32_EventLog_getOldestRecord) return oldest; } -JNIEXPORT jobject SIGAR_JNI(win32_EventLog_read) +JNIEXPORT jobject SIGAR_JNI(win32_EventLog_readlog) (JNIEnv *env, jobject obj, jstring jname, jint recordOffset) { EVENTLOGRECORD *pevlr; diff --git a/bindings/java/src/net/hyperic/sigar/win32/EventLog.java b/bindings/java/src/net/hyperic/sigar/win32/EventLog.java index eb52d8c8..b17971e1 100644 --- a/bindings/java/src/net/hyperic/sigar/win32/EventLog.java +++ b/bindings/java/src/net/hyperic/sigar/win32/EventLog.java @@ -18,6 +18,7 @@ public class EventLog extends Win32 { // Event log timeouts public static final int EVENTLOG_WAIT_INFINITE = -1; + private String name; /** * Create an event log. @@ -30,7 +31,12 @@ public class EventLog extends Win32 { * Application, System or Security. * @exception Win32Exception If opening the event log fails. */ - public native void open(String lpSourceName) throws Win32Exception; + public void open(String name) throws Win32Exception { + this.name = name; + openlog(name); + } + + public native void openlog(String name) throws Win32Exception; /** * Close the event log. @@ -65,13 +71,18 @@ public class EventLog extends Win32 { * EVENTLOG_SEEK_READ flag, no sequential reading is currently * supported. * - * @param logName The event log name * @param recordOffset The record offset to read. * @exception Win32Exception If the event log is not open, or * if the specified record could not be * found */ - public native EventLogRecord read(String logName, int recordOffset) + public EventLogRecord read(int recordOffset) + throws Win32Exception { + + return readlog(this.name, recordOffset); + } + + private native EventLogRecord readlog(String name, int recordOffset) throws Win32Exception; /** diff --git a/bindings/java/src/net/hyperic/sigar/win32/EventLogThread.java b/bindings/java/src/net/hyperic/sigar/win32/EventLogThread.java index 30470e0d..6ff51cbe 100644 --- a/bindings/java/src/net/hyperic/sigar/win32/EventLogThread.java +++ b/bindings/java/src/net/hyperic/sigar/win32/EventLogThread.java @@ -101,7 +101,7 @@ public class EventLogThread implements Runnable { EventLogRecord record; try { - record = log.read(this.logName, i); + record = log.read(i); } catch (Win32Exception e) { logger.error("Unable to read event id " + i + ": " + e); continue;