Relocate NN ProtectCallback to 1.0/utils
This change is part of a larger chain of changes to remove HIDL and AIDL libraries from neuralnetworks_utils_hal_common. Bug: N/A Test: mma Change-Id: Ib43f1cb683a09ae5c9116a6dea4d269c9c2c78b4
This commit is contained in:
parent
15965821e8
commit
e8645c3b8d
34 changed files with 64 additions and 44 deletions
|
@ -24,9 +24,10 @@
|
|||
#include <nnapi/Result.h>
|
||||
#include <nnapi/Types.h>
|
||||
#include <nnapi/hal/CommonUtils.h>
|
||||
#include <nnapi/hal/ProtectCallback.h>
|
||||
#include <nnapi/hal/TransferValue.h>
|
||||
|
||||
#include "nnapi/hal/1.0/ProtectCallback.h"
|
||||
|
||||
// See hardware/interfaces/neuralnetworks/utils/README.md for more information on HIDL interface
|
||||
// lifetimes across processes and for protecting asynchronous calls across HIDL.
|
||||
|
||||
|
|
|
@ -24,7 +24,8 @@
|
|||
#include <nnapi/Result.h>
|
||||
#include <nnapi/Types.h>
|
||||
#include <nnapi/hal/CommonUtils.h>
|
||||
#include <nnapi/hal/ProtectCallback.h>
|
||||
|
||||
#include "nnapi/hal/1.0/ProtectCallback.h"
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
|
|
@ -22,9 +22,9 @@
|
|||
#include <nnapi/Result.h>
|
||||
#include <nnapi/Types.h>
|
||||
#include <nnapi/hal/CommonUtils.h>
|
||||
#include <nnapi/hal/ProtectCallback.h>
|
||||
|
||||
#include "PreparedModel.h"
|
||||
#include "nnapi/hal/1.0/ProtectCallback.h"
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
|
|
@ -22,7 +22,8 @@
|
|||
#include <nnapi/Result.h>
|
||||
#include <nnapi/Types.h>
|
||||
#include <nnapi/hal/CommonUtils.h>
|
||||
#include <nnapi/hal/ProtectCallback.h>
|
||||
|
||||
#include "nnapi/hal/1.0/ProtectCallback.h"
|
||||
|
||||
#include <memory>
|
||||
#include <tuple>
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_HARDWARE_INTERFACES_NEURALNETWORKS_UTILS_COMMON_PROTECT_CALLBACK_H
|
||||
#define ANDROID_HARDWARE_INTERFACES_NEURALNETWORKS_UTILS_COMMON_PROTECT_CALLBACK_H
|
||||
#ifndef ANDROID_HARDWARE_INTERFACES_NEURALNETWORKS_1_0_UTILS_PROTECT_CALLBACK_H
|
||||
#define ANDROID_HARDWARE_INTERFACES_NEURALNETWORKS_1_0_UTILS_PROTECT_CALLBACK_H
|
||||
|
||||
#include <android-base/scopeguard.h>
|
||||
#include <android-base/thread_annotations.h>
|
||||
|
@ -98,4 +98,4 @@ class DeathHandler final {
|
|||
|
||||
} // namespace android::hardware::neuralnetworks::utils
|
||||
|
||||
#endif // ANDROID_HARDWARE_INTERFACES_NEURALNETWORKS_UTILS_COMMON_PROTECT_CALLBACK_H
|
||||
#endif // ANDROID_HARDWARE_INTERFACES_NEURALNETWORKS_1_0_UTILS_PROTECT_CALLBACK_H
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
#include "Conversions.h"
|
||||
#include "PreparedModel.h"
|
||||
#include "ProtectCallback.h"
|
||||
#include "Utils.h"
|
||||
|
||||
#include <android/hardware/neuralnetworks/1.0/IExecutionCallback.h>
|
||||
|
@ -28,7 +29,6 @@
|
|||
#include <nnapi/Types.h>
|
||||
#include <nnapi/hal/CommonUtils.h>
|
||||
#include <nnapi/hal/HandleError.h>
|
||||
#include <nnapi/hal/ProtectCallback.h>
|
||||
#include <nnapi/hal/TransferValue.h>
|
||||
|
||||
#include <utility>
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
#include "Callbacks.h"
|
||||
#include "Conversions.h"
|
||||
#include "ProtectCallback.h"
|
||||
#include "Utils.h"
|
||||
|
||||
#include <android/hardware/neuralnetworks/1.0/IDevice.h>
|
||||
|
@ -30,7 +31,6 @@
|
|||
#include <nnapi/Types.h>
|
||||
#include <nnapi/hal/CommonUtils.h>
|
||||
#include <nnapi/hal/HandleError.h>
|
||||
#include <nnapi/hal/ProtectCallback.h>
|
||||
#include <nnapi/hal/TransferValue.h>
|
||||
|
||||
#include <functional>
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
#include "Callbacks.h"
|
||||
#include "Conversions.h"
|
||||
#include "ProtectCallback.h"
|
||||
#include "Utils.h"
|
||||
|
||||
#include <android/hardware/neuralnetworks/1.0/IPreparedModel.h>
|
||||
|
@ -28,7 +29,6 @@
|
|||
#include <nnapi/Types.h>
|
||||
#include <nnapi/hal/CommonUtils.h>
|
||||
#include <nnapi/hal/HandleError.h>
|
||||
#include <nnapi/hal/ProtectCallback.h>
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "Callbacks.h"
|
||||
#include "Conversions.h"
|
||||
#include "Execution.h"
|
||||
#include "ProtectCallback.h"
|
||||
#include "Utils.h"
|
||||
|
||||
#include <android/hardware/neuralnetworks/1.0/IPreparedModel.h>
|
||||
|
@ -29,7 +30,6 @@
|
|||
#include <nnapi/Types.h>
|
||||
#include <nnapi/hal/CommonUtils.h>
|
||||
#include <nnapi/hal/HandleError.h>
|
||||
#include <nnapi/hal/ProtectCallback.h>
|
||||
|
||||
#include <memory>
|
||||
#include <tuple>
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
#include <nnapi/OperandTypes.h>
|
||||
#include <nnapi/Result.h>
|
||||
#include <nnapi/Types.h>
|
||||
#include <nnapi/hal/1.0/ProtectCallback.h>
|
||||
#include <nnapi/hal/CommonUtils.h>
|
||||
#include <nnapi/hal/ProtectCallback.h>
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
|
|
@ -29,9 +29,9 @@
|
|||
#include <nnapi/Result.h>
|
||||
#include <nnapi/Types.h>
|
||||
#include <nnapi/hal/1.0/Callbacks.h>
|
||||
#include <nnapi/hal/1.0/ProtectCallback.h>
|
||||
#include <nnapi/hal/CommonUtils.h>
|
||||
#include <nnapi/hal/HandleError.h>
|
||||
#include <nnapi/hal/ProtectCallback.h>
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
|
|
@ -27,8 +27,8 @@
|
|||
#include <nnapi/Result.h>
|
||||
#include <nnapi/Types.h>
|
||||
#include <nnapi/hal/1.0/Callbacks.h>
|
||||
#include <nnapi/hal/1.0/ProtectCallback.h>
|
||||
#include <nnapi/hal/CommonUtils.h>
|
||||
#include <nnapi/hal/ProtectCallback.h>
|
||||
#include <nnapi/hal/TransferValue.h>
|
||||
|
||||
// See hardware/interfaces/neuralnetworks/utils/README.md for more information on HIDL interface
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
#include <nnapi/OperandTypes.h>
|
||||
#include <nnapi/Result.h>
|
||||
#include <nnapi/Types.h>
|
||||
#include <nnapi/hal/1.0/ProtectCallback.h>
|
||||
#include <nnapi/hal/CommonUtils.h>
|
||||
#include <nnapi/hal/ProtectCallback.h>
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
#include <nnapi/IExecution.h>
|
||||
#include <nnapi/Result.h>
|
||||
#include <nnapi/Types.h>
|
||||
#include <nnapi/hal/1.0/ProtectCallback.h>
|
||||
#include <nnapi/hal/CommonUtils.h>
|
||||
#include <nnapi/hal/ProtectCallback.h>
|
||||
|
||||
#include "PreparedModel.h"
|
||||
|
||||
|
|
|
@ -32,8 +32,8 @@
|
|||
#include <nnapi/IPreparedModel.h>
|
||||
#include <nnapi/Result.h>
|
||||
#include <nnapi/Types.h>
|
||||
#include <nnapi/hal/1.0/ProtectCallback.h>
|
||||
#include <nnapi/hal/CommonUtils.h>
|
||||
#include <nnapi/hal/ProtectCallback.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include <nnapi/IBurst.h>
|
||||
#include <nnapi/Result.h>
|
||||
#include <nnapi/Types.h>
|
||||
#include <nnapi/hal/ProtectCallback.h>
|
||||
#include <nnapi/hal/1.0/ProtectCallback.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#include <hidl/MQDescriptor.h>
|
||||
#include <nnapi/Result.h>
|
||||
#include <nnapi/Types.h>
|
||||
#include <nnapi/hal/ProtectCallback.h>
|
||||
#include <nnapi/hal/1.0/ProtectCallback.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
#include <nnapi/IPreparedModel.h>
|
||||
#include <nnapi/Result.h>
|
||||
#include <nnapi/Types.h>
|
||||
#include <nnapi/hal/1.0/ProtectCallback.h>
|
||||
#include <nnapi/hal/CommonUtils.h>
|
||||
#include <nnapi/hal/ProtectCallback.h>
|
||||
|
||||
#include <memory>
|
||||
#include <tuple>
|
||||
|
|
|
@ -30,9 +30,9 @@
|
|||
#include <nnapi/hal/1.0/Callbacks.h>
|
||||
#include <nnapi/hal/1.0/Conversions.h>
|
||||
#include <nnapi/hal/1.0/PreparedModel.h>
|
||||
#include <nnapi/hal/1.0/ProtectCallback.h>
|
||||
#include <nnapi/hal/CommonUtils.h>
|
||||
#include <nnapi/hal/HandleError.h>
|
||||
#include <nnapi/hal/ProtectCallback.h>
|
||||
#include <nnapi/hal/TransferValue.h>
|
||||
|
||||
#include <utility>
|
||||
|
|
|
@ -30,10 +30,10 @@
|
|||
#include <nnapi/OperandTypes.h>
|
||||
#include <nnapi/Result.h>
|
||||
#include <nnapi/Types.h>
|
||||
#include <nnapi/hal/1.0/ProtectCallback.h>
|
||||
#include <nnapi/hal/1.1/Conversions.h>
|
||||
#include <nnapi/hal/CommonUtils.h>
|
||||
#include <nnapi/hal/HandleError.h>
|
||||
#include <nnapi/hal/ProtectCallback.h>
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
|
|
@ -28,9 +28,9 @@
|
|||
#include <nnapi/Types.h>
|
||||
#include <nnapi/Validation.h>
|
||||
#include <nnapi/hal/1.0/Conversions.h>
|
||||
#include <nnapi/hal/1.0/ProtectCallback.h>
|
||||
#include <nnapi/hal/CommonUtils.h>
|
||||
#include <nnapi/hal/HandleError.h>
|
||||
#include <nnapi/hal/ProtectCallback.h>
|
||||
#include <nnapi/hal/TransferValue.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
|
|
@ -27,8 +27,8 @@
|
|||
#include <nnapi/Types.h>
|
||||
#include <nnapi/Validation.h>
|
||||
#include <nnapi/hal/1.0/Conversions.h>
|
||||
#include <nnapi/hal/1.0/ProtectCallback.h>
|
||||
#include <nnapi/hal/HandleError.h>
|
||||
#include <nnapi/hal/ProtectCallback.h>
|
||||
#include <nnapi/hal/TransferValue.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include <hidl/MQDescriptor.h>
|
||||
#include <nnapi/Result.h>
|
||||
#include <nnapi/Types.h>
|
||||
#include <nnapi/hal/ProtectCallback.h>
|
||||
#include <nnapi/hal/1.0/ProtectCallback.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
|
|
|
@ -31,9 +31,9 @@
|
|||
#include <nnapi/Result.h>
|
||||
#include <nnapi/Types.h>
|
||||
#include <nnapi/hal/1.0/Conversions.h>
|
||||
#include <nnapi/hal/1.0/ProtectCallback.h>
|
||||
#include <nnapi/hal/CommonUtils.h>
|
||||
#include <nnapi/hal/HandleError.h>
|
||||
#include <nnapi/hal/ProtectCallback.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
|
|
|
@ -30,8 +30,8 @@
|
|||
#include <nnapi/Result.h>
|
||||
#include <nnapi/Types.h>
|
||||
#include <nnapi/hal/1.0/Callbacks.h>
|
||||
#include <nnapi/hal/1.0/ProtectCallback.h>
|
||||
#include <nnapi/hal/CommonUtils.h>
|
||||
#include <nnapi/hal/ProtectCallback.h>
|
||||
#include <nnapi/hal/TransferValue.h>
|
||||
|
||||
// See hardware/interfaces/neuralnetworks/utils/README.md for more information on HIDL interface
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
#include <nnapi/OperandTypes.h>
|
||||
#include <nnapi/Result.h>
|
||||
#include <nnapi/Types.h>
|
||||
#include <nnapi/hal/1.0/ProtectCallback.h>
|
||||
#include <nnapi/hal/CommonUtils.h>
|
||||
#include <nnapi/hal/ProtectCallback.h>
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
#include <nnapi/IPreparedModel.h>
|
||||
#include <nnapi/Result.h>
|
||||
#include <nnapi/Types.h>
|
||||
#include <nnapi/hal/1.0/ProtectCallback.h>
|
||||
#include <nnapi/hal/CommonUtils.h>
|
||||
#include <nnapi/hal/ProtectCallback.h>
|
||||
|
||||
#include <memory>
|
||||
#include <tuple>
|
||||
|
|
|
@ -31,12 +31,12 @@
|
|||
#include <nnapi/hal/1.0/Callbacks.h>
|
||||
#include <nnapi/hal/1.0/Conversions.h>
|
||||
#include <nnapi/hal/1.0/PreparedModel.h>
|
||||
#include <nnapi/hal/1.0/ProtectCallback.h>
|
||||
#include <nnapi/hal/1.2/Callbacks.h>
|
||||
#include <nnapi/hal/1.2/Conversions.h>
|
||||
#include <nnapi/hal/1.2/PreparedModel.h>
|
||||
#include <nnapi/hal/CommonUtils.h>
|
||||
#include <nnapi/hal/HandleError.h>
|
||||
#include <nnapi/hal/ProtectCallback.h>
|
||||
#include <nnapi/hal/TransferValue.h>
|
||||
|
||||
#include <utility>
|
||||
|
|
|
@ -33,13 +33,13 @@
|
|||
#include <nnapi/OperandTypes.h>
|
||||
#include <nnapi/Result.h>
|
||||
#include <nnapi/Types.h>
|
||||
#include <nnapi/hal/1.0/ProtectCallback.h>
|
||||
#include <nnapi/hal/1.1/Conversions.h>
|
||||
#include <nnapi/hal/1.2/Conversions.h>
|
||||
#include <nnapi/hal/1.2/Device.h>
|
||||
#include <nnapi/hal/1.2/Utils.h>
|
||||
#include <nnapi/hal/CommonUtils.h>
|
||||
#include <nnapi/hal/HandleError.h>
|
||||
#include <nnapi/hal/ProtectCallback.h>
|
||||
|
||||
#include <any>
|
||||
#include <functional>
|
||||
|
|
|
@ -30,12 +30,12 @@
|
|||
#include <nnapi/Result.h>
|
||||
#include <nnapi/TypeUtils.h>
|
||||
#include <nnapi/Types.h>
|
||||
#include <nnapi/hal/1.0/ProtectCallback.h>
|
||||
#include <nnapi/hal/1.2/Conversions.h>
|
||||
#include <nnapi/hal/1.2/ExecutionBurstController.h>
|
||||
#include <nnapi/hal/1.2/ExecutionBurstUtils.h>
|
||||
#include <nnapi/hal/CommonUtils.h>
|
||||
#include <nnapi/hal/HandleError.h>
|
||||
#include <nnapi/hal/ProtectCallback.h>
|
||||
|
||||
#include <memory>
|
||||
#include <tuple>
|
||||
|
|
|
@ -32,8 +32,7 @@
|
|||
namespace aidl::android::hardware::neuralnetworks::utils {
|
||||
|
||||
// An AIDL callback class to receive the results of IDevice::prepareModel* asynchronously.
|
||||
class PreparedModelCallback final : public BnPreparedModelCallback,
|
||||
public hal::utils::IProtectedCallback {
|
||||
class PreparedModelCallback final : public BnPreparedModelCallback, public IProtectedCallback {
|
||||
public:
|
||||
using Data = nn::GeneralResult<nn::SharedPreparedModel>;
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include <nnapi/Result.h>
|
||||
#include <nnapi/Types.h>
|
||||
#include <nnapi/hal/CommonUtils.h>
|
||||
#include <nnapi/hal/ProtectCallback.h>
|
||||
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
|
@ -34,19 +33,39 @@
|
|||
|
||||
namespace aidl::android::hardware::neuralnetworks::utils {
|
||||
|
||||
class IProtectedCallback {
|
||||
public:
|
||||
/**
|
||||
* Marks this object as a dead object.
|
||||
*/
|
||||
virtual void notifyAsDeadObject() = 0;
|
||||
|
||||
// Public virtual destructor to allow objects to be stored (and destroyed) as smart pointers.
|
||||
// E.g., std::unique_ptr<IProtectedCallback>.
|
||||
virtual ~IProtectedCallback() = default;
|
||||
|
||||
protected:
|
||||
// Protect the non-destructor special member functions to prevent object slicing.
|
||||
IProtectedCallback() = default;
|
||||
IProtectedCallback(const IProtectedCallback&) = default;
|
||||
IProtectedCallback(IProtectedCallback&&) noexcept = default;
|
||||
IProtectedCallback& operator=(const IProtectedCallback&) = default;
|
||||
IProtectedCallback& operator=(IProtectedCallback&&) noexcept = default;
|
||||
};
|
||||
|
||||
// Thread safe class
|
||||
class DeathMonitor final {
|
||||
public:
|
||||
static void serviceDied(void* cookie);
|
||||
void serviceDied();
|
||||
// Precondition: `killable` must be non-null.
|
||||
void add(hal::utils::IProtectedCallback* killable) const;
|
||||
void add(IProtectedCallback* killable) const;
|
||||
// Precondition: `killable` must be non-null.
|
||||
void remove(hal::utils::IProtectedCallback* killable) const;
|
||||
void remove(IProtectedCallback* killable) const;
|
||||
|
||||
private:
|
||||
mutable std::mutex mMutex;
|
||||
mutable std::vector<hal::utils::IProtectedCallback*> mObjects GUARDED_BY(mMutex);
|
||||
mutable std::vector<IProtectedCallback*> mObjects GUARDED_BY(mMutex);
|
||||
};
|
||||
|
||||
class DeathHandler final {
|
||||
|
@ -62,7 +81,7 @@ class DeathHandler final {
|
|||
using Cleanup = std::function<void()>;
|
||||
// Precondition: `killable` must be non-null.
|
||||
[[nodiscard]] ::android::base::ScopeGuard<Cleanup> protectCallback(
|
||||
hal::utils::IProtectedCallback* killable) const;
|
||||
IProtectedCallback* killable) const;
|
||||
|
||||
std::shared_ptr<DeathMonitor> getDeathMonitor() const { return kDeathMonitor; }
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include <android/binder_auto_utils.h>
|
||||
#include <android/binder_interface_utils.h>
|
||||
#include <nnapi/Result.h>
|
||||
#include <nnapi/hal/ProtectCallback.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
|
@ -37,7 +36,7 @@ namespace aidl::android::hardware::neuralnetworks::utils {
|
|||
void DeathMonitor::serviceDied() {
|
||||
std::lock_guard guard(mMutex);
|
||||
std::for_each(mObjects.begin(), mObjects.end(),
|
||||
[](hal::utils::IProtectedCallback* killable) { killable->notifyAsDeadObject(); });
|
||||
[](IProtectedCallback* killable) { killable->notifyAsDeadObject(); });
|
||||
}
|
||||
|
||||
void DeathMonitor::serviceDied(void* cookie) {
|
||||
|
@ -45,13 +44,13 @@ void DeathMonitor::serviceDied(void* cookie) {
|
|||
deathMonitor->serviceDied();
|
||||
}
|
||||
|
||||
void DeathMonitor::add(hal::utils::IProtectedCallback* killable) const {
|
||||
void DeathMonitor::add(IProtectedCallback* killable) const {
|
||||
CHECK(killable != nullptr);
|
||||
std::lock_guard guard(mMutex);
|
||||
mObjects.push_back(killable);
|
||||
}
|
||||
|
||||
void DeathMonitor::remove(hal::utils::IProtectedCallback* killable) const {
|
||||
void DeathMonitor::remove(IProtectedCallback* killable) const {
|
||||
CHECK(killable != nullptr);
|
||||
std::lock_guard guard(mMutex);
|
||||
const auto removedIter = std::remove(mObjects.begin(), mObjects.end(), killable);
|
||||
|
@ -102,7 +101,7 @@ DeathHandler::~DeathHandler() {
|
|||
}
|
||||
|
||||
[[nodiscard]] ::android::base::ScopeGuard<DeathHandler::Cleanup> DeathHandler::protectCallback(
|
||||
hal::utils::IProtectedCallback* killable) const {
|
||||
IProtectedCallback* killable) const {
|
||||
CHECK(killable != nullptr);
|
||||
kDeathMonitor->add(killable);
|
||||
return ::android::base::make_scope_guard(
|
||||
|
|
Loading…
Reference in a new issue