Esempio n. 1
0
//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
	})
}
Esempio n. 2
0
// GoPermissions converts the provided Java Permissions into a Go Permissions.
func GoPermissions(env jutil.Env, jPermissions jutil.Object) (perms access.Permissions, err error) {
	if jPermissions.IsNull() {
		return
	}
	err = jutil.GoVomCopy(env, jPermissions, jPermissionsClass, &perms)
	return
}
Esempio n. 3
0
func (i *invoker) Signature(ctx *context.T, call rpc.ServerCall) ([]signature.Interface, error) {
	env, freeFunc := jutil.GetEnv()
	jContext, err := jcontext.JavaContext(env, ctx, nil)
	if err != nil {
		freeFunc()
		return nil, err
	}
	// This method will invoke the freeFunc().
	jInterfaces, err := jutil.CallFutureMethod(env, freeFunc, i.jInvoker, "getSignature", []jutil.Sign{contextSign}, jContext)
	if err != nil {
		return nil, err
	}
	env, freeFunc = jutil.GetEnv()
	defer freeFunc()
	defer jutil.DeleteGlobalRef(env, jInterfaces)
	interfacesArr, err := jutil.GoObjectArray(env, jInterfaces)
	if err != nil {
		return nil, err
	}
	result := make([]signature.Interface, len(interfacesArr))
	for i, jInterface := range interfacesArr {
		err = jutil.GoVomCopy(env, jInterface, jInterfaceClass, &result[i])
		if err != nil {
			return nil, err
		}
	}
	return result, nil
}
Esempio n. 4
0
// GoAccessList converts the provided Java AccessList into a Go AccessList.
func GoAccessList(env jutil.Env, jAccessList jutil.Object) (acl access.AccessList, err error) {
	if jAccessList.IsNull() {
		return
	}
	err = jutil.GoVomCopy(env, jAccessList, jAccessListClass, &acl)
	return
}
Esempio n. 5
0
// GoDischarge converts the provided Java Discharge into a Go Discharge.
func GoDischarge(env jutil.Env, jDischarge jutil.Object) (security.Discharge, error) {
	var discharge security.Discharge
	if err := jutil.GoVomCopy(env, jDischarge, jDischargeClass, &discharge); err != nil {
		return security.Discharge{}, err
	}
	return discharge, nil
}
Esempio n. 6
0
//export Java_io_v_v23_security_Blessings_nativeCreate
func Java_io_v_v23_security_Blessings_nativeCreate(jenv *C.JNIEnv, jBlessingsClass C.jclass, jWire C.jobject) C.jlong {
	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
	var blessings security.Blessings
	if err := jutil.GoVomCopy(env, jutil.Object(uintptr(unsafe.Pointer(jWire))), jWireBlessingsClass, &blessings); err != nil {
		jutil.JThrowV(env, err)
		return C.jlong(0)
	}
	ref := jutil.GoNewRef(&blessings) // Un-refed when the Java Blessings object is finalized.
	return C.jlong(ref)
}
Esempio n. 7
0
func setPermissionsArgs(env jutil.Env, jContext, jPermissions C.jobject, jName, jVersion C.jstring, jOptions C.jobject) (context *context.T, permissions access.Permissions, name, version string, options []naming.NamespaceOpt, err error) {
	context, _, err = jcontext.GoContext(env, jutil.Object(uintptr(unsafe.Pointer(jContext))))
	if err != nil {
		return
	}
	err = jutil.GoVomCopy(env, jutil.Object(uintptr(unsafe.Pointer(jPermissions))), jPermissionsClass, &permissions)
	if err != nil {
		return
	}
	options, err = goNamespaceOptions(env, jutil.Object(uintptr(unsafe.Pointer(jOptions))))
	name = jutil.GoString(env, jutil.Object(uintptr(unsafe.Pointer(jName))))
	version = jutil.GoString(env, jutil.Object(uintptr(unsafe.Pointer(jVersion))))
	return
}
Esempio n. 8
0
func getPreresolved(env jutil.Env, obj jutil.Object) (*naming.MountEntry, error) {
	jMountEntry, err := jutil.JObjectField(env, obj, "preresolved", mountEntrySign)
	if err != nil {
		return nil, err
	}

	if !jMountEntry.IsNull() {
		var mountEntry naming.MountEntry
		if err := jutil.GoVomCopy(env, obj, jnamespace.JMountEntryClass, &mountEntry); err != nil {
			return nil, err
		}
		return &mountEntry, nil
	}
	return nil, nil
}
Esempio n. 9
0
func (j javaGlobber) Glob__(ctx *context.T, call rpc.GlobServerCall, g *glob.Glob) error {
	// TODO(sjr,rthellend): Update the Java API to match the new GO API.
	env, freeFunc := jutil.GetEnv()
	jContext, err := jcontext.JavaContext(env, ctx, nil)
	if err != nil {
		freeFunc()
		return err
	}
	jServerCall, err := JavaServerCall(env, call)
	if err != nil {
		freeFunc()
		return err
	}
	convert := func(input jutil.Object) (interface{}, error) {
		env, freeFunc := jutil.GetEnv()
		defer freeFunc()
		var reply naming.GlobReply
		if err := jutil.GoVomCopy(env, input, jGlobReplyClass, &reply); err != nil {
			return nil, err
		}
		return reply, nil
	}
	send := func(item interface{}) error {
		reply, ok := item.(naming.GlobReply)
		if !ok {
			return fmt.Errorf("Expected item of type naming.GlobReply, got: %T", reply)
		}
		return call.SendStream().Send(reply)
	}
	close := func() error {
		return nil
	}
	jOutputChannel, err := jchannel.JavaOutputChannel(env, ctx, nil, convert, send, close)
	if err != nil {
		freeFunc()
		return err
	}
	channelSign := jutil.ClassSign("io.v.v23.OutputChannel")
	// This method will invoke the freeFunc().
	_, err = jutil.CallStaticFutureMethod(env, freeFunc, jServerRPCHelperClass, "glob", []jutil.Sign{invokerSign, contextSign, serverCallSign, jutil.StringSign, channelSign}, j.i.jInvoker, jContext, jServerCall, g.String(), jOutputChannel)
	return err
}
Esempio n. 10
0
//export Java_io_v_v23_security_BlessingStoreImpl_nativeCacheDischarge
func Java_io_v_v23_security_BlessingStoreImpl_nativeCacheDischarge(jenv *C.JNIEnv, jBlessingStoreImpl C.jobject, goRef C.jlong, jDischarge C.jobject, jCaveat C.jobject, jImpetus C.jobject) {
	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
	blessingStore := *(*security.BlessingStore)(jutil.GoRefValue(jutil.Ref(goRef)))
	discharge, err := GoDischarge(env, jutil.Object(uintptr(unsafe.Pointer(jDischarge))))
	if err != nil {
		jutil.JThrowV(env, err)
		return
	}
	caveat, err := GoCaveat(env, jutil.Object(uintptr(unsafe.Pointer(jCaveat))))
	if err != nil {
		jutil.JThrowV(env, err)
		return
	}
	var impetus security.DischargeImpetus
	err = jutil.GoVomCopy(env, jutil.Object(uintptr(unsafe.Pointer(jImpetus))), jDischargeImpetusClass, &impetus)
	if err != nil {
		jutil.JThrowV(env, err)
		return
	}
	blessingStore.CacheDischarge(discharge, caveat, impetus)
}
Esempio n. 11
0
func (i *invoker) MethodSignature(ctx *context.T, call rpc.ServerCall, method string) (signature.Method, error) {
	env, freeFunc := jutil.GetEnv()
	jContext, err := jcontext.JavaContext(env, ctx, nil)
	if err != nil {
		freeFunc()
		return signature.Method{}, err
	}
	// This method will invoke the freeFunc().
	jMethod, err := jutil.CallFutureMethod(env, freeFunc, i.jInvoker, "getMethodSignature", []jutil.Sign{contextSign, jutil.StringSign}, jContext, method)
	if err != nil {
		return signature.Method{}, err
	}
	env, freeFunc = jutil.GetEnv()
	defer freeFunc()
	defer jutil.DeleteGlobalRef(env, jMethod)
	var result signature.Method
	err = jutil.GoVomCopy(env, jMethod, jMethodClass, &result)
	if err != nil {
		return signature.Method{}, err
	}
	return result, nil
}
Esempio n. 12
0
//export Java_io_v_v23_security_BlessingStoreImpl_nativeDischarge
func Java_io_v_v23_security_BlessingStoreImpl_nativeDischarge(jenv *C.JNIEnv, jBlessingStoreImpl C.jobject, goRef C.jlong, jCaveat C.jobject, jImpetus C.jobject) C.jobject {
	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
	blessingStore := *(*security.BlessingStore)(jutil.GoRefValue(jutil.Ref(goRef)))
	caveat, err := GoCaveat(env, jutil.Object(uintptr(unsafe.Pointer(jCaveat))))
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	var impetus security.DischargeImpetus
	err = jutil.GoVomCopy(env, jutil.Object(uintptr(unsafe.Pointer(jImpetus))), jDischargeImpetusClass, &impetus)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	// TODO(sjr): support cachedTime in Java
	discharge, _ := blessingStore.Discharge(caveat, impetus)
	jDischarge, err := JavaDischarge(env, discharge)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	return C.jobject(unsafe.Pointer(jDischarge))
}