-/* 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);
+%typemap(in, numinputs=0) JNIEnv * %{
+ $1 = jenv;
+%}
+
+/* Thread safe JNIEnv handling */
+
+%inline {
+namespace {
+ class ScopedEnv {
+ public:
+ ScopedEnv(JavaVM *jvm);
+ ~ScopedEnv();
+ JNIEnv* operator-> () { return env; }
+ operator bool () const { return (bool)env; }
+ private:
+ JavaVM *jvm;
+ JNIEnv *env;
+ int env_status;
+ };
+ ScopedEnv::ScopedEnv(JavaVM *jvm) : jvm(jvm), env(NULL) {
+ env_status = jvm->GetEnv((void **)&env, JNI_VERSION_1_2);
+ if (env_status == JNI_EDETACHED) {
+%#if defined(__ANDROID__)
+ jvm->AttachCurrentThread(&env, NULL);
+%#else
+ jvm->AttachCurrentThread((void **)&env, NULL);
+%#endif
+ }
+ }
+ ScopedEnv::~ScopedEnv() {
+ if (env_status == JNI_EDETACHED) {
+ jvm->DetachCurrentThread();
+ }