Steven Moreland | 0b1e62a | 2017-10-09 13:03:17 -0700 | [diff] [blame^] | 1 | /* |
| 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 | |
| 22 | using ::android::hidl::base::V1_0::IBase; |
| 23 | |
| 24 | namespace android { |
| 25 | namespace hardware { |
| 26 | namespace details { |
| 27 | |
| 28 | sp<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 | } |
| 38 | auto func = gBsConstructorMap.get(myDescriptor, nullptr); |
| 39 | if (!func) { |
| 40 | return nullptr; |
| 41 | } |
| 42 | |
| 43 | sp<IBase> base = func(static_cast<void*>(iface.get())); |
| 44 | |
| 45 | // To ensure this is an instance of IType, we would normally |
| 46 | // call castFrom, but gBsConstructorMap guarantees that its |
| 47 | // result is of the appropriate type (not necessaryly BsType, |
| 48 | // but definitely a child of IType). |
| 49 | return base; |
| 50 | } |
| 51 | |
| 52 | } // namespace details |
| 53 | } // namespace hardware |
| 54 | } // namespace android |