java plugin: Expose `plugin_log' to Java plugins.
authorFlorian Forster <octo@leeloo.lan.home.verplant.org>
Sun, 22 Feb 2009 17:32:02 +0000 (18:32 +0100)
committerFlorian Forster <octo@leeloo.lan.home.verplant.org>
Sun, 22 Feb 2009 17:32:02 +0000 (18:32 +0100)
bindings/java/org/collectd/api/CollectdAPI.java
src/Makefile.am
src/java.c

index 9dbe7c0..2b6e06c 100644 (file)
@@ -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 : */
index e159026..2f16bf2 100644 (file)
@@ -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 \
index 45f139c..5538270 100644 (file)
@@ -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]);