1 /* 2 * Copyright (C) 2021 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 #ifndef ANDROID_HARDWARE_INTERFACES_NEURALNETWORKS_AIDL_UTILS_CALLBACKS_H 18 #define ANDROID_HARDWARE_INTERFACES_NEURALNETWORKS_AIDL_UTILS_CALLBACKS_H 19 20 #include <aidl/android/hardware/neuralnetworks/BnPreparedModelCallback.h> 21 #include <aidl/android/hardware/neuralnetworks/IDevice.h> 22 #include <nnapi/IPreparedModel.h> 23 #include <nnapi/Result.h> 24 #include <nnapi/Types.h> 25 #include <nnapi/hal/CommonUtils.h> 26 #include <nnapi/hal/TransferValue.h> 27 #include <nnapi/hal/aidl/ProtectCallback.h> 28 29 // See hardware/interfaces/neuralnetworks/utils/README.md for more information on AIDL interface 30 // lifetimes across processes and for protecting asynchronous calls across AIDL. 31 32 namespace aidl::android::hardware::neuralnetworks::utils { 33 34 // An AIDL callback class to receive the results of IDevice::prepareModel* asynchronously. 35 class PreparedModelCallback final : public BnPreparedModelCallback, public IProtectedCallback { 36 public: 37 using Data = nn::GeneralResult<nn::SharedPreparedModel>; 38 PreparedModelCallback(nn::Version featureLevel)39 PreparedModelCallback(nn::Version featureLevel) : kFeatureLevel(featureLevel) {} 40 41 ndk::ScopedAStatus notify(ErrorStatus status, 42 const std::shared_ptr<IPreparedModel>& preparedModel) override; 43 44 void notifyAsDeadObject() override; 45 46 Data get(); 47 48 private: 49 const nn::Version kFeatureLevel; 50 hal::utils::TransferValue<Data> mData; 51 }; 52 53 } // namespace aidl::android::hardware::neuralnetworks::utils 54 55 #endif // ANDROID_HARDWARE_INTERFACES_NEURALNETWORKS_AIDL_UTILS_CALLBACKS_H 56