Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / media / midi / midi_device_android.cc
blob4fa6b137c5dd706ea192c6a3077c23ef25e0baff
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "media/midi/midi_device_android.h"
7 #include <string>
9 #include "jni/MidiDeviceAndroid_jni.h"
10 #include "media/midi/midi_output_port_android.h"
12 namespace media {
13 namespace midi {
15 MidiDeviceAndroid::MidiDeviceAndroid(JNIEnv* env,
16 jobject raw_device,
17 MidiInputPortAndroid::Delegate* delegate)
18 : raw_device_(env, raw_device) {
19 ScopedJavaLocalRef<jobjectArray> raw_input_ports =
20 Java_MidiDeviceAndroid_getInputPorts(env, raw_device);
21 jsize num_input_ports = env->GetArrayLength(raw_input_ports.obj());
23 for (jsize i = 0; i < num_input_ports; ++i) {
24 jobject port = env->GetObjectArrayElement(raw_input_ports.obj(), i);
25 input_ports_.push_back(new MidiInputPortAndroid(env, port, delegate));
28 ScopedJavaLocalRef<jobjectArray> raw_output_ports =
29 Java_MidiDeviceAndroid_getOutputPorts(env, raw_device);
30 jsize num_output_ports = env->GetArrayLength(raw_output_ports.obj());
31 for (jsize i = 0; i < num_output_ports; ++i) {
32 jobject port = env->GetObjectArrayElement(raw_output_ports.obj(), i);
33 output_ports_.push_back(new MidiOutputPortAndroid(env, port));
37 MidiDeviceAndroid::~MidiDeviceAndroid() {}
39 std::string MidiDeviceAndroid::GetManufacturer() {
40 JNIEnv* env = base::android::AttachCurrentThread();
41 ScopedJavaLocalRef<jstring> ret =
42 Java_MidiDeviceAndroid_getManufacturer(env, raw_device_.obj());
43 return std::string(env->GetStringUTFChars(ret.obj(), nullptr),
44 env->GetStringUTFLength(ret.obj()));
47 std::string MidiDeviceAndroid::GetProductName() {
48 JNIEnv* env = base::android::AttachCurrentThread();
49 ScopedJavaLocalRef<jstring> ret =
50 Java_MidiDeviceAndroid_getProduct(env, raw_device_.obj());
51 return std::string(env->GetStringUTFChars(ret.obj(), nullptr),
52 env->GetStringUTFLength(ret.obj()));
55 std::string MidiDeviceAndroid::GetDeviceVersion() {
56 JNIEnv* env = base::android::AttachCurrentThread();
57 ScopedJavaLocalRef<jstring> ret =
58 Java_MidiDeviceAndroid_getVersion(env, raw_device_.obj());
59 return std::string(env->GetStringUTFChars(ret.obj(), nullptr),
60 env->GetStringUTFLength(ret.obj()));
63 bool MidiDeviceAndroid::Register(JNIEnv* env) {
64 return RegisterNativesImpl(env);
67 } // namespace midi
68 } // namespace media