1 /* 2 * Copyright (C) 2023 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 #pragma once 17 18 #include <android-base/thread_annotations.h> 19 #include <jni.h> 20 21 #include <optional> 22 #include <string> 23 24 #include "absl/status/statusor.h" 25 #include "fcp/client/flags.h" 26 #include "fcp/client/log_manager.h" 27 #include "fcp/client/simple_task_environment.h" 28 29 namespace fcp { 30 namespace client { 31 namespace engine { 32 namespace jni { 33 34 // A wrapper around the Java example iterator class. Object is only valid for 35 // the time of a JNI call and must not be kept around for any longer. Can be 36 // created on an arbitrary thread. 37 class ExampleIteratorWrapperImpl : public ExampleIterator { 38 public: 39 ExampleIteratorWrapperImpl(JavaVM *jvm, jobject example_iterator); 40 41 ~ExampleIteratorWrapperImpl() override; 42 43 absl::StatusOr<std::string> Next() override; 44 45 void Close() override final; 46 47 private: 48 jmethodID next_id_; 49 jmethodID close_id_; 50 std::mutex close_mu_; 51 bool closed_ GUARDED_BY(close_mu_); 52 JavaVM *const jvm_; 53 jobject jthis_; 54 }; 55 56 } // namespace jni 57 } // namespace engine 58 } // namespace client 59 } // namespace fcp 60