Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define LOG_TAG "InputApplication" |
| 18 | |
| 19 | #include "JNIHelp.h" |
| 20 | #include "jni.h" |
| 21 | #include <android_runtime/AndroidRuntime.h> |
| 22 | |
| 23 | #include "com_android_server_InputApplication.h" |
| 24 | #include "com_android_server_InputApplicationHandle.h" |
| 25 | |
| 26 | namespace android { |
| 27 | |
| 28 | static struct { |
| 29 | jclass clazz; |
| 30 | |
| 31 | jfieldID inputApplicationHandle; |
| 32 | jfieldID name; |
| 33 | jfieldID dispatchingTimeoutNanos; |
| 34 | } gInputApplicationClassInfo; |
| 35 | |
| 36 | |
| 37 | // --- Global functions --- |
| 38 | |
| 39 | void android_server_InputApplication_toNative( |
| 40 | JNIEnv* env, jobject inputApplicationObj, InputApplication* outInputApplication) { |
| 41 | jobject inputApplicationHandleObj = env->GetObjectField(inputApplicationObj, |
| 42 | gInputApplicationClassInfo.inputApplicationHandle); |
| 43 | if (inputApplicationHandleObj) { |
| 44 | outInputApplication->inputApplicationHandle = |
| 45 | android_server_InputApplicationHandle_getHandle(env, inputApplicationHandleObj); |
| 46 | env->DeleteLocalRef(inputApplicationHandleObj); |
| 47 | } else { |
| 48 | outInputApplication->inputApplicationHandle = NULL; |
| 49 | } |
| 50 | |
| 51 | jstring nameObj = jstring(env->GetObjectField(inputApplicationObj, |
| 52 | gInputApplicationClassInfo.name)); |
| 53 | if (nameObj) { |
| 54 | const char* nameStr = env->GetStringUTFChars(nameObj, NULL); |
| 55 | outInputApplication->name.setTo(nameStr); |
| 56 | env->ReleaseStringUTFChars(nameObj, nameStr); |
| 57 | env->DeleteLocalRef(nameObj); |
| 58 | } else { |
| 59 | LOGE("InputApplication.name should not be null."); |
| 60 | outInputApplication->name.setTo("unknown"); |
| 61 | } |
| 62 | |
| 63 | outInputApplication->dispatchingTimeout = env->GetLongField(inputApplicationObj, |
| 64 | gInputApplicationClassInfo.dispatchingTimeoutNanos); |
| 65 | } |
| 66 | |
| 67 | |
| 68 | // --- JNI --- |
| 69 | |
| 70 | #define FIND_CLASS(var, className) \ |
| 71 | var = env->FindClass(className); \ |
| 72 | LOG_FATAL_IF(! var, "Unable to find class " className); \ |
| 73 | var = jclass(env->NewGlobalRef(var)); |
| 74 | |
| 75 | #define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \ |
| 76 | var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \ |
| 77 | LOG_FATAL_IF(! var, "Unable to find field " fieldName); |
| 78 | |
| 79 | int register_android_server_InputApplication(JNIEnv* env) { |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 80 | FIND_CLASS(gInputApplicationClassInfo.clazz, "com/android/server/wm/InputApplication"); |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 81 | |
| 82 | GET_FIELD_ID(gInputApplicationClassInfo.inputApplicationHandle, |
| 83 | gInputApplicationClassInfo.clazz, |
Dianne Hackborn | a924dc0d | 2011-02-17 14:22:17 -0800 | [diff] [blame] | 84 | "inputApplicationHandle", "Lcom/android/server/wm/InputApplicationHandle;"); |
Jeff Brown | 928e054 | 2011-01-10 11:17:36 -0800 | [diff] [blame] | 85 | |
| 86 | GET_FIELD_ID(gInputApplicationClassInfo.name, gInputApplicationClassInfo.clazz, |
| 87 | "name", "Ljava/lang/String;"); |
| 88 | |
| 89 | GET_FIELD_ID(gInputApplicationClassInfo.dispatchingTimeoutNanos, |
| 90 | gInputApplicationClassInfo.clazz, |
| 91 | "dispatchingTimeoutNanos", "J"); |
| 92 | return 0; |
| 93 | } |
| 94 | |
| 95 | } /* namespace android */ |