X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=bindings%2Fjava%2Forg%2Fsigrok%2Fcore%2Fclasses%2Fclasses.i;h=e953fe5d8331052215b59e5c97608c50e851da8a;hb=e803574173bdac8a7f33085a648c29eaf248a394;hp=1b303464ea34bf16c6eb28d656dfd09f7298401d;hpb=12f2f640cbe9167ad386a2d9069ec882d70cda5b;p=libsigrok.git diff --git a/bindings/java/org/sigrok/core/classes/classes.i b/bindings/java/org/sigrok/core/classes/classes.i index 1b303464..e953fe5d 100644 --- a/bindings/java/org/sigrok/core/classes/classes.i +++ b/bindings/java/org/sigrok/core/classes/classes.i @@ -11,25 +11,25 @@ %pragma(java) jniclassimports=%{ /** * @mainpage API Reference - * + * * Introduction * ------------ - * + * * The sigrok-java API provides an object-oriented Java interface to the * functionality in libsigrok. It is built on top of the libsigrokcxx C++ API. - * + * * Getting started * --------------- - * + * * Usage of the sigrok-java API needs to begin with a call to Context.create(). * This will create the global libsigrok context and returns a Context object. * Methods on this object provide access to the hardware drivers, input and * output formats supported by the library, as well as means of creating other * objects such as sessions and triggers. - * + * * Error handling * -------------- - * + * * When any libsigrok C API call returns an error, an Error exception is raised, * which provides access to the error code and description. */ @@ -76,7 +76,7 @@ namespace Glib { for (auto entry : $1) { *(CValue **) &value = new CValue(entry); - jenv->CallObjectMethod($result, Vector_add, + jenv->CallBooleanMethod($result, Vector_add, jenv->NewObject(Value, Value_init, value, true)); } } @@ -94,10 +94,18 @@ VECTOR(std::shared_ptr, HardwareDevice) "java.util.Map" %typemap(javain, +/* SWIG 4.0.0 changed the std::map wrappers in an incompatible way. */ +#if SWIG_VERSION >= 0x040000 + pre=" $javaclassname temp$javainput = new $javaclassname(); + for (java.util.Map.Entry entry : $javainput.entrySet()) + temp$javainput.put(entry.getKey(), entry.getValue());", + pgcppname="temp$javainput") +#else pre=" $javaclassname temp$javainput = new $javaclassname(); for (java.util.Map.Entry entry : $javainput.entrySet()) temp$javainput.set(entry.getKey(), entry.getValue());", pgcppname="temp$javainput") +#endif std::map< CKey, CValue > "$javaclassname.getCPtr(temp$javainput)" %typemap(javaout) std::map< CKey, CValue > { @@ -193,47 +201,11 @@ MAP_COMMON(const sigrok::ConfigKey *, Glib::VariantBase, ConfigKey, Variant) } } -/* Specialisation for ConfigKey->set maps */ - -MAP_COMMON(const sigrok::ConfigKey *, std::set, - ConfigKey, java.util.Set) - -%typemap(jni) std::map > "jobject" -%typemap(jtype) std::map > - "java.util.Map>" - -%typemap(out) std::map > { - jclass HashMap = jenv->FindClass("java/util/HashMap"); - jmethodID HashMap_init = jenv->GetMethodID(HashMap, "", "()V"); - jmethodID HashMap_put = jenv->GetMethodID(HashMap, "put", - "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); - jclass HashSet = jenv->FindClass("java/util/HashSet"); - jmethodID HashSet_init = jenv->GetMethodID(HashSet, "", "()V"); - jmethodID HashSet_add = jenv->GetMethodID(HashSet, "add", - "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); - jclass ConfigKey = jenv->FindClass("org/sigrok/core/classes/ConfigKey"); - jmethodID ConfigKey_init = jenv->GetMethodID(ConfigKey, "", "(JZ)V"); - jclass Capability = jenv->FindClass("org/sigrok/core/classes/Capability"); - jmethodID Capability_init = jenv->GetMethodID(Capability, "", "(JZ)V"); - $result = jenv->NewObject(HashMap, HashMap_init); - jlong key = 0; - for (auto map_entry : $1) - { - *(const sigrok::ConfigKey **) &key = map_entry.first; - jobject value = jenv->NewObject(HashSet, HashSet_init); - for (auto &set_entry : map_entry.second) - jenv->CallObjectMethod(value, HashSet_add, - jenv->NewObject(Capability, Capability_init, set_entry)); - jenv->CallObjectMethod($result, HashMap_put, - jenv->NewObject(ConfigKey, ConfigKey_init, key, false), value); - } -} - /* Pass JNIEnv parameter to C++ extension methods requiring it. */ %typemap(in, numinputs=0) JNIEnv * %{ $1 = jenv; -%} +%} /* Thread safe JNIEnv handling */