diff options
author | Mike Lockwood <lockwood@android.com> | 2010-11-20 14:06:57 -0500 |
---|---|---|
committer | Mike Lockwood <lockwood@android.com> | 2010-11-23 10:30:31 -0500 |
commit | c0b8b321d5428e4fc425713e3889ef745af3af2d (patch) | |
tree | 7214e83dcf69f7c396779d28e9a64803c6e27401 /media/jni/android_media_PtpCursor.cpp | |
parent | a31560598af25d5116effc2a6af0d9be12a0628d (diff) | |
download | frameworks_base-c0b8b321d5428e4fc425713e3889ef745af3af2d.zip frameworks_base-c0b8b321d5428e4fc425713e3889ef745af3af2d.tar.gz frameworks_base-c0b8b321d5428e4fc425713e3889ef745af3af2d.tar.bz2 |
Rename MtpClient and MtpCursor to PtpClient and PtpCursor
Change-Id: I26fce3bf32c8e9c8d592106af7ab4c35b19e0996
Signed-off-by: Mike Lockwood <lockwood@android.com>
Diffstat (limited to 'media/jni/android_media_PtpCursor.cpp')
-rw-r--r-- | media/jni/android_media_PtpCursor.cpp | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/media/jni/android_media_PtpCursor.cpp b/media/jni/android_media_PtpCursor.cpp new file mode 100644 index 0000000..c5af3a8 --- /dev/null +++ b/media/jni/android_media_PtpCursor.cpp @@ -0,0 +1,136 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "PtpCursorJNI" +#include "utils/Log.h" + +#include <stdio.h> +#include <assert.h> +#include <limits.h> +#include <unistd.h> +#include <fcntl.h> + +#include "jni.h" +#include "JNIHelp.h" +#include "android_runtime/AndroidRuntime.h" +#include "binder/CursorWindow.h" + +#include "MtpClient.h" +#include "MtpCursor.h" + +using namespace android; + +// ---------------------------------------------------------------------------- + +static jfieldID field_context; + +// From android_media_PtpClient.cpp +MtpClient * get_client_from_object(JNIEnv * env, jobject javaClient); + +// ---------------------------------------------------------------------------- + +static bool ExceptionCheck(void* env) +{ + return ((JNIEnv *)env)->ExceptionCheck(); +} + +static void +android_media_PtpCursor_setup(JNIEnv *env, jobject thiz, jobject javaClient, + jint queryType, jint deviceID, jlong storageID, jlong objectID, jintArray javaColumns) +{ +#ifdef HAVE_ANDROID_OS + LOGD("android_media_PtpCursor_setup queryType: %d deviceID: %d storageID: %lld objectID: %lld\n", + queryType, deviceID, storageID, objectID); + + int* columns = NULL; + int columnCount = 0; + if (javaColumns) { + columns = env->GetIntArrayElements(javaColumns, 0); + columnCount = env->GetArrayLength(javaColumns); + } + + MtpClient* client = get_client_from_object(env, javaClient); + MtpCursor* cursor = new MtpCursor(client, queryType, + deviceID, storageID, objectID, columnCount, columns); + + if (columns) + env->ReleaseIntArrayElements(javaColumns, columns, 0); + env->SetIntField(thiz, field_context, (int)cursor); +#endif +} + +static void +android_media_PtpCursor_finalize(JNIEnv *env, jobject thiz) +{ +#ifdef HAVE_ANDROID_OS + LOGD("finalize\n"); + MtpCursor *cursor = (MtpCursor *)env->GetIntField(thiz, field_context); + delete cursor; +#endif +} + +static jint +android_media_PtpCursor_fill_window(JNIEnv *env, jobject thiz, jobject javaWindow, jint startPos) +{ +#ifdef HAVE_ANDROID_OS + CursorWindow* window = get_window_from_object(env, javaWindow); + if (!window) { + LOGE("Invalid CursorWindow"); + jniThrowException(env, "java/lang/IllegalArgumentException", + "Bad CursorWindow"); + return 0; + } + MtpCursor *cursor = (MtpCursor *)env->GetIntField(thiz, field_context); + + return cursor->fillWindow(window, startPos); +#else + return 0; +#endif +} + +// ---------------------------------------------------------------------------- + +static JNINativeMethod gMethods[] = { + {"native_setup", "(Landroid/media/PtpClient;IIJJ[I)V", + (void *)android_media_PtpCursor_setup}, + {"native_finalize", "()V", (void *)android_media_PtpCursor_finalize}, + {"native_fill_window", "(Landroid/database/CursorWindow;I)I", + (void *)android_media_PtpCursor_fill_window}, + +}; + +static const char* const kClassPathName = "android/media/PtpCursor"; + +int register_android_media_PtpCursor(JNIEnv *env) +{ + jclass clazz; + + LOGD("register_android_media_PtpCursor\n"); + + clazz = env->FindClass("android/media/PtpCursor"); + if (clazz == NULL) { + LOGE("Can't find android/media/PtpCursor"); + return -1; + } + field_context = env->GetFieldID(clazz, "mNativeContext", "I"); + if (field_context == NULL) { + LOGE("Can't find PtpCursor.mNativeContext"); + return -1; + } + + return AndroidRuntime::registerNativeMethods(env, + "android/media/PtpCursor", gMethods, NELEM(gMethods)); +} |