1 /* 2 * Copyright (C) 2017 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_NDEBUG 0 18 #define LOG_TAG "Midi-JNI" 19 20 #include <android_util_Binder.h> 21 #include <midi/midi_internal.h> 22 #include <nativehelper/jni.h> 23 #include <utils/Log.h> 24 25 using namespace android; 26 using namespace android::media::midi; 27 28 extern "C" jlong Java_android_media_midi_MidiDevice_native_1mirrorToNative( 29 JNIEnv *env, jobject, jobject midiDeviceServer, jint id) 30 { 31 // ALOGI("native_mirrorToNative(%p)...", midiDeviceServer); 32 sp<IBinder> serverBinder = ibinderForJavaObject(env, midiDeviceServer); 33 if (serverBinder.get() == NULL) { 34 ALOGE("Could not obtain IBinder from passed jobject"); 35 return -EINVAL; 36 } 37 38 AMIDI_Device* devicePtr = new AMIDI_Device; 39 devicePtr->server = new BpMidiDeviceServer(serverBinder); 40 devicePtr->deviceId = id; 41 42 return (jlong)devicePtr; 43 } 44 45 extern "C" void Java_android_media_midi_MidiDevice_native_removeFromNative( 46 JNIEnv *, jobject , jlong nativeToken) 47 { 48 AMIDI_Device* devicePtr = (AMIDI_Device*)nativeToken; 49 delete devicePtr; 50 } 51