blob: 3a7f6dc15b0bd9dbe8215af3dea96c4dee6f4900 [file] [log] [blame]
Yifan Hong6bf733e2016-12-07 14:42:02 -08001/*
2 * Copyright (C) 2016 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#include <hidl/HidlPassthroughSupport.h>
17
18#include <hidl/HidlSupport.h>
Yifan Hong6bf733e2016-12-07 14:42:02 -080019#include <hidl/HidlTransportUtils.h>
Yifan Hong953e6b02017-03-16 14:52:40 -070020#include <hidl/Static.h>
Yifan Hong6bf733e2016-12-07 14:42:02 -080021
22namespace android {
23namespace hardware {
Yifan Honge22d2cc2017-03-13 17:06:52 -070024namespace details {
Yifan Hong6bf733e2016-12-07 14:42:02 -080025
26sp<::android::hidl::base::V1_0::IBase> wrapPassthrough(
27 sp<::android::hidl::base::V1_0::IBase> iface) {
28 if (iface.get() == nullptr || iface->isRemote()) {
29 // doesn't know how to handle it.
30 return iface;
31 }
Yifan Honge22d2cc2017-03-13 17:06:52 -070032 std::string myDescriptor = getDescriptor(iface.get());
Yifan Hong6bf733e2016-12-07 14:42:02 -080033 if (myDescriptor.empty()) {
Yifan Hong2ac326f2017-02-22 18:13:06 -080034 // interfaceDescriptor fails
Yifan Hong6bf733e2016-12-07 14:42:02 -080035 return nullptr;
36 }
Yifan Hong84888d32017-02-06 15:32:41 -080037 auto func = gBsConstructorMap.get(myDescriptor, nullptr);
38 if (!func) {
Yifan Hong6bf733e2016-12-07 14:42:02 -080039 return nullptr;
40 }
Yifan Hong84888d32017-02-06 15:32:41 -080041 return func(reinterpret_cast<void *>(iface.get()));
Yifan Hong6bf733e2016-12-07 14:42:02 -080042}
43
Yifan Honge22d2cc2017-03-13 17:06:52 -070044} // namespace details
Yifan Hong6bf733e2016-12-07 14:42:02 -080045} // namespace hardware
46} // namespace android