Пример #1
0
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
//export Java_io_v_v23_i18n_Catalog_nativeFormatParams
func Java_io_v_v23_i18n_Catalog_nativeFormatParams(jenv *C.JNIEnv, jCatalog C.jclass, jFormat C.jstring, jParams C.jobjectArray) C.jstring {
	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
	format := jutil.GoString(env, jutil.Object(uintptr(unsafe.Pointer(jFormat))))
	strParams, err := jutil.GoStringArray(env, jutil.Object(uintptr(unsafe.Pointer(jParams))))
	if err != nil {
		jutil.JThrowV(env, err)
		return nil
	}
	params := make([]interface{}, len(strParams))
	for i, strParam := range strParams {
		params[i] = strParam
	}
	result := i18n.FormatParams(format, params...)
	jRet := jutil.JString(env, result)
	return C.jstring(unsafe.Pointer(jRet))
}
Пример #3
0
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)
}
Пример #4
0
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
}
Пример #5
0
//export Java_io_v_impl_google_rpc_ServerCallImpl_nativeSuffix
func Java_io_v_impl_google_rpc_ServerCallImpl_nativeSuffix(jenv *C.JNIEnv, jServerCall C.jobject, goRef C.jlong) C.jstring {
	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
	jSuffix := jutil.JString(env, (*(*rpc.ServerCall)(jutil.GoRefValue(jutil.Ref(goRef)))).Suffix())
	return C.jstring(unsafe.Pointer(jSuffix))
}
Пример #6
0
//export Java_io_v_v23_security_BlessingStoreImpl_nativeToString
func Java_io_v_v23_security_BlessingStoreImpl_nativeToString(jenv *C.JNIEnv, jBlessingStoreImpl C.jobject, goRef C.jlong) C.jstring {
	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
	str := fmt.Sprintf("%s", (*(*security.BlessingStore)(jutil.GoRefValue(jutil.Ref(goRef)))))
	jStr := jutil.JString(env, str)
	return C.jstring(unsafe.Pointer(jStr))
}
Пример #7
0
//export Java_io_v_v23_security_BlessingStoreImpl_nativeDebugString
func Java_io_v_v23_security_BlessingStoreImpl_nativeDebugString(jenv *C.JNIEnv, jBlessingStoreImpl C.jobject, goRef C.jlong) C.jstring {
	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
	debug := (*(*security.BlessingStore)(jutil.GoRefValue(jutil.Ref(goRef)))).DebugString()
	jDebug := jutil.JString(env, debug)
	return C.jstring(unsafe.Pointer(jDebug))
}
Пример #8
0
//export Java_io_v_v23_security_CallImpl_nativeRemoteEndpoint
func Java_io_v_v23_security_CallImpl_nativeRemoteEndpoint(jenv *C.JNIEnv, jCall C.jobject, goRef C.jlong) C.jstring {
	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
	jEndpoint := jutil.JString(env, (*(*security.Call)(jutil.GoRefValue(jutil.Ref(goRef)))).RemoteEndpoint().String())
	return C.jstring(unsafe.Pointer(jEndpoint))

}
Пример #9
0
//export Java_io_v_v23_security_CallImpl_nativeMethod
func Java_io_v_v23_security_CallImpl_nativeMethod(jenv *C.JNIEnv, jCall C.jobject, goRef C.jlong) C.jstring {
	env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
	method := (*(*security.Call)(jutil.GoRefValue(jutil.Ref(goRef)))).Method()
	jMethod := jutil.JString(env, jutil.CamelCase(method))
	return C.jstring(unsafe.Pointer(jMethod))
}
Пример #10
0
// 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
}