//export Java_io_v_impl_google_rpc_ServerRPCHelper_nativeGoAuthorizer func Java_io_v_impl_google_rpc_ServerRPCHelper_nativeGoAuthorizer(jenv *C.JNIEnv, jServerRPCHelper C.jclass, jAuthorizer C.jobject) C.jlong { env := jutil.Env(uintptr(unsafe.Pointer(jenv))) auth, err := jsecurity.GoAuthorizer(env, jutil.Object(uintptr(unsafe.Pointer(jAuthorizer)))) if err != nil { jutil.JThrowV(env, err) return C.jlong(0) } ref := jutil.GoNewRef(&auth) // Un-refed when the Go authorizer is returned to the Go runtime return C.jlong(ref) }
//export Java_io_v_v23_security_access_AccessList_nativeCreate func Java_io_v_v23_security_access_AccessList_nativeCreate(jenv *C.JNIEnv, jAccessList C.jobject) C.jlong { env := jutil.Env(uintptr(unsafe.Pointer(jenv))) acl, err := GoAccessList(env, jutil.Object(uintptr(unsafe.Pointer(jAccessList)))) if err != nil { jutil.JThrowV(env, err) return C.jlong(0) } ref := jutil.GoNewRef(&acl) // Un-refed when the AccessList object is finalized return C.jlong(ref) }
//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) }
func (self *Environment) setLongField(z interface{}, static bool, name string, val int64) (err error) { jval, field, err := self.getField(z, static, name, types.Basic(types.IntKind)) if err != nil { return } if static { C.envSetStaticLongField(self.env, C.valObject(jval), field.field, C.jlong(val)) } else { C.envSetLongField(self.env, C.valObject(jval), field.field, C.jlong(val)) } if self.ExceptionCheck() { err = self.ExceptionOccurred() } return }
func jLongValue(v interface{}) (C.jvalue, error) { val, ok := intValue(v) if !ok { return errJValue, fmt.Errorf("%#v isn't long", v) } return C.jLongValue(C.jlong(val)), nil }
func requestLocationUpdates(provider string, minTime int64, minDistance float32) { err := mobileinit.RunOnJVM(func(vm, env, ctx uintptr) error { cProvider := C.CString(provider) defer C.free(unsafe.Pointer(cProvider)) C.location_manager_requestLocationUpdates(C.uintptr_t(vm), C.uintptr_t(env), C.uintptr_t(ctx), cProvider, C.jlong(minTime), C.jfloat(minDistance)) return nil }) if err != nil { log.Fatalf("requestLocationUpdates: %v", err) } log.Print("requestLocationUpdates succeeded") }
// TODO(refcounting): any constructed objects will be leaked on call return, // as nothing cleans up proxy objects. I'm also torn on how to differentiate // the objects made here and those coming in from other references. // // Refcounting attempt 1, objects _we_ construct will be returned in the objStack, // otherwise refcounts of 'pass-through' java natives are untouched by the call to newArgList. // // On error, the stack has already been blown (and will be empty). func newArgList(ctx *Environment, params ...interface{}) (alp argList, objStack []*Object, err error) { alp = make(argList, 0) defer func() { if err != nil { blowStack(ctx, objStack) objStack = []*Object{} } }() for i, param := range params { var ok C.int switch v := param.(type) { case int: alp = append(alp, C.intValue(C.jint(v))) case int64: alp = append(alp, C.longValue(C.jlong(v))) case C.jstring: alp = append(alp, C.objValue(v)) case C.jboolean: alp = append(alp, C.boolValue(v)) case C.jint: alp = append(alp, C.intValue(v)) case C.jobject: alp = append(alp, C.objValue(v)) case *Object: alp = append(alp, C.objValue(v.object)) case *Class: alp = append(alp, C.objValue(v.class)) case C.jvalue: alp = append(alp, v) case string: var str *Object str, err = ctx.NewStringObject(v) if err == nil { objStack = append(objStack, str) alp = append(alp, C.objValue(str.object)) } case []string: var klass *Class var obj *Object klass, err = ctx.GetClassStr("java/lang/String") // classes via this channel are cached and globally referenced by gojvm, not stacked. if err == nil { obj, err = ctx.newObjectArray(len(v), klass, nil) } if err == nil { objStack = append(objStack, obj) for i, s := range v { var str *Object str, err = ctx.NewStringObject(s) if err == nil { // I'm assuming stuffing the array adds a reference inside the JVM. defer ctx.DeleteLocalRef(str) ctx.setObjectArrayElement(obj, i, str) if ctx.ExceptionCheck() { err = ctx.ExceptionOccurred() } } if err != nil { break } } } if err == nil { alp = append(alp, C.objValue(obj.object)) } case []byte: var obj *Object obj, err = ctx.newByteObject(v) if err == nil { alp = append(alp, C.objValue(obj.object)) } objStack = append(objStack, obj) case bool: val := C.jboolean(C.JNI_FALSE) if v { val = C.JNI_TRUE } alp = append(alp, C.boolValue(val)) default: err = errors.New(fmt.Sprintf("Unknown type: %T/%s", v, v)) } if ok != 0 { err = errors.New("Couldn't parse arg #" + strconv.Itoa(i+1)) } if err != nil { break } } return }
//export Java_io_v_v23_security_BlessingPattern_nativeCreate func Java_io_v_v23_security_BlessingPattern_nativeCreate(jenv *C.JNIEnv, jBlessingPatternClass C.jclass, jValue C.jstring) C.jlong { env := jutil.Env(uintptr(unsafe.Pointer(jenv))) pattern := security.BlessingPattern(jutil.GoString(env, jutil.Object(uintptr(unsafe.Pointer(jValue))))) ref := jutil.GoNewRef(&pattern) // Un-refed when the BlessingPattern object is finalized. return C.jlong(ref) }