OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 #include "webrtc/sdk/android/src/jni/jni_helpers.h" | 10 #include "webrtc/sdk/android/src/jni/jni_helpers.h" |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 jclass enumClass = FindClass(jni, className.c_str()); | 300 jclass enumClass = FindClass(jni, className.c_str()); |
301 jmethodID nameMethod = | 301 jmethodID nameMethod = |
302 GetMethodID(jni, enumClass, "name", "()Ljava/lang/String;"); | 302 GetMethodID(jni, enumClass, "name", "()Ljava/lang/String;"); |
303 jstring name = | 303 jstring name = |
304 reinterpret_cast<jstring>(jni->CallObjectMethod(j_enum, nameMethod)); | 304 reinterpret_cast<jstring>(jni->CallObjectMethod(j_enum, nameMethod)); |
305 CHECK_EXCEPTION(jni) << "error during CallObjectMethod for " << className | 305 CHECK_EXCEPTION(jni) << "error during CallObjectMethod for " << className |
306 << ".name"; | 306 << ".name"; |
307 return JavaToStdString(jni, name); | 307 return JavaToStdString(jni, name); |
308 } | 308 } |
309 | 309 |
| 310 std::map<std::string, std::string> JavaToStdMapStrings(JNIEnv* jni, |
| 311 jobject j_map) { |
| 312 jclass map_class = jni->FindClass("java/util/Map"); |
| 313 jclass set_class = jni->FindClass("java/util/Set"); |
| 314 jclass iterator_class = jni->FindClass("java/util/Iterator"); |
| 315 jclass entry_class = jni->FindClass("java/util/Map$Entry"); |
| 316 jmethodID entry_set_method = |
| 317 jni->GetMethodID(map_class, "entrySet", "()Ljava/util/Set;"); |
| 318 jmethodID iterator_method = |
| 319 jni->GetMethodID(set_class, "iterator", "()Ljava/util/Iterator;"); |
| 320 jmethodID has_next_method = |
| 321 jni->GetMethodID(iterator_class, "hasNext", "()Z"); |
| 322 jmethodID next_method = |
| 323 jni->GetMethodID(iterator_class, "next", "()Ljava/lang/Object;"); |
| 324 jmethodID get_key_method = |
| 325 jni->GetMethodID(entry_class, "getKey", "()Ljava/lang/Object;"); |
| 326 jmethodID get_value_method = |
| 327 jni->GetMethodID(entry_class, "getValue", "()Ljava/lang/Object;"); |
| 328 |
| 329 jobject j_entry_set = jni->CallObjectMethod(j_map, entry_set_method); |
| 330 jobject j_iterator = jni->CallObjectMethod(j_entry_set, iterator_method); |
| 331 |
| 332 std::map<std::string, std::string> result; |
| 333 while (jni->CallBooleanMethod(j_iterator, has_next_method)) { |
| 334 jobject j_entry = jni->CallObjectMethod(j_iterator, next_method); |
| 335 jstring j_key = |
| 336 static_cast<jstring>(jni->CallObjectMethod(j_entry, get_key_method)); |
| 337 jstring j_value = |
| 338 static_cast<jstring>(jni->CallObjectMethod(j_entry, get_value_method)); |
| 339 result[JavaToStdString(jni, j_key)] = JavaToStdString(jni, j_value); |
| 340 } |
| 341 |
| 342 return result; |
| 343 } |
| 344 |
310 jobject NewGlobalRef(JNIEnv* jni, jobject o) { | 345 jobject NewGlobalRef(JNIEnv* jni, jobject o) { |
311 jobject ret = jni->NewGlobalRef(o); | 346 jobject ret = jni->NewGlobalRef(o); |
312 CHECK_EXCEPTION(jni) << "error during NewGlobalRef"; | 347 CHECK_EXCEPTION(jni) << "error during NewGlobalRef"; |
313 RTC_CHECK(ret); | 348 RTC_CHECK(ret); |
314 return ret; | 349 return ret; |
315 } | 350 } |
316 | 351 |
317 void DeleteGlobalRef(JNIEnv* jni, jobject o) { | 352 void DeleteGlobalRef(JNIEnv* jni, jobject o) { |
318 jni->DeleteGlobalRef(o); | 353 jni->DeleteGlobalRef(o); |
319 CHECK_EXCEPTION(jni) << "error during DeleteGlobalRef"; | 354 CHECK_EXCEPTION(jni) << "error during DeleteGlobalRef"; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 return value_; | 428 return value_; |
394 } | 429 } |
395 | 430 |
396 bool Iterable::Iterator::AtEnd() const { | 431 bool Iterable::Iterator::AtEnd() const { |
397 RTC_CHECK(thread_checker_.CalledOnValidThread()); | 432 RTC_CHECK(thread_checker_.CalledOnValidThread()); |
398 return jni_ == nullptr || IsNull(jni_, iterator_); | 433 return jni_ == nullptr || IsNull(jni_, iterator_); |
399 } | 434 } |
400 | 435 |
401 } // namespace jni | 436 } // namespace jni |
402 } // namespace webrtc | 437 } // namespace webrtc |
OLD | NEW |