//export Java_io_v_impl_google_namespace_NamespaceImpl_nativeGetPermissions func Java_io_v_impl_google_namespace_NamespaceImpl_nativeGetPermissions(jenv *C.JNIEnv, jNamespaceClass C.jclass, goRef C.jlong, jContext C.jobject, jName C.jstring, jOptions C.jobject, jCallbackObj C.jobject) { env := jutil.Env(uintptr(unsafe.Pointer(jenv))) n := *(*namespace.T)(jutil.GoRefValue(jutil.Ref(goRef))) jCallback := jutil.Object(uintptr(unsafe.Pointer(jCallbackObj))) context, name, options, err := getPermissionsArgs(env, jContext, jName, jOptions) if err != nil { jutil.CallbackOnFailure(env, jCallback, err) return } jutil.DoAsyncCall(env, jCallback, func() (jutil.Object, error) { return doGetPermissions(n, context, name, options) }) }
//export Java_io_v_impl_google_namespace_NamespaceImpl_nativeDelete func Java_io_v_impl_google_namespace_NamespaceImpl_nativeDelete(jenv *C.JNIEnv, jNamespaceClass C.jclass, goRef C.jlong, jContext C.jobject, jName C.jstring, jDeleteSubtree C.jboolean, jOptions C.jobject, jCallbackObj C.jobject) { env := jutil.Env(uintptr(unsafe.Pointer(jenv))) n := *(*namespace.T)(jutil.GoRefValue(jutil.Ref(goRef))) jCallback := jutil.Object(uintptr(unsafe.Pointer(jCallbackObj))) context, options, name, deleteSubtree, err := deleteArgs(env, jContext, jOptions, jName, jDeleteSubtree) if err != nil { jutil.CallbackOnFailure(env, jCallback, err) return } jutil.DoAsyncCall(env, jCallback, func() (jutil.Object, error) { return jutil.NullObject, n.Delete(context, name, deleteSubtree, options...) }) }
//export Java_io_v_impl_google_namespace_NamespaceImpl_nativeUnmount func Java_io_v_impl_google_namespace_NamespaceImpl_nativeUnmount(jenv *C.JNIEnv, jNamespaceClass C.jclass, goRef C.jlong, jContext C.jobject, jName C.jstring, jServer C.jstring, jOptions C.jobject, jCallbackObj C.jobject) { env := jutil.Env(uintptr(unsafe.Pointer(jenv))) n := *(*namespace.T)(jutil.GoRefValue(jutil.Ref(goRef))) jCallback := jutil.Object(uintptr(unsafe.Pointer(jCallbackObj))) name, server, context, options, err := unmountArgs(env, jName, jServer, jContext, jOptions) if err != nil { jutil.CallbackOnFailure(env, jCallback, err) return } jutil.DoAsyncCall(env, jCallback, func() (jutil.Object, error) { return jutil.NullObject, n.Unmount(context, name, server, options...) }) }
//export Java_io_v_impl_google_rpc_ClientImpl_nativeStartCall func Java_io_v_impl_google_rpc_ClientImpl_nativeStartCall(jenv *C.JNIEnv, jClientObj C.jobject, goRef C.jlong, jContext C.jobject, jName C.jstring, jMethod C.jstring, jVomArgs C.jobjectArray, jOptionsObj C.jobject, jCallbackObj C.jobject) { env := jutil.Env(uintptr(unsafe.Pointer(jenv))) name := jutil.GoString(env, jutil.Object(uintptr(unsafe.Pointer(jName)))) method := jutil.GoString(env, jutil.Object(uintptr(unsafe.Pointer(jMethod)))) jOptions := jutil.Object(uintptr(unsafe.Pointer(jOptionsObj))) jCallback := jutil.Object(uintptr(unsafe.Pointer(jCallbackObj))) ctx, cancel, err := jcontext.GoContext(env, jutil.Object(uintptr(unsafe.Pointer(jContext)))) if err != nil { jutil.CallbackOnFailure(env, jCallback, err) return } args, err := decodeArgs(env, jVomArgs) if err != nil { jutil.CallbackOnFailure(env, jCallback, err) return } opts, err := jopts.GoRpcOpts(env, jOptions) if err != nil { jutil.CallbackOnFailure(env, jCallback, err) return } // Create a global reference to the client object for the duration of the call // so that the java object doesn't get garbage collected while the async call // is happening. This is an issue because if the java object is garbage collected, // the go ref will also be collected causing doStartCall to panic. jClient := jutil.NewGlobalRef(env, jutil.Object(uintptr(unsafe.Pointer(jClientObj)))) jutil.DoAsyncCall(env, jCallback, func() (jutil.Object, error) { obj, err := doStartCall(ctx, cancel, name, method, opts, goRef, args) env, freeFunc := jutil.GetEnv() jutil.DeleteGlobalRef(env, jClient) freeFunc() return obj, err }) }
//export Java_io_v_impl_google_channel_OutputChannelImpl_nativeSend func Java_io_v_impl_google_channel_OutputChannelImpl_nativeSend(jenv *C.JNIEnv, jOutputChannelClass C.jclass, goConvertRef C.jlong, goSendRef C.jlong, jItemObj C.jobject, jCallbackObj C.jobject) { env := jutil.Env(uintptr(unsafe.Pointer(jenv))) convert := *(*func(jutil.Object) (interface{}, error))(jutil.GoRefValue(jutil.Ref(goConvertRef))) send := *(*func(interface{}) error)(jutil.GoRefValue(jutil.Ref(goSendRef))) jItem := jutil.Object(uintptr(unsafe.Pointer(jItemObj))) jCallback := jutil.Object(uintptr(unsafe.Pointer(jCallbackObj))) // NOTE(spetrovic): Conversion must be done outside of DoAsyncCall as it references a Java // object. item, err := convert(jItem) if err != nil { jutil.CallbackOnFailure(env, jCallback, err) return } jutil.DoAsyncCall(env, jCallback, func() (jutil.Object, error) { return jutil.NullObject, send(item) }) }
//export Java_io_v_v23_context_VContext_nativeOnDone func Java_io_v_v23_context_VContext_nativeOnDone(jenv *C.JNIEnv, jVContext C.jobject, goRef C.jlong, jCallbackObj C.jobject) { env := jutil.Env(uintptr(unsafe.Pointer(jenv))) jCallback := jutil.Object(uintptr(unsafe.Pointer(jCallbackObj))) ctx := (*(*context.T)(jutil.GoRefValue(jutil.Ref(goRef)))) c := ctx.Done() if c == nil { jutil.CallbackOnFailure(env, jCallback, errors.New("Context isn't cancelable")) return } jutil.DoAsyncCall(env, jCallback, func() (jutil.Object, error) { <-c env, freeFunc := jutil.GetEnv() defer freeFunc() jReason, err := JavaContextDoneReason(env, ctx.Err()) if err != nil { return jutil.NullObject, err } // Must grab a global reference as we free up the env and all local references that come along // with it. return jutil.NewGlobalRef(env, jReason), nil // Un-refed in DoAsyncCall }) }