//export Java_io_v_impl_google_lib_discovery_UpdateImpl_nativeAttachment func Java_io_v_impl_google_lib_discovery_UpdateImpl_nativeAttachment(jenv *C.JNIEnv, _ C.jobject, goRef C.jlong, jCtx C.jobject, jName C.jstring, jCbObj C.jobject) { env := jutil.Env(uintptr(unsafe.Pointer(jenv))) ctx, _, err := jcontext.GoContext(env, jutil.Object(uintptr(unsafe.Pointer(jCtx)))) if err != nil { jutil.JThrowV(env, err) return } update := *(*discovery.Update)(jutil.GoRefValue(jutil.Ref(goRef))) name := jutil.GoString(env, jutil.Object(uintptr(unsafe.Pointer(jName)))) jCb := jutil.Object(uintptr(unsafe.Pointer(jCbObj))) jutil.DoAsyncCall(env, jCb, func() (jutil.Object, error) { dataOrErr := <-update.Attachment(ctx, name) if dataOrErr.Error != nil { return jutil.NullObject, err } env, freeFunc := jutil.GetEnv() defer freeFunc() jData, err := jutil.JByteArray(env, dataOrErr.Data) 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, jData), nil // Un-refed in DoAsyncCall }) }
//export Java_io_v_impl_google_rpc_ClientCallImpl_nativeCloseSend func Java_io_v_impl_google_rpc_ClientCallImpl_nativeCloseSend(jenv *C.JNIEnv, jCall C.jobject, goRef C.jlong, jCallbackObj C.jobject) { env := jutil.Env(uintptr(unsafe.Pointer(jenv))) jCallback := jutil.Object(uintptr(unsafe.Pointer(jCallbackObj))) jutil.DoAsyncCall(env, jCallback, func() (jutil.Object, error) { return jutil.NullObject, (*(*rpc.ClientCall)(jutil.GoRefValue(jutil.Ref(goRef)))).CloseSend() }) }
//export Java_io_v_impl_google_rpc_StreamImpl_nativeRecv func Java_io_v_impl_google_rpc_StreamImpl_nativeRecv(jenv *C.JNIEnv, jStream C.jobject, goRef C.jlong, jCallbackObj C.jobject) { env := jutil.Env(uintptr(unsafe.Pointer(jenv))) jCallback := jutil.Object(uintptr(unsafe.Pointer(jCallbackObj))) result := new(vdl.Value) jutil.DoAsyncCall(env, jCallback, func() (jutil.Object, error) { if err := (*(*rpc.Stream)(jutil.GoRefValue(jutil.Ref(goRef)))).Recv(&result); err != nil { if err == io.EOF { // Java uses EndOfFile error to detect EOF. err = verror.NewErrEndOfFile(nil) } return jutil.NullObject, err } vomResult, err := vom.Encode(result) if err != nil { return jutil.NullObject, err } env, freeFunc := jutil.GetEnv() defer freeFunc() jResult, err := jutil.JByteArray(env, vomResult) 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, jResult), nil // Un-refed in DoAsyncCall }) }
//export Java_io_v_impl_google_rpc_ClientCallImpl_nativeFinish func Java_io_v_impl_google_rpc_ClientCallImpl_nativeFinish(jenv *C.JNIEnv, jCall C.jobject, goRef C.jlong, jNumResults C.jint, jCallbackObj C.jobject) { env := jutil.Env(uintptr(unsafe.Pointer(jenv))) numResults := int(jNumResults) jCallback := jutil.Object(uintptr(unsafe.Pointer(jCallbackObj))) jutil.DoAsyncCall(env, jCallback, func() (jutil.Object, error) { return doFinish(goRef, numResults) }) }
//export Java_io_v_impl_google_channel_OutputChannelImpl_nativeClose func Java_io_v_impl_google_channel_OutputChannelImpl_nativeClose(jenv *C.JNIEnv, jOutputChannelClass C.jclass, goCloseRef C.jlong, jCallbackObj C.jobject) { env := jutil.Env(uintptr(unsafe.Pointer(jenv))) close := *(*func() error)(jutil.GoRefValue(jutil.Ref(goCloseRef))) jCallback := jutil.Object(uintptr(unsafe.Pointer(jCallbackObj))) jutil.DoAsyncCall(env, jCallback, func() (jutil.Object, error) { return jutil.NullObject, close() }) }
//export Java_io_v_impl_google_lib_discovery_DiscoveryImpl_nativeAdvertise func Java_io_v_impl_google_lib_discovery_DiscoveryImpl_nativeAdvertise(jenv *C.JNIEnv, _ C.jobject, goRef C.jlong, jCtx C.jobject, jAdObj C.jobject, jVisibilityObj C.jobject, jCbObj C.jobject) { env := jutil.Env(uintptr(unsafe.Pointer(jenv))) ctx, _, err := jcontext.GoContext(env, jutil.Object(uintptr(unsafe.Pointer(jCtx)))) if err != nil { jutil.JThrowV(env, err) return } d := *(*discovery.T)(jutil.GoRefValue(jutil.Ref(goRef))) jAd := jutil.Object(uintptr(unsafe.Pointer(jAdObj))) jVisibility := jutil.Object(uintptr(unsafe.Pointer(jVisibilityObj))) var ad discovery.Advertisement if err := jutil.GoVomCopy(env, jAd, jAdvertisementClass, &ad); err != nil { jutil.JThrowV(env, err) return } jVisibilityList, err := jutil.GoObjectList(env, jVisibility) if err != nil { jutil.JThrowV(env, err) return } visibility := make([]security.BlessingPattern, len(jVisibilityList)) for i, jPattern := range jVisibilityList { if err := jutil.GoVomCopy(env, jPattern, jBlessingPatternClass, &visibility[i]); err != nil { jutil.JThrowV(env, err) return } } done, err := d.Advertise(ctx, &ad, visibility) if err != nil { jutil.JThrowV(env, err) return } // Copy back the advertisement id. jId, err := jutil.JVomCopy(env, &ad.Id, jAdIdClass) if err != nil { jutil.JThrowV(env, err) return } if err = jutil.CallVoidMethod(env, jAd, "setId", []jutil.Sign{adIdSign}, jId); err != nil { jutil.JThrowV(env, err) return } jCb := jutil.Object(uintptr(unsafe.Pointer(jCbObj))) jutil.DoAsyncCall(env, jCb, func() (jutil.Object, error) { <-done return jutil.NullObject, nil }) }
//export Java_io_v_impl_google_rpc_StreamImpl_nativeSend func Java_io_v_impl_google_rpc_StreamImpl_nativeSend(jenv *C.JNIEnv, jStream C.jobject, goRef C.jlong, jVomItem C.jbyteArray, jCallbackObj C.jobject) { env := jutil.Env(uintptr(unsafe.Pointer(jenv))) jCallback := jutil.Object(uintptr(unsafe.Pointer(jCallbackObj))) vomItem := jutil.GoByteArray(env, jutil.Object(uintptr(unsafe.Pointer(jVomItem)))) jutil.DoAsyncCall(env, jCallback, func() (jutil.Object, error) { item, err := jutil.VomDecodeToValue(vomItem) if err != nil { return jutil.NullObject, err } return jutil.NullObject, (*(*rpc.Stream)(jutil.GoRefValue(jutil.Ref(goRef)))).Send(item) }) }
//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_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_impl_google_rpc_ServerImpl_nativeAllPublished func Java_io_v_impl_google_rpc_ServerImpl_nativeAllPublished(jenv *C.JNIEnv, jServer C.jobject, goRef C.jlong, jContext C.jobject, jCallbackObj C.jobject) { env := jutil.Env(uintptr(unsafe.Pointer(jenv))) server := *(*rpc.Server)(jutil.GoRefValue(jutil.Ref(goRef))) jCallback := jutil.Object(uintptr(unsafe.Pointer(jCallbackObj))) jutil.DoAsyncCall(env, jCallback, func() (jutil.Object, error) { for { status := server.Status() done := true for _, pub := range status.PublisherStatus { if pub.LastState != pub.DesiredState { done = false break } } if done { break } <-status.Dirty } return jutil.NullObject, nil }) }
//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 }) }
//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_InputChannelImpl_nativeRecv func Java_io_v_impl_google_channel_InputChannelImpl_nativeRecv(jenv *C.JNIEnv, jInputChannelImpl C.jobject, goRecvRef C.jlong, jCallbackObj C.jobject) { env := jutil.Env(uintptr(unsafe.Pointer(jenv))) recv := *(*func() (jutil.Object, error))(jutil.GoRefValue(jutil.Ref(goRecvRef))) jCallback := jutil.Object(uintptr(unsafe.Pointer(jCallbackObj))) jutil.DoAsyncCall(env, jCallback, recv) }