blob: b79d21c6729351d2bdb550cb89237170c4770128 [file] [log] [blame]
Steven Moreland0b1e62a2017-10-09 13:03:17 -07001/*
2 * Copyright (C) 2017 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 <hidl/HidlPassthroughSupport.h>
18
19#include <hidl/HidlTransportUtils.h>
20#include <hidl/Static.h>
21
22using ::android::hidl::base::V1_0::IBase;
23
24namespace android {
25namespace hardware {
26namespace details {
27
28sp<IBase> wrapPassthroughInternal(sp<IBase> iface) {
29 if (iface == nullptr || iface->isRemote()) {
30 // doesn't know how to handle it.
31 return iface;
32 }
33 std::string myDescriptor = getDescriptor(iface.get());
34 if (myDescriptor.empty()) {
35 // interfaceDescriptor fails
36 return nullptr;
37 }
Yifan Hong97f88f32017-11-09 16:05:37 -080038 auto func = getBsConstructorMap().get(myDescriptor, nullptr);
Steven Moreland0b1e62a2017-10-09 13:03:17 -070039 if (!func) {
Yifan Hong97f88f32017-11-09 16:05:37 -080040 func = gBsConstructorMap.get(myDescriptor, nullptr);
41 if (!func) {
42 return nullptr;
43 }
Steven Moreland0b1e62a2017-10-09 13:03:17 -070044 }
45
46 sp<IBase> base = func(static_cast<void*>(iface.get()));
47
48 // To ensure this is an instance of IType, we would normally
49 // call castFrom, but gBsConstructorMap guarantees that its
50 // result is of the appropriate type (not necessaryly BsType,
51 // but definitely a child of IType).
52 return base;
53}
54
55} // namespace details
56} // namespace hardware
Yifan Hong97f88f32017-11-09 16:05:37 -080057} // namespace android