X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=bindings%2Fjava%2Forg%2Fsigrok%2Fcore%2Fclasses%2Fclasses.i;h=7e1919e2dce0b1864272dd6d9e5de4df604d5362;hb=f3095e7e2e2a4cc034a9253179c04dc5d129e882;hp=c7173e4a77d010937b824377fc2e4d40baba2955;hpb=ca3291e3ee7415c4c4505164ec931b91ea15cefe;p=libsigrok.git diff --git a/bindings/java/org/sigrok/core/classes/classes.i b/bindings/java/org/sigrok/core/classes/classes.i index c7173e4a..7e1919e2 100644 --- a/bindings/java/org/sigrok/core/classes/classes.i +++ b/bindings/java/org/sigrok/core/classes/classes.i @@ -16,7 +16,7 @@ * ------------ * * The sigrok-java API provides an object-oriented Java interface to the - * functionality in libsigrok. It is built on top of the sigrok++ C++ API. + * functionality in libsigrok. It is built on top of the libsigrokcxx C++ API. * * Getting started * --------------- @@ -36,27 +36,16 @@ import org.sigrok.core.interfaces.LogCallback; import org.sigrok.core.interfaces.DatafeedCallback; -import org.sigrok.core.interfaces.SourceCallback; %} -/* Map Java FileDescriptor objects to int fds */ -%typemap(jni) int fd "jobject" -%typemap(jtype) int fd "java.io.FileDescriptor" -%typemap(jstype) int fd "java.io.FileDescriptor" -%typemap(javain) int fd "$javainput" - -%typemap(in) int fd { - jclass FileDescriptor = jenv->FindClass("java/io/FileDescriptor"); - jfieldID fd = jenv->GetFieldID(FileDescriptor, "fd", "I"); - $1 = jenv->GetIntField($input, fd); -} - /* Map Glib::VariantBase to a Variant class in Java */ %rename(Variant) VariantBase; namespace Glib { class VariantBase {}; } +%include "bindings/swig/templates.i" + /* Map between std::vector and java.util.Vector */ %define VECTOR(CValue, JValue) @@ -65,20 +54,12 @@ namespace Glib { %typemap(jstype) std::vector< CValue > "java.util.Vector" %typemap(javain, - pre=" $javaclassname temp$javainput = $javaclassname.convertVector($javainput);", + pre=" $javaclassname temp$javainput = new $javaclassname(); + for (JValue value : $javainput) + temp$javainput.add(value);", pgcppname="temp$javainput") std::vector< CValue > "$javaclassname.getCPtr(temp$javainput)" -%typemap(javacode) std::vector< CValue > %{ - static $javaclassname convertVector(java.util.Vector in) - { - $javaclassname out = new $javaclassname(); - for (JValue value : in) - out.add(value); - return out; - } -%} - %typemap(javaout) std::vector< CValue > { return (java.util.Vector)$jnicall; } @@ -113,20 +94,12 @@ VECTOR(std::shared_ptr, HardwareDevice) "java.util.Map" %typemap(javain, - pre=" $javaclassname temp$javainput = $javaclassname.convertMap($javainput);", + pre=" $javaclassname temp$javainput = new $javaclassname(); + for (java.util.Map.Entry entry : $javainput.entrySet()) + temp$javainput.set(entry.getKey(), entry.getValue());", pgcppname="temp$javainput") std::map< CKey, CValue > "$javaclassname.getCPtr(temp$javainput)" -%typemap(javacode) std::map< CKey, CValue > %{ - static $javaclassname convertMap(java.util.Map in) - { - $javaclassname out = new $javaclassname(); - for (java.util.Map.Entry entry : in.entrySet()) - out.set(entry.getKey(), entry.getValue()); - return out; - } -%} - %typemap(javaout) std::map< CKey, CValue > { return (java.util.Map)$jnicall; } @@ -137,6 +110,11 @@ VECTOR(std::shared_ptr, HardwareDevice) MAP_COMMON(std::string, std::string, String, String) +%typemap(jni) std::map + "jobject" +%typemap(jtype) std::map + "java.util.Map" + %typemap(out) std::map { jclass HashMap = jenv->FindClass("java/util/HashMap"); jmethodID init = jenv->GetMethodID(HashMap, "", "()V"); @@ -216,31 +194,69 @@ MAP_COMMON(const sigrok::ConfigKey *, Glib::VariantBase, ConfigKey, Variant) } /* Support Driver.scan() with no arguments. */ +%ignore sigrok::Driver::scan; + %extend sigrok::Driver { std::vector > scan() { std::map options; return $self->scan(options); } + + std::vector > scan( + std::map options) + { + return $self->scan(options); + } } -/* Support InputFormat.create_input() with no options. */ +/* Support InputFormat.create_input() with or without options. */ +%ignore sigrok::InputFormat::create_input; + %extend sigrok::InputFormat { std::shared_ptr create_input() { - std::map options; + return $self->create_input(); + } + + std::shared_ptr create_input( + std::map options) + { return $self->create_input(options); } } -/* Support OutputFormat.create_output(device) with no options. */ +/* Support OutputFormat.create_output() with or without options. */ +%ignore sigrok::OutputFormat::create_output; + %extend sigrok::OutputFormat { std::shared_ptr create_output( std::shared_ptr device) { - std::map options; + return $self->create_output(device); + } + + std::shared_ptr create_output( + std::shared_ptr device, + std::map options) + { return $self->create_output(device, options); } + + std::shared_ptr create_output( + std::string filename, + std::shared_ptr device) + { + return $self->create_output(filename, device); + } + + std::shared_ptr create_output( + std::string filename, + std::shared_ptr device, + std::map options) + { + return $self->create_output(filename, device, options); + } } /* Pass JNIEnv parameter to C++ extension methods requiring it. */ @@ -341,43 +357,22 @@ typedef jobject jdatafeedcallback; } } -/* Support Java event source callbacks. */ - -%typemap(javaimports) sigrok::EventSource - "import org.sigrok.core.interfaces.SourceCallback;" - -%inline { -typedef jobject jsourcecallback; -} +%include "doc.i" -%typemap(jni) jsourcecallback "jsourcecallback" -%typemap(jtype) jsourcecallback "SourceCallback" -%typemap(jstype) jsourcecallback "SourceCallback" -%typemap(javain) jsourcecallback "$javainput" +%define %attributevector(Class, Type, Name, Get) +%attributeval(sigrok::Class, Type, Name, Get); +%enddef -%extend sigrok::EventSource -{ - std::shared_ptr create( - int fd, Glib::IOCondition events, int timeout, - JNIEnv *env, jsourcecallback obj) - { - (void) $self; - jclass obj_class = env->GetObjectClass(obj); - jmethodID method = env->GetMethodID(obj_class, "run", "(I)V"); - jobject obj_ref = env->NewGlobalRef(obj); +%define %attributemap(Class, Type, Name, Get) +%attributeval(sigrok::Class, Type, Name, Get); +%enddef - return sigrok::EventSource::create(fd, events, timeout, [=] (int revents) - { - bool result = env->CallBooleanMethod(obj_ref, method, revents); - if (env->ExceptionCheck()) - throw sigrok::Error(SR_ERR); - return result; - }); - } -} +%define %enumextras(Class) +%enddef -/* Currently broken due to some std::map typemap issues. */ -%ignore sigrok::Meta::get_config; +/* Ignore these for now, need fixes. */ +%ignore sigrok::Context::create_analog_packet; +%ignore sigrok::Context::create_meta_packet; -%include "doc.i" %include "bindings/swig/classes.i" +