Martijn Coenen | 3079100 | 2016-12-01 15:40:46 +0100 | [diff] [blame] | 1 | /* |
| 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 | #define LOG_TAG "libhidlmemory" |
| 17 | |
| 18 | #include <hidlmemory/mapping.h> |
| 19 | |
| 20 | #include <android-base/logging.h> |
| 21 | #include <android/hidl/memory/1.0/IMapper.h> |
| 22 | #include <hidl/HidlSupport.h> |
| 23 | |
| 24 | using android::sp; |
| 25 | using android::hidl::memory::V1_0::IMemory; |
| 26 | |
| 27 | namespace android { |
| 28 | namespace hardware { |
| 29 | |
| 30 | sp<IMemory> mapMemory(const hidl_memory &memory) { |
| 31 | using android::hidl::memory::V1_0::IMapper; |
| 32 | |
| 33 | sp<IMapper> mapper = IMapper::getService(memory.name(), true /* getStub */); |
| 34 | |
| 35 | if (mapper == nullptr) { |
| 36 | LOG(FATAL) << "Could not fetch mapper for " << memory.name() << " shared memory"; |
| 37 | } |
| 38 | |
| 39 | if (mapper->isRemote()) { |
| 40 | LOG(FATAL) << "IMapper must be a passthrough service."; |
| 41 | } |
| 42 | |
Martijn Coenen | d272cb9 | 2017-01-02 15:20:38 +0100 | [diff] [blame] | 43 | Return<sp<IMemory>> ret = mapper->mapMemory(memory); |
Martijn Coenen | 3079100 | 2016-12-01 15:40:46 +0100 | [diff] [blame] | 44 | |
| 45 | if (!ret.isOk()) { |
| 46 | LOG(FATAL) << "hidl_memory map returned transport error."; |
| 47 | } |
| 48 | |
Martijn Coenen | d272cb9 | 2017-01-02 15:20:38 +0100 | [diff] [blame] | 49 | return ret; |
Martijn Coenen | 3079100 | 2016-12-01 15:40:46 +0100 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | } // namespace hardware |
Martijn Coenen | d272cb9 | 2017-01-02 15:20:38 +0100 | [diff] [blame] | 53 | } // namespace android |