示例#1
0
文件: util.go 项目: vanadium/go.jni
func javaDischargeMap(env jutil.Env, discharges map[string]security.Discharge) (jutil.Object, error) {
	objectMap := make(map[jutil.Object]jutil.Object)
	for key, discharge := range discharges {
		jKey := jutil.JString(env, key)
		jDischarge, err := JavaDischarge(env, discharge)
		if err != nil {
			return jutil.NullObject, err
		}
		objectMap[jKey] = jDischarge
	}
	return jutil.JObjectMap(env, objectMap)
}
示例#2
0
文件: driver.go 项目: vanadium/go.jni
func (d *driver) AddService(uuid string, characteristics map[string][]byte) error {
	env, freeFunc := jutil.GetEnv()
	defer freeFunc()

	csObjMap := make(map[jutil.Object]jutil.Object, len(characteristics))
	for uuid, characteristic := range characteristics {
		jUuid := jutil.JString(env, uuid)
		jCharacteristic, err := jutil.JByteArray(env, characteristic)
		if err != nil {
			return err
		}
		csObjMap[jUuid] = jCharacteristic
	}
	jCharacteristics, err := jutil.JObjectMap(env, csObjMap)
	if err != nil {
		return err
	}
	return jutil.CallVoidMethod(env, d.jDriver, "addService", []jutil.Sign{jutil.StringSign, jutil.MapSign}, uuid, jCharacteristics)
}
示例#3
0
文件: jni.go 项目: vanadium/go.jni
func doGetPermissions(n namespace.T, context *context.T, name string, options []naming.NamespaceOpt) (jutil.Object, error) {
	permissions, version, err := n.GetPermissions(context, name, options...)
	if err != nil {
		return jutil.NullObject, err
	}
	env, freeFunc := jutil.GetEnv()
	defer freeFunc()
	jPermissions, err := jutil.JVomCopy(env, permissions, jPermissionsClass)
	if err != nil {
		return jutil.NullObject, err
	}
	result := make(map[jutil.Object]jutil.Object)
	result[jutil.JString(env, version)] = jPermissions
	jResult, err := jutil.JObjectMap(env, result)
	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
}
示例#4
0
文件: jni.go 项目: vanadium/go.jni
//export Java_io_v_v23_security_BlessingStoreImpl_nativePeerBlessings
func Java_io_v_v23_security_BlessingStoreImpl_nativePeerBlessings(jenv *C.JNIEnv, jBlessingStoreImpl C.jobject, goRef C.jlong) C.jobject {
	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
	blessingsMap := (*(*security.BlessingStore)(jutil.GoRefValue(jutil.Ref(goRef)))).PeerBlessings()
	bmap := make(map[jutil.Object]jutil.Object)
	for pattern, blessings := range blessingsMap {
		jPattern, err := JavaBlessingPattern(env, pattern)
		if err != nil {
			jutil.JThrowV(env, err)
			return nil
		}
		jBlessings, err := JavaBlessings(env, blessings)
		if err != nil {
			jutil.JThrowV(env, err)
			return nil
		}
		bmap[jPattern] = jBlessings
	}
	jBlessingsMap, err := jutil.JObjectMap(env, bmap)
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	return C.jobject(unsafe.Pointer(jBlessingsMap))
}
示例#5
0
文件: util.go 项目: vanadium/go.jni
// JavaServerStatus converts the provided rpc.ServerStatus value into a Java
// ServerStatus object.
func JavaServerStatus(env jutil.Env, status rpc.ServerStatus) (jutil.Object, error) {
	// Create Java state enum value.
	jState, err := JavaServerState(env, status.State)
	if err != nil {
		return jutil.NullObject, err
	}

	// Create Java array of publisher entries.
	pubarr := make([]jutil.Object, len(status.PublisherStatus))
	for i, e := range status.PublisherStatus {
		var err error
		if pubarr[i], err = JavaPublisherEntry(env, e); err != nil {
			return jutil.NullObject, err
		}
	}
	jPublisherStatus, err := jutil.JObjectArray(env, pubarr, jPublisherEntryClass)
	if err != nil {
		return jutil.NullObject, err
	}

	// Create an array of endpoint strings.
	eps := make([]string, len(status.Endpoints))
	for i, ep := range status.Endpoints {
		eps[i] = ep.String()
	}

	lnErrors := make(map[jutil.Object]jutil.Object)
	for addr, lerr := range status.ListenErrors {
		jAddr, err := JavaListenAddr(env, addr.Protocol, addr.Address)
		if err != nil {
			return jutil.NullObject, err
		}
		jVExp, err := jutil.JVException(env, lerr)
		if err != nil {
			return jutil.NullObject, err
		}
		lnErrors[jAddr] = jVExp
	}
	jLnErrors, err := jutil.JObjectMap(env, lnErrors)
	if err != nil {
		return jutil.NullObject, err
	}

	proxyErrors := make(map[jutil.Object]jutil.Object)
	for s, perr := range status.ProxyErrors {
		jVExp, err := jutil.JVException(env, perr)
		if err != nil {
			return jutil.NullObject, err
		}
		proxyErrors[jutil.JString(env, s)] = jVExp
	}
	jProxyErrors, err := jutil.JObjectMap(env, proxyErrors)
	if err != nil {
		return jutil.NullObject, err
	}

	// Create final server status.
	publisherEntrySign := jutil.ClassSign("io.v.v23.rpc.PublisherEntry")
	jServerStatus, err := jutil.NewObject(env, jServerStatusClass, []jutil.Sign{serverStateSign, jutil.BoolSign, jutil.ArraySign(publisherEntrySign), jutil.ArraySign(jutil.StringSign), jutil.MapSign, jutil.MapSign}, jState, status.ServesMountTable, jPublisherStatus, eps, jLnErrors, jProxyErrors)
	if err != nil {
		return jutil.NullObject, err
	}
	return jServerStatus, nil
}