blob: 4df84362a39d746a9d2314202da4e419edd319af [file] [log] [blame]
Mikhail Naganovc276c592016-08-31 18:08:10 -07001/*
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 Crosseb27d272017-05-15 18:10:40 -070021#include <midi_internal.h>
Mikhail Naganovc276c592016-08-31 18:08:10 -070022#include <nativehelper/jni.h>
23#include <utils/Log.h>
24
25using namespace android;
26using namespace android::media::midi;
27
Paul McLean71f672b2017-03-05 08:12:18 -070028extern "C" jlong Java_android_media_midi_MidiDevice_native_1mirrorToNative(
29 JNIEnv *env, jobject, jobject midiDeviceServer, jint id)
Mikhail Naganovc276c592016-08-31 18:08:10 -070030{
Paul McLean71f672b2017-03-05 08:12:18 -070031 // ALOGI("native_mirrorToNative(%p)...", midiDeviceServer);
Mikhail Naganovc276c592016-08-31 18:08:10 -070032 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 McLean71f672b2017-03-05 08:12:18 -070037
38 AMIDI_Device* devicePtr = new AMIDI_Device;
39 devicePtr->server = new BpMidiDeviceServer(serverBinder);
40 devicePtr->deviceId = id;
41
42 return (jlong)devicePtr;
Mikhail Naganovc276c592016-08-31 18:08:10 -070043}
44
Paul McLean71f672b2017-03-05 08:12:18 -070045extern "C" void Java_android_media_midi_MidiDevice_native_removeFromNative(
46 JNIEnv *, jobject , jlong nativeToken)
Mikhail Naganovc276c592016-08-31 18:08:10 -070047{
Paul McLean71f672b2017-03-05 08:12:18 -070048 AMIDI_Device* devicePtr = (AMIDI_Device*)nativeToken;
49 delete devicePtr;
Mikhail Naganovc276c592016-08-31 18:08:10 -070050}