]> sigrok.org Git - libsigrok.git/blobdiff - bindings/java/org/sigrok/core/classes/classes.i
session: Make event source injection API private
[libsigrok.git] / bindings / java / org / sigrok / core / classes / classes.i
index 52eace85a7acfc7ed778b6fe07a8d3bf821dcd19..5cf258369ecb929a0fb6f4a26178878cc237c750 100644 (file)
@@ -7,25 +7,37 @@
   }
 %}
 
-/* Import interfaces. */
+/* Documentation & importing interfaces. */
 %pragma(java) jniclassimports=%{
-  import org.sigrok.core.interfaces.LogCallback;
-  import org.sigrok.core.interfaces.DatafeedCallback;
-  import org.sigrok.core.interfaces.SourceCallback;
+/**
+ * @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 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 {
@@ -112,6 +124,11 @@ VECTOR(std::shared_ptr<sigrok::HardwareDevice>, HardwareDevice)
 
 MAP_COMMON(std::string, std::string, String, String)
 
+%typemap(jni) std::map<std::string, std::string>
+  "jobject"
+%typemap(jtype) std::map<std::string, std::string>
+  "java.util.Map<String,String>"
+
 %typemap(out) std::map<std::string, std::string> {
   jclass HashMap = jenv->FindClass("java/util/HashMap");
   jmethodID init = jenv->GetMethodID(HashMap, "<init>", "()V");
@@ -199,6 +216,15 @@ MAP_COMMON(const sigrok::ConfigKey *, Glib::VariantBase, ConfigKey, Variant)
   }
 }
 
+/* Support InputFormat.create_input() with no options. */
+%extend sigrok::InputFormat {
+  std::shared_ptr<sigrok::Input> create_input()
+  {
+    std::map<std::string, Glib::VariantBase> options;
+    return $self->create_input(options);
+  }
+}
+
 /* Support OutputFormat.create_output(device) with no options. */
 %extend sigrok::OutputFormat {
   std::shared_ptr<sigrok::Output> create_output(
@@ -307,42 +333,21 @@ 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<sigrok::EventSource> 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 this for now, needs a fix. */
+%ignore sigrok::Context::create_analog_packet;
 
 %include "bindings/swig/classes.i"
+