-
Notifications
You must be signed in to change notification settings - Fork 2
/
jni.go
78 lines (68 loc) · 1.83 KB
/
jni.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build java android
package jni
import (
"os"
"unsafe"
"v.io/x/lib/vlog"
jgoogle "v.io/x/jni/impl/google"
jutil "v.io/x/jni/util"
jv23 "v.io/x/jni/v23"
)
// #include "jni.h"
import "C"
//export Java_io_v_v23_V_nativeInitGlobalShared
func Java_io_v_v23_V_nativeInitGlobalShared(jenv *C.JNIEnv, jVClass C.jclass) {
env := jutil.Env(uintptr(unsafe.Pointer(jenv)))
// Ignore all args except for the first one.
if len(os.Args) > 1 {
os.Args = os.Args[:1]
}
// Send all vlog logs to stderr during the init so that we don't crash on android trying
// to create a log file. These settings will be overwritten in
// nativeInitJava/nativeInitAndroid.
vlog.Log.Configure(vlog.OverridePriorConfiguration(true), vlog.LogToStderr(true))
if err := jutil.Init(env); err != nil {
jutil.JThrowV(env, err)
return
}
if err := jv23.Init(env); err != nil {
jutil.JThrowV(env, err)
return
}
if err := jgoogle.Init(env); err != nil {
jutil.JThrowV(env, err)
return
}
}
func loggingOpts(env jutil.Env, jOpts jutil.Object) (dir vlog.LogDir, toStderr vlog.LogToStderr, level vlog.Level, vmodule vlog.ModuleSpec, err error) {
var d string
d, err = jutil.GetStringOption(env, jOpts, "io.v.v23.LOG_DIR")
if err != nil {
return
}
dir = vlog.LogDir(d)
var s bool
s, err = jutil.GetBooleanOption(env, jOpts, "io.v.v23.LOG_TO_STDERR")
if err != nil {
return
}
toStderr = vlog.LogToStderr(s)
var l int
l, err = jutil.GetIntOption(env, jOpts, "io.v.v23.LOG_VLEVEL")
if err != nil {
return
}
level = vlog.Level(l)
var m string
m, err = jutil.GetStringOption(env, jOpts, "io.v.v23.LOG_VMODULE")
if err != nil {
return
}
err = vmodule.Set(m)
return
}
func main() {
}