From c3aa8a690528c832c665eecef688a30fdb77ed36 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Thu, 19 Feb 2009 21:59:09 +0100 Subject: [PATCH] java plugin: Implement `plugin_get_ds' aka. GetDS. --- bindings/java/org/collectd/api/CollectdAPI.java | 4 ++++ src/java.c | 30 ++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/bindings/java/org/collectd/api/CollectdAPI.java b/bindings/java/org/collectd/api/CollectdAPI.java index bd8d950e..67c8e6ad 100644 --- a/bindings/java/org/collectd/api/CollectdAPI.java +++ b/bindings/java/org/collectd/api/CollectdAPI.java @@ -21,11 +21,15 @@ package org.collectd.api; +import java.util.List; import org.collectd.protocol.ValueList; +import org.collectd.protocol.DataSource; public class CollectdAPI { native public static int DispatchValues (ValueList vl); + + native public static List GetDS (String type); } /* class CollectdAPI */ /* vim: set sw=2 sts=2 et fdm=marker : */ diff --git a/src/java.c b/src/java.c index a1e4971e..779847ed 100644 --- a/src/java.c +++ b/src/java.c @@ -1125,9 +1125,37 @@ static jint JNICALL cjni_api_dispatch_values (JNIEnv *jvm_env, /* {{{ */ return (status); } /* }}} jint cjni_api_dispatch_values */ +static jobject JNICALL cjni_api_get_ds (JNIEnv *jvm_env, /* {{{ */ + jobject this, jobject o_string_type) +{ + const char *ds_name; + const data_set_t *ds; + jobject o_dataset; + + ds_name = (*jvm_env)->GetStringUTFChars (jvm_env, o_string_type, 0); + if (ds_name == NULL) + { + ERROR ("java plugin: cjni_api_get_ds: GetStringUTFChars failed."); + return (NULL); + } + + ds = plugin_get_ds (ds_name); + DEBUG ("java plugin: cjni_api_get_ds: " + "plugin_get_ds (%s) = %p;", ds_name, (void *) ds); + + (*jvm_env)->ReleaseStringUTFChars (jvm_env, o_string_type, ds_name); + + if (ds == NULL) + return (NULL); + + o_dataset = ctoj_data_set (jvm_env, ds); + return (o_dataset); +} /* }}} jint cjni_api_get_ds */ + static JNINativeMethod jni_api_functions[] = { - { "DispatchValues", "(Lorg/collectd/protocol/ValueList;)I", cjni_api_dispatch_values } + { "DispatchValues", "(Lorg/collectd/protocol/ValueList;)I", cjni_api_dispatch_values }, + { "GetDS", "(Ljava/lang/String;)Ljava/util/List;", cjni_api_get_ds } }; static size_t jni_api_functions_num = sizeof (jni_api_functions) / sizeof (jni_api_functions[0]); -- 2.11.0