From: Florian Forster Date: Sun, 22 Feb 2009 17:32:02 +0000 (+0100) Subject: java plugin: Expose `plugin_log' to Java plugins. X-Git-Tag: collectd-4.7.0~114^2~25 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=5f195369;p=collectd.git java plugin: Expose `plugin_log' to Java plugins. --- diff --git a/bindings/java/org/collectd/api/CollectdAPI.java b/bindings/java/org/collectd/api/CollectdAPI.java index 9dbe7c0d..2b6e06cf 100644 --- a/bindings/java/org/collectd/api/CollectdAPI.java +++ b/bindings/java/org/collectd/api/CollectdAPI.java @@ -28,15 +28,11 @@ package org.collectd.api; */ public class CollectdAPI { - /** - * Java representation of collectd/src/plugin.h:plugin_dispatch_values - */ - native public static int DispatchValues (ValueList vl); - - /** - * Java representation of collectd/src/plugin.h:plugin_get_ds - */ - native public static DataSet GetDS (String type); + private static final int LOG_ERR = 3; + private static final int LOG_WARNING = 4; + private static final int LOG_NOTICE = 5; + private static final int LOG_INFO = 6; + private static final int LOG_DEBUG = 7; /** * Java representation of collectd/src/plugin.h:plugin_register_config @@ -67,6 +63,47 @@ public class CollectdAPI */ native public static int RegisterShutdown (String name, CollectdShutdownInterface obj); + + /** + * Java representation of collectd/src/plugin.h:plugin_dispatch_values + */ + native public static int DispatchValues (ValueList vl); + + /** + * Java representation of collectd/src/plugin.h:plugin_get_ds + */ + native public static DataSet GetDS (String type); + + /** + * Java representation of collectd/src/plugin.h:plugin_log + */ + native private static void Log (int severity, String message); + + public static void LogError (String message) + { + Log (LOG_ERR, message); + } /* void LogError */ + + public static void LogWarning (String message) + { + Log (LOG_WARNING, message); + } /* void LogWarning */ + + public static void LogNotice (String message) + { + Log (LOG_NOTICE, message); + } /* void LogNotice */ + + public static void LogInfo (String message) + { + Log (LOG_INFO, message); + } /* void LogInfo */ + + public static void LogDebug (String message) + { + Log (LOG_DEBUG, message); + } /* void LogDebug */ + } /* class CollectdAPI */ /* vim: set sw=2 sts=2 et fdm=marker : */ diff --git a/src/Makefile.am b/src/Makefile.am index e159026c..2f16bf24 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -38,6 +38,7 @@ collectd_SOURCES = collectd.c collectd.h \ utils_ignorelist.c utils_ignorelist.h \ utils_llist.c utils_llist.h \ utils_parse_option.c utils_parse_option.h \ + utils_rwlock.c utils_rwlock.h \ utils_tail_match.c utils_tail_match.h \ utils_match.c utils_match.h \ utils_mount.c utils_mount.h \ diff --git a/src/java.c b/src/java.c index 45f139c3..55382706 100644 --- a/src/java.c +++ b/src/java.c @@ -1254,6 +1254,28 @@ static jint JNICALL cjni_api_register_shutdown (JNIEnv *jvm_env, /* {{{ */ CB_TYPE_SHUTDOWN)); } /* }}} jint cjni_api_register_shutdown */ +static void JNICALL cjni_api_log (JNIEnv *jvm_env, /* {{{ */ + jobject this, jint severity, jobject o_message) +{ + const char *c_str; + + c_str = (*jvm_env)->GetStringUTFChars (jvm_env, o_message, 0); + if (c_str == NULL) + { + ERROR ("java plugin: cjni_api_log: GetStringUTFChars failed."); + return; + } + + if (severity < LOG_ERR) + severity = LOG_ERR; + if (severity > LOG_DEBUG) + severity = LOG_DEBUG; + + plugin_log (severity, "%s", c_str); + + (*jvm_env)->ReleaseStringUTFChars (jvm_env, o_message, c_str); +} /* }}} void cjni_api_log */ + /* List of ``native'' functions, i. e. C-functions that can be called from * Java. */ static JNINativeMethod jni_api_functions[] = /* {{{ */ @@ -1284,8 +1306,11 @@ static JNINativeMethod jni_api_functions[] = /* {{{ */ { "RegisterShutdown", "(Ljava/lang/String;Lorg/collectd/api/CollectdShutdownInterface;)I", - cjni_api_register_shutdown } + cjni_api_register_shutdown }, + { "Log", + "(ILjava/lang/String;)V", + cjni_api_log }, }; static size_t jni_api_functions_num = sizeof (jni_api_functions) / sizeof (jni_api_functions[0]);