X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=bindings%2Fjava%2Forg%2Fsigrok%2Fcore%2Fclasses%2Fclasses.i;h=34323b16a8df7f24131cde337b38360f3aba1a69;hb=dd13d47a9ef6c9a5c1c1920d8ac57e22bd1d9960;hp=20e55d572dbd1947c78bbb5b97a836cdf6fc14fe;hpb=9fcf4d0b5b9969b0b7770e71994b960f15f7757f;p=libsigrok.git diff --git a/bindings/java/org/sigrok/core/classes/classes.i b/bindings/java/org/sigrok/core/classes/classes.i index 20e55d57..34323b16 100644 --- a/bindings/java/org/sigrok/core/classes/classes.i +++ b/bindings/java/org/sigrok/core/classes/classes.i @@ -7,17 +7,36 @@ } %} -/* 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); -} +/* Documentation & importing interfaces. */ +%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. + */ + +import org.sigrok.core.interfaces.LogCallback; +import org.sigrok.core.interfaces.DatafeedCallback; +%} /* Map Glib::VariantBase to a Variant class in Java */ %rename(Variant) VariantBase; @@ -105,6 +124,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"); @@ -157,6 +181,10 @@ STRING_TO_SHARED_PTR_MAP(OutputFormat) MAP_COMMON(const sigrok::ConfigKey *, Glib::VariantBase, ConfigKey, Variant) +%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"); @@ -180,22 +208,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 OutputFormat.create_output(device) with no options. */ +/* Support InputFormat.create_input() with or without options. */ +%ignore sigrok::InputFormat::create_input; + +%extend sigrok::InputFormat { + std::shared_ptr create_input() + { + return $self->create_input(); + } + + std::shared_ptr create_input( + std::map options) + { + return $self->create_input(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. */ @@ -206,6 +281,9 @@ MAP_COMMON(const sigrok::ConfigKey *, Glib::VariantBase, ConfigKey, Variant) /* Support Java log callbacks. */ +%typemap(javaimports) sigrok::Context + "import org.sigrok.core.interfaces.LogCallback;" + %inline { typedef jobject jlogcallback; } @@ -245,6 +323,9 @@ typedef jobject jlogcallback; /* Support Java datafeed callbacks. */ +%typemap(javaimports) sigrok::Session + "import org.sigrok.core.interfaces.DatafeedCallback;" + %inline { typedef jobject jdatafeedcallback; } @@ -290,36 +371,21 @@ typedef jobject jdatafeedcallback; } } -/* Support Java event source callbacks. */ +%include "doc.i" -%inline { -typedef jobject jsourcecallback; -} +%define %attributevector(Class, Type, Name, Get) +%attributeval(sigrok::Class, Type, Name, Get); +%enddef -%typemap(jni) jsourcecallback "jsourcecallback" -%typemap(jtype) jsourcecallback "SourceCallback" -%typemap(jstype) jsourcecallback "SourceCallback" -%typemap(javain) jsourcecallback "$javainput" +%define %attributemap(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 %enumextras(Class) +%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; - }); - } -} +/* Ignore this for now, needs a fix. */ +%ignore sigrok::Context::create_analog_packet; %include "bindings/swig/classes.i" +