Mikhail Naganov | c276c59 | 2016-08-31 18:08:10 -0700 | [diff] [blame] | 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> |
Colin Cross | eb27d27 | 2017-05-15 18:10:40 -0700 | [diff] [blame^] | 21 | #include <midi_internal.h> |
Mikhail Naganov | c276c59 | 2016-08-31 18:08:10 -0700 | [diff] [blame] | 22 | #include <nativehelper/jni.h> |
| 23 | #include <utils/Log.h> |
| 24 | |
| 25 | using namespace android; |
| 26 | using namespace android::media::midi; |
| 27 | |
Paul McLean | 71f672b | 2017-03-05 08:12:18 -0700 | [diff] [blame] | 28 | extern "C" jlong Java_android_media_midi_MidiDevice_native_1mirrorToNative( |
| 29 | JNIEnv *env, jobject, jobject midiDeviceServer, jint id) |
Mikhail Naganov | c276c59 | 2016-08-31 18:08:10 -0700 | [diff] [blame] | 30 | { |
Paul McLean | 71f672b | 2017-03-05 08:12:18 -0700 | [diff] [blame] | 31 | // ALOGI("native_mirrorToNative(%p)...", midiDeviceServer); |
Mikhail Naganov | c276c59 | 2016-08-31 18:08:10 -0700 | [diff] [blame] | 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 | } |
Paul McLean | 71f672b | 2017-03-05 08:12:18 -0700 | [diff] [blame] | 37 | |
| 38 | AMIDI_Device* devicePtr = new AMIDI_Device; |
| 39 | devicePtr->server = new BpMidiDeviceServer(serverBinder); |
| 40 | devicePtr->deviceId = id; |
| 41 | |
| 42 | return (jlong)devicePtr; |
Mikhail Naganov | c276c59 | 2016-08-31 18:08:10 -0700 | [diff] [blame] | 43 | } |
| 44 | |
Paul McLean | 71f672b | 2017-03-05 08:12:18 -0700 | [diff] [blame] | 45 | extern "C" void Java_android_media_midi_MidiDevice_native_removeFromNative( |
| 46 | JNIEnv *, jobject , jlong nativeToken) |
Mikhail Naganov | c276c59 | 2016-08-31 18:08:10 -0700 | [diff] [blame] | 47 | { |
Paul McLean | 71f672b | 2017-03-05 08:12:18 -0700 | [diff] [blame] | 48 | AMIDI_Device* devicePtr = (AMIDI_Device*)nativeToken; |
| 49 | delete devicePtr; |
Mikhail Naganov | c276c59 | 2016-08-31 18:08:10 -0700 | [diff] [blame] | 50 | } |