1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Tester Core
3 * ----------------------------------------
5 * Copyright 2014 The Android Open Source Project
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 * \brief Android JNI interface.
22 *//*--------------------------------------------------------------------*/
24 #include "tcuDefs.hpp"
26 #include "tcuAndroidExecService.hpp"
27 #include "tcuTestLog.hpp"
28 #include "tcuCommandLine.hpp"
36 #include <android/log.h>
38 // ExecService entry points.
40 static jfieldID getExecServiceField (JNIEnv* env, jobject obj)
42 jclass cls = env->GetObjectClass(obj);
43 TCU_CHECK_INTERNAL(cls);
45 jfieldID fid = env->GetFieldID(cls, "m_server", "J");
46 TCU_CHECK_INTERNAL(fid);
51 static tcu::Android::ExecService* getExecService (JNIEnv* env, jobject obj)
53 jfieldID field = getExecServiceField(env, obj);
54 return (tcu::Android::ExecService*)(deIntptr)env->GetLongField(obj, field);
57 static void setExecService (JNIEnv* env, jobject obj, tcu::Android::ExecService* service)
59 jfieldID field = getExecServiceField(env, obj);
60 env->SetLongField(obj, field, (jlong)(deIntptr)service);
63 static void logException (const std::exception& e)
65 __android_log_print(ANDROID_LOG_ERROR, "dEQP", "%s", e.what());
70 JNIEXPORT void JNICALL Java_com_drawelements_deqp_execserver_ExecService_startServer (JNIEnv* env, jobject obj, jint port)
72 tcu::Android::ExecService* service = DE_NULL;
77 DE_ASSERT(!getExecService(env, obj));
80 TCU_CHECK_INTERNAL(vm);
82 service = new tcu::Android::ExecService(vm, obj, port);
85 setExecService(env, obj, service);
87 catch (const std::exception& e)
91 tcu::die("ExecService.startServer() failed");
95 JNIEXPORT void JNICALL Java_com_drawelements_deqp_execserver_ExecService_stopServer (JNIEnv* env, jobject obj)
99 tcu::Android::ExecService* service = getExecService(env, obj);
100 TCU_CHECK_INTERNAL(service);
105 setExecService(env, obj, DE_NULL);
107 catch (const std::exception& e)
110 tcu::die("ExecService.stopServer() failed");