1 /*
2  * Copyright (C) 2019 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 #include "SampleDriverUtils.h"
18 
19 #include <android-base/logging.h>
20 
21 #include "SampleDriver.h"
22 
23 namespace android {
24 namespace nn {
25 namespace sample_driver {
26 
notify(const sp<V1_0::IPreparedModelCallback> & callback,const V1_3::ErrorStatus & status,const sp<SamplePreparedModel> & preparedModel)27 void notify(const sp<V1_0::IPreparedModelCallback>& callback, const V1_3::ErrorStatus& status,
28             const sp<SamplePreparedModel>& preparedModel) {
29     const auto ret = callback->notify(convertToV1_0(status), preparedModel);
30     if (!ret.isOk()) {
31         LOG(ERROR) << "Error when calling IPreparedModelCallback::notify: " << ret.description();
32     }
33 }
34 
notify(const sp<V1_2::IPreparedModelCallback> & callback,const V1_3::ErrorStatus & status,const sp<SamplePreparedModel> & preparedModel)35 void notify(const sp<V1_2::IPreparedModelCallback>& callback, const V1_3::ErrorStatus& status,
36             const sp<SamplePreparedModel>& preparedModel) {
37     const auto ret = callback->notify_1_2(convertToV1_0(status), preparedModel);
38     if (!ret.isOk()) {
39         LOG(ERROR) << "Error when calling IPreparedModelCallback::notify_1_2: "
40                    << ret.description();
41     }
42 }
43 
notify(const sp<V1_3::IPreparedModelCallback> & callback,const V1_3::ErrorStatus & status,const sp<SamplePreparedModel> & preparedModel)44 void notify(const sp<V1_3::IPreparedModelCallback>& callback, const V1_3::ErrorStatus& status,
45             const sp<SamplePreparedModel>& preparedModel) {
46     const auto ret = callback->notify_1_3(status, preparedModel);
47     if (!ret.isOk()) {
48         LOG(ERROR) << "Error when calling IPreparedModelCallback::notify_1_3: "
49                    << ret.description();
50     }
51 }
52 
notify(const sp<V1_0::IExecutionCallback> & callback,const V1_3::ErrorStatus & status,const hardware::hidl_vec<V1_2::OutputShape> &,V1_2::Timing)53 void notify(const sp<V1_0::IExecutionCallback>& callback, const V1_3::ErrorStatus& status,
54             const hardware::hidl_vec<V1_2::OutputShape>&, V1_2::Timing) {
55     const auto ret = callback->notify(convertToV1_0(status));
56     if (!ret.isOk()) {
57         LOG(ERROR) << "Error when calling IExecutionCallback::notify: " << ret.description();
58     }
59 }
60 
notify(const sp<V1_2::IExecutionCallback> & callback,const V1_3::ErrorStatus & status,const hardware::hidl_vec<V1_2::OutputShape> & outputShapes,V1_2::Timing timing)61 void notify(const sp<V1_2::IExecutionCallback>& callback, const V1_3::ErrorStatus& status,
62             const hardware::hidl_vec<V1_2::OutputShape>& outputShapes, V1_2::Timing timing) {
63     const auto ret = callback->notify_1_2(convertToV1_0(status), outputShapes, timing);
64     if (!ret.isOk()) {
65         LOG(ERROR) << "Error when calling IExecutionCallback::notify_1_2: " << ret.description();
66     }
67 }
68 
notify(const sp<V1_3::IExecutionCallback> & callback,const V1_3::ErrorStatus & status,const hardware::hidl_vec<V1_2::OutputShape> & outputShapes,V1_2::Timing timing)69 void notify(const sp<V1_3::IExecutionCallback>& callback, const V1_3::ErrorStatus& status,
70             const hardware::hidl_vec<V1_2::OutputShape>& outputShapes, V1_2::Timing timing) {
71     const auto ret = callback->notify_1_3(status, outputShapes, timing);
72     if (!ret.isOk()) {
73         LOG(ERROR) << "Error when calling IExecutionCallback::notify_1_3" << ret.description();
74     }
75 }
76 
77 }  // namespace sample_driver
78 }  // namespace nn
79 }  // namespace android
80