blob: 3f7224ea3f7fd93eda3f9d058b6ecfd5dab87fc9 [file] [log] [blame]
Jiri Simsa5293dcb2014-05-10 09:56:38 -07001// +build android
2
Srdjan Petrovice2f5fce2014-08-21 15:07:24 -07003package ipc
Jiri Simsa5293dcb2014-05-10 09:56:38 -07004
5import (
Srdjan Petrovic16376622014-06-04 13:49:42 -07006 "io"
7 "time"
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -07008 "unsafe"
Jiri Simsa5293dcb2014-05-10 09:56:38 -07009
Srdjan Petrovice2f5fce2014-08-21 15:07:24 -070010 jnisecurity "veyron/jni/runtimes/google/security"
11 "veyron/jni/runtimes/google/util"
Srdjan Petrovic16376622014-06-04 13:49:42 -070012 "veyron2"
Srdjan Petrovic96928962014-06-20 10:03:15 -070013 ctx "veyron2/context"
Jiri Simsa5293dcb2014-05-10 09:56:38 -070014 "veyron2/ipc"
15 "veyron2/rt"
Jiri Simsa5293dcb2014-05-10 09:56:38 -070016)
17
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -070018// #cgo LDFLAGS: -ljniwrapper
19// #include "jni_wrapper.h"
Jiri Simsa5293dcb2014-05-10 09:56:38 -070020// #include <stdlib.h>
Jiri Simsa5293dcb2014-05-10 09:56:38 -070021import "C"
22
23var (
Srdjan Petrovic16376622014-06-04 13:49:42 -070024 // Global reference for com.veyron.runtimes.google.ipc.Runtime$ServerCall class.
25 jServerCallClass C.jclass
Srdjan Petrovic96928962014-06-20 10:03:15 -070026 // Global reference for com.veyron.runtimes.google.ipc.VDLInvoker class.
27 jVDLInvokerClass C.jclass
Srdjan Petrovic86560d42014-08-01 17:23:15 -070028 // Global reference for com.veyron2.OptionDefs class.
29 jOptionDefsClass C.jclass
Srdjan Petrovic16376622014-06-04 13:49:42 -070030 // Global reference for java.io.EOFException class.
31 jEOFExceptionClass C.jclass
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -070032 // Global reference for java.lang.String class.
33 jStringClass C.jclass
Jiri Simsa5293dcb2014-05-10 09:56:38 -070034)
35
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -070036// Init initializes the JNI code with the given Java environment. This method
37// must be called from the main Java thread.
38// NOTE: Because CGO creates package-local types and because this method may be
39// invoked from a different package, Java environment is passed in an empty
40// interface and then cast into the package-local environment type.
41func Init(jEnv interface{}) {
42 env := (*C.JNIEnv)(unsafe.Pointer(util.PtrValue(jEnv)))
Jiri Simsa5293dcb2014-05-10 09:56:38 -070043 // Cache global references to all Java classes used by the package. This is
44 // necessary because JNI gets access to the class loader only in the system
45 // thread, so we aren't able to invoke FindClass in other threads.
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -070046 jServerCallClass = C.jclass(util.JFindClassPtrOrDie(env, "com/veyron/runtimes/google/Runtime$ServerCall"))
47 jVDLInvokerClass = C.jclass(util.JFindClassPtrOrDie(env, "com/veyron/runtimes/google/VDLInvoker"))
Srdjan Petrovic86560d42014-08-01 17:23:15 -070048 jOptionDefsClass = C.jclass(util.JFindClassPtrOrDie(env, "com/veyron2/OptionDefs"))
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -070049 jEOFExceptionClass = C.jclass(util.JFindClassPtrOrDie(env, "java/io/EOFException"))
50 jStringClass = C.jclass(util.JFindClassPtrOrDie(env, "java/lang/String"))
Jiri Simsa5293dcb2014-05-10 09:56:38 -070051}
52
Srdjan Petrovic96928962014-06-20 10:03:15 -070053//export Java_com_veyron_runtimes_google_Runtime_nativeInit
Srdjan Petrovic86560d42014-08-01 17:23:15 -070054func Java_com_veyron_runtimes_google_Runtime_nativeInit(env *C.JNIEnv, jRuntime C.jclass, jOptions C.jobject) C.jlong {
55 opts := goRuntimeOpts(env, jOptions)
56 r := rt.Init(opts...)
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -070057 util.GoRef(&r) // Un-refed when the Java Runtime object is finalized.
58 return C.jlong(util.PtrValue(&r))
Srdjan Petrovic16376622014-06-04 13:49:42 -070059}
60
Srdjan Petrovic86560d42014-08-01 17:23:15 -070061//export Java_com_veyron_runtimes_google_Runtime_nativeNewRuntime
62func Java_com_veyron_runtimes_google_Runtime_nativeNewRuntime(env *C.JNIEnv, jRuntime C.jclass, jOptions C.jobject) C.jlong {
63 opts := goRuntimeOpts(env, jOptions)
64 r, err := rt.New(opts...)
65 if err != nil {
66 util.JThrowV(env, err)
67 return C.jlong(0)
68 }
69 util.GoRef(&r)
70 return C.jlong(util.PtrValue(&r))
71}
72
73// goRuntimeOpts converts Java runtime options into Go runtime options.
74func goRuntimeOpts(env *C.JNIEnv, jOptions C.jobject) (ret []veyron2.ROpt) {
75 // Process RuntimeIDOpt.
76 runtimeIDKey := util.JStaticStringField(env, jOptionDefsClass, "RUNTIME_ID")
77 if util.CallBooleanMethodOrCatch(env, jOptions, "has", []util.Sign{util.StringSign}, runtimeIDKey) {
78 jPrivateID := C.jobject(util.CallObjectMethodOrCatch(env, jOptions, "get", []util.Sign{util.StringSign}, util.ObjectSign, runtimeIDKey))
79 id := jnisecurity.NewPrivateID(env, jPrivateID)
80 ret = append(ret, veyron2.RuntimeID(id))
81 }
Srdjan Petrovic7602c272014-08-21 13:56:28 -070082 // Process RuntimePublicIDStoreOpt
83 runtimePublicIDStoreKey := util.JStaticStringField(env, jOptionDefsClass, "RUNTIME_PUBLIC_ID_STORE")
84 if util.CallBooleanMethodOrCatch(env, jOptions, "has", []util.Sign{util.StringSign}, runtimePublicIDStoreKey) {
85 jStore := C.jobject(util.CallObjectMethodOrCatch(env, jOptions, "get", []util.Sign{util.StringSign}, util.ObjectSign, runtimePublicIDStoreKey))
86 store := jnisecurity.NewPublicIDStore(env, jStore)
87 ret = append(ret, veyron2.RuntimePublicIDStore(store))
88 }
Srdjan Petrovic86560d42014-08-01 17:23:15 -070089 return
90}
91
Srdjan Petrovic96928962014-06-20 10:03:15 -070092//export Java_com_veyron_runtimes_google_Runtime_nativeNewClient
Matt Rosencrantz137b8d22014-08-18 09:56:15 -070093// TODO(mattr): Eliminate timeoutMillis, it is no longer functional.
Srdjan Petrovic96928962014-06-20 10:03:15 -070094func Java_com_veyron_runtimes_google_Runtime_nativeNewClient(env *C.JNIEnv, jRuntime C.jobject, goRuntimePtr C.jlong, timeoutMillis C.jlong) C.jlong {
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -070095 r := (*veyron2.Runtime)(util.Ptr(goRuntimePtr))
Matt Rosencrantz137b8d22014-08-18 09:56:15 -070096 rc, err := (*r).NewClient()
Srdjan Petrovic16376622014-06-04 13:49:42 -070097 if err != nil {
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -070098 util.JThrowV(env, err)
Srdjan Petrovic16376622014-06-04 13:49:42 -070099 return C.jlong(0)
100 }
101 c := newClient(rc)
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -0700102 util.GoRef(c) // Un-refed when the Java Client object is finalized.
103 return C.jlong(util.PtrValue(c))
Srdjan Petrovic16376622014-06-04 13:49:42 -0700104}
Jiri Simsa5293dcb2014-05-10 09:56:38 -0700105
Srdjan Petrovic96928962014-06-20 10:03:15 -0700106//export Java_com_veyron_runtimes_google_Runtime_nativeNewServer
107func Java_com_veyron_runtimes_google_Runtime_nativeNewServer(env *C.JNIEnv, jRuntime C.jobject, goRuntimePtr C.jlong) C.jlong {
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -0700108 r := (*veyron2.Runtime)(util.Ptr(goRuntimePtr))
Srdjan Petrovic16376622014-06-04 13:49:42 -0700109 s, err := (*r).NewServer()
110 if err != nil {
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -0700111 util.JThrowV(env, err)
Srdjan Petrovic16376622014-06-04 13:49:42 -0700112 return C.jlong(0)
113 }
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -0700114 util.GoRef(&s) // Un-refed when the Java Server object is finalized.
115 return C.jlong(util.PtrValue(&s))
Srdjan Petrovic16376622014-06-04 13:49:42 -0700116}
117
Srdjan Petrovic96928962014-06-20 10:03:15 -0700118//export Java_com_veyron_runtimes_google_Runtime_nativeGetClient
119func Java_com_veyron_runtimes_google_Runtime_nativeGetClient(env *C.JNIEnv, jRuntime C.jobject, goRuntimePtr C.jlong) C.jlong {
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -0700120 r := (*veyron2.Runtime)(util.Ptr(goRuntimePtr))
Srdjan Petrovic16376622014-06-04 13:49:42 -0700121 rc := (*r).Client()
122 c := newClient(rc)
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -0700123 util.GoRef(c) // Un-refed when the Java Client object is finalized.
124 return C.jlong(util.PtrValue(c))
Srdjan Petrovic16376622014-06-04 13:49:42 -0700125}
126
Srdjan Petrovic96928962014-06-20 10:03:15 -0700127//export Java_com_veyron_runtimes_google_Runtime_nativeNewContext
128func Java_com_veyron_runtimes_google_Runtime_nativeNewContext(env *C.JNIEnv, jRuntime C.jobject, goRuntimePtr C.jlong) C.jlong {
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -0700129 r := (*veyron2.Runtime)(util.Ptr(goRuntimePtr))
Srdjan Petrovic16376622014-06-04 13:49:42 -0700130 c := (*r).NewContext()
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -0700131 util.GoRef(&c) // Un-refed when the Java context object is finalized.
132 return C.jlong(util.PtrValue(&c))
Srdjan Petrovic16376622014-06-04 13:49:42 -0700133}
134
Srdjan Petrovic731e8402014-08-22 09:58:32 -0700135//export Java_com_veyron_runtimes_google_Runtime_nativeGetPublicIDStore
136func Java_com_veyron_runtimes_google_Runtime_nativeGetPublicIDStore(env *C.JNIEnv, jRuntime C.jobject, goRuntimePtr C.jlong) C.jlong {
137 r := (*veyron2.Runtime)(util.Ptr(goRuntimePtr))
138 s := (*r).PublicIDStore()
139 util.GoRef(&s) // Un-refed when the Java PublicIDStore object is finalized.
140 return C.jlong(util.PtrValue(&s))
141}
142
Srdjan Petrovic96928962014-06-20 10:03:15 -0700143//export Java_com_veyron_runtimes_google_Runtime_nativeFinalize
144func Java_com_veyron_runtimes_google_Runtime_nativeFinalize(env *C.JNIEnv, jRuntime C.jobject, goRuntimePtr C.jlong) {
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -0700145 util.GoUnref((*veyron2.Runtime)(util.Ptr(goRuntimePtr)))
Jiri Simsa5293dcb2014-05-10 09:56:38 -0700146}
147
Srdjan Petrovic96928962014-06-20 10:03:15 -0700148//export Java_com_veyron_runtimes_google_Runtime_00024Server_nativeListen
149func Java_com_veyron_runtimes_google_Runtime_00024Server_nativeListen(env *C.JNIEnv, server C.jobject, goServerPtr C.jlong, protocol C.jstring, address C.jstring) C.jstring {
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -0700150 s := (*ipc.Server)(util.Ptr(goServerPtr))
151 ep, err := (*s).Listen(util.GoString(env, protocol), util.GoString(env, address))
Jiri Simsa5293dcb2014-05-10 09:56:38 -0700152 if err != nil {
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -0700153 util.JThrowV(env, err)
Jiri Simsa5293dcb2014-05-10 09:56:38 -0700154 return nil
155 }
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -0700156 return C.jstring(util.JStringPtr(env, ep.String()))
157}
158
159//export Java_com_veyron_runtimes_google_Runtime_00024Server_nativeServe
160func Java_com_veyron_runtimes_google_Runtime_00024Server_nativeServe(env *C.JNIEnv, jServer C.jobject, goServerPtr C.jlong, name C.jstring, jDispatcher C.jobject) {
161 s := (*ipc.Server)(util.Ptr(goServerPtr))
162 d, err := newDispatcher(env, jDispatcher)
163 if err != nil {
164 util.JThrowV(env, err)
165 return
166 }
167 if err := (*s).Serve(util.GoString(env, name), d); err != nil {
168 util.JThrowV(env, err)
169 return
170 }
171}
172
173//export Java_com_veyron_runtimes_google_Runtime_00024Server_nativeGetPublishedNames
174func Java_com_veyron_runtimes_google_Runtime_00024Server_nativeGetPublishedNames(env *C.JNIEnv, jServer C.jobject, goServerPtr C.jlong) C.jobjectArray {
175 names, err := (*(*ipc.Server)(util.Ptr(goServerPtr))).Published()
176 if err != nil {
177 util.JThrowV(env, err)
178 return nil
179 }
180 ret := C.NewObjectArray(env, C.jsize(len(names)), jStringClass, nil)
181 for i, name := range names {
182 C.SetObjectArrayElement(env, ret, C.jsize(i), C.jobject(util.JStringPtr(env, string(name))))
183 }
184 return ret
Jiri Simsa5293dcb2014-05-10 09:56:38 -0700185}
186
Benjamin Prosnitza0603d42014-06-27 09:27:56 -0700187//export Java_com_veyron_runtimes_google_Runtime_00024Server_nativeStop
188func Java_com_veyron_runtimes_google_Runtime_00024Server_nativeStop(env *C.JNIEnv, server C.jobject, goServerPtr C.jlong) {
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -0700189 s := (*ipc.Server)(util.Ptr(goServerPtr))
Srdjan Petrovic16376622014-06-04 13:49:42 -0700190 if err := (*s).Stop(); err != nil {
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -0700191 util.JThrowV(env, err)
Jiri Simsa5293dcb2014-05-10 09:56:38 -0700192 return
193 }
194}
195
Srdjan Petrovicec6f5112014-07-22 14:41:54 -0700196//export Java_com_veyron_runtimes_google_Runtime_00024Server_nativeFinalize
197func Java_com_veyron_runtimes_google_Runtime_00024Server_nativeFinalize(env *C.JNIEnv, server C.jobject, goServerPtr C.jlong) {
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -0700198 util.GoUnref((*ipc.Server)(util.Ptr(goServerPtr)))
Jiri Simsa5293dcb2014-05-10 09:56:38 -0700199}
200
Srdjan Petrovic96928962014-06-20 10:03:15 -0700201//export Java_com_veyron_runtimes_google_Runtime_00024Client_nativeStartCall
202func Java_com_veyron_runtimes_google_Runtime_00024Client_nativeStartCall(env *C.JNIEnv, jClient C.jobject, goClientPtr C.jlong, jContext C.jobject, name C.jstring, method C.jstring, jsonArgs C.jobjectArray, jPath C.jstring, timeoutMillis C.jlong) C.jlong {
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -0700203 c := (*client)(util.Ptr(goClientPtr))
204 call, err := c.StartCall(env, jContext, util.GoString(env, name), util.GoString(env, method), jsonArgs, jPath, timeoutMillis)
Jiri Simsa5293dcb2014-05-10 09:56:38 -0700205 if err != nil {
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -0700206 util.JThrowV(env, err)
Jiri Simsa5293dcb2014-05-10 09:56:38 -0700207 return C.jlong(0)
208 }
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -0700209 util.GoRef(call)
210 return C.jlong(util.PtrValue(call))
Jiri Simsa5293dcb2014-05-10 09:56:38 -0700211}
212
Srdjan Petrovic96928962014-06-20 10:03:15 -0700213//export Java_com_veyron_runtimes_google_Runtime_00024Client_nativeClose
214func Java_com_veyron_runtimes_google_Runtime_00024Client_nativeClose(env *C.JNIEnv, jClient C.jobject, goClientPtr C.jlong) {
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -0700215 (*client)(util.Ptr(goClientPtr)).Close()
Jiri Simsa5293dcb2014-05-10 09:56:38 -0700216}
217
Srdjan Petrovic96928962014-06-20 10:03:15 -0700218//export Java_com_veyron_runtimes_google_Runtime_00024Client_nativeFinalize
219func Java_com_veyron_runtimes_google_Runtime_00024Client_nativeFinalize(env *C.JNIEnv, jClient C.jobject, goClientPtr C.jlong) {
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -0700220 util.GoUnref((*client)(util.Ptr(goClientPtr)))
Jiri Simsa5293dcb2014-05-10 09:56:38 -0700221}
222
Srdjan Petrovic96928962014-06-20 10:03:15 -0700223//export Java_com_veyron_runtimes_google_Runtime_00024Context_nativeFinalize
224func Java_com_veyron_runtimes_google_Runtime_00024Context_nativeFinalize(env *C.JNIEnv, jClient C.jobject, goContextPtr C.jlong) {
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -0700225 util.GoUnref((*ctx.T)(util.Ptr(goContextPtr)))
Srdjan Petrovic16376622014-06-04 13:49:42 -0700226}
227
Srdjan Petrovic96928962014-06-20 10:03:15 -0700228//export Java_com_veyron_runtimes_google_Runtime_00024Stream_nativeSend
229func Java_com_veyron_runtimes_google_Runtime_00024Stream_nativeSend(env *C.JNIEnv, jStream C.jobject, goStreamPtr C.jlong, jItem C.jstring) {
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -0700230 (*stream)(util.Ptr(goStreamPtr)).Send(env, jItem)
Srdjan Petrovic16376622014-06-04 13:49:42 -0700231}
232
Srdjan Petrovic96928962014-06-20 10:03:15 -0700233//export Java_com_veyron_runtimes_google_Runtime_00024Stream_nativeRecv
234func Java_com_veyron_runtimes_google_Runtime_00024Stream_nativeRecv(env *C.JNIEnv, jStream C.jobject, goStreamPtr C.jlong) C.jstring {
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -0700235 ret, err := (*stream)(util.Ptr(goStreamPtr)).Recv(env)
Srdjan Petrovic16376622014-06-04 13:49:42 -0700236 if err != nil {
237 if err == io.EOF {
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -0700238 util.JThrow(env, jEOFExceptionClass, err.Error())
Srdjan Petrovic16376622014-06-04 13:49:42 -0700239 return nil
240 }
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -0700241 util.JThrowV(env, err)
Srdjan Petrovic16376622014-06-04 13:49:42 -0700242 return nil
243 }
244 return ret
245}
246
Srdjan Petrovic96928962014-06-20 10:03:15 -0700247//export Java_com_veyron_runtimes_google_Runtime_00024ClientCall_nativeFinish
248func Java_com_veyron_runtimes_google_Runtime_00024ClientCall_nativeFinish(env *C.JNIEnv, jClientCall C.jobject, goClientCallPtr C.jlong) C.jobjectArray {
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -0700249 ret, err := (*clientCall)(util.Ptr(goClientCallPtr)).Finish(env)
Jiri Simsa5293dcb2014-05-10 09:56:38 -0700250 if err != nil {
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -0700251 util.JThrowV(env, err)
Jiri Simsa5293dcb2014-05-10 09:56:38 -0700252 return nil
253 }
Jiri Simsa5293dcb2014-05-10 09:56:38 -0700254 return ret
255}
256
Srdjan Petrovic96928962014-06-20 10:03:15 -0700257//export Java_com_veyron_runtimes_google_Runtime_00024ClientCall_nativeCancel
258func Java_com_veyron_runtimes_google_Runtime_00024ClientCall_nativeCancel(env *C.JNIEnv, jClientCall C.jobject, goClientCallPtr C.jlong) {
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -0700259 (*clientCall)(util.Ptr(goClientCallPtr)).Cancel()
Srdjan Petrovic16376622014-06-04 13:49:42 -0700260}
261
Srdjan Petrovic96928962014-06-20 10:03:15 -0700262//export Java_com_veyron_runtimes_google_Runtime_00024ClientCall_nativeFinalize
263func Java_com_veyron_runtimes_google_Runtime_00024ClientCall_nativeFinalize(env *C.JNIEnv, jClientCall C.jobject, goClientCallPtr C.jlong) {
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -0700264 util.GoUnref((*clientCall)(util.Ptr(goClientCallPtr)))
265}
266
267//export Java_com_veyron_runtimes_google_Runtime_00024ServerCall_nativeBlessing
268func Java_com_veyron_runtimes_google_Runtime_00024ServerCall_nativeBlessing(env *C.JNIEnv, jServerCall C.jobject, goServerCallPtr C.jlong) C.jlong {
269 id := (*serverCall)(util.Ptr(goServerCallPtr)).Blessing()
270 util.GoRef(&id) // Un-refed when the Java PublicID object is finalized.
271 return C.jlong(util.PtrValue(&id))
Jiri Simsa5293dcb2014-05-10 09:56:38 -0700272}
273
Srdjan Petrovic96928962014-06-20 10:03:15 -0700274//export Java_com_veyron_runtimes_google_Runtime_00024ServerCall_nativeDeadline
275func Java_com_veyron_runtimes_google_Runtime_00024ServerCall_nativeDeadline(env *C.JNIEnv, jServerCall C.jobject, goServerCallPtr C.jlong) C.jlong {
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -0700276 s := (*serverCall)(util.Ptr(goServerCallPtr))
Srdjan Petrovic16376622014-06-04 13:49:42 -0700277 var d time.Time
278 if s == nil {
279 // Error, return current time as deadline.
280 d = time.Now()
281 } else {
Matt Rosencrantz137b8d22014-08-18 09:56:15 -0700282 // TODO(mattr): Deal with missing deadlines by adjusting the JAVA api to allow it.
283 d, _ = s.Deadline()
Srdjan Petrovic16376622014-06-04 13:49:42 -0700284 }
285 return C.jlong(d.UnixNano() / 1000)
286}
287
Srdjan Petrovic96928962014-06-20 10:03:15 -0700288//export Java_com_veyron_runtimes_google_Runtime_00024ServerCall_nativeClosed
289func Java_com_veyron_runtimes_google_Runtime_00024ServerCall_nativeClosed(env *C.JNIEnv, jServerCall C.jobject, goServerCallPtr C.jlong) C.jboolean {
Srdjan Petrovic6f6b2c02014-07-11 12:36:23 -0700290 s := (*serverCall)(util.Ptr(goServerCallPtr))
Matt Rosencrantz137b8d22014-08-18 09:56:15 -0700291 select {
292 case <-s.Done():
Srdjan Petrovic16376622014-06-04 13:49:42 -0700293 return C.JNI_TRUE
Matt Rosencrantz137b8d22014-08-18 09:56:15 -0700294 default:
295 return C.JNI_FALSE
Srdjan Petrovic16376622014-06-04 13:49:42 -0700296 }
Srdjan Petrovic16376622014-06-04 13:49:42 -0700297}